Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Cookbook

Ishtar services implements a protocol for remote procedure call (RPC) and provides basic bricks for building such procedures, called Ishtar::Service. It relies on Ishtar net for basic types serialisation.

The basic data type which goes through the network is Ishtar::ValueVector, which is a vector of basic types. An Ishtar::Service is a class that accept and returns value vectors (through the virtual methods Ishtar::Services::setValues and Ishtar::Services::getValues) and thus provides the functionality. It also contains a description (Ishtar::Service::description) which has to be filled correctly by constructors of subclasses.

testservice.cpp:

#include <ishtar/services.h>

// Example of server, could be controlling wheels of a robot
class SpeedService : public Ishtar::Service
{
public:
    SpeedService()
    {
        // Characteristics of the service
        description.name = "sbot.motor.track.speed";
        description.type = Ishtar::ValueVector::INT;
        description.flags = Ishtar::ServiceDescription::NAMED_VALUES | Ishtar::ServiceDescription::CONSTRAINT_VALUES;
        description.length = 2;
        description.subnames.resize(2);
        description.subnames[0] = "l";
        description.subnames[1] = "r";
        Ishtar::IntValueVector *m;
        m = new Ishtar::IntValueVector(2);
        m->value[0] = -60;
        m->value[1] = -60;
        description.mins = m;
        m = new Ishtar::IntValueVector(2);
        m->value[0] = 60;
        m->value[1] = 60;
        description.maxs = m;
    }

    virtual Ishtar::ValueVector *getValues(void)
    {
        // Return dummy values
        Ishtar::IntValueVector *vv = new Ishtar::IntValueVector(2);
        vv->value[0]=14;
        vv->value[1]=-3;
        return vv;
    }

    virtual void setValues(Ishtar::ValueVector *values)
    {
        // Print received values
        std::cout << values->toString(0) << std::endl;
        std::cout << values->toString(1) << std::endl;
    }
};

int main(int argc, char *argv[])
{
    // Create server which contains services and respond to network queries
    Ishtar::ServicesServer server(1234);
    
    // Create a test service
    server.addService(new SpeedService());
    
    // Run the server until something stops the program
    server.run();
}

You can then compile this program, assuming its name is testservice.cpp, with the following command:

g++-3.4 testservice.cpp -o testservice -lishtarservices -lishtarnet

Generated on Mon Oct 24 17:31:22 2005 for libishtarservices by  doxygen 1.4.2