00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _DVCBASE_I_H_
00031 #define _DVCBASE_I_H_
00032
00033
00034
00035
00036
00037
00038 #include <device.h>
00039
00040
00041 #include "corba_utility.h"
00042 #include "deviceS.h"
00043 #include "servantlocators.h"
00044
00045
00046
00047
00048
00049 namespace OSB_CORBA {
00050
00051 using corba::common::OsbCorbaException;
00052 using corba::dvc::DeviceId;
00053 using corba::dvc::DeviceStatus;
00054 using corba::dvc::DeviceType;
00055
00056
00057
00058
00059
00060
00061
00062
00063
00067 class Device_i : public virtual POA_corba::dvc::Device {
00068 public:
00070 static const std::string IFC;
00071 public:
00078 Device_i(
00079 OSB_LIB::Device::Oid dvcId,
00080 Locators& srvtLoc
00081 );
00083 virtual ~Device_i();
00084 private:
00086 Device_i(const Device_i&);
00088 void operator=(const Device_i&);
00089
00090 public:
00092 DeviceType type()
00093 throw (OsbCorbaException);
00095 DeviceId id()
00096 throw (OsbCorbaException);
00098 DeviceStatus status()
00099 throw (OsbCorbaException);
00106 corba::imgmt::PoolId poolId()
00107 throw (OsbCorbaException);
00108
00115 void destroy() throw();
00116
00117 public:
00119 static OSB_LIB::Device::Status dvcStatus(DeviceStatus);
00121 static DeviceStatus dvcStatus(OSB_LIB::Device::Status);
00122
00124 Locators::Key loctKey() const;
00125
00127 enum GuardStatus {
00129 success = 0,
00131 lockFailed = 1,
00133 notFound = 2
00134 };
00135
00149 template<typename D>
00150 static const D& get(
00151 const OSB_LIB::ReadGuard<D*>& rg,
00152 OSB_LIB::Device::Oid dvcId
00153 ) throw (OsbCorbaException);
00154
00155 protected:
00157 typedef OSB_LIB::ReadGuard<OSB_LIB::Device*> ReadGuard;
00158
00160 virtual ReadGuard lock() const = 0;
00161
00162 protected:
00164 OSB_LIB::Device::Oid dvcId_;
00166 Locators& srvtLoc_;
00167 private:
00169 Locators::Key loctKey_;
00170 };
00171 }
00172
00173
00174
00175 namespace OSB_CORBA {
00176
00177
00178 template<typename D>
00179 const D& Device_i::get(
00180 const OSB_LIB::ReadGuard<D*>& rg,
00181 OSB_LIB::Device::Oid dvcId
00182 ) throw (OsbCorbaException)
00183 {
00184
00185 const D* rc = rg.get();
00186 if (0 != rc) return *rc;
00187
00188
00189 using OSB_LIB::OsbError;
00190 OsbError error;
00191 switch (rg.status_) {
00192 case notFound:
00193 error = OsbError(991);
00194 error << dvcId;
00195 break;
00196
00197 case lockFailed:
00198 error = OsbError(992);
00199 error << dvcId;
00200 break;
00201
00202 case success:
00203 if (rg.locked()) error = OsbError(993);
00204 else error = OsbError(994);
00205 break;
00206 }
00207
00208 if (error.noError()) {
00209 error = OsbError(995);
00210 error << rg.status_;
00211 }
00212 throw osbCorbaException(error);
00213 }
00214 }
00215 #endif // #ifndef _DVCBASE_I_H_