KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PDU_Factory.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: PDU_Factory
32  created: 06/12/2008
33  author: Karl Jones
34 
35  purpose: Using a factory design pattern to decode a data stream to
36  the correct PDU type.
37 *********************************************************************/
38 
39 #pragma once
40 
41 #include <memory>
42 #include <vector>
43 #include "./../PDU/Header.h"
44 #include "./PDU_Factory_Filters.h"
45 
46 namespace KDIS {
47 namespace UTILS {
48 
50 {
51 protected:
52 
53  std::vector<PDU_Factory_Filter*> m_vFilters;
54 
55  //************************************
56  // FullName: KDIS::UTILS::PDU_Factory::applyFilters
57  //!Description: Applies the filter/s to the PDU and returns a NULL
58  //! pointer if the PDU does not pass all filters.
59  // Parameter: Header * H
60  //************************************
61  std::auto_ptr<KDIS::PDU::Header> applyFilters( KDIS::PDU::Header * H );
62 
63 public:
64 
65  PDU_Factory();
66 
67  ~PDU_Factory();
68 
69  //************************************
70  // FullName: KDIS::UTILS::PDU_Factory::AddFilter
71  //!Description: Add a filter that will be applied to all PDU's.
72  //! Note: All filters will be automatically deleted when the PDU factory is deleted.
73  // Parameter: PDU_Factory_Filter * F
74  //************************************
75  void AddFilter( PDU_Factory_Filter * F );
76 
77  //************************************
78  // FullName: KDIS::UTILS::PDU_Factory::RemoveFilter
79  //!Description: Remove a filter.
80  // Parameter: PDU_Factory_Filters * F
81  //************************************
82  void RemoveFilter( PDU_Factory_Filter * F );
83 
84  //************************************
85  // FullName: KDIS::UTILS::PDU_Factory::Decode
86  //!Description: Converts a stream of OCTETS into the correct PDU type.
87  //! If the PDU type is unknown or not currently
88  //! implemented in KDIS a NULL auto_ptr is returned.
89  // Parameter: KOCTET * Buffer
90  // Parameter: KUINT16 BufferSize
91  //************************************
92  virtual std::auto_ptr<KDIS::PDU::Header> Decode( KOCTET * Buffer, KUINT16 BufferSize )throw( KException );
93 
94  //************************************
95  // FullName: KDIS::UTILS::PDU_Factory::Decode
96  //!Description: Converts data stream into the correct PDU type.
97  //! If the PDU type is unknown or not currently
98  //! implemented a NULL auto_ptr is returned.
99  // Parameter: KDataStream & Stream
100  //************************************
101  virtual std::auto_ptr<KDIS::PDU::Header> Decode( KDataStream & Stream )throw( KException );
102 
103  //************************************
104  // FullName: KDIS::UTILS::PDU_Factory::Decode
105  //!Description: Converts data stream into the correct PDU.
106  //! This version takes a known PDU and decodes just the body.
107  //! Note: If you wanted to add support for your own PDU this would be a great
108  //! place to add it, just override this function and check for your PDU first,
109  //! if the PDU is not yours then call the parent function.
110  // Parameter: const Header & H
111  // Parameter: KDataStream & Stream
112  //************************************
113  virtual std::auto_ptr<KDIS::PDU::Header> Decode( const KDIS::PDU::Header & H, KDataStream & Stream )throw( KException );
114 };
115 
116 } // END namespace UTILS
117 } // END namespace KDIS
unsigned short int KUINT16
Definition: KDefines.h:101
Definition: PDU_Factory.h:49
Definition: PDU_Factory_Filters.h:52
Definition: KDefines.h:182
std::vector< PDU_Factory_Filter * > m_vFilters
Definition: PDU_Factory.h:53
Definition: KDataStream.h:48
Definition: Header7.h:142
char KOCTET
Definition: KDefines.h:108
#define KDIS_EXPORT
Definition: KDefines.h:82