Object.h

Go to the documentation of this file.
00001 #ifndef __OBJECT_H__
00002 #define __OBJECT_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include <time.h>
00011 
00012 #include <map>
00013 #include <set>
00014 
00015 #include "Support.h"
00016 #include "String.h"
00017 #include "StringList.h"
00018 #include "Limits.h"
00019 
00020 // Messages.
00021 static const char *const MSG_OBJECT_SIGNAL_ALREADY_EXISTS                    = "Signal '%s' already exists.";
00022 static const char *const MSG_OBJECT_SIGNAL_IS_NOT_CONNECTED                  = "Signal '%s' is not connected to object with id %llu.";
00023 static const char *const MSG_OBJECT_REGISTRY_ALREADY_EXISTS                  = "Registry '%s' already exists.";
00024 static const char *const MSG_OBJECT_ALREADY_REGISTERED_FOR_DEFERRED_DELETION = "Object with id = %llu is already registered for deferred deletion.";
00025 static const char *const MSG_OBJECT_NOT_FOUND                                = "Object with id = %llu is not found.";
00026 static const char *const MSG_OBJECT_INVALID_ID                               = "Invalid object id %llu.";
00027 
00028 using namespace std;
00029 
00030 class Object;
00031 class Core;
00032 class SignalBase;
00033 class RegistryBase;
00034 class NamedObject;
00035 
00036 typedef unsigned long long ObjectId;
00037 
00038 #define __OBJECT_PART__ \
00039 public: \
00040 static String CLASS_NAME() \
00041 { \
00042   static String name; \
00043   if (name.empty()) { \
00044     String name(__PRETTY_FUNCTION__); \
00045     String functionName = "::" + String(__FUNCTION__) + "()"; \
00046     name = name.erase(0, name.find("String ") + strlen("String ")); \
00047     return name.erase(name.find(functionName), functionName.length()); \
00048   } \
00049   return name; \
00050 } \
00051 inline \
00052 virtual String className() const \
00053 { \
00054   return CLASS_NAME(); \
00055 } \
00056 
00057 #define PYLON_OBJECT \
00058 __OBJECT_PART__ \
00059 virtual void __abstract__() const {};
00060 
00061 class Object : public Support
00062 {
00063 
00064 friend class Core;
00065 friend class SignalBase;
00066 friend class RegistryBase;
00067 friend class NamedObject;
00068 
00069   __OBJECT_PART__
00070 
00071 public:
00072 
00073   static const ObjectId nid = 0;
00074 
00075   virtual void __abstract__() const = 0;
00076 
00077   Object();
00078   virtual ~Object();
00079 
00080   ObjectId id() const;
00081 
00082   static int get(const ObjectId id, Object **obj);
00083 
00084   virtual int suspend();
00085   bool suspended() const;
00086 
00087   virtual int resume();
00088 
00089   static int listObjects(String &text);
00090   static int listSignals(String &text);
00091   int listMySignals(String &text);
00092   static int listRegistry(String &text);
00093   int listMyRegistry(String &text);
00094   static int listInstances(String &text);
00095   static int listTop(String &text, const unsigned int itemsNum = LIMIT_OBJECT_TOP_ITEMS_NUM);
00096 
00097   void profBegin();
00098   void profEnd();
00099 
00100   unsigned long long cpuTime() const;
00101 
00102 protected:
00103 
00104   void deleteLater(Object *obj);
00105 
00106 private:
00107 
00108   typedef map<ObjectId, Object *> ObjectList;
00109   typedef set<Object *> DefferedDeletionObjectList;
00110 
00111   typedef set<SignalBase *> SignalList;
00112   typedef map<String, RegistryBase *> RegistryList;
00113 
00114   int bindSignal(SignalBase *sgn);
00115   int unbindSignal(SignalBase *sgn);
00116 
00117   static int bindRegistry(Object *owner, RegistryBase *reg);
00118 
00119   static int deletePostponed();
00120 
00121   static bool compareCpuTime(const Object *o1, const Object *o2);
00122 
00123   static ObjectList _objects;
00124   static DefferedDeletionObjectList _deferredDeletionObjects;
00125   static unsigned int _idCounter;
00126   ObjectId _id;
00127   SignalList _signals;
00128   static RegistryList _registryStatic;
00129   RegistryList _registryPrivate;
00130   bool _suspended;
00131   clock_t _cpuTimestamp;
00132   unsigned long long _cpuTime;
00133 };
00134 
00135 template<class T>
00136 inline
00137 T *queryInterface(Support *obj)
00138 {
00139   return obj ? dynamic_cast<T *>(obj) : NULL;
00140 }
00141 
00142 inline
00143 String OBJECT_COLOR_TITLE(const String &str)
00144 {
00145   return COLOR_STRING(str, LIGHT_CYAN, NONE);
00146 }
00147 
00148 template<class T>
00149 inline
00150 String CLASS_NAME()
00151 {
00152   return T::CLASS_NAME();
00153 }
00154 
00155 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1