// Implements persistance for Bro's data structures. #ifndef persistence_serializer_h #define persistence_serializer_h #include "Serializer.h" #include "List.h" class StateAccess; class PersistenceSerializer : public FileSerializer { public: PersistenceSerializer(); virtual ~PersistenceSerializer(); // Define the directory where to store the data. void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); } // Register/unregister the ID/connection to be saved by WriteAll(). void Register(ID* id); void Unregister(ID* id); void Register(Connection* conn); void Unregister(Connection* conn); // Read all data that has been changed since last scan of directory. // is_init should be true for the first read upon start-up. All existing // state will be cleared. If delete_files is true, file which have been // read are removed (even if the read was unsuccessful!). bool ReadAll(bool is_init, bool delete_files); // Each of the following four methods may suspend operation. // If they do, they install a Timer which resumes after some // amount of time. If a function is called again before it // has completely finished its task, it will do nothing and // return false. bool WriteState(bool may_suspend); // Writes Bro's configuration (w/o dynamic state). bool WriteConfig(bool may_suspend); // Sends all registered state to remote host // (by leveraging the remote_serializer). bool SendState(SourceID peer, bool may_suspend); // Sends Bro's config to remote host // (by leveraging the remote_serializer). bool SendConfig(SourceID peer, bool may_suspend); // Returns true if a serialization is currently running. bool IsSerializationRunning() const { return running.length(); } // Tells the serializer that this access was performed. If a // serialization is going on, it may store it. (Need only be called if // IsSerializationRunning() returns true.) bool LogAccess(const StateAccess& s); protected: friend class RemoteSerializer; friend class IncrementalWriteTimer; virtual void GotID(ID* id, Val* val); virtual void GotEvent(const char* name, double time, EventHandlerPtr event, val_list* args); virtual void GotFunctionCall(const char* name, double time, Func* func, val_list* args) ; virtual void GotStateAccess(StateAccess* s); virtual void GotTimer(Timer* t); virtual void GotConnection(Connection* c); virtual void GotPacket(Packet* packet); // If file has changed since last check, read it. bool CheckForFile(UnserialInfo* info, const char* file, bool delete_file); // Returns true if it's a regular file and has a more recent timestamp // than last time we checked it. bool CheckTimestamp(const char* file); // Move file from