00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _RESOURCE_I_H_
00032 #define _RESOURCE_I_H_
00033
00034
00035
00036
00037
00038
00039 #include <resourcelists.h>
00040
00041
00042 #include "resourceS.h"
00043 #include "corba_utility.h"
00044 #include "networkmanager_i.h"
00045
00046
00047
00048
00049
00050 namespace OSB_CORBA {
00051
00052
00053
00054 using CORBA::Boolean;
00055 using corba::common::Date;
00056
00057
00058
00062 class Resource_i :
00063 public virtual POA_corba::res::Resource
00064 {
00065 public:
00067 static const std::string IFC;
00068
00070 Resource_i(
00071 NetworkManager_i& nmgri,
00072 const OSB_LIB::Resource::Oid& oid
00073 );
00074
00076 ~Resource_i();
00077
00078 public:
00080
00081
00082 ResourceTypeId type()
00083 throw (CORBA::SystemException, OsbCorbaException);
00084
00086 ResourceId id()
00087 throw (CORBA::SystemException, OsbCorbaException);
00088
00095 corba::imgmt::PoolId poolId()
00096 throw (CORBA::SystemException, OsbCorbaException);
00097
00099 Boolean isPrepaid()
00100 throw (CORBA::SystemException, OsbCorbaException);
00101
00103 Utf8String* resNumber()
00104 throw (CORBA::SystemException, OsbCorbaException);
00105
00107 ResourceStatus status()
00108 throw (CORBA::SystemException, OsbCorbaException);
00109
00121 Boolean isAvailable()
00122 throw (CORBA::SystemException, OsbCorbaException);
00123
00129 Date quarantineEnd()
00130 throw (CORBA::SystemException, OsbCorbaException);
00131
00137 NetworkId networkId()
00138 throw (CORBA::SystemException, OsbCorbaException);
00139
00145 NetworkElementId networkElementId()
00146 throw (CORBA::SystemException, OsbCorbaException);
00147
00153 Date assigned()
00154 throw (CORBA::SystemException, OsbCorbaException);
00155
00157 Boolean canUpd()
00158 throw (CORBA::SystemException, OsbCorbaException);
00159
00161 Boolean canDel()
00162 throw (CORBA::SystemException, OsbCorbaException);
00164
00165 protected:
00167 typedef OSB_LIB::ResourceList<OSB_LIB::Resource>::Rg ReadGuard;
00168
00170 virtual ReadGuard lock() const = 0;
00171
00172 protected:
00174 NetworkManager_i& nmgri_;
00175
00177 const OSB_LIB::Resource::Oid resId_;
00178 };
00179
00186 class ResourceWriter_i :
00187 public virtual POA_corba::res::ResourceWriter,
00188 public virtual Resource_i
00189 {
00190 public:
00192 static const std::string IFC;
00193
00195 ResourceWriter_i(
00196 NetworkManager_i& nmgri,
00197 const OSB_LIB::Resource::Oid& resId
00198 );
00199
00201 virtual ~ResourceWriter_i();
00202
00203 private:
00205 ResourceWriter_i(const ResourceWriter_i&);
00207 ResourceWriter_i& operator=(const ResourceWriter_i&);
00208
00209 public:
00211 void setLoctKey(const Locators::Key& key);
00212
00222 void setPool(
00223 const corba::imgmt::PoolId& poolId
00224 ) throw (CORBA::SystemException, OsbCorbaException);
00235 void setStatus(
00236 ResourceStatus newStatus
00237 ) throw (OsbCorbaException);
00238
00254 virtual ResourceId create(
00255 CORBA::Boolean noWait
00256 ) throw (CORBA::SystemException, OsbCorbaException);
00257
00258 virtual void updData(
00259 CORBA::Boolean noWait
00260 ) throw (CORBA::SystemException, OsbCorbaException);
00261
00262 virtual void updStatus(
00263 CORBA::Boolean noWait
00264 ) throw (CORBA::SystemException, OsbCorbaException);
00265
00269 void destroy() throw (CORBA::SystemException);
00270
00271 protected:
00273 virtual OSB_LIB::Resource& resource() = 0;
00274
00293 virtual bool writeToList(bool isNew) const = 0;
00294
00295 private:
00297 Locators::Key loctKey_;
00298 };
00299
00300
00301
00315 template<typename R>
00316 const R& getResource(
00317 const OSB_LIB::ReadGuard<R*>& rg,
00318 OSB_LIB::Resource::Oid resId
00319 ) throw (OsbCorbaException);
00320
00334 template<typename R>
00335 R& getResource(
00336 OSB_LIB::WriteGuard<R*>& wg,
00337 OSB_LIB::Resource::Oid resId
00338 ) throw (OsbCorbaException);
00339
00343 OSB_LIB::Resource::Status rsStatus(ResourceStatus s);
00344
00348 ResourceStatus rsStatus(const OSB_LIB::Resource::Status s);
00349 }
00350
00351
00352
00353 namespace OSB_CORBA {
00354
00355 template<typename R>
00356 const R& getResource(
00357 const OSB_LIB::ReadGuard<R*>& rg,
00358 OSB_LIB::Resource::Oid resId
00359 ) throw (OsbCorbaException)
00360 {
00361
00362 const R* rc = rg.get();
00363 if (0 != rc) return *rc;
00364
00365
00366 typedef OSB_LIB::ResourceList<R> List;
00367 typedef typename List::GuardStatus Status;
00368
00369 using OSB_LIB::OsbError;
00370
00371 OsbError error;
00372 switch (Status(rg.status_)) {
00373 case List::objectNotFound:
00374 error = OsbError(721);
00375 error << resId;
00376 break;
00377
00378 case List::lockFailed:
00379 error = OsbError(722);
00380 error << resId;
00381 break;
00382
00383 case List::success:
00384 if (rg.locked()) error = OsbError(723);
00385 else error = OsbError(724);
00386 break;
00387 }
00388
00389 if (error.noError()) {
00390 error = OsbError(725);
00391 error << rg.status_;
00392 }
00393 throw osbCorbaException(error);
00394 }
00395
00396 template<typename R>
00397 R& getResource(
00398 OSB_LIB::WriteGuard<R*>& wg,
00399 OSB_LIB::Resource::Oid resId
00400 ) throw (OsbCorbaException)
00401 {
00402
00403 R* rc = wg.get();
00404 if (0 != rc) return *rc;
00405
00406
00407 typedef OSB_LIB::ResourceList<R> List;
00408 typedef typename List::GuardStatus Status;
00409
00410 using OSB_LIB::OsbError;
00411
00412 OsbError error;
00413 switch (Status(wg.status_)) {
00414 case List::objectNotFound:
00415 error = OsbError(721);
00416 error << resId;
00417 break;
00418
00419 case List::lockFailed:
00420 error = OsbError(726);
00421 error << resId;
00422 break;
00423
00424 case List::success:
00425 if (wg.locked()) error = OsbError(723);
00426 else error = OsbError(727);
00427 break;
00428 }
00429
00430 if (error.noError()) {
00431 error = OsbError(728);
00432 error << wg.status_;
00433 }
00434 throw osbCorbaException(error);
00435 }
00436 }
00437 #endif // #ifndef _RESOURCE_I_H_