MeVisLab Toolbox Reference
mlObjMgr.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_OBJ_MGR_H
14 #define ML_OBJ_MGR_H
15 
16 
18 
19 #include "MLObjMgrSystem.h"
20 #include "mlObjMgrBase.h"
22 #include "mlObjMgrEvent.h"
23 #include <mlCallOnNextOpportunity.h>
24 
25 ML_START_NAMESPACE
26 
27  class ObjMgrClient;
28 
29 #ifdef WITH_NETCOM
30 
31  class omSServer;
32  class omSClient;
33  class omEventComm;
34 
35 #endif
36 
39  class MLOBJMGR_EXPORT ObjMgr : public ObjMgrBase
40  {
41  friend class ObjMgrBase;
42  friend class ObjMgrClient;
43 
44 #ifdef WITH_NETCOM
45 
46  friend class omEventComm;
47 
48 #endif
49 
50  typedef ObjMgrBase inherited;
51 
54 
55  public:
56 
57 #ifdef WITH_NETCOM
58 
60  enum NetworkModes {
61  NET_NONE= 0,
62  NET_SERVER,
63  NET_CLIENT,
64  NUM_NETWORK_MODES
65  };
66 
68  static const char *NetworkModeStrings[NUM_NETWORK_MODES];
69 
70 #endif
71 
72  public:
73 
76 
79 
82 
85 
88 
91 
94 
95 #ifdef WITH_NETCOM
96 
98  EnumField *netModeFld;
99 
101  StringField *netAddrFld;
102 
104  IntField *netPortFld;
105 
108  BoolField *commOnlyMarkedInfoFld;
109 
110 #endif
111 
114 
116  ~ObjMgr() override;
117 
119  void setDefaultAddressFlags(const omFlags &flags) {
120  _defaultAddressFlags = flags;
121  }
124  return _defaultAddressFlags;
125  }
126 
130  void addEvent(const ObjMgrEvent &event);
131 
134  inline void disableEventRecording() {
135  _silent = true;
136  }
139  inline void enableEventRecording() {
140  _silent = false;
141  }
142 
146  _preventSocketDistribution = true;
147  }
151  _preventSocketDistribution = false;
152  }
153 
155  const omObjectContainer *getObjectContainer() const { return _objects; }
156 
158  void saveNetworkInfo(const std::string &filename);
159 
160  protected:
161 
163  void activateAttachments() override;
164 
166  void handleNotification(Field *field) override;
167 
169  void addClient(ObjMgrClient *client);
171  void removeClient(ObjMgrClient *client);
172 
176  void sendNotification(ObjMgrBase *sendingClient);
177 
180 
182  std::string getDebugComment() const override {
183  return "ObjMgr";
184  }
185 
188 
192 
194  CallOnNextOpportunity _callLater;
195 
196 #ifdef WITH_NETCOM
197 
199  omSServer *_serverSocket;
200  omSClient *_clientSocket;
201 
202 #endif
203 
204  private:
205 
207  omFlags _defaultAddressFlags;
208 
210  std::set<ObjMgrClient *> _clientModules;
211 
213  omEventContainer _events;
214 
216  std::list<omEventContainer> _undoBuffer;
217  std::list<omEventContainer> _redoBuffer;
218 
221  bool _silent;
222 
224  bool _preventSocketDistribution;
225 
227  bool _networkInitialized;
228 
230  void evalClient(std::fstream &info, ObjMgrClient *client);
231  void evalNetwork(std::fstream &info, const std::multimap<ObjMgrBase *, ObjMgrBase *> &graph, ObjMgrBase *current);
233 
234  // Callback for sendNotification without providing a sender
235  static void sendNotificationCB(void *self);
236  };
237 
238 ML_END_NAMESPACE
239 
240 #endif // __mlObjMgr_H
Field to encapsulate a boolean value.
Definition: mlFields.h:62
Field to encapsulate an enumerated value.
Definition: mlFields.h:363
Base class for all fields used in the ML.
Definition: mlField.h:73
Field to encapsulate an integer value.
Definition: mlFields.h:161
Field without value for notifications.
Definition: mlFields.h:1049
Base class for all communicating modules.
Definition: mlObjMgrBase.h:37
Base class for all modules that wish to use and communicate (send and receive notifications) with the...
Event information.
Definition: mlObjMgrEvent.h:33
Database manager and communication switchboard.
Definition: mlObjMgr.h:40
~ObjMgr() override
Destructor.
ObjMgr()
Constructor.
omObjectContainer * _objects
Objects map.
Definition: mlObjMgr.h:187
BoolField * eventFilterFld
Filter events and remove duplicates etc. if toggle is on. Default is ON.
Definition: mlObjMgr.h:78
void addEvent(const ObjMgrEvent &event)
Add event to event container.
NotifyField * clearObjContainerFld
Clear object container.
Definition: mlObjMgr.h:87
MLint32 _notifyRecursionDepth
This value represents the current recursion depth in the sendNotification() method caused by an initi...
Definition: mlObjMgr.h:191
BoolField * eventLoggingFld
Macro for declaring methods for the runtime system.
Definition: mlObjMgr.h:75
std::string getDebugComment() const override
Return debug comment.
Definition: mlObjMgr.h:182
void handleNotification(Field *field) override
Called when input changes.
const omObjectContainer * getObjectContainer() const
Get read-only access to object container.
Definition: mlObjMgr.h:155
void disableEventRecordingForSocketDistribution()
Modifications to the object container go without any notice for ObjMgrs connected via socket interfac...
Definition: mlObjMgr.h:145
BoolField * permitRecursiveNotificationFld
Permit recursive reentry in handleNotification() of ObjMgrClient modules if toggle is on....
Definition: mlObjMgr.h:81
void disableEventRecording()
Modifications to the object container go without any notice (no events generated).
Definition: mlObjMgr.h:134
CallOnNextOpportunity _callLater
Helper object to schedule a call on next opportunity.
Definition: mlObjMgr.h:194
StringField * infoFileNameFld
Specifies the name of a file in which information about the current ObjMgr network are written.
Definition: mlObjMgr.h:90
NotifyField * saveInfoFld
Write information about the current ObjMgr network to a file whose name is given in infoFileFld.
Definition: mlObjMgr.h:93
const omFlags & getDefaultAddressFlags() const
Get default address flags to be assigned to newly created objects or attributes.
Definition: mlObjMgr.h:123
void enableEventRecording()
Modifications to the object container will be recorded (events are generated).
Definition: mlObjMgr.h:139
void activateAttachments() override
Initialize module after loading.
void removeClient(ObjMgrClient *client)
Remove ObjMgrClient from the container of instantiated modules.
BoolField * clientsReceiveOwnNotifyFld
Client modules receive notification sent by themselves if toggle is on. Default is OFF.
Definition: mlObjMgr.h:84
void sendNotificationOnNextOpportunity()
Send notification to all connected ObjMgrClient modules on next opportunity.
void saveNetworkInfo(const std::string &filename)
Write information about the current ObjMgr network to a file.
void setDefaultAddressFlags(const omFlags &flags)
Set default address flags to be assigned to newly created objects or attributes.
Definition: mlObjMgr.h:119
void addClient(ObjMgrClient *client)
Add a new ObjMgrClient to the container of instantiated modules.
void enableEventRecordingForSocketDistribution()
Modifications to the object container will be recorded for ObjMgrs connected via socket interface.
Definition: mlObjMgr.h:150
void sendNotification(ObjMgrBase *sendingClient)
Send notification to all connected ObjMgrClient modules (the BaseField is touched) that something has...
Field to encapsulate a string value.
Definition: mlFields.h:1000
Managed special flags of information address components.
Definition: mlObjMgrFlags.h:28
Database (object container) - manages all objects.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
signed int MLint32
Definition: mlTypeDefs.h:167
std::list< ObjMgrEvent > omEventContainer
Declare type for event container;.