1 / 5

EIToolkit stub doc

EIToolkit stub doc. main.cpp file. int main( int argc , char* argv []) { EIProperties :: UseStandards (); // create the stub ExampleStub stub; stub.Start (); printf ( &quot;Press ESC to quit.<br><br>&quot;); while (_ getch () != 27); printf ( &quot;Cleaning up ...<br>&quot;); stub.Stop ();

candra
Télécharger la présentation

EIToolkit stub doc

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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‘)

More Related