summaryrefslogtreecommitdiff
path: root/ace/QoS_Session_Factory.cpp
blob: 1e0e892bbd0eb81aea4105e109bf5acdafdc6115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// QoS_Session_Factory.cpp
// $Id$

#define ACE_BUILD_DLL

#include "ace/QoS_Session_Factory.h"
#include "ace/QoS_Session_Impl.h"

ACE_RCSID(ace, QoS_Session_Factory, "$Id$")
  
ACE_ALLOC_HOOK_DEFINE(ACE_QoS_Session_Factory)

ACE_QoS_Session_Factory::ACE_QoS_Session_Factory (void)
{
  ACE_TRACE ("ACE_QoS_Session_Factory::ACE_QoS_Session_Factory");
}

ACE_QoS_Session_Factory::~ACE_QoS_Session_Factory (void)
{
  ACE_TRACE ("ACE_QoS_Session_Factory::~ACE_QoS_Session_Factory");
}

// Create a QoS session of the given type (RAPI or GQoS).
ACE_QoS_Session *
ACE_QoS_Session_Factory::create_session (ACE_QoS_Session_Type qos_session_type)
{
  
  ACE_QoS_Session * qos_session = 0;

#if defined (ACE_HAS_RAPI)
  if (qos_session_type == ACE_RAPI_SESSION)
    ACE_NEW_RETURN (qos_session,
                    ACE_RAPI_Session,
                    0);
#endif /* ACE_HAS_RAPI */

  if (qos_session_type == ACE_GQOS_SESSION)
    ACE_NEW_RETURN (qos_session,
                    ACE_GQoS_Session,
                    0);
  
  if (this->add_session (qos_session) == -1)
    {
      delete qos_session;
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Error in adding session\n"),
                        0);
    }
             
  return qos_session;
}

// Destroy the QoS Session.
int
ACE_QoS_Session_Factory::destroy_session (ACE_QoS_Session *qos_session)
{
  
  if ((qos_session != 0) && (this->remove_session (qos_session) == -1))
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Error in destroying session\n"),
                      -1);
  
  return 0;
}

// Add a session to the set of sessions created by this factory. This is a 
// private method called by the create_session ().
int
ACE_QoS_Session_Factory::add_session (ACE_QoS_Session *qos_session)
{
  if (this->qos_session_set_.insert (qos_session) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Error in adding a new session to the session set\n"),
                      -1);

  return 0;
}

// Remove a session from the set of sessions created by this factory. This is a   
// private method called by the destroy_session ().
int
ACE_QoS_Session_Factory::remove_session (ACE_QoS_Session *qos_session)
{
  if (this->qos_session_set_.remove (qos_session) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Error in removing a session from the session set\n"),
                      -1);
  
  return 0;
}