7.4. Interfaces

7.4.1. Applet main class details

All the applets being a part of the system will have to extend their main class from our class AppletBase. AppletBase class will provide the following methods:

public class AppletBase {

}

class Message {

}

The register method will have to be called first. Its task is to notify the Demon about new Applet connected to it and and establish communication channel.

Each time the Applet wants to send a message, it should create new object of Message class and invoke send method passing message as a parameter.

Our system guarantees that each time a message comes to the Applet, its receive method will be called with incoming message as a parameter. Because in AppletBase receive is decared as abstract, it is responsibility of application programmer to write its body which will handle incoming messages.

Class message is a generic class to exchange the information. It consists of byte array that should represent the information specific to the application.

7.4.2. C interface

The C inteface will provide the following structures and functions:

struct Event {

}

int register(int AID, int port);

void sendEvent(int sockfd, struct Event *e);

(struct Event *) receiveEvent(int sockfd);

(struct Event *)createEvent(int len, char *data);

int getLen (struct Event *e);

int getData (struct Event *e);

void destroyEvent( struct Event *e);

Function register will connect application to the Demon by establishing socket connection and transmitting AID number. It will return socket descriptor to be used by other functions.

Function sendEvent will be used to send messages to the system. It will take socket descriptor and message wrapped in Event sructure as parameters.

Function receiveEvent should be called each time we want to receive a message.

Functions getLen and getData are used to retrieve the content of Event structure.

Function destroyEvent is used to destroy the Event structure and free the memory.