<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to PDU_Factory_Tutorial</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>Recent changes to PDU_Factory_Tutorial</description><atom:link href="https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 18 Nov 2015 10:05:57 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/feed" rel="self" type="application/rss+xml"/><item><title>PDU_Factory_Tutorial modified by Karl  Jones</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v5
+++ v6
@@ -89,7 +89,7 @@

     if( pHeader-&amp;gt;GetProtocolFamily() == Entity_Infomation_Interaction )
     {
-       cout &amp;lt;Entity_State_PDU*&amp;gt;( pHeader.get() );
+    Entity_State_PDU * pES = dynamic_cast&amp;lt;Entity_State_PDU*&amp;gt;( pHeader.get() );
     if( pES )
     {
        // Upcast was successful, now what?
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl  Jones</dc:creator><pubDate>Wed, 18 Nov 2015 10:05:57 -0000</pubDate><guid>https://sourceforge.net3b261693ee94af35e63b8f83dc9409127a98dbaa</guid></item><item><title>PDU_Factory_Tutorial modified by Karl  Jones</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -30,8 +30,15 @@
     PDU_Factory Factory;

-  
+### Add a filter

+    In version **1-15-0** and onwards it is possible to add a filter to the PDU factory. 
+    
+    // Lets apply a filter to the factory so it only lets through PDU that have an exercise ID of 1.
+    Factory.AddFilter( new FactoryFilterExerciseID( 1 ) );
+    
+
+     See [Creating_Custom_PDU_Factory_Filters] for further details on filters. 

 ## Decode a PDU

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl  Jones</dc:creator><pubDate>Fri, 27 Jun 2014 12:06:11 -0000</pubDate><guid>https://sourceforge.net49be8f7d05f2fe2495b100acd1571eee7883ae7d</guid></item><item><title>PDU_Factory_Tutorial modified by Karl  Jones</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl  Jones</dc:creator><pubDate>Fri, 27 Jun 2014 12:06:11 -0000</pubDate><guid>https://sourceforge.netb0a538440a451a83cd4257fe5dad6faad073307d</guid></item><item><title>PDU_Factory_Tutorial modified by Karl  Jones</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -2,63 +2,83 @@

 ## Intro

-The **PDU_Factory** is based on the [Factory Design Pattern](http://en.wikipedia.org/wiki/Factory_design_pattern)
+    The **PDU_Factory** is based on the [Factory Design Pattern](http://en.wikipedia.org/wiki/Factory_design_pattern)

-The **PDU_Factory** converts any DIS network packet into its correct PDU format and returns this PDU as a safe pointer to the PDU base class(_Header_). 
+    The **PDU_Factory** converts any DIS network packet into its correct PDU format and returns this PDU as a safe pointer to the PDU base class(_Header_). 

-**Note:** An example of using the **PDU_Factory** can also be found in the examples folder that comes with the KDIS distribution. 
+    **Note:** An example of using the **PDU_Factory** can also be found in the examples folder that comes with the KDIS distribution. 
+
+  
+

 ## Includes

-We first need to include the relevant header file/s. 
+    We first need to include the relevant header file/s. 

-We need to include the PDU_Factory.h which can be found in the _KDIS/Extras_ folder. 
+    We need to include the PDU_Factory.h which can be found in the _KDIS/Extras_ folder. 

     #include "KDIS/Extras/PDU_Factory.h"

+  
+
+
 ## Create the PDU_Factory

-We first need to create a **PDU_Factory** object. 
+    We first need to create a **PDU_Factory** object. 

     PDU_Factory Factory;

+  
+
+
 ## Decode a PDU

-We are now ready to start decoding DIS data. 
+    We are now ready to start decoding DIS data. 

-**Note:** I do not cover the use of sockets in this tutorial but the PDU_Factory example does come with some simple sockets that will work in Windows only. 
+    **Note:** I do not cover the use of sockets in this tutorial but the PDU_Factory example does come with some simple sockets that will work in Windows only. 

-The DIS network data should have been received in a char array format. in this example a KOCTET represents a char datatype. 
+    The DIS network data should have been received in a char array format. in this example a KOCTET represents a char datatype. 

     KOCTET cBuffer[MAX_PDU_SIZE]; // This is our buffer

-**Note:** MAX_PDU_SIZE is defined in KDefines.h, it is the maximun size a PDU can be in DIS. It should be safe to use this value for your buffer/s. 
+    **Note:** MAX_PDU_SIZE is defined in KDefines.h, it is the maximun size a PDU can be in DIS. It should be safe to use this value for your buffer/s. 

-Once some DIS data has been received into the buffer we can use the **PDU_Factory** to decode it. 
+    Once some DIS data has been received into the buffer we can use the **PDU_Factory** to decode it. 

     auto_ptr&amp;lt;Header&amp;gt; pHeader = Factory.Decode( cBuffer, ui32Recv ); // ui32Recv should be the size of the data packet received.

+  
+
+
 ## What do i do with the auto_ptr

-We now have a auto_ptr to the base class of our PDU. The auto_ptr is a safe pointer belonging to the STL. 
+    We now have a auto_ptr to the base class of our PDU. The auto_ptr is a safe pointer belonging to the STL. 

-When the auto_ptr object goes out of scope it will delete the pointer contained within thus preventing memory leaks. 
+    When the auto_ptr object goes out of scope it will delete the pointer contained within thus preventing memory leaks. 

-We now have 2 options. 
+    We now have 2 options. 
+
+  
+

 ### Do nothing

-We could just let the object expire if we are not interested in it, we do not need to do anything, the auto_ptr will clean up memory when it goes out of scope. 
+    We could just let the object expire if we are not interested in it, we do not need to do anything, the auto_ptr will clean up memory when it goes out of scope. 
+
+  
+

 ### Check For a Certain Type Of PDU

 #### Example 1

-E.G if we only wanted PDU that belonged to the _Entity Info Interaction_ protocol family we could do the following: 
+    
+
+  * E.G if we only wanted PDU that belonged to the _Entity Info Interaction_ protocol family we could do the following: 

     if( pHeader-&amp;gt;GetProtocolFamily() == Entity_Infomation_Interaction )
     {
@@ -69,18 +89,20 @@
     }

-This method is fine providing we don’t mind the PDU being deleted once we go out of scope, but what is we wanted to keep the PDU? 
+    This method is fine providing we don’t mind the PDU being deleted once we go out of scope, but what is we wanted to keep the PDU? 

 #### Take Ownership

-We can prevent the auto_ptr from deleting the PDU pointer when it goes out of scope by taking ownership of the pointer. 
+    We can prevent the auto_ptr from deleting the PDU pointer when it goes out of scope by taking ownership of the pointer. 

-We do this using the _release_ function. 
+    We do this using the _release_ function. 

-E.G if we wanted the contents of a Entity_State_PDU: 
+    
+
+  * E.G if we wanted the contents of a Entity_State_PDU: 

     Entity_State_PDU * pES = dynamic_cast&amp;lt;Entity_State_PDU*&amp;gt;( pHeader.release() );
     if( pES )
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl  Jones</dc:creator><pubDate>Fri, 27 Jun 2014 12:06:10 -0000</pubDate><guid>https://sourceforge.neta2863f0b9f4d51958b1df518ffb787cb16f9fb43</guid></item><item><title>PDU_Factory_Tutorial modified by Karl  Jones</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -24,9 +24,11 @@
     PDU_Factory Factory;

-## Decode A PDU
+## Decode a PDU

-We are now ready to start decoding DIS data. **Note:** I do not cover the use of sockets in this tutorial but the PDU_Factory example does come with some simple sockets that will work in Windows only. 
+We are now ready to start decoding DIS data. 
+
+**Note:** I do not cover the use of sockets in this tutorial but the PDU_Factory example does come with some simple sockets that will work in Windows only. 

 The DIS network data should have been received in a char array format. in this example a KOCTET represents a char datatype. 

@@ -40,9 +42,11 @@
     auto_ptr&amp;lt;Header&amp;gt; pHeader = Factory.Decode( cBuffer, ui32Recv ); // ui32Recv should be the size of the data packet received.

-## Upcast The Pointer
+## What do i do with the auto_ptr

-We now have a auto_ptr to the base class of our PDU. The auto_ptr is a safe pointer belonging to the STL. When the auto_ptr object goes out of scope it will delete the pointer contained within thus preventing memory leaks. 
+We now have a auto_ptr to the base class of our PDU. The auto_ptr is a safe pointer belonging to the STL. 
+
+When the auto_ptr object goes out of scope it will delete the pointer contained within thus preventing memory leaks. 

 We now have 2 options. 

@@ -59,8 +63,6 @@
     if( pHeader-&amp;gt;GetProtocolFamily() == Entity_Infomation_Interaction )
     {
        cout &amp;lt;Entity_State_PDU*&amp;gt;( pHeader.get() );
-    
-    
     if( pES )
     {
        // Upcast was successful, now what?
@@ -72,15 +74,15 @@

-##### Take Ownership
+#### Take Ownership

-We can prevent the auto_ptr from deleting the PDU pointer when it goes out of scope by taking ownership of the pointer. We do this using the _release_ function. 
+We can prevent the auto_ptr from deleting the PDU pointer when it goes out of scope by taking ownership of the pointer. 
+
+We do this using the _release_ function. 

 E.G if we wanted the contents of a Entity_State_PDU: 

     Entity_State_PDU * pES = dynamic_cast&amp;lt;Entity_State_PDU*&amp;gt;( pHeader.release() );
-    
-    
     if( pES )
     {
        // Upcast was successful and we now have complete ownership of it. Don’t forget to delete it when you are finished. delete pES;
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl  Jones</dc:creator><pubDate>Fri, 27 Jun 2014 12:06:10 -0000</pubDate><guid>https://sourceforge.net0d4b43c7cfad661661ceb9492829ce7492cea540</guid></item><item><title>PDU_Factory_Tutorial modified by Karl  Jones</title><link>https://sourceforge.net/p/kdis/wiki/PDU_Factory_Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#intro"&gt;Intro&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#includes"&gt;Includes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#create-the-pdu_factory"&gt;Create the PDU_Factory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#decode-a-pdu"&gt;Decode A PDU&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#upcast-the-pointer"&gt;Upcast The Pointer&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#do-nothing"&gt;Do nothing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#check-for-a-certain-type-of-pdu"&gt;Check For a Certain Type Of PDU&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#example-1"&gt;Example 1&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#take-ownership"&gt;Take Ownership&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="intro"&gt;Intro&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;PDU_Factory&lt;/strong&gt; is based on the &lt;a class="" href="http://en.wikipedia.org/wiki/Factory_design_pattern" rel="nofollow"&gt;Factory Design Pattern&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;PDU_Factory&lt;/strong&gt; converts any DIS network packet into its correct PDU format and returns this PDU as a safe pointer to the PDU base class(&lt;em&gt;Header&lt;/em&gt;). &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; An example of using the &lt;strong&gt;PDU_Factory&lt;/strong&gt; can also be found in the examples folder that comes with the KDIS distribution. &lt;/p&gt;
&lt;h2 id="includes"&gt;Includes&lt;/h2&gt;
&lt;p&gt;We first need to include the relevant header file/s. &lt;/p&gt;
&lt;p&gt;We need to include the PDU_Factory.h which can be found in the &lt;em&gt;KDIS/Extras&lt;/em&gt; folder. &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="c"&gt;#include &amp;quot;KDIS/Extras/PDU_Factory.h&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="create-the-pdu_factory"&gt;Create the PDU_Factory&lt;/h2&gt;
&lt;p&gt;We first need to create a &lt;strong&gt;PDU_Factory&lt;/strong&gt; object. &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;PDU_Factory&lt;/span&gt; &lt;span class="n"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="decode-a-pdu"&gt;Decode A PDU&lt;/h2&gt;
&lt;p&gt;We are now ready to start decoding DIS data. &lt;strong&gt;Note:&lt;/strong&gt; I do not cover the use of sockets in this tutorial but the PDU_Factory example does come with some simple sockets that will work in Windows only. &lt;/p&gt;
&lt;p&gt;The DIS network data should have been received in a char array format. in this example a KOCTET represents a char datatype. &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;KOCTET&lt;/span&gt; &lt;span class="n"&gt;cBuffer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MAX_PDU_SIZE&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// This is our buffer&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; MAX_PDU_SIZE is defined in KDefines.h, it is the maximun size a PDU can be in DIS. It should be safe to use this value for your buffer/s. &lt;/p&gt;
&lt;p&gt;Once some DIS data has been received into the buffer we can use the &lt;strong&gt;PDU_Factory&lt;/strong&gt; to decode it. &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;auto_ptr&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;Header&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;pHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;cBuffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ui32Recv&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ui32Recv should be the size of the data packet received.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="upcast-the-pointer"&gt;Upcast The Pointer&lt;/h2&gt;
&lt;p&gt;We now have a auto_ptr to the base class of our PDU. The auto_ptr is a safe pointer belonging to the STL. When the auto_ptr object goes out of scope it will delete the pointer contained within thus preventing memory leaks. &lt;/p&gt;
&lt;p&gt;We now have 2 options. &lt;/p&gt;
&lt;h3 id="do-nothing"&gt;Do nothing&lt;/h3&gt;
&lt;p&gt;We could just let the object expire if we are not interested in it, we do not need to do anything, the auto_ptr will clean up memory when it goes out of scope. &lt;/p&gt;
&lt;h3 id="check-for-a-certain-type-of-pdu"&gt;Check For a Certain Type Of PDU&lt;/h3&gt;
&lt;h4 id="example-1"&gt;Example 1&lt;/h4&gt;
&lt;p&gt;E.G if we only wanted PDU that belonged to the &lt;em&gt;Entity Info Interaction&lt;/em&gt; protocol family we could do the following: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;pHeader&lt;/span&gt;&lt;span class="o"&gt;-&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;GetProtocolFamily&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;Entity_Infomation_Interaction&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;Entity_State_PDU&lt;/span&gt;&lt;span class="o"&gt;*&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;(&lt;/span&gt; &lt;span class="n"&gt;pHeader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;pES&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// Upcast was successful, now what?&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This method is fine providing we don’t mind the PDU being deleted once we go out of scope, but what is we wanted to keep the PDU? &lt;/p&gt;
&lt;h5 id="take-ownership"&gt;Take Ownership&lt;/h5&gt;
&lt;p&gt;We can prevent the auto_ptr from deleting the PDU pointer when it goes out of scope by taking ownership of the pointer. We do this using the &lt;em&gt;release&lt;/em&gt; function. &lt;/p&gt;
&lt;p&gt;E.G if we wanted the contents of a Entity_State_PDU: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;Entity_State_PDU&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;pES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dynamic_cast&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;Entity_State_PDU&lt;/span&gt;&lt;span class="o"&gt;*&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;(&lt;/span&gt; &lt;span class="n"&gt;pHeader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;pES&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// Upcast was successful and we now have complete ownership of it. Don’t forget to delete it when you are finished. delete pES;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl  Jones</dc:creator><pubDate>Fri, 27 Jun 2014 12:06:10 -0000</pubDate><guid>https://sourceforge.net4ff33e68998cff2f28ac31a7b7d6f6950df2079b</guid></item></channel></rss>