[[Tutorial]]
// This page was translated by Tafifet

Up:[[Tutorial]]

----

The aim of this tutorial is to explain how to create a service provider for SIGVerse using Microsoft Visual Studio.

We will create a simple service provider as example to send messages to a specified entity of the SIGVerse virtual world from the client side to the server side. 

Microsoft Visual Studio 2008 will be used as a development tool.  



#contents


* Creation of the Service Provider [#uc0b86f0]
** Downloading the libraries [#uc0b86v5]

We first need to download SIGVerse libraries, to do so, go to the [[service libraries]] web page and download the appropriate version. 

** Creating a new project [#uc0b86v7]
Now let's create a new project on MVS 2008.

Go to: File -> New Project , then select Empty Project, enter the project name "MyService" and press Ok.

Right click on Source Files -> Add -> New Item -> C++ File (.cpp), then enter "MyService.cpp" in the Name field.

** Service sample [#uc0b86v8]

Now let's create our example.

Copy/past the following code to MyService.cpp file:

MyService.cpp

#highlight(cpp){{

#include "SIGService.h"

int main(int argc, char** argv)
{
	// Create an instance of the service class with the specified service name
	sigverse::SIGService srv("MyService");

	// connect to the server using host/port
	srv.connect("hostname", 9001);  

	// Send the message "Hello" to the "man_000" entity  
	srv.sendMsg("man_000", "Hello");

	// disconnect from the server
	srv.disconnect();

	return 0;
}
}}


Replace the hostname and port number with your server arguments.


** Setting the library [#v01acfa7]
Extract the libraries in MyService project directory.

Go to the MVS, Right click on the project, and go to properties.

*** Add the include directory [#v01acfa8]
-Go to Configuration Properties -> C/C++ -> General -> Additional Include Directories, and specify the following path: 
--"..\SIGService_v2-1-0\include" 

*** Add the library directory [#v01acfa9]
-Then, go to linker -> General -> Additional Library Directories, and add the following path: 
--"..\SIGService_v2-1-0\lib\Debug" 

*** Add the "SIGService.lib" library [#v01acfa8]
*** Add the "SIGService.lib" library [#v01acfb8]
-In Linker -> Input -> Additional Dependencies, and add the following library:
--SIGService.lib 

* Server [#uc0b8445]

In the server side, we have to create the controller and the world file.


** Controller [#uc0b8445]
controller.cpp


#highlight(cpp){{

#include "Controller.h"  
#include <ControllerEvent.h>
#include "Logger.h"  
  
#define PI 3.141592  
  

#define DEG2RAD(DEG) ( (PI) * (DEG) / 180.0 )   
  
class AgentController : public Controller  
{  
public:  
  double onAction(ActionEvent &evt);  
  void   onRecvMsg(RecvMsgEvent &evt);
};   
  
 
double AgentController::onAction(ActionEvent &evt)  
{  
  try {  

    SimObj *my = getObj(myname());  
    if (!my->dynamics()) {   
      my->setJointAngle("LARM_JOINT2", DEG2RAD(45));  
   }  
  
 } catch(SimObj::Exception &) {  
   ;  
 }  
  
 return 5.0;  
}  


  void AgentController::onRecvMsg(RecvMsgEvent &evt)
{
  char *all_msg = (char*)evt.getMsg();
  std::string msg;
  msg= evt.getMsg();
  LOG_MSG((msg.c_str()));
}
  
extern "C"  Controller * createController ()  
{  
  return new AgentController;  
}  

}}



** World file [#uc0b8446]
worl.xml

#highlight(xml){{
<?xml version="1.0" encoding="utf8"?>
 <world name="myworld2">
 
   <gravity x="0.0" y="-980.7" z="0.0"/>  
   <instanciate class="Man-nii.xml"> 
         <set-attr-value name="name" value="man_000"/> 
         <set-attr-value name="language" value="c++"/> 
         <set-attr-value name="implementation"
 value="./controller.so"/> 
        <set-attr-value name="dynamics" value="false"/> 
        <set-attr-value name="x" value="0.0"/>
        <set-attr-value name="y" value="57.0"/>
        <set-attr-value name="z" value="0.0"/>
 
  </instanciate>
</world>
}}

* Running the service [#uc0b8444]
- Server side:

In the server side, compile and run the the controller:

 $ cd path-to-the-controller
 $ make
 $ sigserver.sh -w ./world.xml

- In the client side:

-- Run SIGViewer
-- Start the service provider

In the server side you will see the following message:

 $ [MSG]  man_000(0.0.0.0) Hello

* Registering the plugin [#uc0b8s46]

To register the plugin in SIGViewer, you have to follow these steps:

1- Rename the MyService.exe in debug directory to MyService.sig.

2- Run SIGVIewer, go to Services -> Add, then click on Add button.

3- Select the path to the MyService.sig file and press OK.


#ref(./MyService.PNG,80%)


4- To run the service, go to Services -> Start -> MyService.sig.


#highlight(end)
#counter


Front page   New List of pages Search Recent changes   Help   RSS of recent changes