PreviousNext

Using cxx_new to Declare an Object Creator Function

Member functions can be specified as static object creator functions by applying the cxx_new attribute to the function name. An object creator function allows clients to dynamically create remote objects of an interface class. Servers require this feature to specify their implementation-specific manager class, and clients can use this feature to specify their local implementation of the interface class. The cxx_new attribute is applied to an operation and has the following format:

[cxx_new (manager_class) ] creator_function( );

The associated IDL file must contain a function that returns a pointer to the interface class and that matches the creator_function name.

The manager_class argument to the cxx_new attribute specifies the class name the application uses to locally implement the interface class. The server stub requires the manager_class, which must be declared for it in a header file and included by using the sstub attribute with the include statement. The format in C++ of the manager_class declaration is as follows:

class manager_class : public interface_class {
// The constructor, destructor, function declarations, and data.
...
}

The manager class can include not only a constructor to create objects of the class, but also all the nonstatic member functions declared in the interface class. A server implements the manager_class member functions in its manager code. Manager code handles requests from clients for all of the interface's member functions (static and nonstatic), including the creator_function, which dynamically creates interface objects on the server for the client.

When a client calls the creator_function, the client stub executes a proxy function that uses RPCs to execute a manager class constructor on a server. A client can use the manager_class argument to specify a class name when implementing its own local version of the interface class. In this case, the client links into its application the idl-generated server stub along with a local implementation of the interface class. When the client uses the new operator to create objects of the manager_class type, the object is local and no RPCs are involved.