<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.na-mic.org/w/index.php?action=history&amp;feed=atom&amp;title=NaviTrack_Tutorial%3ACreating_module%3AModule_structure_with_thread</id>
	<title>NaviTrack Tutorial:Creating module:Module structure with thread - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.na-mic.org/w/index.php?action=history&amp;feed=atom&amp;title=NaviTrack_Tutorial%3ACreating_module%3AModule_structure_with_thread"/>
	<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=NaviTrack_Tutorial:Creating_module:Module_structure_with_thread&amp;action=history"/>
	<updated>2026-04-08T10:12:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=NaviTrack_Tutorial:Creating_module:Module_structure_with_thread&amp;diff=10451&amp;oldid=prev</id>
		<title>Tokuda at 23:15, 15 May 2007</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=NaviTrack_Tutorial:Creating_module:Module_structure_with_thread&amp;diff=10451&amp;oldid=prev"/>
		<updated>2007-05-15T23:15:34Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Classes for thread module =&lt;br /&gt;
== Module class ==&lt;br /&gt;
In a thread module, the only difference from a normal module&lt;br /&gt;
is a module class, where a thread is implemented.&lt;br /&gt;
&lt;br /&gt;
MyTutorialThreadModule.h&lt;br /&gt;
 #ifndef __MY_TUTORIAL_THREAD_MODULE_H__&lt;br /&gt;
 #define __MY_TUTORIAL_THREAD_MODULE_H__ &lt;br /&gt;
 &lt;br /&gt;
 #include &amp;lt;OpenTracker/OpenTracker.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;OpenTracker/dllinclude.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;OpenTracker/input/SPLModules.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;OpenTracker/input/MyTutorialThreadSink.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;OpenTracker/input/MyTutorialThreadSource.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;string&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 namespace ot { &lt;br /&gt;
 &lt;br /&gt;
 class OPENTRACKER_API MyTutorialThreadModule : public ThreadModule, public NodeFactory&lt;br /&gt;
 {&lt;br /&gt;
  private:&lt;br /&gt;
   int stop;&lt;br /&gt;
 &lt;br /&gt;
  protected:&lt;br /&gt;
   void run();&lt;br /&gt;
 &lt;br /&gt;
  public:&lt;br /&gt;
   &lt;br /&gt;
   // Constructor and destructor&lt;br /&gt;
   MyTutorialThreadModule();&lt;br /&gt;
   virtual ~MyTutorialThreadModule();&lt;br /&gt;
   &lt;br /&gt;
   Node* createNode(const std::string&amp;amp; name,  ot::StringTable&amp;amp; attributes);&lt;br /&gt;
   void  pushEvent();&lt;br /&gt;
   void  pullEvent() {};&lt;br /&gt;
   void  init(StringTable&amp;amp;, ConfigNode *); &lt;br /&gt;
 &lt;br /&gt;
   virtual void  start();&lt;br /&gt;
   virtual void  close();&lt;br /&gt;
   &lt;br /&gt;
  private:&lt;br /&gt;
   &lt;br /&gt;
   MyTutorialThreadSink*   sink;&lt;br /&gt;
   MyTutorialThreadSource* source;&lt;br /&gt;
   &lt;br /&gt;
   friend class  MyTutorialThreadSink;&lt;br /&gt;
   friend class  MyTutorialThreadSource;&lt;br /&gt;
 };&lt;br /&gt;
 OT_MODULE(MyTutorialThreadModule);&lt;br /&gt;
  &lt;br /&gt;
 &lt;br /&gt;
 } // end of namespace ot &lt;br /&gt;
 &lt;br /&gt;
 #endif // __MY_TUTORIAL_THREAD_MODULE_H__&lt;br /&gt;
 &lt;br /&gt;
The differences from MyTutorialModule.h is :&lt;br /&gt;
# MyTutorialThreadModule inherits ThreadModule instead of Module class.&lt;br /&gt;
# init(): ThreadModule::init() needs to be called in init() for threading.&lt;br /&gt;
# run(): a main part of the thread.&lt;br /&gt;
# start(): a function to start the thread.&lt;br /&gt;
# close(): a function to stop the thread.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== init() ===&lt;br /&gt;
 void MyTutorialThreadModule::init(StringTable&amp;amp; attributes, ConfigNode * localTree)&lt;br /&gt;
 {&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; &amp;quot;MyTutorialThreadModule::init() is called.&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
   ThreadModule::init( attributes, localTree );      &lt;br /&gt;
   &lt;br /&gt;
   std::string strName=attributes.get(&amp;quot;name&amp;quot;);&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; &amp;quot;MyTutorialThreadModule::init(): attribute \&amp;quot;name\&amp;quot; is &amp;quot; &lt;br /&gt;
             &amp;lt;&amp;lt; strName &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== run() ===&lt;br /&gt;
 void MyTutorialThreadModule::run()&lt;br /&gt;
 {&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; &amp;quot;MyTutorialThreadModule::run() is called.&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
   while (stop == 0) {&lt;br /&gt;
     sleep(1);&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;MyTutorialThreadModule::run(): looping.&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== start() ===&lt;br /&gt;
 void MyTutorialThreadModule::start()&lt;br /&gt;
 {&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; &amp;quot;MyTutorialThreadModule::start() is called.&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
   stop = 0;&lt;br /&gt;
   if (isInitialized() &amp;amp;&amp;amp; source != NULL)&lt;br /&gt;
     ThreadModule::start();&lt;br /&gt;
 }&lt;br /&gt;
NOTE that start() function may be called even if the module is not&lt;br /&gt;
specified in the configuration XML file.&lt;br /&gt;
Therefore, you should explicitly check if the module is used before&lt;br /&gt;
calling ThreadModule::start().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== close() ===&lt;br /&gt;
 void MyTutorialThreadModule::close()&lt;br /&gt;
 {&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; &amp;quot;MyTutorialThreadModule::close() is called.&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
   lock();&lt;br /&gt;
   stop = 1;&lt;br /&gt;
   unlock();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Sink class ==&lt;br /&gt;
Same as MyTutorialSink.&lt;br /&gt;
&lt;br /&gt;
== Source class ==&lt;br /&gt;
Same as MyTutorialSource.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Go back to [[NaviTrack_Tutorial:Creating_module|Creating module]].&lt;/div&gt;</summary>
		<author><name>Tokuda</name></author>
		
	</entry>
</feed>