Difference between revisions of "NaviTrack Tutorial:Creating module:Module structure"

From NAMIC Wiki
Jump to: navigation, search
 
 
(36 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Make directory: '''navitrack''' ==
+
= Classes for normal module =
 +
== Module class ==
  
* Create this directory anywhere you want on your machine
+
This class is used to configure and manage source and sink nodes.
* This directory will be the root directory for your NaviTrack
 
  
== Download NaviTrack source code ==
+
The following example class contains only essential functions for
* Change directory to '''navitrack''' you just created
+
a NaviTrack module.
* Run the following command to check out NaviTrack source tree:
 
svn co --username ivs --password ivs https://ariser.uio.no/svn/navitrack/branches/nt-brp NaviTrack
 
  
== Configure NaviTrack for compiling ==
+
MyTutorialModule.h:
* In the directory '''navitrack''', create a new directory '''NaviTrack-build'''. Now navitrack has two sub-directories: NaviTrack and NaviTrack-build
 
* Change directory to '''NaviTrack-build'''
 
* Run this command to configure NaviTrack:
 
cmake ../NaviTrack
 
(Note: Make sure you have CMake 2.4 or later installed on your system. If you don't, here is the website to get it: <br> http://www.cmake.org/HTML/Download.html)
 
  
== Build NaviTrack ==
+
#ifndef __MY_TUTORIAL_MODULE_H__
* To compile NaviTrack, in the same directory, e.g. NaviTrack-build, run:
+
#define __MY_TUTORIAL_MODULE_H__
  make
+
 +
#include <OpenTracker/OpenTracker.h>
 +
#include <OpenTracker/dllinclude.h>
 +
#include <OpenTracker/input/SPLModules.h>
 +
#include <OpenTracker/input/MyTutorialSink.h>
 +
#include <OpenTracker/input/MyTutorialSource.h>
 +
#include <string>
 +
 +
namespace ot {
 +
 +
class OPENTRACKER_API MyTutorialModule : public Module, public NodeFactory
 +
 +
  public:
 +
 
 +
  // Constructor and destructor
 +
  MyTutorialModule();
 +
  virtual ~MyTutorialModule();
 +
 
 +
  Node* createNode( const std::string& name, ot::StringTable& attributes);
 +
  void  pushEvent();
 +
  void  pullEvent() {};
 +
  void  init(StringTable&, ConfigNode *);
 +
 
 +
  private:
 +
  MyTutorialSink*  sink;
 +
  MyTutorialSource* source;
 +
 
 +
  friend class  MyTutorialSink;
 +
  friend class  MyTutorialSource;
 +
};
 +
 +
OT_MODULE(MyTutorialModule);
 +
 +
} // end of namespace ot
 +
  #endif // __MY_TUTORIAL_MODULE_H__
  
== Windows Notes ==
+
=== init() ===
 +
Function init() is called when the NaviTrack detects MyTutorialConfig in configuration section
 +
of the XML file, during starting up.
 +
You can put codes to initialize the module into this function.
 +
void MyTutorialModule::init(StringTable& attributes, ConfigNode * localTree)
 +
{
 +
  std::cout << "MyTutorialModule::init() is called." << std::endl;
 +
 +
  std::string strName=attributes.get("name");
 +
  std::cout << "MyTutorialModule::init(): attribute \"name\" is "
 +
            << strName << std::endl;
 +
}
  
=== Prerequisite software ===
+
Also, you can get a parameter in configuration section of the XML file,
 +
by calling attributes.get(<parameter name>);
  
You need to get the following packages prior to compiling NaviTrack.  While still experimental, it should work on a properly configured windows environment. Current requirements are:
+
=== createNode() ===
  
* Developer studio 8 Visual C++ Express which is free from Microsoft - be sure to install the Platform SDK and follow the ridiculous manual steps to set up the paths (see below).
+
When the NaviTrack detects either MyTutorialSource or MyTutorialSink in the XML file,
** Other releases of visual studio also work (7 and 7.1)
+
function createNode is called. The code for this function might be as following:
* [http://www.cygwin.com Cygwin] with the following packages
 
** svn
 
  
* [http://www.cmake.org CMake (2.4.1 or later)]
+
ot::Node * MyTutorialModule::createNode( const std::string& name,  ot::StringTable& attributes)
 +
{
 +
  if( name.compare("MyTutorialSink") == 0 )
 +
    {
 +
      std::string strName=attributes.get("name");
 +
      std::cout << "MyTutorialModule::createNode(): creating a MyTutorialSink node" << std::endl;       
 +
      std::cout << "MyTutorialModule::createNode(): attribute\"name\" is " << strName << std::endl;
 +
      sink =  new MyTutorialSink();
 +
      return sink;
 +
    }
 +
  if(name.compare("MyTutorialSource") == 0 )
 +
    {
 +
      std::string strName=attributes.get("name");
 +
      std::cout << "MyTutorialModule::createNode(): creating a MyTutorialSource node" << std::endl;
 +
      std::cout << "MyTutorialModule::createNode(): attribute\"name\" is " << strName << std::endl;
 +
      source = new MyTutorialSource(strName);
 +
      return source;
 +
    }
 +
  return NULL;
 +
}
  
=== Information on Free Microsoft C++ Compiler on Windows ===
+
Note that the class in above example can have only one sink node and one source node.
 +
But you can manage more than two nodes with same type, by using array or vector,
 +
since createNode is called each time the NaviTrack detects the corresponding type of node.
  
Be sure to follow '''all''' the steps on Microsoft link. Yes it means you need to download the compiler '''and''' sdk.
+
You can get any parameters specified for a certain node in XML configuration file,
 +
by calling attribute.get(<parameter name>) function, as shown in above code.
  
* http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/
+
=== pushEvent() and pullEvent() ===
 +
These are a sort of event handling function.
 +
These are called whenever a push or pull event occurs.
 +
 
 +
== Sink class ==
 +
 
 +
This class is for a Sink node itself.
 +
The following example class contains only essential functions for a Sink node.
 +
 
 +
MyTutorialSink.h:
 +
#ifndef __MY_TUTORIAL_SINK_H__
 +
#define __MY_TUTORIAL_SINK_H__
 +
 +
#include <OpenTracker/OpenTracker.h>
 +
 +
namespace ot {
 +
 
 +
  class MyTutorialSink : public ot::Node
 +
  {
 +
  public:
 +
   
 +
    MyTutorialSink();
 +
    ~MyTutorialSink();
 +
   
 +
  public:
 +
   
 +
    virtual int isEventGenerator() {return 1;};
 +
    virtual void onEventGenerated(Event&, Node&);
 +
   
 +
  };
 +
 +
} // end of namespace ot
 +
 +
#endif // end of __MY_TUTORIAL_SINK_H
 +
 
 +
=== isEventGenerator() ===
 +
This function lets NaviTrack know whether the node is event generating node.
 +
 
 +
It returns 1, if the node has event generator.
 +
 
 +
=== onEventGenerated() ===
 +
This is an event handler for generated event.
 +
 
 +
== Source class ==
 +
This class is a Source node itself. The following example class contains only essential functions for a Source node.
 +
 
 +
MyTutorialSource.h:
 +
#ifndef __MY_TUTORIAL_SOURCE_H__
 +
#define __MY_TUTORIAL_SOURCE_H__
 +
 +
#include <OpenTracker/OpenTracker.h>
 +
#include <string>
 +
 +
namespace ot {
 +
 +
  class MyTutorialSource : public Node
 +
  {
 +
  private:
 +
   
 +
  public:
 +
   
 +
    std::string StationName;
 +
   
 +
  public:
 +
    MyTutorialSource(std::string stationName) {};
 +
    virtual int isEventGenerator() {return 1;};
 +
    int changed;
 +
   
 +
    Event event;
 +
  };
 +
   
 +
} // end of namespace ot
 +
 +
#endif // __MYTUTORIAL_SOURCE_H__
 +
 
 +
=== isEventGenerator() ===
 +
This is same as isEventGenerator() in Sink class.
 +
 
 +
 
 +
Go back to [[NaviTrack_Tutorial:Creating_module|Creating module]].

Latest revision as of 23:16, 15 May 2007

Home < NaviTrack Tutorial:Creating module:Module structure

Classes for normal module

Module class

This class is used to configure and manage source and sink nodes.

The following example class contains only essential functions for a NaviTrack module.

MyTutorialModule.h:

#ifndef __MY_TUTORIAL_MODULE_H__
#define __MY_TUTORIAL_MODULE_H__

#include <OpenTracker/OpenTracker.h>
#include <OpenTracker/dllinclude.h>
#include <OpenTracker/input/SPLModules.h>
#include <OpenTracker/input/MyTutorialSink.h>
#include <OpenTracker/input/MyTutorialSource.h>
#include <string>

namespace ot {

class OPENTRACKER_API MyTutorialModule : public Module, public NodeFactory
{   
 public:
 
  // Constructor and destructor
  MyTutorialModule();
  virtual ~MyTutorialModule();
  
  Node* createNode( const std::string& name,  ot::StringTable& attributes);
  void  pushEvent();
  void  pullEvent() {};
  void  init(StringTable&, ConfigNode *);
 
 private:
  MyTutorialSink*   sink;
  MyTutorialSource* source;
  
  friend class  MyTutorialSink;
  friend class  MyTutorialSource;
};

OT_MODULE(MyTutorialModule);

} // end of namespace ot
#endif // __MY_TUTORIAL_MODULE_H__

init()

Function init() is called when the NaviTrack detects MyTutorialConfig in configuration section of the XML file, during starting up. You can put codes to initialize the module into this function.

void MyTutorialModule::init(StringTable& attributes, ConfigNode * localTree)
{
  std::cout << "MyTutorialModule::init() is called." << std::endl; 

  std::string strName=attributes.get("name");
  std::cout << "MyTutorialModule::init(): attribute \"name\" is " 
            << strName << std::endl;
}

Also, you can get a parameter in configuration section of the XML file, by calling attributes.get(<parameter name>);

createNode()

When the NaviTrack detects either MyTutorialSource or MyTutorialSink in the XML file, function createNode is called. The code for this function might be as following:

ot::Node * MyTutorialModule::createNode( const std::string& name,  ot::StringTable& attributes)
{
  if( name.compare("MyTutorialSink") == 0 )
    {
      std::string strName=attributes.get("name");
      std::cout << "MyTutorialModule::createNode(): creating a MyTutorialSink node" << std::endl;        
      std::cout << "MyTutorialModule::createNode(): attribute\"name\" is " << strName << std::endl;
      sink =  new MyTutorialSink();
      return sink;
    }
  if(name.compare("MyTutorialSource") == 0 )
    {
      std::string strName=attributes.get("name");
      std::cout << "MyTutorialModule::createNode(): creating a MyTutorialSource node" << std::endl;
      std::cout << "MyTutorialModule::createNode(): attribute\"name\" is " << strName << std::endl;
      source = new MyTutorialSource(strName);
      return source;
    }
  return NULL;
}

Note that the class in above example can have only one sink node and one source node. But you can manage more than two nodes with same type, by using array or vector, since createNode is called each time the NaviTrack detects the corresponding type of node.

You can get any parameters specified for a certain node in XML configuration file, by calling attribute.get(<parameter name>) function, as shown in above code.

pushEvent() and pullEvent()

These are a sort of event handling function. These are called whenever a push or pull event occurs.

Sink class

This class is for a Sink node itself. The following example class contains only essential functions for a Sink node.

MyTutorialSink.h:

#ifndef __MY_TUTORIAL_SINK_H__
#define __MY_TUTORIAL_SINK_H__ 

#include <OpenTracker/OpenTracker.h>

namespace ot {
  
  class MyTutorialSink : public ot::Node
  {
  public:
    
    MyTutorialSink();
    ~MyTutorialSink();
    
  public:
    
    virtual int isEventGenerator() {return 1;};
    virtual void onEventGenerated(Event&, Node&);
    
  }; 

} // end of namespace ot

#endif // end of __MY_TUTORIAL_SINK_H

isEventGenerator()

This function lets NaviTrack know whether the node is event generating node.

It returns 1, if the node has event generator.

onEventGenerated()

This is an event handler for generated event.

Source class

This class is a Source node itself. The following example class contains only essential functions for a Source node.

MyTutorialSource.h:

#ifndef __MY_TUTORIAL_SOURCE_H__
#define __MY_TUTORIAL_SOURCE_H__

#include <OpenTracker/OpenTracker.h>
#include <string>

namespace ot {

  class MyTutorialSource : public Node
  {
  private:
    
  public:
    
    std::string StationName;
    
  public:
    MyTutorialSource(std::string stationName) {};
    virtual int isEventGenerator() {return 1;};
    int changed;
    
    Event event;
  };
    
} // end of namespace ot

#endif // __MYTUTORIAL_SOURCE_H__

isEventGenerator()

This is same as isEventGenerator() in Sink class.


Go back to Creating module.