The Mobile Object Layer (MOL) is one subsystem of the Portable Runtime Environment for Mobile Applications (PREMA) that is intended for provided the illusion of a global address space without special hardware. Quoting from here,
MOL supports a global distributed object space and provides correct and efficient protocols for message forwarding and communication between migrating objects. MOL is lean, language-independent, and easy to port and maintain system for developing dynamic load balancing libraries.
However, even though the underlying model is object-oriented, MOL's interface is in C, and there are no "nice" way to use MOL from a language like C++. So see this, let's consider a short example.
First, suppose we have a type Foo:
struct Foo { ... void method(void* pParam); // Some method that does something ... };// This handler must be defined externally to the struct, or else // be static. void myHandler(int nSrc, mol_mobile_ptr_t mp, void* pObject, void* pData, int nSize, void* pArg) { Foo* pFoo = (Foo*)pObject; pFoo->method(pData); }
Currently, if we want a Mobile Object of type Foo, we would need to do this:
mol_init(argc, argv); // Params are passed to main() mol_msg_handler_t handlers[] = {myHandler}; mol_register_msg_handlers(handlers, 1); Foo* pFoo = new Foo(); mol_mobile_ptr_t mp = mol_create_mobile_ptr(pFoo);
Then, assuming another processor had the mobile pointer mp, it could communicate with the mobile object like this:
void* pData = <something>; mol_message(mp, myHandler, pData, <data size>, MOL_DELAYED_HANDLER, NULL);
This works fine, but it would be nice if there was a way to express this in a way that was much closer to the way in which programmers write sequential, "normal" code. For instance, it would be more natural to declare Mobile objects like this,.
MobileObject<Foo>* pObject = new MobileObject<Foo>;
and use them like this,
pObject->method(pData);
There are several differences between the two. First, we no longer need to call a routine to initialize the Mobile Object layer. Second, we no longer need static handlers or handlers defined externally to the class definition.
There are two basic approaches that one might use for creating a C++ interface for MOL. The first is to use templates and other standard C++ features to create the interface. The second is to incorporate the interface into the C++ language by creating language extensions and to implement a preprocessor that translates the extended syntax into the standard syntax plus calls to the MOL library.
A very useful tool for creating syntactic extensions to C++ is the Open C++ system.
The goals of the project are the following :-