EmbodimentCogServer

From OpenCog
Jump to: navigation, search

EmbodimentCogServer is an abstract class that extends CogServer class and overrides its customLoopRun method in order to provide specific network services as defined in Design for Embodiment Communications Layer. See a skeleton of EmbodimentCogServer class bellow:

 class EmbodimentCogServer : public opencog::CogServer {
    NetworkElement* ne;
    EmbodimentCogServer();
    void setNetworkElement(NetworkElement*);
    NetworkElement& getNetworkElement(void);
    virtual bool customLoopRun(void); // overridden 
    virtual bool processNextMessage(Message *message) = 0;
 };

The customLoopRun method is implemented as shown in the following pseudo code:

 bool customLoopRun() { 
     retrieveMessagesFromRouter()
     if (!externalTickMode) {
         while (incomingQueue has Messages) {
             processNextMessage(incomingQueue.pop())
         }
         return true;
     } else {
         while (incomingQueue has Messages) {
             Message* msg = incomingQueue.pop();
             if (msg is a TICK message) return true;
             processNextMessage(msg);
         }
     }
     sleep; // just a bit; to avoid cpu overload
     return false;
 }

As you see, when externalTickMode is false, after processing all incoming messages, it returns true, which means a new CogServer cycle will take place. Otherwise, it returns true only when a TICK message is received. This way, the CogServer cycles depend on an external component that must send TICK messages periodically. Each concrete subclass of EmbodimentCogServer must implement the processNextMessage method properly.

Any element in an Embodiment network is an EmbodimentCogServer, except for the router, which has its own specific server loop. There are 2 main Embodiment servers, as follows:

  • OAC (Operational Avatar Controller): controls the "brain" of an avatar in a virtual world. This server uses the external tick mode in order to synchronize its activities with the virtual world's "clock".
  • LS (Learning Server): responsible for learning new tricks based on examples given by the avatar's owner or another avatar. Currently, this server does not run in external tick mode, which means it has its own internal cycle frequency.

There are still some other servers (spawner, pvpSimulator, etc) that extends EmbodimentCogServer but don't need/use any AtomSpace. They just uses the Embodiment's network services provided by this class.