HelloInterface is an abstract class with a single method (hello()) and no implementation.
Let's begin with the IDL description of the HelloInterface class.
The #import directive is similar to C++ #include with standard #ifdef guards - the specified file will be included only if has not been included yet. The core.idl file includes all public IDL files from the Core:
(1) #import "core.idl"
|
All classes in this example are defined in the example namespace:
(3) namespace example {
|
IDL class description uses syntax similar to C++ class definitions:
(5) class (6) < (7) abstract, (8) kind = SERVER, (9) root (10) > (11) HelloInterface : ::Massiv::Core::Object |
The key differences are:
Values of special attributes may be set per-class. This is a generic way how to specify additional information about a class, similar to various compiler-specific C++ ways to specify such information (__declspec, __attribute__, etc.). In this case the class is abstract (objects of the class can't be instantiated), garbage collector root (see Section 5.4, “Garbage Collector”) and it's kind is SERVER - objects of the class can be owned only by server nodes, client nodes don't know anything about the class. This may seem a bit weird, but remember that client nodes are not allowed to call methods of any objects but their account object.
Only the public inheritance is supported. Otherwise the inheritance specification is the same as in C++ - there may be multiple base classes and virtual inheritance can be used. The Massiv::Core::Object class is root of the hierarchy of managed classes and all managed classes must include it exactly once (so you should include it virtually if you intend to use multiple inheritance).
The class body follows. It may contain description of nested classes and enumeration types and description of class properties and methods:
(12) { (13) method< virtual > hello (14) ( (15) in string callee_name (16) ) : string; (17) } |
The HelloInterface class is really simple. It contains single method called hello(). The method is virtual (this is specified by a method attribute), single string argument is passed to the method and it returns another string (Pascal-like syntax is used to specify the return type).
The C++ defintion of the class begins with standard #includes:
(4) #ifndef MASSIV_CORE_H (5) #include "core.h" (6) #endif (7) (8) #include <string> |
The core.h header includes nearly all public headers from the Massiv Core that you can ever need. We precompile the core.h header on platforms that support that, therefore it should be included as the first headers everywhere (because most compilers only support precompiling of the first header). The standard string header is included too.
The C++ definitions must be in the same namespace as their IDL descriptions:
(10) namespace example {
|
The definition of the class HelloInterface follows:
(11) /** (12) * Interface of hello classes. (13) * (14) * This is generic interface of all classes that implement the (15) * hello() method. (16) * (17) * As described in the IDL, all Hello classes should be root objects (18) * of KIND_SERVER kind. (19) */ (20) class HelloInterface : public ::Massiv::Core::Object (21) { (22) public: (23) (24) /** (25) * The "say hello" method. (26) * (27) * It should generate a hello message for the callee @a callee_name, (28) * print it anywhere it wants and return it. (29) */ (30) virtual std::string hello (31) ( (32) const std::string & callee_name (33) ) = 0; (34) (35) }; // class HelloInterface |
As described in the IDL, the HelloInterface's base class is Massiv::Core::Object and it has a single method, hello(). The method is pure virtual. Note that the IDL does not care that the method is pure (and there is no way to specify that), but it needs to know that objects of the class can't be instantiated, as specified by the abstract class attribute. The type of the only argument and the return type of the method follow type mappings described in Section 10.13, “Property and Argument Types”.