00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _SECSTWOMSG_H
00021 #define _SECSTWOMSG_H
00022
00023 #include <unistd.h>
00024 #include <string.h>
00025 #include <string>
00026 #include <vector>
00027 #include <functional>
00028 #include <ostream>
00029 #include <algorithm>
00030 #include "secstwo_shared_ptr.h"
00031
00036 #define NUM(x) ((uint32_t)x)
00037
00042 #define VAR_ARRAY_ELEMENT ((uint32_t)-1)
00043
00044 namespace freesecs
00045 {
00046 namespace secstwo
00047 {
00048 class data_item_t;
00049 class msg_t;
00050
00055 typedef enum
00056 {
00057 e_list_t =0x00,
00058 e_binary_t =0x08,
00059 e_boolean_t =0x09,
00060 e_ascii_t =0x10,
00061 e_jis8_t =0x11,
00062 e_wchar_t =0x12,
00063 e_int64_t =0x18,
00064 e_int8_t =0x19,
00065 e_int16_t =0x1a,
00066 e_int32_t =0x1c,
00067 e_double_t =0x20,
00068 e_float_t =0x24,
00069 e_uint64_t =0x28,
00070 e_uint8_t =0x29,
00071 e_uint16_t =0x2a,
00072 e_uint32_t =0x2c,
00073 e_none_t =0x2d
00074 }data_type_t;
00075
00079 typedef shared_ptr_t<data_item_t> pdata_item_t;
00080
00089 typedef enum {STRUCT,DATA,NON_EMPTY_DATA,ALL}match_t;
00090
00094 class data_item_t
00095 {
00096 public:
00101 data_item_t(const char *name);
00105 virtual ~data_item_t();
00106 public:
00114 virtual operator bool () const;
00122 virtual operator int8_t () const;
00130 virtual operator uint8_t () const;
00138 virtual operator int16_t () const;
00146 virtual operator uint16_t () const;
00154 virtual operator int32_t () const;
00162 virtual operator uint32_t () const;
00170 virtual operator int64_t () const;
00178 virtual operator uint64_t () const;
00186 virtual operator float () const;
00194 virtual operator double () const;
00202 virtual operator std::string () const;
00203
00214 virtual data_item_t& operator[](uint32_t ix);
00222 virtual data_item_t& operator[](const char *name);
00223
00224 public:
00230 virtual bool match(const data_item_t& it, match_t match=ALL)const;
00237 virtual bool operator == (const data_item_t&)const;
00244 virtual bool operator == (const bool&)const;
00251 virtual bool operator == (const int8_t&)const;
00258 virtual bool operator == (const uint8_t&)const;
00265 virtual bool operator == (const int16_t&)const;
00272 virtual bool operator == (const uint16_t&)const;
00279 virtual bool operator == (const int32_t&)const;
00286 virtual bool operator == (const uint32_t&)const;
00293 virtual bool operator == (const int64_t&)const;
00300 virtual bool operator == (const uint64_t&)const;
00307 virtual bool operator == (const float&)const;
00314 virtual bool operator == (const double&)const;
00321 virtual bool operator == (const std::string&)const;
00322 bool operator != (const data_item_t&)const;
00323 bool operator != (const bool&)const;
00324 bool operator != (const int8_t&)const;
00325 bool operator != (const uint8_t&)const;
00326 bool operator != (const int16_t&)const;
00327 bool operator != (const uint16_t&)const;
00328 bool operator != (const int32_t&)const;
00329 bool operator != (const uint32_t&)const;
00330 bool operator != (const int64_t&)const;
00331 bool operator != (const uint64_t&)const;
00332 bool operator != (const float&)const;
00333 bool operator != (const double&)const;
00334 bool operator != (const std::string&)const;
00335 public:
00343 virtual pdata_item_t clone() const =0;
00347 virtual void clear_data() =0;
00348
00349 public:
00358 virtual data_item_t& operator = (const bool&);
00367 virtual data_item_t& operator = (const uint8_t&);
00376 virtual data_item_t& operator = (const int8_t&);
00385 virtual data_item_t& operator = (const uint16_t&);
00394 virtual data_item_t& operator = (const int16_t&);
00403 virtual data_item_t& operator = (const uint32_t&);
00412 virtual data_item_t& operator = (const int32_t&);
00421 virtual data_item_t& operator = (const uint64_t&);
00430 virtual data_item_t& operator = (const int64_t&);
00439 virtual data_item_t& operator = (const float&);
00448 virtual data_item_t& operator = (const double&);
00457 virtual data_item_t& operator = (const char*);
00466 virtual data_item_t& operator = (const std::string&);
00467
00468 virtual data_item_t& operator += (const pdata_item_t&);
00469 virtual data_item_t& operator += (const bool&);
00470 virtual data_item_t& operator += (const uint8_t&);
00471 virtual data_item_t& operator += (const int8_t&);
00472 virtual data_item_t& operator += (const uint16_t&);
00473 virtual data_item_t& operator += (const int16_t&);
00474 virtual data_item_t& operator += (const uint32_t&);
00475 virtual data_item_t& operator += (const int32_t&);
00476 virtual data_item_t& operator += (const uint64_t&);
00477 virtual data_item_t& operator += (const int64_t&);
00478 virtual data_item_t& operator += (const float&);
00479 virtual data_item_t& operator += (const double&);
00480 virtual data_item_t& operator += (const char*);
00481 virtual data_item_t& operator += (const std::string&);
00482
00483 public:
00487 virtual size_t size()const;
00491 virtual data_type_t type()const;
00495 const char * name()const;
00499 virtual void print(std::ostream&, const char *prefix = NULL)const = 0;
00503 virtual size_t raw_size() const = 0;
00504 public:
00514 virtual int copy_data(const data_item_t&);
00515 private:
00519 std::string _name;
00520
00521 private:
00525 data_item_t();
00526 };
00527
00531 std::ostream & operator << (std::ostream &os, pdata_item_t it);
00532
00536 typedef shared_ptr_t<msg_t> pmsg_t;
00540 class msg_t
00541 {
00542 public:
00546 const std::string name;
00550 const unsigned short stream;
00554 const unsigned short function;
00558 unsigned char wbit;
00562 unsigned int sysbytes;
00563
00564 public:
00573 data_item_t& operator[](uint32_t ix);
00583 data_item_t& operator[](const char *name);
00589 void print(std::ostream& os, const char *prefix = NULL)const;
00590
00591
00592 public:
00597 bool operator == (const msg_t&)const;
00598 bool operator != (const msg_t&)const;
00605 bool match(const msg_t& m, match_t match=ALL)const;
00613 int copy_data(const msg_t&);
00614 public:
00619 msg_t& operator = (const msg_t&);
00631 pmsg_t clone() const;
00635 void clear_data();
00636 protected:
00640 pdata_item_t _pitem;
00641
00642 protected:
00646 msg_t(const char *n,
00647 unsigned short s,
00648 unsigned short f);
00649
00650 friend class binary_deserializer_t;
00651 friend class binary_serializer_t;
00652 friend class xml_deserializer_t;
00653 friend class xml_serializer_t;
00654 };
00655
00656
00657 std::ostream & operator << (std::ostream &os, pmsg_t pmsg);
00658 };
00659 };
00660
00661 #endif