00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _agentx_h_
00023 #define _agentx_h_
00024
00025
00026 #include <agent_pp/agent++.h>
00027 #include <agentx_pp/agentx_def.h>
00028 #include <agentx_pp/agentx_pdu.h>
00029 #include <agentx_pp/agentx_queue.h>
00030 #include <agentx_pp/agentx_peer.h>
00031 #include <agentx_pp/agentx_session.h>
00032 #include <agentx_pp/agentx_threads.h>
00033
00034
00035 #define AGENTX_UNIX_SOCKET_STALE 30
00036
00037 #ifndef WIN32
00038 #define AX_UNIX_SOCKET
00039 #endif
00040 #define AX_TCP_SOCKET
00041
00042
00043
00044
00045
00046 #ifdef AGENTPP_NAMESPACE
00047 namespace Agentpp {
00048 #endif
00049
00050
00051
00058 #if !defined (AGENTXPP_DECL_TEMPL_LIST_AGENTXPEER)
00059 #define AGENTXPP_DECL_TEMPL_LIST_AGENTXPEER
00060 AGENTXPP_DECL_TEMPL template class AGENTXPP_DECL List<AgentXPeer>;
00061 #endif
00062
00063 class AGENTXPP_DECL AgentX {
00064
00065 public:
00066
00070 AgentX();
00071
00075 virtual ~AgentX();
00076
00086 void set_connect_mode(int m) { connectMode = m; }
00087
00096 int get_connect_mode() { return connectMode; }
00097
00098 #ifdef AX_UNIX_SOCKET
00099
00105 void set_unix_port_loc(const NS_SNMP OctetStr&);
00106 #endif
00107
00108 #ifdef AX_TCP_SOCKET
00109
00115 void set_tcp_port(int);
00116 #endif
00117
00123 virtual boolean quit() { return stopit; }
00124
00130 virtual void reinit() { stopit = FALSE; }
00131
00132
00144 virtual int send_agentx(int, const AgentXPdu&);
00145
00157 virtual int receive_agentx(int, AgentXPdu&);
00158
00165 virtual ListCursor<AgentXPeer> peers();
00166
00177 virtual AgentXPeer* remove_peer(const AgentXPeer&);
00178
00179 #ifdef AX_UNIX_SOCKET
00180
00186 virtual boolean bind_unix() = 0;
00187
00194 int get_unix_socket();
00195 #endif
00196
00197 #ifdef AX_TCP_SOCKET
00198
00204 virtual boolean bind_tcp() = 0;
00205
00212 int get_tcp_socket();
00213
00214 #endif
00215
00216 int set_file_descriptors(fd_set*);
00217 boolean check_peer_closed(fd_set*);
00218
00219 void lock_socket();
00220 void unlock_socket();
00221
00222
00223 void lock_queue() { axQueue.lock(); }
00224 void unlock_queue() { axQueue.unlock(); }
00225
00226 void lock_peers() { axPeersLock.lock(); }
00227 void unlock_peers() { axPeersLock.unlock(); }
00228
00229 AgentXQueue* get_queue() { return &axQueue; }
00230
00242 virtual boolean is_response(const AgentXPdu&,
00243 const AgentXPdu&) = 0;
00244
00255 void close_session(const AgentXSession&, u_int,
00256 u_char);
00257
00266 void ping_session(const AgentXSession&, u_int);
00267
00282 static time_t compute_timeout(u_int, u_int = 0);
00283
00284 boolean stopit;
00285
00286 protected:
00287
00288
00289 #ifdef AX_TCP_SOCKET
00290 int axTCPSocket;
00291 int axTCPPort;
00292 #endif
00293 #ifdef AX_UNIX_SOCKET
00294 int axSocket;
00295 NS_SNMP OctetStr axUnixSocketLocation;
00296 #endif
00297 AgentXQueue axQueue;
00298 List<AgentXPeer> axPeers;
00299 Synchronized axPeersLock;
00300
00301 Synchronized axSocketLock;
00302
00303 int connectMode;
00304 };
00305
00306
00307
00308 class AGENTXPP_DECL AgentXMaster: public AgentX {
00309
00310 public:
00311 AgentXMaster();
00312
00313 virtual ~AgentXMaster();
00314
00321 void set_timeout(int t) { timeout = t; }
00322
00323 #ifdef AX_UNIX_SOCKET
00324 virtual int bind_unix();
00325 #endif
00326
00327 #ifdef AX_TCP_SOCKET
00328 virtual int bind_tcp();
00329 #endif
00330
00339 virtual void connect_request(fd_set*, int*);
00340
00352 virtual boolean is_response(const AgentXPdu&,
00353 const AgentXPdu&);
00354
00355 protected:
00356
00364 #ifdef AX_UNIX_SOCKET
00365 virtual int accept_unix();
00366 #endif
00367 int timeout;
00368
00375 virtual boolean validate_address(const NS_SNMP OctetStr&) const;
00376 };
00377
00378
00379
00380 class AGENTXPP_DECL AgentXSlave: public AgentX {
00381
00382 public:
00383
00384 AgentXSlave();
00385 virtual ~AgentXSlave();
00386
00387 #ifdef AX_UNIX_SOCKET
00388 virtual boolean bind_unix();
00389 #endif
00390
00391 #ifdef AX_TCP_SOCKET
00392
00399 void set_master_address(const NS_SNMP UdpAddress& addr)
00400 { masterAddress = addr; }
00401
00402 virtual boolean bind_tcp();
00403 #endif
00404
00418 virtual AgentXPdu* receive(const u_int, int&);
00419
00428 virtual int send(const AgentXPdu&);
00429
00440 virtual int send_synch(AgentXPdu&, AgentXPdu&);
00441
00451 virtual int open_session(AgentXSession&);
00452
00464 virtual boolean is_response(const AgentXPdu&,
00465 const AgentXPdu&);
00466
00467 void lock_rcv_socket();
00468 void unlock_rcv_socket();
00469
00477 int get_socket() { return axSlaveSocket; }
00478
00479 protected:
00480
00481 int axSlaveSocket;
00482
00483 typedef enum { UNCONNECTED, UNIX, TCP } ConnectionType;
00484
00485 ConnectionType connectionType;
00486
00487 #ifdef AX_TCP_SOCKET
00488 NS_SNMP UdpAddress masterAddress;
00489 #endif
00490
00491 };
00492
00493 #ifdef AGENTPP_NAMESPACE
00494 }
00495 #endif
00496
00497 #endif