AgentX++  2.0.5
agentx_session.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## agentx_session.h
4  _##
5  _##
6  _## AgentX++ 2
7  _## -------------------------------------
8  _## Copyright (C) 2000-2013 - Frank Fock
9  _##
10  _## Use of this software is subject to the license agreement you received
11  _## with this software and which can be downloaded from
12  _## http://www.agentpp.com
13  _##
14  _## This is licensed software and may not be used in a commercial
15  _## environment, except for evaluation purposes, unless a valid
16  _## license has been purchased.
17  _##
18  _##########################################################################*/
19 
20 #ifndef _agentx_session_h_
21 #define _agentx_session_h_
22 
23 #include <agent_pp/agent++.h>
24 #include <agent_pp/snmp_pp_ext.h>
25 #include <agentx_pp/agentx_reg.h>
26 #include <agentx_pp/agentx_def.h>
28 #include <agentx_pp/agentx_peer.h>
29 
30 #ifdef AGENTPP_NAMESPACE
31 namespace Agentpp {
32 #endif
33 
34 #if !defined (AGENTXPP_DECL_TEMPL_LIST_VBX)
35 #define AGENTXPP_DECL_TEMPL_LIST_VBX
37 #endif
38 
40 
41 friend class AgentXRequest;
42 friend class AgentXQueue;
43 friend class AgentXSessions;
44 
45  public:
46  AgentXSession();
47  AgentXSession(u_int);
48 
49  ~AgentXSession();
50 
51  int get_state() const { return state; }
52  void set_state(int s) { state = s; }
53 
54  u_int get_id() const { return sessionID; }
55  void set_id(u_int i) { sessionID = i; }
56 
57  bool get_byte_order() const { return networkByteOrder; }
58  void set_byte_order(bool newOrder)
59  { networkByteOrder = newOrder; }
60  u_char get_timeout() const { return defaultTimeout; }
61  void set_timeout(u_char t) { defaultTimeout = t; }
62  Oidx get_oid() const { return id; }
63  NS_SNMP OctetStr get_descr() const { return descr; }
64 
65  void set_peer(const AgentXPeer& p) { peer = p; }
66  AgentXPeer get_peer() const { return peer; }
67 
68  static u_int get_next_session_id();
69 
70  void add_agent_caps(const NS_SNMP OctetStr& c, const Oidx& oid)
71  { sysORIDs.add(new Vbx(oid, c));}
72  void remove_agent_caps(const NS_SNMP OctetStr&, const Oidx& id);
73 
74  ListCursor<Vbx>* get_agent_caps() {
75  return new ListCursor<Vbx>(&sysORIDs); }
76 
77  AgentXSession& operator=(const AgentXSession&);
78 
79  void inc_timeouts() { consecutiveTimeouts++; }
80  void reset_timeouts() { consecutiveTimeouts = 0; }
81  bool is_unable_to_respond()
82  { return (consecutiveTimeouts >=
84 
86 
87  protected:
88  u_int sessionID;
89 
92 
93  int state;
94 
95  Oidx id;
96  NS_SNMP OctetStr descr;
97 
99 
101 };
102 
103 
111 #if !defined (AGENTXPP_DECL_TEMPL_LIST_AGENTXSESSION)
112 #define AGENTXPP_DECL_TEMPL_LIST_AGENTXSESSION
114 #endif
115 
116 class AGENTXPP_DECL AgentXSessions: public Synchronized
117 {
118  public:
119  AgentXSessions();
120  virtual ~AgentXSessions();
121 
136  virtual bool get_session(u_int, AgentXSession&);
137 
148  virtual AgentXSession* get_session(u_int);
149 
159  virtual AgentXSession* remove(u_int);
160 
177  virtual u_int make_new_session(bool, u_char,
178  const Oidx&,
179  const NS_SNMP OctetStr&,
180  const AgentXPeer&);
181 
188  ListCursor<AgentXSession> get_sessions()
189  { return ListCursor<AgentXSession>(&sessions); }
190 
194  void clear() { sessions.clearAll(); }
195 
203  virtual void remove(const AgentXPeer&);
204 
218  List<AgentXSession>* remove_sessions_of_peer(const AgentXPeer&);
219 
232  List<AgentXSession>* get_sessions_of_peer(const AgentXPeer&);
233 
234  protected:
235 
237 
239 };
240 
241 #ifdef AGENTPP_NAMESPACE
242 }
243 #endif
244 
245 
246 #endif
247