36 |
namespace python |
namespace python |
37 |
{ |
{ |
38 |
/** |
/** |
39 |
* |
* A cache for python scripts that allows multiple objects to access the |
40 |
|
* same python instance. This avoids multiple instanciation of python |
41 |
|
* objects that could easily be shared. |
42 |
*/ |
*/ |
43 |
class pool |
class pool |
44 |
{ |
{ |
54 |
static void cleanup (); |
static void cleanup (); |
55 |
|
|
56 |
/** |
/** |
57 |
* |
* Return a python method from the given script and class. If the |
58 |
|
* class is not yet cached in the pool, it is instanciated. |
59 |
|
* @param file name of the python script. |
60 |
|
* @param classname name of the python class to access. |
61 |
|
* @param callback name of the method to retrieve from that class. |
62 |
|
* @return python method from cached object or \c NULL on error. |
63 |
*/ |
*/ |
64 |
static python::method * connect (const std::string & file, |
static python::method * connect (const std::string & file, |
65 |
const std::string & classname, const std::string & callback); |
const std::string & classname, const std::string & callback); |
66 |
|
|
67 |
/** |
/** |
68 |
* |
* Return a python object from the given script. If it is not |
69 |
|
* yet cached, the script will be loaded and the given class |
70 |
|
* will be instanciated. |
71 |
|
* @param file name of the python script. |
72 |
|
* @param classname name of the python class to access. |
73 |
|
* @return python object from cache or \c NULL on error. |
74 |
*/ |
*/ |
75 |
static python::script * reconnect (const std::string & file, |
static python::script * reconnect (const std::string & file, |
76 |
const std::string & classname); |
const std::string & classname); |
77 |
|
|
78 |
private: |
private: |
79 |
/** |
/// All python scripts currently kept in cache |
|
* |
|
|
*/ |
|
80 |
static std::map<const char*, python::script*> Pool; |
static std::map<const char*, python::script*> Pool; |
81 |
}; |
}; |
82 |
} |
} |