summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/LifespanStrategyTransient.cpp
blob: eb6ed65faeb6defada4259951cbff0e0372ae03c (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// -*- C++ -*-
#include "tao/PortableServer/LifespanStrategyTransient.h"
#include "ace/OS_NS_sys_time.h"
#include "ace/OS_NS_string.h"
#include "tao/PortableServer/POAManager.h"
#include "tao/PortableServer/Root_POA.h"
#include "tao/ORB_Constants.h"
#include "tao/PortableServer/Creation_Time.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  namespace Portable_Server
  {
    LifespanStrategyTransient::LifespanStrategyTransient () :
      creation_time_ (ACE_OS::gettimeofday ())
    {
    }

    void
    LifespanStrategyTransient::notify_startup ()
    {
    }

    void
    LifespanStrategyTransient::notify_shutdown ()
    {
    }

    CORBA::Boolean
    LifespanStrategyTransient::is_persistent () const
    {
      return false;
    }

    bool
    LifespanStrategyTransient::validate (CORBA::Boolean is_persistent,
                                         const TAO::Portable_Server::
                                         Temporary_Creation_Time
                                         &creation_time) const
    {
      return (!is_persistent && this->creation_time_ == creation_time);
    }

    CORBA::ULong
    LifespanStrategyTransient::key_length () const
    {
      CORBA::ULong keylength = sizeof (char);

#if (POA_NO_TIMESTAMP == 0)
      // Calculate the space required for the timestamp.
      keylength += TAO::Portable_Server::Creation_Time::creation_time_length
        ();
#endif /* POA_NO_TIMESTAMP */

      return keylength;
    }

    void
    LifespanStrategyTransient::create_key (CORBA::Octet *buffer,
                                           CORBA::ULong &starting_at)
    {
      // Copy the persistence byte.
      buffer[starting_at] = (CORBA::Octet)this->key_type ();
      starting_at += this->key_type_length ();

#if (POA_NO_TIMESTAMP == 0)
      // Then copy the timestamp for transient POAs.
      ACE_OS::memcpy (&buffer[starting_at],
                      this->creation_time_.creation_time (),
                      TAO::Portable_Server::Creation_Time::creation_time_length
                      ());
      starting_at += TAO::Portable_Server::Creation_Time::creation_time_length
        ();
#endif /* POA_NO_TIMESTAMP */
    }

    char
    LifespanStrategyTransient::key_type () const
    {
      return 'T';
    }

    void
    LifespanStrategyTransient::check_state ()
    {
      if (this->poa_->tao_poa_manager ().get_state_i () ==
        PortableServer::POAManager::INACTIVE)
        {
          throw ::CORBA::OBJECT_NOT_EXIST (CORBA::OMGVMCID | 4, CORBA::COMPLETED_NO);
        }
      else
        {
          this->poa_->tao_poa_manager ().check_state ();
        }
    }

    bool
    LifespanStrategyTransient::use_imr () const
    {
      return false;
    }

    CORBA::Object_ptr
    LifespanStrategyTransient::imr_key_to_object (const TAO::ObjectKey &,
                                                  const char *) const
    {
      return CORBA::Object::_nil();
    }
  } /* namespace Portable_Server */
} /* namespace TAO */

TAO_END_VERSIONED_NAMESPACE_DECL