SlideServe
Menu
Préférences
© SlideServe · v2026

EIToolkit stub doc

candra avatar
5 diapositives · 216 Views · Oct 09, 2014

EIToolkit stub doc. main.cpp file. int main( int argc , char* argv []) { EIProperties :: UseStandards (); // create the stub ExampleStub stub; stub.Start (); printf ( "Press ESC to quit.

"); while (_ getch () != 27); printf ( "Cleaning up ...
"); stub.Stop ();

EIToolkit stub doc - slide 1
01 / 5EIToolkit stub doc
1 / 17

Télécharger la présentation

EIToolkit stub doc
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. EIToolkit stub doc

  2. main.cpp file int main(intargc, char* argv[]) { EIProperties::UseStandards(); // create the stub ExampleStub stub; stub.Start(); printf("Press ESC to quit.\n\n"); while (_getch() != 27); printf("Cleaning up ...\n"); stub.Stop(); EIProperties::StopStandards(); return 0; } The main method should not contain much more than the example shows. A stub might be created from another application and then the main method will not be called. Put most initialisation code into the constructor of the stub or its Start() method. Wait for the user to press ESC. (In Java, this is not possible – need to wait for ENTER)

  3. Main Compiler Options • The following defines can be made globally in the Compiler options dialog in VStudio (or by using the /D compiler option) #define _NO_LISTENERS // if you don't need to listen to (UDP) packets #define _NO_SENDERS // if you don't need to send (UDP) packets #define _NO_PARTICLE_COMM // if you don't need particle communication • In Java, use the following (static) boolean variables: • EIProperties.NO_SENDERS = …; • EIProperties.NO_LISTENERS = …;

  4. ExampleStub.cpp file Code that is executed once. The APPNAME can be retrieved using GetName() ExampleStub::ExampleStub(void) : APPNAME("ExampleStub") { } ExampleStub::~ExampleStub(void) { ExampleStub::Stop(); } void ExampleStub::Start() { Stub::Start(); // register the stub to receive messages EIProperties::GetPacketReceiver()->AddPacketObserver(this); } void ExampleStub::Stop() { Stub::Stop(); } In Java, one instead overrides method getName(). If not, the classname is used as default. public String getName() { return "FacebookStub"; } Code that is executed right before the stub is closed. Code that is executed when the stub is activated (most probably only once when started ...) If you want to receive toolkit messages, register yourself here. Code that is executed when the stub is deactivated (most probably only once when exited ...) In Java, these method calls look like this: EIProperties.getPacketReceiver().addPacketObserver(this);

  5. void ExampleStub::PacketReceived(PacketEvent &pktEvent) { Packet *pkt = pktEvent.GetPacket(); std::string msg; pkt->ToString(&msg); std::string *recvId = pkt->GetReceiverId(); // e.g.: only accept message if directed to all (GetWildcardAll()) or specifically to this stub (GetName()) if (*recvId == GetName() || *recvId == EIProperties::GetPacketFormatter()->GetWildcardAll()) { } // TODO react to packet or msg } // Example of how to send a message as UDP void ExampleStub::SendMessageToID(const char *msg, const char *id) { std::string message = GetName() + "::" + std::string(msg) + ":" + std::string(id); Packet packet(message); EIProperties::GetPacketSender()->SendPacket(&packet); } This method is automatically called whenever a toolkit message has arrived (if you have previously registered yourself) The GetWildcardAll() method gives the placeholder used to denote ‚everything‘ – currently the „*“ star To send a message, build a packet (sender, message type, message content, receiver) and use GetPacketSender()->SendPacket to send it (one could use the GetWildcardAll() placeholder for a placeholder meaning e.g. this packet is meant for ‚all‘)