summaryrefslogtreecommitdiff
path: root/TAO/examples/POA/DSI/Database_i.h
blob: 3824d71f23bb260c16936e5d5e1460d5eb5e8a1e (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// $Id$

#include "DatabaseS.h"
#include "ace/Malloc.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

class DatabaseImpl
{
public:

  //typedef ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC;
  typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex> MALLOC;

  class Simpler_Malloc : public MALLOC
  {
  public:
    Simpler_Malloc (void);
    ~Simpler_Malloc (void);
  };

  typedef ACE_Singleton<Simpler_Malloc, ACE_Null_Mutex> DATABASE;
  //typedef ACE_Malloc_Iterator<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> DATABASE_ITERATOR;
  typedef ACE_Malloc_Iterator<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex> DATABASE_ITERATOR;

  class Entry : public PortableServer::DynamicImplementation
  {
  public:
    Entry (CORBA::ORB_ptr orb,
           PortableServer::POA_ptr poa,
           CORBA::Environment &);
    ~Entry (void);

    virtual void invoke (CORBA::ServerRequest_ptr request,
                         CORBA::Environment &env);
    // The invoke() method receives requests issued to any CORBA
    // object incarnated by the DSI servant and performs the
    // processing necessary to execute the request.

    virtual CORBA::RepositoryId _primary_interface (const PortableServer::ObjectId &oid,
                                                    PortableServer::POA_ptr poa,
                                                    CORBA::Environment &env);
    // The _primary_interface() method receives an ObjectId value and
    // a POA_ptr as input parameters and returns a valid RepositoryId
    // representing the most-derived interface for that oid.

    virtual PortableServer::POA_ptr _default_POA (CORBA::Environment &env);
    // Returns the default POA for this servant.

    virtual void is_a (CORBA::ServerRequest_ptr request,
                       CORBA::Environment &env);
    // Handles the _is_a call

  protected:
    CORBA::ORB_var orb_;
    // ORB (auto) pointer

    PortableServer::POA_var poa_;
    // Default POA

    PortableServer::Current_var poa_current_;
    // POA Current.
  };

  class Agent : public POA_Database::Agent
  {
  public:
    Agent (CORBA::ORB_ptr orb,
           PortableServer::POA_ptr poa,
           CORBA::Environment &);
    ~Agent (void);

    virtual Database::Entry_ptr create_entry (const char *key,
                                              const char *entry_type,
                                              const Database::NVPairSequence &initial_attributes,
                                              CORBA::Environment &env)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       Database::Unknown_Type,
                       Database::Duplicate_Key));

    virtual Database::Entry_ptr find_entry (const char *key,
                                            const char *entry_type,
                                            CORBA::Environment &env)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       Database::Unknown_Type,
                       Database::Not_Found));

    virtual void destroy_entry (const char *key,
                                const char *entry_type,
                                CORBA::Environment &env)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       Database::Unknown_Type,
                       Database::Unknown_Key));

    virtual void shutdown (CORBA::Environment &env)
      ACE_THROW_SPEC ((CORBA::SystemException));

    virtual PortableServer::POA_ptr _default_POA (CORBA::Environment &env);
    // Returns the default POA for this servant.

  protected:
    CORBA::ORB_var orb_;
    // ORB (auto) pointer

    PortableServer::POA_var poa_;
    // Default POA

    Entry common_servant_;
  };

  static char *entry_type_to_repository_id (const char *entry_type);

  class Employee
  {
  public:
    Employee (const char* name,
              CORBA::Long id);

    ~Employee (void);

    const char *name (void) const
      ACE_THROW_SPEC ((CORBA::SystemException));
    void name (const char* name)
      ACE_THROW_SPEC ((CORBA::SystemException));

    CORBA::Long id (void) const
      ACE_THROW_SPEC ((CORBA::SystemException));
    void id (CORBA::Long id)
      ACE_THROW_SPEC ((CORBA::SystemException));

    void *operator new (size_t);
    void operator delete (void *pointer);

  private:
    CORBA::Long id_;
    // Employee ID.

    char *name_;
    // Employee name.
  };
};