Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Advanced / ch_18 / server.h
blobbdb54aa4787772cb7ed0dc166a8c39e0298382e6
1 //=============================================================================
2 /**
3 * @file server.h
5 * @author Source code used in TAO has been modified and adapted from the codeprovided in the book
6 * @author "Advanced CORBA Programming with C++" by MichiHenning and Steve Vinoski. Copyright 1999. Addison-Wesley
7 * @author Reading
8 * @author MA.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
9 */
10 //=============================================================================
16 #ifndef server_HH_
17 #define server_HH_
19 #include "CCSS.h"
20 #include "icp.h"
21 #include <map>
22 #include <list>
23 #include <assert.h>
24 #include "tao/PortableServer/PortableServer.h"
25 #include "tao/PortableServer/ServantLocatorC.h"
27 using namespace std;
29 class Controller_impl;
31 class Thermometer_impl : public virtual POA_CCS::Thermometer {
32 public:
33 // CORBA attributes
34 virtual CCS::ModelType model();
35 virtual CCS::AssetType asset_num();
36 virtual CCS::TempType temperature();
37 virtual CCS::LocType location();
38 virtual void location(const char *loc);
39 virtual void remove();
41 // Constructor & destructor
42 Thermometer_impl(CCS::AssetType anum);
43 virtual ~Thermometer_impl();
45 static Controller_impl * m_ctrl; // My controller
46 const CCS::AssetType m_anum; // My asset number
48 private:
49 // Helper functions
50 CCS::ModelType get_model();
51 CCS::TempType get_temp();
52 CCS::LocType get_loc();
53 void set_loc(const char * new_loc);
55 // Copy and assignment not supported
56 Thermometer_impl(const Thermometer_impl &);
57 void operator=(const Thermometer_impl &);
60 class Thermostat_impl :
61 public virtual POA_CCS::Thermostat,
62 public virtual Thermometer_impl {
63 public:
64 // CORBA operations
65 virtual CCS::TempType get_nominal();
66 virtual CCS::TempType set_nominal(CCS::TempType new_temp);
68 // Constructor and destructor
69 Thermostat_impl(CCS::AssetType anum);
70 virtual ~Thermostat_impl();
72 private:
73 // Helper functions
74 CCS::TempType get_nominal_temp();
75 CCS::TempType set_nominal_temp(CCS::TempType new_temp);
77 // Copy and assignment not supported
78 Thermostat_impl(const Thermostat_impl &);
79 void operator=(const Thermostat_impl &);
82 class Controller_impl : public virtual POA_CCS::Controller {
83 public:
84 // CORBA operations
85 virtual CCS::Controller::ThermometerSeq* list();
86 virtual void find(CCS::Controller::SearchSeq & slist);
87 virtual void change(const CCS::Controller::ThermostatSeq & tlist,
88 CORBA::Short delta);
89 virtual CCS::Thermometer_ptr
90 create_thermometer(
91 CCS::AssetType anum,
92 const char* loc
94 virtual CCS::Thermostat_ptr
95 create_thermostat(
96 CCS::AssetType anum,
97 const char* loc,
98 CCS::TempType temp
101 // Constructor and destructor
102 Controller_impl(
103 PortableServer::POA_ptr poa,
104 const char * asset_file
106 virtual ~Controller_impl();
108 // Helper functions to allow access to the object map
109 void add_impl(
110 CCS::AssetType anum,
111 Thermometer_impl * tip
113 void remove_impl(CCS::AssetType anum);
114 bool exists(CCS::AssetType anum);
116 private:
117 // Map of existing assets. The servant pointer is null
118 // the corresponding servant is not in memory.
119 typedef map<CCS::AssetType, Thermometer_impl *> AssetMap;
120 AssetMap m_assets;
122 // POA for thermometers and thermostats
123 PortableServer::POA_var m_poa;
125 // Name of asset number file
126 CORBA::String_var m_asset_file;
128 // Copy and assignment not supported
129 Controller_impl(const Controller_impl &);
130 void operator=(const Controller_impl &);
132 // Function object for the find_if algorithm to search for
133 // devices by location and model string.
134 class StrFinder {
135 public:
136 StrFinder(
137 CCS::Controller::SearchCriterion sc,
138 const char * str
139 ) : m_sc(sc), m_str(str) {}
140 bool operator()(
141 pair<const CCS::AssetType, Thermometer_impl *> & p
142 ) const
144 char buf[32];
145 switch (m_sc) {
146 case CCS::Controller::LOCATION:
147 ICP_get(p.first, "location", buf, sizeof(buf));
148 break;
149 case CCS::Controller::MODEL:
150 ICP_get(p.first, "model", buf, sizeof(buf));
151 break;
152 default:
153 assert(0); // Precondition violation
155 return strcmp(buf, m_str) == 0;
157 private:
158 CCS::Controller::SearchCriterion m_sc;
159 const char * m_str;
163 class DeviceLocator_impl :
164 public virtual PortableServer::ServantLocator {
165 public:
166 DeviceLocator_impl(Controller_impl * ctrl);
168 virtual PortableServer::Servant
169 preinvoke(
170 const PortableServer::ObjectId & oid,
171 PortableServer::POA_ptr poa,
172 const char * operation,
173 void * & cookie);
175 virtual void
176 postinvoke(
177 const PortableServer::ObjectId & /* oid */,
178 PortableServer::POA_ptr /* poa */,
179 const char * /* operation */,
180 void * /* cookie */,
181 PortableServer::Servant /* servant */) {}
183 private:
184 Controller_impl * m_ctrl;
186 typedef list<Thermometer_impl *> EvictorQueue;
187 typedef map<CCS::AssetType, EvictorQueue::iterator>
188 ActiveObjectMap;
190 static const unsigned int MAX_EQ_SIZE;// = 100;
191 EvictorQueue m_eq;
192 ActiveObjectMap m_aom;
194 // Copy and assignment not supported
195 DeviceLocator_impl(const DeviceLocator_impl &);
196 void operator=(const DeviceLocator_impl &);
199 #endif