vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SystemInfo.h
Go to the documentation of this file.
1 #ifndef SYSTEMINFO_H
2 #define SYSTEMINFO_H
3 
4 // An ability to periodically check various information
5 // and write them to the debug log.
6 
7 #include <windows.h>
8 
9 #include <vrecko/Ability.h>
10 #include <vrecko/World.h>
11 #include <vrecko/EventDispatcher.h>
12 
13 
14 namespace base {
15 
16 #define SI_UNKNOWN_THREAD_NAME "?"
17 
18 class SystemInfo: public vrecko::Ability {
19 public:
20 
22  public:
23  virtual const char* getMessageId() { return "MessageSIThreadCreated"; }
24 
26  MessageSIThreadCreated(DWORD _dwThreadId, const char *_name) { dwThreadId = _dwThreadId; name = _name; }
27  virtual bool setValueFromString(const char *valueAsString) { return false; }
28  virtual bool isEqualTo(VreckoMessage *otherMsg) { return false; }
29 
30  DWORD dwThreadId;
31  std::string name;
32  };
33 
34  SystemInfo();
35  ~SystemInfo();
36 
37  virtual void preInitialize();
38  virtual void postInitialize();
39 
40  bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parametersNode);
41  //XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *saveXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *);
42 
43  virtual void update();
44 
45  static bool TryToSendThreadCreatedEvent(DWORD dwThreadId, const char *pName) {
46  SystemInfo *siInst = (SystemInfo*)vrecko::world->getAbility("base::SystemInfo");
47  if (!siInst)
48  siInst = (SystemInfo*)vrecko::world->getAbility("SystemInfo");
49  if (!siInst)
50  return false;
51 
52  return vrecko::world->getEventDispatcherPtr()->reportEvent(siInst, "ThreadCreated", new MessageSIThreadCreated(dwThreadId, pName));
53  }
54 
55 protected:
56  DWORD dwLastTick;
57 
59 
60  bool initThread(DWORD dwThreadId, std::string &threadName);
61 
62  struct SIThreadInfo {
63  // statistical information about a thread
64  public:
66 
67  std::string name;
68 
69  bool bThreadInitialized; // are the thread values initialized (affinity etc.)
70 
71  bool bTimeInitialized; // are the time values initialized?
72  DWORD dwLastUserTime; // ms
73  DWORD dwLastKernelTime; // ms
74  };
75 
76  struct SIThreadInit {
77  // structure used to initialize a thread
78  public:
79  DWORD dwAffinity;
80  };
81 
82  std::map<DWORD, SIThreadInfo> threadsInfo; // stats
83 
84  std::map<std::string, SIThreadInit> threadsInit; // initialization values
85 
86  DECLARE_INPUT(ThreadCreated, MessageSIThreadCreated);
87 };
88 
89 }
90 
91 
92 #endif