Update build system, documentation and delete temp files
[wave300.git] / tools / rtlogger / logcnv / LogInfo.h
blob8a3bb9c0eec853923a60bdce95be1c4753f227d9
1 /******************************************************************************
3 Copyright (c) 2012
4 Lantiq Deutschland GmbH
6 For licensing information, see the file 'LICENSE' in the root folder of
7 this software module.
9 ******************************************************************************/
10 #ifndef __LOG_INFO_H__
11 #define __LOG_INFO_H__
13 #include <string>
14 #include <istream>
15 #include <sstream>
16 #include <iomanip>
18 #include "logdefs.h"
20 using namespace std;
22 #include "aux_utils.h"
23 #include "logsrv_protocol.h"
25 class CLogInfo
27 friend istream &operator>> (istream &is, CLogInfo &info);
29 class exc_bad_info_magic : public exc_basic
31 public:
32 exc_bad_info_magic (uint32 magic) {
33 ostringstream ss;
34 ss << "Incorrect Log Info magic:" << hex << showbase << setfill('0') << setw(8) << magic ;
35 m_str = ss.str();
38 class exc_bad_info_size : public exc_basic
40 public:
41 exc_bad_info_size (uint32 size) {
42 ostringstream ss;
43 ss << "Incorrect Log Info size:" << hex << showbase << setfill('0') << setw(8) << size ;
44 m_str = ss.str();
47 class exc_bad_info_ver_major : public exc_basic
49 public:
50 exc_bad_info_ver_major (uint16 major, uint16 supported) {
51 ostringstream ss;
52 ss << "Incorrect Log Info major: " << major << " (required: " << supported <<")";
53 m_str = ss.str();
57 public:
58 CLogInfo(void)
60 memset(&m_info, 0, sizeof(m_info));
63 ~CLogInfo()
64 { }
66 protected:
67 void Read (istream &in_s) {
68 try {
69 in_s.read((char *)&m_info, sizeof(m_info));
71 catch (const ios_base::failure &/*ex*/) {
72 if (in_s.eof()) {
73 /* EOF is not an error in our case */
74 return;
76 /* Other stream error */
77 throw; /* throw this exception up */
80 m_info.magic = ntohl(m_info.magic);
81 if (m_info.magic != LOGSRV_INFO_MAGIC) {
82 throw exc_bad_info_magic(m_info.magic);
85 m_info.size = ntohl(m_info.size);
86 if (m_info.size != sizeof(m_info)) {
87 throw exc_bad_info_size(m_info.size);
90 m_info.log_ver_major = ntohs(m_info.log_ver_major);
91 if (m_info.log_ver_major != RTLOGGER_VER_MAJOR) {
92 throw exc_bad_info_ver_major(m_info.log_ver_major, RTLOGGER_VER_MAJOR);
95 m_info.log_ver_minor = ntohs(m_info.log_ver_minor);
98 struct logsrv_info m_info;
101 istream &operator>> (istream &is, CLogInfo &info)
103 info.Read(is);
104 return is;
107 #endif /* __LOG_INFO_H__ */