00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __SERDES_H__
00032 #define __SERDES_H__
00033
00034 #include "dynutil/h/util.h"
00035 #include "dynutil/h/Annotatable.h"
00036 #include "dynutil/h/Serialization.h"
00037
00038 #if !defined(SERIALIZATION_DISABLED)
00039
00040 #if defined(cap_have_libxml)
00041
00042 #undef cap_have_libxml
00043 #endif
00044
00045 #include "common/h/headers.h"
00046
00047 #include <string>
00048 #include <vector>
00049 #include <map>
00050 #include <stdexcept>
00051 #include <stdio.h>
00052
00053 #if defined(os_windows)
00054 #if defined (cap_have_libxml)
00055 #include <libxml/xmlversion.h>
00056 #undef LIBXML_ICONV_ENABLED
00057 #endif
00058 #endif
00059
00060 #if defined (cap_have_libxml)
00061 #include <libxml/xmlwriter.h>
00062 #endif
00063
00064 #include "common/h/Types.h"
00065 #include "common/h/sha1.h"
00066 #include "common/h/pathName.h"
00067
00068
00069 #define SERIALIZE_ENABLE_FLAG (short) 1
00070 #define DESERIALIZE_ENABLE_FLAG (short) 2
00071 #define DESERIALIZE_ENFORCE_FLAG (short) 4
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 #define SER_ERR(cmsg) \
00082 do { \
00083 if (serializer_debug_flag()) { \
00084 serialize_printf("SER_ERR: %s", cmsg); \
00085 throw SerializerError(__FILE__, __LINE__, std::string(cmsg)); \
00086 } else { \
00087 throw SerializerError(__FILE__, __LINE__, std::string(cmsg)); \
00088 } \
00089 } while (0)
00090
00091 namespace Dyninst {
00092
00093 #define CACHE_DIR_VAR "DYNINST_CACHE_DIR"
00094 #define DEFAULT_DYNINST_DIR ".dyninstAPI"
00095 #define DEFAULT_CACHE_DIR "caches"
00096 #define CACHE_MAGIC 0x555
00097 #define CACHE_PREFIX "cache_"
00098
00099 #ifndef PATH_MAX
00100 #define PATH_MAX 512
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109 #define SER_CATCH(x) catch (const SerializerError &err) { \
00110 fprintf(stderr, "%s[%d]: %s from %s[%d]\n", FILE__, __LINE__, \
00111 err.what(), err.file().c_str(), err.line()); \
00112 SER_ERR(x); }
00113
00114 void COMMON_EXPORT serialize_debug_init();
00115
00116 class SerDes;
00117 class SerFile;
00118
00119 #if 0
00120 class SerializerBase {
00121 friend class Serializable;
00122
00123 public:
00124 static std::vector<SerializerBase *> active_serializers;
00125
00126 COMMON_EXPORT static dyn_hash_map<std::string, SerializerBase *> active_bin_serializers;
00127 static bool global_disable;
00128 private:
00129
00130 SerFile *sf;
00131 SerDes *sd;
00132 SerContextBase *scon;
00133 unsigned short ser_index;
00134
00135 std::string serializer_name;
00136
00137 typedef dyn_hash_map<std::string, SerializerBase *> subsystem_serializers_t;
00138 COMMON_EXPORT static dyn_hash_map<std::string, subsystem_serializers_t> all_serializers;
00139
00140 dyn_hash_map<void *, AnnotatableSparse *> *sparse_annotatable_map;
00141 dyn_hash_map<void *, AnnotatableDense *> *dense_annotatable_map;
00142 public:
00143 COMMON_EXPORT void set_annotatable_sparse_map(AnnotatableSparse *, void *);
00144 COMMON_EXPORT void set_annotatable_dense_map(AnnotatableDense *, void *);
00145 COMMON_EXPORT unsigned short getIndex();
00146 COMMON_EXPORT static void globalDisable();
00147 COMMON_EXPORT static bool serializationDisabled();
00148 COMMON_EXPORT static void globalEnable();
00149
00150 COMMON_EXPORT virtual bool isXML() = 0;
00151 COMMON_EXPORT virtual bool isBin ()= 0;
00152 COMMON_EXPORT bool isEOF();
00153
00154 COMMON_EXPORT SerContextBase *getContext();
00155 COMMON_EXPORT bool isInput ();
00156 COMMON_EXPORT bool isOutput ();
00157 COMMON_EXPORT AnnotatableSparse *findSparseAnnotatable(void *id);
00158 COMMON_EXPORT AnnotatableDense *findDenseAnnotatable(void *id);
00159
00160 COMMON_EXPORT static void dumpActiveBinSerializers();
00161
00162 COMMON_EXPORT SerializerBase(SerContextBase *scb, std::string name_, std::string filename,
00163 iomode_t dir, bool verbose);
00164
00165 COMMON_EXPORT SerializerBase();
00166
00167 COMMON_EXPORT virtual ~SerializerBase();
00168
00169 COMMON_EXPORT virtual SerDes &getSD() { assert(sd); return *sd;}
00170 COMMON_EXPORT SerFile &getSF() {assert(sf); return *sf;}
00171 COMMON_EXPORT std::string &name() {return serializer_name;}
00172 COMMON_EXPORT static SerializerBase *getSerializer(std::string subsystem, std::string fname);
00173 COMMON_EXPORT static bool addSerializer(std::string subsystem, std::string fname, SerializerBase *sb);
00174
00175 COMMON_EXPORT virtual void vector_start(unsigned int &, const char * = NULL);
00176 COMMON_EXPORT virtual void vector_end();
00177 COMMON_EXPORT virtual void hash_map_start(unsigned int &size, const char *tag = NULL);
00178 COMMON_EXPORT virtual void hash_map_end();
00179 COMMON_EXPORT virtual void annotation_start(AnnotationClassID &a_id, void *&lparent_id, sparse_or_dense_anno_t &lsod, const char *);
00180 COMMON_EXPORT virtual void annotation_end();
00181 COMMON_EXPORT virtual void annotation_container_start(void *&id);
00182 COMMON_EXPORT virtual void annotation_container_end();
00183 COMMON_EXPORT virtual void annotation_container_item_start(void *&id);
00184 COMMON_EXPORT virtual void annotation_container_item_end();
00185 COMMON_EXPORT void translate_base(bool &v, const char *&t);
00186 COMMON_EXPORT void translate_base(short &v, const char *&t);
00187 COMMON_EXPORT void translate_base(unsigned short &v, const char *&t);
00188 COMMON_EXPORT void translate_base(char &v, const char *&t);
00189 COMMON_EXPORT void translate_base(int &v, const char *&t);
00190 COMMON_EXPORT void translate_base(unsigned int &v, const char *&t);
00191 COMMON_EXPORT void translate_base(unsigned long &v, const char *&t);
00192 COMMON_EXPORT void translate_base(long &v, const char *&t);
00193 COMMON_EXPORT void translate_base(float &v, const char *&t);
00194 COMMON_EXPORT void translate_base(double &v, const char *&t);
00195 COMMON_EXPORT void translate_base(const char * &v, int bufsize, const char *&t);
00196 COMMON_EXPORT void translate_base(char * &v, int bufsize, const char *&t);
00197 COMMON_EXPORT void translate_base(void * &v, const char *&t);
00198 COMMON_EXPORT void translate_base(std::string &v, const char *t);
00199
00200 COMMON_EXPORT virtual iomode_t iomode();
00201
00202 COMMON_EXPORT void serialize_annotations(void *, std::vector<ser_rec_t> &sers, const char * = NULL);
00203 COMMON_EXPORT bool serialize_post_annotation(void *parent_id, void *anno, AnnotationClassBase *acb, sparse_or_dense_anno_t , const char * = NULL);
00204 };
00205 #endif
00206
00207 class SerDesXML;
00208
00209 class SerializerXML : public SerializerBase
00210 {
00211 public:
00212 COMMON_EXPORT virtual bool isXML() {return true;}
00213 COMMON_EXPORT virtual bool isBin () {return false;}
00214
00215 COMMON_EXPORT SerializerXML(SerContextBase *sc, std::string name_, std::string filename,
00216 iomode_t dir, bool verbose) :
00217 SerializerBase(sc, name_, filename, dir, verbose) {}
00218
00219 COMMON_EXPORT virtual ~SerializerXML() {}
00220
00221 COMMON_EXPORT SerDesXML &getSD_xml();
00222
00223 COMMON_EXPORT static bool start_xml_element(SerializerBase *sb, const char *tag);
00224 COMMON_EXPORT static bool end_xml_element(SerializerBase *sb, const char *);
00225 };
00226
00227 class SerDesBin;
00228
00229 class SerializerBin : public SerializerBase {
00230 friend class SerDesBin;
00231
00232 public:
00233 COMMON_EXPORT virtual bool isXML() {return false;}
00234 COMMON_EXPORT virtual bool isBin () {return true;}
00235
00236 COMMON_EXPORT SerializerBin() :
00237 SerializerBase() {}
00238
00239
00240 COMMON_EXPORT SerializerBin(SerContextBase *s, std::string name_, std::string filename,
00241 iomode_t dir, bool verbose);
00242
00243 COMMON_EXPORT virtual ~SerializerBin();
00244
00245 COMMON_EXPORT SerDesBin &getSD_bin();
00246
00247 #if 0
00248 static SerializerBin *findSerializerByName(const char *name_);
00249 #endif
00250
00251 };
00252
00253
00254 #if 0
00255 class SerializerBase {
00256
00257 public:
00258
00259 COMMON_EXPORT static dyn_hash_map<std::string, SerializerBase *> active_bin_serializers;
00260 static bool global_disable;
00261 private:
00262
00263 SerFile *sf;
00264 SerDes *sd;
00265 SerContextBase *scon;
00266
00267 std::string serializer_name;
00268
00269 typedef dyn_hash_map<std::string, SerializerBase *> subsystem_serializers_t;
00270 COMMON_EXPORT static dyn_hash_map<std::string, subsystem_serializers_t> all_serializers;
00271
00272 public:
00273 COMMON_EXPORT static void globalDisable()
00274 {
00275 global_disable = true;
00276 }
00277 COMMON_EXPORT static bool serializationDisabled()
00278 {
00279 return global_disable;
00280 }
00281
00282 COMMON_EXPORT static void globalEnable()
00283 {
00284 global_disable = false;
00285 }
00286
00287 COMMON_EXPORT SerContextBase *getContext() {return scon;}
00288 COMMON_EXPORT virtual bool isXML() = 0;
00289 COMMON_EXPORT virtual bool isBin ()= 0;
00290 COMMON_EXPORT bool isInput () {return iomode() == sd_deserialize;}
00291 COMMON_EXPORT bool isOutput () {return iomode() == sd_serialize;}
00292
00293 COMMON_EXPORT static void dumpActiveBinSerializers();
00294
00295 COMMON_EXPORT SerializerBase(SerContextBase *scb, const char *name_, std::string filename,
00296 iomode_t dir, bool verbose);
00297
00298 COMMON_EXPORT SerializerBase();
00299
00300 COMMON_EXPORT virtual ~SerializerBase()
00301 {
00302 serialize_printf("%s[%d]: serializer %p-%sdtor\n", FILE__, __LINE__,
00303 this, serializer_name.c_str());
00304 }
00305
00306 COMMON_EXPORT virtual SerDes &getSD() { assert(sd); return *sd;}
00307 COMMON_EXPORT SerFile &getSF() {assert(sf); return *sf;}
00308 COMMON_EXPORT std::string &name() {return serializer_name;}
00309 COMMON_EXPORT static SerializerBase *getSerializer(std::string subsystem, std::string fname);
00310 COMMON_EXPORT static bool addSerializer(std::string subsystem, std::string fname, SerializerBase *sb);
00311
00312 COMMON_EXPORT virtual void vector_start(unsigned int &, const char * = NULL);
00313 COMMON_EXPORT virtual void vector_end();
00314 COMMON_EXPORT virtual void hash_map_start(unsigned int &size, const char *tag = NULL);
00315 COMMON_EXPORT virtual void hash_map_end();
00316 COMMON_EXPORT void translate_base(bool &v, const char *&t);
00317 COMMON_EXPORT void translate_base(short &v, const char *&t);
00318 COMMON_EXPORT void translate_base(char &v, const char *&t);
00319 COMMON_EXPORT void translate_base(int &v, const char *&t);
00320 COMMON_EXPORT void translate_base(unsigned int &v, const char *&t);
00321 COMMON_EXPORT void translate_base(unsigned long &v, const char *&t);
00322 COMMON_EXPORT void translate_base(long &v, const char *&t);
00323 COMMON_EXPORT void translate_base(float &v, const char *&t);
00324 COMMON_EXPORT void translate_base(double &v, const char *&t);
00325 COMMON_EXPORT void translate_base(const char * &v, int bufsize, const char *&t);
00326 COMMON_EXPORT void translate_base(char * &v, int bufsize, const char *&t);
00327 COMMON_EXPORT void translate_base(void * &v, const char *&t);
00328 COMMON_EXPORT void translate_base(std::string &v, const char *t);
00329
00330 COMMON_EXPORT virtual iomode_t iomode();
00331
00332 protected:
00333
00334
00335 };
00336 #endif
00337
00338 class SerDes {
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 public:
00353
00354 #if 0
00355 COMMON_EXPORT static dyn_hash_map<std::string, AnnoFunc > anno_funcs;
00356
00357
00358
00359
00360
00361
00362 dyn_hash_map<unsigned, std::string> old_anno_name_to_id_map;
00363 #endif
00364
00365 protected:
00366
00367 iomode_t iomode_;
00368
00369 public:
00370
00371 #if 0
00372 COMMON_EXPORT AnnoFunc *findAnnoFunc(unsigned anno_type,
00373 std::string anno_name = AnnotatableBase::emptyString);
00374
00375 COMMON_EXPORT static bool addAnnoFunc(std::string type_name, AnnoFunc sf);
00376 #endif
00377
00378 COMMON_EXPORT SerDes() {assert(0);}
00379 COMMON_EXPORT SerDes(iomode_t mode) : iomode_(mode){}
00380 COMMON_EXPORT virtual ~SerDes() {}
00381
00382 COMMON_EXPORT virtual void file_start(std::string &) {}
00383 COMMON_EXPORT virtual void vector_start(unsigned long &size,
00384 const char *tag = NULL) DECLTHROW(SerializerError) = 0;
00385 COMMON_EXPORT virtual void vector_end() = 0;
00386 COMMON_EXPORT virtual void multimap_start(unsigned long &size,
00387 const char *tag = NULL) DECLTHROW(SerializerError) = 0;
00388 COMMON_EXPORT virtual void multimap_end() = 0;
00389 COMMON_EXPORT virtual void pair_start(
00390 const char *tag = NULL) DECLTHROW(SerializerError) = 0;
00391 COMMON_EXPORT virtual void pair_end() = 0;
00392 COMMON_EXPORT virtual void hash_map_start(unsigned long &size,
00393 const char *tag = NULL) DECLTHROW(SerializerError) = 0;
00394 COMMON_EXPORT virtual void hash_map_end() = 0;
00395 COMMON_EXPORT virtual void annotation_start(Dyninst::AnnotationClassID &a_id, void *&parent_id, sparse_or_dense_anno_t &, const char *string_id,
00396 const char *tag = "Annotation") = 0;
00397 COMMON_EXPORT virtual void annotation_end() = 0;
00398
00399 COMMON_EXPORT virtual void annotation_container_start(void *&id) = 0;
00400 COMMON_EXPORT virtual void annotation_container_end() = 0;
00401 COMMON_EXPORT virtual void annotation_container_item_start(void *&id) = 0;
00402 COMMON_EXPORT virtual void annotation_container_item_end() = 0;
00403 COMMON_EXPORT virtual void annotation_list_start(Address &id, unsigned long &nelem,
00404 const char *tag = "AnnotationList") = 0;
00405 COMMON_EXPORT virtual void annotation_list_end() = 0;
00406
00407 COMMON_EXPORT virtual void translate(bool ¶m, const char *tag = NULL) = 0;
00408 COMMON_EXPORT virtual void translate(char ¶m, const char *tag = NULL) = 0;
00409 COMMON_EXPORT virtual void translate(int ¶m, const char *tag = NULL) = 0;
00410 COMMON_EXPORT virtual void translate(long ¶m, const char *tag = NULL) = 0;
00411
00412 COMMON_EXPORT virtual void translate(short ¶m, const char *tag = NULL) = 0;
00413 COMMON_EXPORT virtual void translate(unsigned short ¶m, const char *tag = NULL) = 0;
00414 COMMON_EXPORT virtual void translate(unsigned int ¶m, const char *tag = NULL) = 0;
00415 COMMON_EXPORT virtual void translate(float ¶m, const char *tag = NULL) = 0;
00416 COMMON_EXPORT virtual void translate(double ¶m, const char *tag = NULL) = 0;
00417 COMMON_EXPORT virtual void translate(Address ¶m, const char *tag = NULL) = 0;
00418 COMMON_EXPORT virtual void translate(void * ¶m, const char *tag = NULL) = 0;
00419 COMMON_EXPORT virtual void translate(const char * ¶m, int bufsize = 0,
00420 const char *tag = NULL) = 0;
00421 COMMON_EXPORT virtual void translate(char * ¶m, int bufsize = 0,
00422 const char *tag = NULL) = 0;
00423 COMMON_EXPORT virtual void translate(std::string ¶m, const char *tag = NULL) = 0;
00424 COMMON_EXPORT virtual void translate(std::vector<std::string> ¶m, const char *tag = NULL,
00425 const char *elem_tag = NULL) = 0;
00426 COMMON_EXPORT virtual void magic_check(const char *file__, unsigned int line__) = 0;
00427
00428 COMMON_EXPORT virtual iomode_t iomode() {return iomode_;}
00429 COMMON_EXPORT virtual bool isEOF() {return false;}
00430 };
00431
00432 class SerDesXML : public SerDes {
00433 friend class SerFile;
00434 friend class SerializerXML;
00435 friend bool COMMON_EXPORT ifxml_start_element(SerializerBase *, const char *);
00436 friend bool COMMON_EXPORT ifxml_end_element(SerializerBase *, const char *);
00437 friend bool COMMON_EXPORT start_xml_elem(SerDesXML &, const char *);
00438 friend bool COMMON_EXPORT end_xml_elem(SerDesXML &);
00439
00440
00441
00442 #if defined (cap_have_libxml)
00443 xmlTextWriterPtr writer;
00444 COMMON_EXPORT SerDesXML(xmlTextWriterPtr w, iomode_t mode) : SerDes(mode), writer(w) { }
00445 COMMON_EXPORT static xmlTextWriterPtr init(std::string fname, iomode_t mode, bool verbose);
00446 #else
00447 void *writer;
00448 COMMON_EXPORT SerDesXML(void * w, iomode_t mode) : SerDes(mode), writer(w) { }
00449 #endif
00450
00451 public:
00452 COMMON_EXPORT SerDesXML() { assert(0);}
00453 COMMON_EXPORT virtual ~SerDesXML();
00454
00455 COMMON_EXPORT virtual void vector_start(unsigned long &size,
00456 const char *tag = NULL) DECLTHROW(SerializerError);
00457 COMMON_EXPORT virtual void vector_end();
00458 COMMON_EXPORT virtual void multimap_start(unsigned long &size,
00459 const char *tag = NULL) DECLTHROW(SerializerError);
00460 COMMON_EXPORT virtual void multimap_end();
00461 COMMON_EXPORT virtual void pair_start(
00462 const char *tag = NULL) DECLTHROW(SerializerError);
00463 COMMON_EXPORT virtual void pair_end();
00464 COMMON_EXPORT virtual void hash_map_start(unsigned long &size,
00465 const char *tag = NULL) DECLTHROW(SerializerError);
00466 COMMON_EXPORT virtual void hash_map_end();
00467 COMMON_EXPORT virtual void annotation_start(Dyninst::AnnotationClassID &a_id, void *&, sparse_or_dense_anno_t &, const char *string_id, const char *tag = NULL);
00468 COMMON_EXPORT virtual void annotation_end();
00469 COMMON_EXPORT virtual void annotation_container_start(void *&id);
00470 COMMON_EXPORT virtual void annotation_container_end();
00471 COMMON_EXPORT virtual void annotation_container_item_start(void *&id);
00472 COMMON_EXPORT virtual void annotation_container_item_end();
00473 COMMON_EXPORT virtual void annotation_list_start(Address &id, unsigned long &nelem,
00474 const char *tag = "AnnotationList");
00475 COMMON_EXPORT virtual void annotation_list_end();
00476 COMMON_EXPORT virtual void translate(bool ¶m, const char *tag = NULL);
00477 COMMON_EXPORT virtual void translate(char ¶m, const char *tag = NULL);
00478 COMMON_EXPORT virtual void translate(int ¶m, const char *tag = NULL);
00479 COMMON_EXPORT virtual void translate(long ¶m, const char *tag = NULL);
00480 COMMON_EXPORT virtual void translate(short ¶m, const char *tag = NULL);
00481 COMMON_EXPORT virtual void translate(unsigned short ¶m, const char *tag = NULL);
00482 COMMON_EXPORT virtual void translate(unsigned int ¶m, const char *tag = NULL);
00483 COMMON_EXPORT virtual void translate(float ¶m, const char *tag = NULL);
00484 COMMON_EXPORT virtual void translate(double ¶m, const char *tag = NULL);
00485 COMMON_EXPORT virtual void translate(Address ¶m, const char *tag = NULL);
00486 COMMON_EXPORT virtual void translate(void * ¶m, const char *tag = NULL);
00487 COMMON_EXPORT virtual void translate(const char * ¶m, int bufsize = 0,
00488 const char *tag = NULL);
00489 COMMON_EXPORT virtual void translate(char * ¶m, int bufsize = 0, const char *tag = NULL);
00490 COMMON_EXPORT virtual void translate(std::string ¶m, const char *tag = NULL);
00491 COMMON_EXPORT virtual void translate(std::vector<std::string> ¶m, const char *tag = NULL,
00492 const char *elem_tag = NULL);
00493 COMMON_EXPORT virtual void magic_check(const char *, unsigned int ) {}
00494
00495 #if 0
00496 COMMON_EXPORT void start_element(const char *tag);
00497 COMMON_EXPORT void end_element();
00498 COMMON_EXPORT void xml_value(const char *val, const char *tag);
00499 #endif
00500 };
00501
00502
00503
00504 class SerDesBin : public SerDes {
00505
00506 typedef struct {
00507 unsigned int cache_magic;
00508 unsigned int source_file_size;
00509 char sha1[SHA1_DIGEST_LEN*2];
00510 } cache_header_t;
00511
00512 FILE *f;
00513
00514 bool noisy;
00515
00516 public:
00517
00518
00519 COMMON_EXPORT static FILE *init(std::string fname, iomode_t mode, bool verbose);
00520
00521 COMMON_EXPORT SerDesBin() {assert(0);}
00522
00523 COMMON_EXPORT SerDesBin(FILE *ff, iomode_t mode, bool verbose = false) :
00524 SerDes(mode),
00525 f(ff),
00526 noisy(verbose) {}
00527
00528 COMMON_EXPORT virtual ~SerDesBin();
00529
00530 COMMON_EXPORT bool isEOF();
00531
00532
00533 COMMON_EXPORT virtual void file_start(std::string &full_file_path);
00534 COMMON_EXPORT virtual void vector_start(unsigned long &size,
00535 const char *tag = NULL) DECLTHROW(SerializerError);
00536 COMMON_EXPORT virtual void vector_end();
00537 COMMON_EXPORT virtual void multimap_start(unsigned long &size,
00538 const char *tag = NULL) DECLTHROW(SerializerError);
00539 COMMON_EXPORT virtual void multimap_end();
00540 COMMON_EXPORT virtual void pair_start(
00541 const char *tag = NULL) DECLTHROW(SerializerError);
00542 COMMON_EXPORT virtual void pair_end();
00543 COMMON_EXPORT virtual void hash_map_start(unsigned long &size,
00544 const char *tag = NULL) DECLTHROW(SerializerError);
00545 COMMON_EXPORT virtual void hash_map_end();
00546 COMMON_EXPORT virtual void annotation_start(Dyninst::AnnotationClassID &a_id, void *&, sparse_or_dense_anno_t &, const char *string_id, const char *tag = NULL);
00547 COMMON_EXPORT virtual void annotation_end();
00548 COMMON_EXPORT virtual void annotation_container_start(void *&id);
00549 COMMON_EXPORT virtual void annotation_container_end();
00550 COMMON_EXPORT virtual void annotation_container_item_start(void *&id);
00551 COMMON_EXPORT virtual void annotation_container_item_end();
00552 COMMON_EXPORT virtual void annotation_list_start(Address &id, unsigned long &nelem,
00553 const char *tag = "AnnotationList");
00554 COMMON_EXPORT virtual void annotation_list_end();
00555 COMMON_EXPORT virtual void translate(bool ¶m, const char *tag = NULL);
00556 COMMON_EXPORT virtual void translate(char ¶m, const char *tag = NULL);
00557 COMMON_EXPORT virtual void translate(int ¶m, const char *tag = NULL);
00558 COMMON_EXPORT virtual void translate(long ¶m, const char *tag = NULL);
00559 COMMON_EXPORT virtual void translate(short ¶m, const char *tag = NULL);
00560 COMMON_EXPORT virtual void translate(unsigned short ¶m, const char *tag = NULL);
00561 COMMON_EXPORT virtual void translate(unsigned int ¶m, const char *tag = NULL);
00562 COMMON_EXPORT virtual void translate(float ¶m, const char *tag = NULL);
00563 COMMON_EXPORT virtual void translate(double ¶m, const char *tag = NULL);
00564 COMMON_EXPORT virtual void translate(Address ¶m, const char *tag = NULL);
00565 COMMON_EXPORT virtual void translate(void * ¶m, const char *tag = NULL);
00566 COMMON_EXPORT virtual void translate(const char * ¶m,
00567 int bufsize = 0, const char *tag = NULL);
00568 COMMON_EXPORT virtual void translate(char * ¶m, int bufsize = 0, const char *tag = NULL);
00569 COMMON_EXPORT virtual void translate(std::string ¶m, const char *tag = NULL);
00570 COMMON_EXPORT virtual void translate(std::vector<std::string> ¶m, const char *tag = NULL,
00571 const char *elem_tag = NULL);
00572 COMMON_EXPORT virtual void magic_check(const char *file__, unsigned int line__);
00573
00574
00575
00576
00577
00578 COMMON_EXPORT static void readHeaderAndVerify(std::string full_file_path,
00579 std::string cache_name, FILE *f = NULL);
00580
00581 COMMON_EXPORT static void writeHeaderPreamble(FILE *f, std::string full_file_path,
00582 std::string cache_name);
00583
00584 COMMON_EXPORT static bool getDefaultCacheDir(std::string &cache_dir);
00585 COMMON_EXPORT static bool resolveCachePath(std::string fname, std::string &cache_name);
00586 COMMON_EXPORT static bool verifyChecksum(std::string &filename,
00587 const char comp_checksum[SHA1_DIGEST_LEN]);
00588 COMMON_EXPORT static bool cacheFileExists(std::string fname);
00589 COMMON_EXPORT static bool invalidateCache(std::string cache_name);
00590
00591 };
00592
00593 bool start_xml_elem(void *writer, const char *tag);
00594 bool end_xml_elem(void *);
00595
00596 class SerFile {
00597
00598 SerDes *sd;
00599 #if defined (cap_have_libxml)
00600 xmlTextWriterPtr writer;
00601 #else
00602 void * writer;
00603 #endif
00604 FILE *f;
00605
00606 public:
00607
00608 COMMON_EXPORT SerDes *getSD();
00609 COMMON_EXPORT SerFile(std::string fname, iomode_t mode, bool verbose = false);
00610 COMMON_EXPORT iomode_t iomode();
00611
00612 static bool validCacheExistsFor(std::string full_file_path);
00613
00614 protected:
00615
00616 std::string filename;
00617 iomode_t iomode_;
00618
00619 public:
00620
00621 bool noisy;
00622 std::string getFileName() {return filename;}
00623 std::string getCacheFileName();
00624
00625 };
00626
00627 template <class S, class T>
00628 class SpecAdaptor {
00629
00630 public:
00631
00632 COMMON_EXPORT SpecAdaptor() {}
00633
00634 COMMON_EXPORT T *operator()(S *s, T &t, const char *tag)
00635 {
00636 s->translate_base(t, tag);
00637 return &t;
00638 }
00639 };
00640
00641 template <class S, class T>
00642 class SpecAdaptor<S, T *> {
00643
00644 public:
00645
00646 COMMON_EXPORT SpecAdaptor() {}
00647
00648 COMMON_EXPORT T* operator()(S *s, T *t, const char *tag)
00649 {
00650 assert(t);
00651 assert(s);
00652 s->translate_base(*t, tag);
00653 return t;
00654 }
00655 };
00656
00657 template <class S, class T>
00658 void sd_translate(S *sd, T &it, const char * tag)
00659 {
00660 fprintf(stderr, "%s[%d]: welcome to sd_translate<%s, %s>(%p)\n",
00661 FILE__, __LINE__,
00662 typeid(S).name(),
00663 typeid(T).name(), &it);
00664
00665 SpecAdaptor<S,T> saf;
00666
00667 if (NULL == saf(sd, it, tag))
00668 {
00669 fprintf(stderr, "%s[%d]: ERROR here\n", FILE__, __LINE__);
00670 }
00671
00672 return;
00673 }
00674
00675
00676 #if 0
00677 template<class S, class T, class TT2>
00678 class trans_adaptor<S, dyn_hash_map<T, TT2> > {
00679
00680 public:
00681
00682 COMMON_EXPORT trans_adaptor()
00683 {
00684 fprintf(stderr, "%s[%d]: welcome to trans_adaptor<%s, hash<%s, %s> >()\n",
00685 FILE__, __LINE__,
00686 typeid(S).name(),
00687 typeid(T).name(), typeid(TT2).name() );
00688 }
00689
00690 COMMON_EXPORT dyn_hash_map<T, TT2> * operator()(S *ser, dyn_hash_map<T, TT2> &m,
00691 const char *tag = NULL, const char *tag2 = NULL)
00692 {
00693 fprintf(stderr, "%s[%d]: hash_size = %d\n", FILE__, __LINE__, m.size());
00694 translate_hash_map(ser, m, tag, tag2);
00695
00696
00697 return &m;
00698 }
00699 };
00700 #endif
00701
00702
00703
00704 #if 0
00705 class SerTest : public Serializable {
00706
00707 int my_int;
00708
00709 public:
00710
00711 SerTest()
00712 {
00713 my_int = 777;
00714 }
00715
00716 ~SerTest() {}
00717
00718 void serialize(SerializerBase *s, const char * = NULL)
00719 {
00720 try
00721 {
00722 gtranslate(s, my_int);
00723 } SER_CATCH("SerTest");
00724 }
00725
00726 void testit()
00727 {
00728 SerializerBase sb("SerTest", std::string("boogabooga"), sd_serialize, true);
00729 serialize( &sb);
00730 }
00731 };
00732 #endif
00733 }
00734
00735 #endif
00736
00737 #endif