KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ConnectionSubscriber.h
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
29 
30 /********************************************************************
31  class: ConnectionSubscriber
32  created: 19/10/2010
33  author: Karl Jones
34 
35  purpose: This class allows you to handle PDU in an event based manner.
36  It also allows for an IP address filter mechanisms to be created.
37  Note: Any PDU filtering should be done in the PDU_Factory.
38 
39  An example of some of the uses of the ConnectionSubscriber could be:
40  Statistics
41  EntityManager
42  IpAddressFilter
43  Logging
44 *********************************************************************/
45 
46 #pragma once
47 
48 #include "./../PDU/Header.h"
49 
50 namespace KDIS {
51 namespace NETWORK {
52 
54 {
55 public:
56 
58  {
59  };
60 
62  {
63  };
64 
65  //************************************
66  // FullName: KDIS::NETWORK::ConnectionSubscriber::OnDataReceived
67  //!Description: This function is first called when data is received on the connection,
68  //! before any decoding has been performed.
69  //! You should return true if you wish the connection to continue processing
70  //! the data(i.e decode the PDU) or false if you want it to stop and discard the data.
71  //! This means you can create a filter mechanism here for IP address.
72  // Parameter: const KOCTET * Data
73  // Parameter: KUINT32 DataLength
74  // Parameter: const KString & SenderIp
75  //************************************
76  virtual KBOOL OnDataReceived( const KOCTET * Data, KUINT32 DataLength, const KString & SenderIp )
77  {
78  return true;
79  };
80 
81  //************************************
82  // FullName: KDIS::NETWORK::ConnectionSubscriber::OnPDUReceived
83  //!Description: Called after a PDU has been decoded (GetNextPDU). Use this function to handle various PDU,
84  //! e.g a data logger or entity manager class.
85  //! Note: This function is not for filtering, for PDU based filtering see the PDU_Factory.
86  //! Note: By default this PDU will be deleted unless it is released(auto_ptr) by the function that calls GetNextPDU.
87  // Parameter: const KOCTET * Data
88  //************************************
89  virtual void OnPDUReceived( const KDIS::PDU::Header * H )
90  {
91  };
92 
93  //************************************
94  // FullName: KDIS::NETWORK::ConnectionSubscriber::OnPDUReceived
95  //!Description: Called before a PDU is transmitted over the network.
96  //! Note: This function is not for filtering, for PDU based filtering see the PDU_Factory.
97  // Parameter: const KOCTET * Data
98  //************************************
99  virtual void OnPDUTransmit( KDIS::PDU::Header * H )
100  {
101  };
102 };
103 
104 } // END namespace NETWORK
105 } // END namespace KDIS
unsigned int KUINT32
Definition: KDefines.h:103
virtual KBOOL OnDataReceived(const KOCTET *Data, KUINT32 DataLength, const KString &SenderIp)
Definition: ConnectionSubscriber.h:76
virtual void OnPDUReceived(const KDIS::PDU::Header *H)
Definition: ConnectionSubscriber.h:89
Definition: ConnectionSubscriber.h:53
virtual ~ConnectionSubscriber()
Definition: ConnectionSubscriber.h:61
virtual void OnPDUTransmit(KDIS::PDU::Header *H)
Definition: ConnectionSubscriber.h:99
bool KBOOL
Definition: KDefines.h:119
std::string KString
Definition: KDefines.h:116
Definition: Header7.h:142
char KOCTET
Definition: KDefines.h:108
#define KDIS_EXPORT
Definition: KDefines.h:82
ConnectionSubscriber()
Definition: ConnectionSubscriber.h:57