00001 /*_############################################################################ 00002 _## 00003 _## agentx_session.h 00004 _## 00005 _## 00006 _## AgentX++ v1.4.17 00007 _## ------------------------------------- 00008 _## Copyright (C) 2000-2009 - Frank Fock 00009 _## 00010 _## Use of this software is subject to the license agreement you received 00011 _## with this software and which can be downloaded from 00012 _## http://www.agentpp.com 00013 _## 00014 _## This is licensed software and may not be used in a commercial 00015 _## environment, except for evaluation purposes, unless a valid 00016 _## license has been purchased. 00017 _## 00018 _## Last updated: Tue May 26 23:31:10 CEST 2009 00019 _## 00020 _##########################################################################*/ 00021 00022 #ifndef _agentx_session_h_ 00023 #define _agentx_session_h_ 00024 00025 #include <agent_pp/agent++.h> 00026 #include <agent_pp/snmp_pp_ext.h> 00027 #include <agentx_pp/agentx_reg.h> 00028 #include <agentx_pp/agentx_def.h> 00029 #include <agentx_pp/agentx_threads.h> 00030 #include <agentx_pp/agentx_peer.h> 00031 00032 #ifdef AGENTPP_NAMESPACE 00033 namespace Agentpp { 00034 #endif 00035 00036 #if !defined (AGENTXPP_DECL_TEMPL_LIST_VBX) 00037 #define AGENTXPP_DECL_TEMPL_LIST_VBX 00038 AGENTXPP_DECL_TEMPL template class AGENTXPP_DECL List<Vbx>; 00039 #endif 00040 00041 class AGENTXPP_DECL AgentXSession { 00042 00043 friend class AgentXRequest; 00044 friend class AgentXQueue; 00045 friend class AgentXSessions; 00046 00047 public: 00048 AgentXSession(); 00049 AgentXSession(u_int); 00050 00051 ~AgentXSession(); 00052 00053 int get_state() const { return state; } 00054 void set_state(int s) { state = s; } 00055 00056 u_int get_id() const { return sessionID; } 00057 void set_id(u_int i) { sessionID = i; } 00058 00059 boolean get_byte_order() const { return networkByteOrder; } 00060 void set_byte_order(boolean newOrder) 00061 { networkByteOrder = newOrder; } 00062 u_char get_timeout() const { return defaultTimeout; } 00063 void set_timeout(u_char t) { defaultTimeout = t; } 00064 Oidx get_oid() const { return id; } 00065 NS_SNMP OctetStr get_descr() const { return descr; } 00066 00067 void set_peer(const AgentXPeer& p) { peer = p; } 00068 AgentXPeer get_peer() const { return peer; } 00069 00070 static u_int get_next_session_id(); 00071 00072 void add_agent_caps(const NS_SNMP OctetStr& c, const Oidx& oid) 00073 { sysORIDs.add(new Vbx(oid, c));} 00074 void remove_agent_caps(const NS_SNMP OctetStr&, const Oidx& id); 00075 00076 ListCursor<Vbx>* get_agent_caps() { 00077 return new ListCursor<Vbx>(&sysORIDs); } 00078 00079 AgentXSession& operator=(const AgentXSession&); 00080 00081 void inc_timeouts() { consecutiveTimeouts++; } 00082 void reset_timeouts() { consecutiveTimeouts = 0; } 00083 boolean is_unable_to_respond() 00084 { return (consecutiveTimeouts >= 00085 AGENTX_MAX_TIMEOUTS); } 00086 00087 AgentXPeer peer; 00088 00089 protected: 00090 u_int sessionID; 00091 00092 boolean networkByteOrder; 00093 u_char defaultTimeout; 00094 00095 int state; 00096 00097 Oidx id; 00098 NS_SNMP OctetStr descr; 00099 00100 List<Vbx> sysORIDs; 00101 00102 u_char consecutiveTimeouts; 00103 }; 00104 00105 00113 #if !defined (AGENTXPP_DECL_TEMPL_LIST_AGENTXSESSION) 00114 #define AGENTXPP_DECL_TEMPL_LIST_AGENTXSESSION 00115 AGENTXPP_DECL_TEMPL template class AGENTXPP_DECL List<AgentXSession>; 00116 #endif 00117 00118 class AGENTXPP_DECL AgentXSessions: public Synchronized 00119 { 00120 public: 00121 AgentXSessions(); 00122 virtual ~AgentXSessions(); 00123 00138 virtual boolean get_session(u_int, AgentXSession&); 00139 00150 virtual AgentXSession* get_session(u_int); 00151 00161 virtual AgentXSession* remove(u_int); 00162 00179 virtual u_int make_new_session(boolean, u_char, 00180 const Oidx&, 00181 const NS_SNMP OctetStr&, 00182 const AgentXPeer&); 00183 00190 ListCursor<AgentXSession> get_sessions() 00191 { return ListCursor<AgentXSession>(&sessions); } 00192 00196 void clear() { sessions.clearAll(); } 00197 00205 virtual void remove(const AgentXPeer&); 00206 00220 List<AgentXSession>* remove_sessions_of_peer(const AgentXPeer&); 00221 00234 List<AgentXSession>* get_sessions_of_peer(const AgentXPeer&); 00235 00236 protected: 00237 00238 u_int lastSessionID; 00239 00240 List<AgentXSession> sessions; 00241 }; 00242 00243 #ifdef AGENTPP_NAMESPACE 00244 } 00245 #endif 00246 00247 00248 #endif 00249