Muster SDK  8.5.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 
92  } ;
93 
94  class MTemplate;
95 
99  {
100  private:
101  int uid;
102  std::string md5hash;
103  std::string filename;
104  public:
105  MTemplateHash(void);
106  ~MTemplateHash(void);
107  int getUid();
108  std::string getMd5Hash();
109  std::string getFilename();
110 
111  void setUid(int _uid);
112  void setMd5Hash(std::string _hash);
113  void setFilename(std::string _filename);
114 
115  };
116 
117  typedef std::map<int,MTemplateHash*> templatesHashesMap;
118  typedef std::map<int,MTemplate*> templatesMap;
120  typedef void (*redirectionFuncPtr)(const char*,const char*);
121 
125  {
126 
127  public:
128  MManager();
129  ~MManager();
130  public:
131  static MManager* getUniqueClass(bool alloc = true);
132  static void destroyUniqueClass(void);
133  static MManager* allocateClass(void);
134  static void destroyClass(MManager*);
135  static void setIsMacBundle(bool isMacBundle);
136  static void setPythonPath(const std::string& _pythonPath);
137  static std::string getPythonPath();
138  static std::string getInterpreterModuleName();
139  static void initializePythonPath(bool showPath=false, std::string moduleName=std::string());
141  bool installTemplate(MTemplate* templateClass);
142  MTemplate* getFirstTemplate();
143  MTemplate* getNextTemplate(int previous_uid);
144  std::string resolveMappingToJob(int template_id, const char* key) ;
145  std::string resolveMappingToTemplate(int template_id, const char* key) ;
147  void Lock(void);
148  void Unlock(void);
149  void acquirePython(void);
150  void releasePython(void);
151  std::string getPyExceptionStr();
152  bool runPythonFile(const char* path,MClientLib::MStringRef& _err);
153  bool runPythonString(const char* buffer,const char* sourceFile,MClientLib::MStringRef& _err);
154  void registerPythonOutputCallbacks(redirectionFuncPtr, redirectionFuncPtr);
155  void onPythonStdout(const char* out);
156  void onPythonStderr(const char* out);
157  void onPythonStderrFlush();
158  void onPythonStdoutFlush();
160  bool _installPyTemplate(void* templateClass);
161  void clear(void);
162  void flushGC(void);
163  void addTemplateToGC(MTemplate* t);
165  void copyFrom(MManager*);
166  MTemplate* parsePython(const char* template_buf,const char* template_filename,bool _recache,MClientLib::MStringRef& err, bool store=true);
167  MTemplate* getTemplate(const char* name);
168  MTemplate* getTemplateByFilename(const char* filename);
169  MTemplate* getTemplate(int id);
170  MTemplate* getTemplateAt(int num);
171  void unloadTemplate(int id);
172  int getTemplatesCount();
173  int getNextFreeUID();
174  void deallocateTemplate(MTemplate* t);
175  templatesHashesMap* getInternalHashesMap();
176  void fillInternalHashesMap();
177  std::string marshallHashesMap(templatesHashesMap*);
178  void unmarshallHashesMap(templatesHashesMap*, const char*);
179  void makeHashesMap(templatesHashesMap*);
180  void calculateHashesDiffs(templatesHashesMap* remote, templatesHashesMap* out_of_date, templatesHashesMap* invalid);
181  void deleteHashesMap(templatesHashesMap*);
182  void updateTemplateHash(MTemplate* t) ;
183  void sortListByField(const std::string& field, std::list<MTemplate*>* list);
184  bool validateJobSubmission(MClientLib::MJob& job, MClientLib::MStringRef& err);
186  private:
187  void* _mutex;
188  templatesMap list;
189  templatesHashesMap hash_map;
190  static MManager* _unique_class;
191  static bool _isMacBundle;
192  static bool pythonFromHere;
193  static std::map<MThread,void*> threadStates;
194  static void* mainThreadState;
195  static MThread mainThread;
196  static void* m_PyFormatException;
197  static void* m_pMainModule;
198  static void* m_pMainDict;
199  static std::string pythonPath;
200  static std::string interpreterModuleName;
201  static std::list<MTemplate*> gc;
202  redirectionFuncPtr stdoutCallback;
203  redirectionFuncPtr stderrCallback;
204  std::string callbackContext;
205 
206  MTemplate* lastInstalledTemplate;
207  struct sortFunctor {
208  const std::string field;
209  sortFunctor(const std::string& field) : field(field) {}
210  bool operator()(MTemplate* a,MTemplate* b);
211  };
212  };
213 
214 };
215 
216 #endif