Muster SDK  8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2 **
3 ** Header file for Virtual Vertex Template manager class
4 **
5 ** Name : MManager.h
6 ** Author : Leonardo Bernardini
7 ** Version : Alpha 0.1, Sun Aug 15th 2006
8 **
9 ** Copyright 2000-2014, Virtual Vertex
10 ** All Rights Reserved.
11 **
12 ** This file contains UNPUBLISHED PROPRIETARY SOURCE CODE.
13 ** The contents of this file may not be disclosed to third parties, copied
14 ** or duplicated in any form, in whole or in part, without the prior written
15 ** permission of the author.
16 **
17 *****************************************************************************/
18 #ifndef MMANAGER_H
19 #define MMANAGER_H
20 
21 #ifdef WIN32
22 // Windows definitions
23 #ifdef MTEMPLATE_EXPORTS
24 #define MTEMPLATE_API __declspec(dllexport)
25 #else
26 #define MTEMPLATE_API __declspec(dllimport)
27 #endif
28 #else
29 
30 #ifndef MTEMPLATE_EXPORTS
31 #ifdef LINUX
32 #define MTEMPLATE_API
33 #else
34 #define MTEMPLATE_API
35 #endif
36 #else
37 #define MTEMPLATE_API
38 #endif
39 
40 #endif
41 
42 #ifdef WIN32
43 #define MThread uintptr_t
44 #else
45 #define MThread pthread_t
46 #endif
47 
48 #include "MClientLib/MProcess.h"
49 #include "MClientLib/MStringRef.h"
50 #include "MClientLib/MJob.h"
51 
52 #include <list>
53 
54 // Disable STL Export warning
55 #if defined(_WIN32)
56 #pragma warning(disable: 4251)
57 #endif // _WIN32
58 
59 namespace MTemplateEngine {
60 
68  } ;
69 
76  } ;
77 
81  {
85  };
86 
87  class MTemplate;
88 
92  {
93  private:
94  int uid;
95  std::string md5hash;
96  std::string filename;
97  public:
98  MTemplateHash(void);
99  ~MTemplateHash(void);
100  int getUid();
101  std::string getMd5Hash();
102  std::string getFilename();
103 
104  void setUid(int _uid);
105  void setMd5Hash(std::string _hash);
106  void setFilename(std::string _filename);
107 
108  };
109 
110  typedef std::map<int,MTemplateHash*> templatesHashesMap;
111  typedef std::map<int,MTemplate*> templatesMap;
113  typedef void (*redirectionFuncPtr)(const char*);
114 
118  {
119 
120  public:
121  MManager();
122  ~MManager();
123  public:
124  static MManager* getUniqueClass(bool alloc = true);
125  static void destroyUniqueClass(void);
126  static MManager* allocateClass(void);
127  static void destroyClass(MManager*);
128  static void setIsMacBundle(bool isMacBundle);
129  static void setPythonPath(const std::string& _pythonPath);
130  static std::string getPythonPath();
131  static void initializePythonPath(bool showPath=false);
133  bool installTemplate(MTemplate* templateClass);
134  MTemplate* getFirstTemplate();
135  MTemplate* getNextTemplate(int previous_uid);
136  std::string resolveMappingToJob(int template_id, const char* key) ;
137  std::string resolveMappingToTemplate(int template_id, const char* key) ;
139  void Lock(void);
140  void Unlock(void);
141  void acquirePython(void);
142  void releasePython(void);
143  std::string getPyExceptionStr();
144  bool runPythonFile(const char* path,MClientLib::MStringRef& _err);
145  bool runPythonString(const char* buffer,const char* sourceFile,MClientLib::MStringRef& _err);
146  void registerPythonOutputCallbacks(redirectionFuncPtr, redirectionFuncPtr);
147  void onPythonStdout(const char* out);
148  void onPythonStderr(const char* out);
149  void onPythonStderrFlush();
150  void onPythonStdoutFlush();
152  bool _installPyTemplate(void* templateClass);
153  void clear(void);
154  void flushGC(void);
155  void addTemplateToGC(MTemplate* t);
157  void copyFrom(MManager*);
158  MTemplate* parsePython(const char* template_buf,const char* template_filename,bool _recache,MClientLib::MStringRef& err, bool store=true);
159  MTemplate* getTemplate(const char* name);
160  MTemplate* getTemplateByFilename(const char* filename);
161  MTemplate* getTemplate(int id);
162  MTemplate* getTemplateAt(int num);
163  void unloadTemplate(int id);
164  int getTemplatesCount();
165  int getNextFreeUID();
166  void deallocateTemplate(MTemplate* t);
167  templatesHashesMap* getInternalHashesMap();
168  void fillInternalHashesMap();
169  std::string marshallHashesMap(templatesHashesMap*);
170  void unmarshallHashesMap(templatesHashesMap*, const char*);
171  void makeHashesMap(templatesHashesMap*);
172  void calculateHashesDiffs(templatesHashesMap* remote, templatesHashesMap* out_of_date, templatesHashesMap* invalid);
173  void deleteHashesMap(templatesHashesMap*);
174  void updateTemplateHash(MTemplate* t) ;
175  void sortListByField(const std::string& field, std::list<MTemplate*>* list);
176  bool validateJobSubmission(MClientLib::MJob& job, MClientLib::MStringRef& err);
178  private:
179  void* _mutex;
180  templatesMap list;
181  templatesHashesMap hash_map;
182  static MManager* _unique_class;
183  static bool _isMacBundle;
184  static bool pythonFromHere;
185  static std::map<MThread,void*> threadStates;
186  static void* mainThreadState;
187  static MThread mainThread;
188  static void* m_PyFormatException;
189  static void* m_pMainModule;
190  static void* m_pMainDict;
191  static std::string pythonPath;
192  static std::list<MTemplate*> gc;
193  redirectionFuncPtr stdoutCallback;
194  redirectionFuncPtr stderrCallback;
195 
196  MTemplate* lastInstalledTemplate;
197  struct sortFunctor {
198  const std::string field;
199  sortFunctor(const std::string& field) : field(field) {}
200  bool operator()(MTemplate* a,MTemplate* b);
201  };
202  };
203 
204 };
205 
206 #endif