Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Advanced / ch_21 / server.h
blob4935b0522234d2787de6dd019e014b286012a9a7
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 <set>
22 #include <list>
23 #include <map>
24 #include <assert.h>
25 #include "tao/PortableServer/PortableServer.h"
26 #include "tao/PortableServer/ServantLocatorC.h"
28 #include "CCSS.h"
30 using namespace std;
32 class Controller_impl;
34 class Thermometer_impl : public virtual POA_CCS::Thermometer {
35 public:
36 // CORBA attributes
37 virtual CCS::ModelType model();
38 virtual CCS::AssetType asset_num();
39 virtual CCS::TempType temperature();
40 virtual CCS::LocType location();
41 virtual void location(const char *loc);
42 virtual void remove();
44 // Constructor & destructor
45 Thermometer_impl(CCS::AssetType anum);
46 virtual ~Thermometer_impl();
48 static Controller_impl * m_ctrl; // My controller
49 const CCS::AssetType m_anum; // My asset number
51 void _add_ref();
52 void _remove_ref();
54 private:
55 // Helper functions
56 CCS::ModelType get_model();
57 CCS::TempType get_temp();
58 CCS::LocType get_loc();
59 void set_loc(const char * new_loc);
61 ACE_Mutex m_count_mutex;
62 CORBA::ULong m_ref_count;
63 bool m_removed;
65 // Copy and assignment not supported
66 Thermometer_impl(const Thermometer_impl &);
67 void operator=(const Thermometer_impl &);
70 class Thermostat_impl :
71 public virtual POA_CCS::Thermostat,
72 public virtual Thermometer_impl {
73 public:
74 // CORBA operations
75 virtual CCS::TempType get_nominal();
76 virtual CCS::TempType set_nominal(CCS::TempType new_temp);
78 // Constructor and destructor
79 Thermostat_impl(CCS::AssetType anum);
80 virtual ~Thermostat_impl();
82 private:
83 // Helper functions
84 CCS::TempType get_nominal_temp();
85 CCS::TempType set_nominal_temp(CCS::TempType new_temp);
87 // Copy and assignment not supported
88 Thermostat_impl(const Thermostat_impl &);
89 void operator=(const Thermostat_impl &);
92 class Controller_impl : public virtual POA_CCS::Controller {
93 public:
94 // CORBA operations
95 virtual CCS::Controller::ThermometerSeq* list();
96 virtual void find(CCS::Controller::SearchSeq & slist);
97 virtual void change(const CCS::Controller::ThermostatSeq & tlist,
98 CORBA::Short delta);
100 virtual CCS::Thermometer_ptr create_thermometer(CCS::AssetType anum,
101 const char* loc);
103 virtual CCS::Thermostat_ptr create_thermostat(CCS::AssetType anum,
104 const char* loc,
105 CCS::TempType temp);
107 // Constructor and destructor
108 Controller_impl(PortableServer::POA_ptr poa,
109 const char * asset_file);
111 virtual ~Controller_impl();
113 // Helper functions to allow access to the object map
114 void add_impl(CCS::AssetType anum);
115 void remove_impl(CCS::AssetType anum);
116 bool exists(CCS::AssetType anum);
118 ACE_Mutex m_assets_mutex;
120 private:
121 typedef set<CCS::AssetType> AssetSet;
122 AssetSet m_assets;
124 // POA for thermometers and thermostats
125 PortableServer::POA_var m_poa;
127 // Name of asset number file
128 CORBA::String_var m_asset_file;
130 // Copy and assignment not supported
131 Controller_impl(const Controller_impl &);
132 void operator=(const Controller_impl &);
134 // Function object for the find_if algorithm to search for
135 // devices by location and model string.
136 class StrFinder {
137 public:
138 StrFinder(
139 CCS::Controller::SearchCriterion sc,
140 const char * str
141 ) : m_sc(sc), m_str(str) {}
142 bool operator()(
143 CCS::AssetType anum
144 ) const
146 char buf[32];
147 switch (m_sc) {
148 case CCS::Controller::LOCATION:
149 ICP_get(anum, "location", buf, sizeof(buf));
150 break;
151 case CCS::Controller::MODEL:
152 ICP_get(anum, "model", buf, sizeof(buf));
153 break;
154 default:
155 assert(0); // Precondition violation
157 return strcmp(buf, m_str) == 0;
159 private:
160 CCS::Controller::SearchCriterion m_sc;
161 const char * m_str;
165 class DeviceLocator_impl :
166 public virtual PortableServer::ServantLocator {
167 public:
168 DeviceLocator_impl(Controller_impl * ctrl);
170 virtual PortableServer::Servant
171 preinvoke(
172 const PortableServer::ObjectId & oid,
173 PortableServer::POA_ptr /* poa */ ,
174 const char * operation,
175 void * & /* cookie */
178 virtual void
179 postinvoke(
180 const PortableServer::ObjectId & /* oid */ ,
181 PortableServer::POA_ptr /* poa */ ,
182 const char * /* operation */ ,
183 void * /* cookie */ ,
184 PortableServer::Servant /* servant */
185 ) {}
186 private:
187 Controller_impl * m_ctrl;
189 typedef list<Thermometer_impl *> EvictorQueue;
190 typedef map<CCS::AssetType, EvictorQueue::iterator>
191 ActiveObjectMap;
193 static const unsigned int MAX_EQ_SIZE;// = 100;
194 EvictorQueue m_eq;
195 ActiveObjectMap m_aom;
197 // Copy and assignment not supported
198 DeviceLocator_impl(const DeviceLocator_impl &);
199 void operator=(const DeviceLocator_impl &);
202 #endif