Version: 0.6.0
tcp.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: TCP network classes.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2012,2014 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/net/servernet.h"
24 #include "wxgis/net/netfactory.h"
25 
32 class WXDLLIMPEXP_GIS_NET wxServerTCPNetworkPlugin : public INetPlugin
33 {
34  DECLARE_DYNAMIC_CLASS(wxServerTCPNetworkPlugin)
35 
36  enum{
37  // id for sockets
38  UDP_SERVER_ID = 100,
39  TCP_SERVER_ID
40  };
41 public:
43  virtual ~wxServerTCPNetworkPlugin(void);
44  bool CreateUDPNotifier(void);
45  bool CreateListenSocket(void);
46  //INetPlugin
47  virtual bool Start(INetService* pNetService, const wxXmlNode* pConfig);
48  virtual bool Stop(void);
49  //events
50  virtual void OnUDPServerEvent(wxSocketEvent& event);
51  virtual void OnTCPServerEvent(wxSocketEvent& event);
52 protected:
53  int m_nPort, m_nAdvPort;
54  wxString m_sAddr;
55  INetService* m_pNetService;
56  wxDatagramSocket *m_udp_socket;
57  wxSocketServer* m_listeningSocket;
58 
59  DECLARE_EVENT_TABLE()
60 };
61 
68 class WXDLLIMPEXP_GIS_NET wxClientTCPNetConnection :
70 {
71  DECLARE_CLASS(wxClientTCPNetConnection)
72  enum{
73  // id for sockets
74  SOCKET_ID = 101
75  };
76 public:
78  virtual ~wxClientTCPNetConnection(void);
79  //INetClientConnection
80  virtual bool Connect(void);
81  virtual bool Disconnect(void);
82  virtual wxString GetName(void) const {return m_sConnName;};
83  //virtual WXGISMSG GetInMessage(void) = 0;
84  //virtual void PutInMessage(WXGISMSG msg);
85  //wxGISNetClientConnection
86  virtual bool HasAttributes(void) const {return true;};
87  virtual wxJSONValue GetAttributes(void) const;
88  virtual bool SetAttributes(const wxJSONValue& oProperties);
89  virtual wxString GetLastError(void) const;
90  //virtual void SetCallback(INetCallback* pNetCallback){m_pCallBack = pNetCallback;};
91  // virtual wxString GetUser(void){return m_sUserName;};
92  // virtual wxString GetCryptPasswd(void){return m_sCryptPass;};
93 protected:
94  //events
95  virtual void OnSocketEvent(wxSocketEvent& event);
96 protected:
97  wxString m_sConnName;
98  wxString m_sUserName;
99  wxString m_sCryptPass;
100  wxString m_sIP;
101  wxString m_sPort;
102  long m_nConnTimeout;
103 
104  //wxNetTCPReader* m_pClientTCPReader;
105  //wxNetTCPWriter* m_pClientTCPWriter;
106  //wxNetTCPWaitlost* m_pClientTCPWaitlost;
107  //INetCallback* m_pCallBack;
108 private:
109  DECLARE_EVENT_TABLE()
110 };
111 
118 class WXDLLIMPEXP_GIS_NET wxClientTCPNetFactory :
119  public INetConnFactory
120 {
121  DECLARE_DYNAMIC_CLASS(wxClientTCPNetFactory)
122  enum{
123  // id for sockets
124  BROADCAST_ID = 100
125  };
126 public:
127  wxClientTCPNetFactory(void);
128  ~wxClientTCPNetFactory(void);
129  //INetConnFactory
130  virtual wxString GetName(void) const {return wxString(_("TCP/IP Network"));};
131  virtual bool StartServerSearch();
132  virtual bool StopServerSearch();
133  virtual void Serialize(wxXmlNode* pConfigNode, bool bSave = true);
134  virtual wxGISNetClientConnection* const GetConnection(const wxJSONValue &oProperties);
135  //wxClientTCPNetFactory
136  virtual unsigned short GetAdvPort(void){return m_nAdvPort;};
137  virtual unsigned short GetPort(void){return m_nPort;};
138 protected:
139  //events
140  virtual void OnBroadcastEvent(wxSocketEvent& event);
141 protected:
142  wxDatagramSocket *m_udp_socket;
143  wxString m_sAddr;
144  unsigned short m_nPort, m_nAdvPort;
145 private:
146  DECLARE_EVENT_TABLE()
147 };
148 
The JSON value class implementation.
Definition: jsonval.h:91
The network connection factory interface class.
Definition: netfactory.h:33
The network connection interface class.
Definition: netconn.h:88
virtual bool SetAttributes(const wxJSONValue &oProperties)=0
Set Properties of plugin.
Definition: tcp.h:118
Definition: servernet.h:32
A Server side TCPNetworkPlugin.
Definition: tcp.h:32
virtual void Serialize(wxXmlNode *pConfigNode, bool bSave=true)
Store Properties of Factory.
Definition: netfactory.cpp:65
virtual wxJSONValue GetAttributes(void) const =0
Get Properties of plugin.
The network service base interface class.
Definition: netconn.h:70
Definition: tcp.h:68