NeL Network Class Transport Sample
Summary
This sample shows how to use the NeL Network architecture system for transporting classes from one NeL service to another. The CTransportClass system attempts to make the complicated task of sharing classes between services - sometimes ones with API versions out of sync - and tries to make it simple and as transparent as possible. This sample shows you a basic shared class mechanism in action with simple and easy to read code.
Services Summary
The services are basic NLNET 5 service framework implementations. They implement the necessary methods. They manually define the service-up callback so that when either the gd_service or the ai_service come online they will tell the other one about their shared class.
CTransportClass Summary
The CTransportClass is at the core of this system. To use it you must first do the following during your service initialization:
This initializes the system. It does some pretty critical things behind the scenes. First it assumes that you are using layer 5 of the NLNET architecture. This means you must have a CUnifiedNetwork active - NeL services take care of this for you. It sets up some callbacks that pertain to it:
- CT_LRC
- CT_MSG
These two callbacks allow class transports on all services to receive each others class registrations and class tranmissions.
Sharing a class between services requires that the class being shared implements the CTransportClass class. Implementing this class requires that you write implementation for two methods:
Implementing the Description Method
The point to implementing the description method is that it is called to register it's information with the class transport system. It must inform the system the name of the class and all properties that belong to it. The ''class_transport'' sample gives a good example of what you would put into the description method. Here are some options:
- className - You must _always_ define a class name. It's a sort of unique identifier for the shared class type.
- property - defines a property that will be part of the data shared. It must be a serializable property and in the TProps enum.
- propertyCont - this method is the same as above but works on containers such as lists and vectors.
Implementing the Callback Method
The implementation of the callback method really depends on the needs of you as a programmer. Since the ''class_transport'' sample isn't taking shared instances and spawning new local instances or anything of the sort it simply does an nlinfo to inform you that a service has sent it a new shared class:
Registering the Class
The following code must be added after the transport class system is initialized for the object to be shared:
This macro takes care of some finer implementation details and registration.