| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2004,2006, Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Core Framework. |
|---|
| 6 | |
|---|
| 7 | OSSIE Core Framework is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the Lesser GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Core Framework is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | Lesser GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the Lesser GNU General Public License |
|---|
| 18 | along with OSSIE Core Framework; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | Nov/10/03 C. Neely Created |
|---|
| 22 | C. Aguayo |
|---|
| 23 | |
|---|
| 24 | ****************************************************************************/ |
|---|
| 25 | #include <iostream> |
|---|
| 26 | |
|---|
| 27 | #include <string.h> |
|---|
| 28 | #ifdef HAVE_UNISTD_H |
|---|
| 29 | #include <unistd.h> |
|---|
| 30 | #else /// \todo change else to ifdef windows var |
|---|
| 31 | #include <process.h> |
|---|
| 32 | #endif |
|---|
| 33 | #ifdef HAVE_STDLIB_H |
|---|
| 34 | #include <stdlib.h> |
|---|
| 35 | #endif |
|---|
| 36 | #include <errno.h> |
|---|
| 37 | |
|---|
| 38 | #include "ossie/debug.h" |
|---|
| 39 | #include "ossie/ossieSupport.h" |
|---|
| 40 | #include "ossie/DeviceManager_impl.h" |
|---|
| 41 | #include "ossie/portability.h" |
|---|
| 42 | |
|---|
| 43 | DeviceManager_impl::~DeviceManager_impl () |
|---|
| 44 | { |
|---|
| 45 | DEBUG(6, DeviceManager, "Entering destructor."); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | DeviceManager_impl::DeviceManager_impl(const char *DCDInput) |
|---|
| 50 | |
|---|
| 51 | { |
|---|
| 52 | DEBUG(6, DeviceManager, "Entering constructor with " << DCDInput); |
|---|
| 53 | |
|---|
| 54 | _deviceConfigurationProfile = DCDInput; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | //Parsing constructor |
|---|
| 58 | void DeviceManager_impl::post_constructor (CF::DeviceManager_var my_object_var) throw (CORBA::SystemException) |
|---|
| 59 | |
|---|
| 60 | { |
|---|
| 61 | DEBUG(6, DeviceManager, "Entering post_constructor."); |
|---|
| 62 | orb_obj = new ossieSupport::ORB(); |
|---|
| 63 | |
|---|
| 64 | myObj = my_object_var; |
|---|
| 65 | |
|---|
| 66 | _registeredDevices.length(0); |
|---|
| 67 | _registeredServices.length(0); |
|---|
| 68 | |
|---|
| 69 | fs_servant = new FileSystem_impl(); |
|---|
| 70 | _fileSys = fs_servant->_this(); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | if (_fileSys->exists (_deviceConfigurationProfile.c_str())) |
|---|
| 74 | { |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | //Get Device Manager attributes (deviceConfigurationProfile, identifier and label) |
|---|
| 78 | //from DCD file |
|---|
| 79 | |
|---|
| 80 | DCDParser _DCDParser (_deviceConfigurationProfile.c_str()); |
|---|
| 81 | |
|---|
| 82 | _identifier = _DCDParser.getID(); |
|---|
| 83 | _label = _DCDParser.getName(); |
|---|
| 84 | |
|---|
| 85 | //get DomainManager reference |
|---|
| 86 | |
|---|
| 87 | getDomainManagerReference ((char *)_DCDParser.getDomainManagerName ()); |
|---|
| 88 | |
|---|
| 89 | //Register DeviceManager with DomainManager |
|---|
| 90 | _dmnMgr->registerDeviceManager (my_object_var); |
|---|
| 91 | |
|---|
| 92 | _adminState = DEVMGR_REGISTERED; |
|---|
| 93 | |
|---|
| 94 | //parse filesystem names |
|---|
| 95 | |
|---|
| 96 | //Parse local componenents from DCD files |
|---|
| 97 | std::vector <componentPlacement> componentPlacements = _DCDParser.getComponentPlacements (); |
|---|
| 98 | |
|---|
| 99 | for (unsigned int i = 0; i < componentPlacements.size(); i++) |
|---|
| 100 | { |
|---|
| 101 | //get spd reference |
|---|
| 102 | //parse spd file |
|---|
| 103 | SPDParser _SPDParser (_DCDParser.getFileNameFromRefId(componentPlacements[i].refId())); |
|---|
| 104 | |
|---|
| 105 | //get code file name from implementation |
|---|
| 106 | std::vector < SPDImplementation * >*_implementations = |
|---|
| 107 | _SPDParser.getImplementations (); |
|---|
| 108 | |
|---|
| 109 | ///----------Assuming only one implementation |
|---|
| 110 | //spawn device |
|---|
| 111 | |
|---|
| 112 | #ifdef MS_dotNET //FIXME PJB |
|---|
| 113 | int myPid2 = _spawnl (_P_DETACH, |
|---|
| 114 | //Device Proxy |
|---|
| 115 | (*_implementations)[0]->getCodeFile (), |
|---|
| 116 | //argv[0] |
|---|
| 117 | (*_implementations)[0]->getCodeFile (), |
|---|
| 118 | componentPlacements[i].usageName(), //Device Label --argv[1] |
|---|
| 119 | _DCDParser.getFileNameFromRefId(componentPlacements[i].refId()), //Device SoftwareProfile --argv[2] |
|---|
| 120 | NULL); |
|---|
| 121 | #endif |
|---|
| 122 | #ifdef HAVE_WORKING_FORK |
|---|
| 123 | int myPid2; |
|---|
| 124 | |
|---|
| 125 | DEBUG(2, DevMgr, "Launching Device file " << (*_implementations)[0]->getCodeFile () << " Usage name " << componentPlacements[i].usageName()) |
|---|
| 126 | |
|---|
| 127 | if ((myPid2 = fork()) < 0) |
|---|
| 128 | std::cout << "Fork Error" << std::endl; |
|---|
| 129 | |
|---|
| 130 | if (myPid2 == 0) |
|---|
| 131 | { |
|---|
| 132 | // in child |
|---|
| 133 | if (getenv("VALGRIND")) { |
|---|
| 134 | string logFile = "--log-file="; |
|---|
| 135 | logFile += (*_implementations)[0]->getCodeFile (); |
|---|
| 136 | char *val = "/usr/local/bin/valgrind"; |
|---|
| 137 | execl(val, val, logFile.c_str(), (*_implementations)[0]->getCodeFile (), componentPlacements[i].id(), componentPlacements[i].usageName() , _DCDParser.getFileNameFromRefId(componentPlacements[i].refId()), NULL); |
|---|
| 138 | } else { |
|---|
| 139 | execl((*_implementations)[0]->getCodeFile (), (*_implementations)[0]->getCodeFile (),componentPlacements[i].id(), componentPlacements[i].usageName() , _DCDParser.getFileNameFromRefId(componentPlacements[i].refId()), NULL); |
|---|
| 140 | |
|---|
| 141 | } |
|---|
| 142 | std::cout << "Device did not execute : " << strerror(errno) << std::endl; |
|---|
| 143 | exit (-1); |
|---|
| 144 | } |
|---|
| 145 | #endif |
|---|
| 146 | |
|---|
| 147 | CORBA::Object_var _obj = CORBA::Object::_nil(); |
|---|
| 148 | char nameStr[255]; |
|---|
| 149 | sprintf( nameStr, "DomainName1/%s", componentPlacements[i].usageName() ); |
|---|
| 150 | DEBUG(3, DevMgr, "searching for "<< nameStr) |
|---|
| 151 | do |
|---|
| 152 | { |
|---|
| 153 | /// \todo sleep prevents system from beating Name Service to death, Fix better |
|---|
| 154 | ossieSupport::nsleep(0, 50*1000); |
|---|
| 155 | try { |
|---|
| 156 | _obj = orb_obj->get_object_from_name(nameStr); |
|---|
| 157 | } catch (CosNaming::NamingContext::NotFound) {}; |
|---|
| 158 | } |
|---|
| 159 | while (CORBA::is_nil (_obj)); |
|---|
| 160 | DEBUG(3, DevMgr, "found "<< nameStr) |
|---|
| 161 | |
|---|
| 162 | CF::Device_var tempDevice = CF::Device::_narrow (_obj); |
|---|
| 163 | tempDevice->initialize (); |
|---|
| 164 | |
|---|
| 165 | //Get properties from SCD |
|---|
| 166 | PRFParser _PRFparser (_SPDParser.getPRFFile ()); |
|---|
| 167 | std::vector <PRFProperty *> *prfSimpleProp = _PRFparser.getConfigureProperties (); |
|---|
| 168 | CF::Properties configCapacities; |
|---|
| 169 | configCapacities.length (prfSimpleProp->size ()); |
|---|
| 170 | for (unsigned int i = 0; i < prfSimpleProp->size (); i++) |
|---|
| 171 | { |
|---|
| 172 | configCapacities[i] = *((*prfSimpleProp)[i]->getDataType ()); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | //configure properties |
|---|
| 176 | DEBUG(3, DevMgr, "Configuring capacities") |
|---|
| 177 | tempDevice->configure (configCapacities); |
|---|
| 178 | DEBUG(3, DevMgr, "Registering device") |
|---|
| 179 | registerDevice (CF::Device::_duplicate(tempDevice)); |
|---|
| 180 | DEBUG(3, DevMgr, "Device Registered") |
|---|
| 181 | |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | //So far, it is assumed that all components are local |
|---|
| 185 | /*//Obtain DEPLY-ON components |
|---|
| 186 | std::vector<DCDComponentPlacement> DeployOnComponentsVector = _DCDParser.getDeployOnComponents(); |
|---|
| 187 | |
|---|
| 188 | std::vector<char*> DPDList; |
|---|
| 189 | |
|---|
| 190 | //Get DPD file names from DeployOnComponentsVector |
|---|
| 191 | for(int i = 0; i < DeployOnComponentsVector.size(); i++) //Makes list of DPD files. |
|---|
| 192 | DPDList.push_back( DeployOnComponentsVector[i].getDPDFile() ); |
|---|
| 193 | */ |
|---|
| 194 | |
|---|
| 195 | } |
|---|
| 196 | else |
|---|
| 197 | std::cout << "Device Manager DCD file : " << _deviceConfigurationProfile << " doesn't exist." << std::endl; |
|---|
| 198 | |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | void |
|---|
| 203 | DeviceManager_impl::init () |
|---|
| 204 | { |
|---|
| 205 | DEBUG(6, DeviceManager, "Entering init."); |
|---|
| 206 | |
|---|
| 207 | _adminState = DEVMGR_UNREGISTERED; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | void |
|---|
| 212 | DeviceManager_impl::getDomainManagerReference (char *domainManagerName) |
|---|
| 213 | { |
|---|
| 214 | DEBUG(6, DeviceManager, "Entering getDomainManagerReference."); |
|---|
| 215 | |
|---|
| 216 | CORBA::Object_var obj = CORBA::Object::_nil(); |
|---|
| 217 | |
|---|
| 218 | /// \todo sleep prevents system from beating Name Service to death, Fix better |
|---|
| 219 | do{ |
|---|
| 220 | obj = orb_obj->get_object_from_name (domainManagerName); |
|---|
| 221 | usleep(1000); |
|---|
| 222 | }while(CORBA::is_nil(obj)); |
|---|
| 223 | |
|---|
| 224 | _dmnMgr = CF::DomainManager::_narrow (obj); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | char *DeviceManager_impl::deviceConfigurationProfile () |
|---|
| 229 | throw (CORBA::SystemException) |
|---|
| 230 | { |
|---|
| 231 | DEBUG(6, DeviceManager, "Entering deviceConfigurationProfile."); |
|---|
| 232 | return CORBA::string_dup(_deviceConfigurationProfile.c_str()); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | CF::FileSystem_ptr DeviceManager_impl::fileSys ()throw (CORBA:: |
|---|
| 237 | SystemException) |
|---|
| 238 | { |
|---|
| 239 | DEBUG(6, DeviceManager, "Entering fileSys."); |
|---|
| 240 | CF::FileSystem_var result = _fileSys; |
|---|
| 241 | return result._retn(); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | char *DeviceManager_impl::identifier () |
|---|
| 246 | throw (CORBA::SystemException) |
|---|
| 247 | { |
|---|
| 248 | DEBUG(6, DeviceManager, "Entering identifier."); |
|---|
| 249 | return CORBA::string_dup (_identifier.c_str()); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | char *DeviceManager_impl::label () |
|---|
| 254 | throw (CORBA::SystemException) |
|---|
| 255 | { |
|---|
| 256 | DEBUG(6, DeviceManager, "Entering label."); |
|---|
| 257 | return CORBA::string_dup (_label.c_str()); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | CF::DeviceSequence * |
|---|
| 262 | DeviceManager_impl::registeredDevices ()throw (CORBA::SystemException) |
|---|
| 263 | { |
|---|
| 264 | DEBUG(6, DeviceManager, "Entering registeredDevices."); |
|---|
| 265 | CF::DeviceSequence_var result = new CF::DeviceSequence(_registeredDevices); |
|---|
| 266 | return result._retn(); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | CF::DeviceManager::ServiceSequence * |
|---|
| 271 | DeviceManager_impl::registeredServices ()throw (CORBA::SystemException) |
|---|
| 272 | { |
|---|
| 273 | DEBUG(6, DeviceManager, "Entering registeredServices."); |
|---|
| 274 | CF::DeviceManager::ServiceSequence_var result = new CF::DeviceManager::ServiceSequence(_registeredServices); |
|---|
| 275 | return result._retn(); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | void |
|---|
| 280 | DeviceManager_impl::registerDevice (CF::Device_ptr registeringDevice) |
|---|
| 281 | throw (CORBA::SystemException, CF::InvalidObjectReference) |
|---|
| 282 | { |
|---|
| 283 | DEBUG(6, DeviceManager, "Entering registerDevice."); |
|---|
| 284 | if (CORBA::is_nil (registeringDevice)) { |
|---|
| 285 | //writeLogRecord(FAILURE_ALARM,invalid reference input parameter.) |
|---|
| 286 | |
|---|
| 287 | throw (CF:: |
|---|
| 288 | InvalidObjectReference |
|---|
| 289 | ("Cannot register Device. registeringDevice is a nil reference.")); |
|---|
| 290 | return; |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | // Register the device with the Device manager, unless it is already |
|---|
| 294 | // registered |
|---|
| 295 | if (!deviceIsRegistered (registeringDevice)) { |
|---|
| 296 | _registeredDevices.length (_registeredDevices.length () + 1); |
|---|
| 297 | _registeredDevices[_registeredDevices.length () - 1] = |
|---|
| 298 | registeringDevice; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | // If this Device Manager is registered with a Domain Manager, register |
|---|
| 302 | // the new device with the Domain Manager |
|---|
| 303 | if (_adminState == DEVMGR_REGISTERED) { |
|---|
| 304 | _dmnMgr->registerDevice (registeringDevice, myObj); |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | //The registerDevice operation shall write a FAILURE_ALARM log record to a |
|---|
| 308 | //DomainManagers Log, upon unsuccessful registration of a Device to the DeviceManagers |
|---|
| 309 | //registeredDevices. |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | //This function returns TRUE if the input registeredDevice is contained in the _registeredDevices list attribute |
|---|
| 314 | bool DeviceManager_impl::deviceIsRegistered (CF::Device_ptr registeredDevice) |
|---|
| 315 | { |
|---|
| 316 | DEBUG(6, DeviceManager, "Entering deviceIsRegistered."); |
|---|
| 317 | //Look for registeredDevice in _registeredDevices |
|---|
| 318 | for (unsigned int i = 0; i < _registeredDevices.length (); i++) |
|---|
| 319 | { |
|---|
| 320 | if (strcmp (_registeredDevices[i]->label (), registeredDevice->label ()) |
|---|
| 321 | == 0) |
|---|
| 322 | { |
|---|
| 323 | return true; |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | return false; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | //This function returns TRUE if the input serviceName is contained in the _registeredServices list attribute |
|---|
| 331 | bool DeviceManager_impl::serviceIsRegistered (const char *serviceName) |
|---|
| 332 | { |
|---|
| 333 | DEBUG(6, DeviceManager, "Entering serviceIsRegistered."); |
|---|
| 334 | //Look for registeredDevice in _registeredDevices |
|---|
| 335 | for (unsigned int i = 0; i < _registeredServices.length (); i++) |
|---|
| 336 | { |
|---|
| 337 | if (strcmp (_registeredServices[i].serviceName, serviceName) == 0) |
|---|
| 338 | { |
|---|
| 339 | return true; |
|---|
| 340 | } |
|---|
| 341 | } |
|---|
| 342 | return false; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | void |
|---|
| 347 | DeviceManager_impl::unregisterDevice (CF::Device_ptr registeredDevice) |
|---|
| 348 | throw (CORBA::SystemException, CF::InvalidObjectReference) |
|---|
| 349 | { |
|---|
| 350 | DEBUG(6, DeviceManager, "Entering unRegisterDevice."); |
|---|
| 351 | bool deviceFound = false; |
|---|
| 352 | if (CORBA::is_nil (registeredDevice)) //|| !deviceIsRegistered(registeredDevice) ) |
|---|
| 353 | { |
|---|
| 354 | //The unregisterDevice operation shall write a FAILURE_ALARM log record, when it cannot |
|---|
| 355 | //successfully remove a registeredDevice from the DeviceManagers registeredDevices. |
|---|
| 356 | |
|---|
| 357 | //The unregisterDevice operation shall raise the CF InvalidObjectReference when the input |
|---|
| 358 | //registeredDevice is a nil CORBA object reference or does not exist in the DeviceManagers |
|---|
| 359 | //registeredDevices attribute. |
|---|
| 360 | /*writeLogRecord(FAILURE_ALARM,invalid reference input parameter.); */ |
|---|
| 361 | throw (CF:: |
|---|
| 362 | InvalidObjectReference |
|---|
| 363 | ("Cannot unregister Device. registeringDevice is a nil reference.")); |
|---|
| 364 | |
|---|
| 365 | return; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | //The unregisterDevice operation shall remove the input registeredDevice from the |
|---|
| 369 | //DeviceManagers registeredDevices attribute. |
|---|
| 370 | |
|---|
| 371 | //Look for registeredDevice in _registeredDevices |
|---|
| 372 | for (unsigned int i = 0; i < _registeredDevices.length (); i++) |
|---|
| 373 | { |
|---|
| 374 | if (strcmp (_registeredDevices[i]->label (), registeredDevice->label ()) |
|---|
| 375 | == 0) |
|---|
| 376 | { |
|---|
| 377 | //when the appropiater device is found, remove it from the _registeredDevices sequence |
|---|
| 378 | deviceFound = true; |
|---|
| 379 | if (_adminState == DEVMGR_REGISTERED) |
|---|
| 380 | { |
|---|
| 381 | _dmnMgr->unregisterDevice (CF::Device::_duplicate (registeredDevice)); |
|---|
| 382 | CORBA::release (registeredDevice); |
|---|
| 383 | } |
|---|
| 384 | for (unsigned int j = i; j < _registeredDevices.length () - 1; j++) |
|---|
| 385 | { |
|---|
| 386 | //The unregisterDevice operation shall unregister |
|---|
| 387 | //the input registeredDevice from the DomainManager when the input registeredDevice is |
|---|
| 388 | //registered with the DeviceManager and the DeviceManager is not shutting down. |
|---|
| 389 | _registeredDevices[j] = _registeredDevices[j + 1]; |
|---|
| 390 | } |
|---|
| 391 | //_registeredDevices[_registeredDevices.length() - 1] = 0; |
|---|
| 392 | _registeredDevices.length (_registeredDevices.length () - 1); |
|---|
| 393 | //TO DO: Avoid memory leaks by reducing the length of the sequence _registeredDevices |
|---|
| 394 | break; |
|---|
| 395 | } |
|---|
| 396 | } |
|---|
| 397 | if (!deviceFound) |
|---|
| 398 | { |
|---|
| 399 | /*writeLogRecord(FAILURE_ALARM,invalid reference input parameter.); */ |
|---|
| 400 | |
|---|
| 401 | throw (CF:: |
|---|
| 402 | InvalidObjectReference |
|---|
| 403 | ("Cannot unregister Device. registeringDevice was not registered.")); |
|---|
| 404 | return; |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | void |
|---|
| 411 | DeviceManager_impl::shutdown () |
|---|
| 412 | throw (CORBA::SystemException) |
|---|
| 413 | { |
|---|
| 414 | DEBUG(6, DeviceManager, "Entering shutdown."); |
|---|
| 415 | _adminState = DEVMGR_SHUTTING_DOWN; |
|---|
| 416 | |
|---|
| 417 | //The shutdown operation shall unregister the DeviceManager from the DomainManager. |
|---|
| 418 | _dmnMgr->unregisterDeviceManager (this->_this ()); ///\bug This looks wrong. |
|---|
| 419 | |
|---|
| 420 | //The shutdown operation shall perform releaseObject on all of the DeviceManagers registered |
|---|
| 421 | //Devices (DeviceManagers registeredDevices attribute). |
|---|
| 422 | |
|---|
| 423 | for (int i = _registeredDevices.length () - 1; i >= 0; i--) |
|---|
| 424 | { |
|---|
| 425 | //Important Note: It is necessary to manage the lenght of the _registeredDevices sequence |
|---|
| 426 | //otherwise, some elements in the sequence will be null. |
|---|
| 427 | _registeredDevices[i]->label (); ////////////////////////////////////////////////test |
|---|
| 428 | CF::Device_var tempDev = CF::Device::_duplicate (_registeredDevices[i]); |
|---|
| 429 | //_registeredDevices[i]->releaseObject(); |
|---|
| 430 | unregisterDevice (_registeredDevices[i]); |
|---|
| 431 | tempDev->releaseObject (); |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | void |
|---|
| 438 | DeviceManager_impl::registerService (CORBA::Object_ptr registeringService, |
|---|
| 439 | const char *name) |
|---|
| 440 | throw (CORBA::SystemException, CF::InvalidObjectReference) |
|---|
| 441 | { |
|---|
| 442 | DEBUG(6, DeviceManager, "Entering registerService."); |
|---|
| 443 | //This release does not support services |
|---|
| 444 | if (CORBA::is_nil (registeringService)) |
|---|
| 445 | { |
|---|
| 446 | /*writeLogRecord(FAILURE_ALARM,invalid reference input parameter.); */ |
|---|
| 447 | |
|---|
| 448 | throw (CF:: |
|---|
| 449 | InvalidObjectReference |
|---|
| 450 | ("Cannot register Device. registeringDevice is a nil reference.")); |
|---|
| 451 | return; |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | //The registerService operation shall add the input registeringService to the DeviceManagers |
|---|
| 455 | //registeredServices attribute when the input registeringService does not already exist in the |
|---|
| 456 | //registeredServices attribute. The registeringService is ignored when duplicated. |
|---|
| 457 | if (!serviceIsRegistered (name)) |
|---|
| 458 | { |
|---|
| 459 | _registeredServices.length (_registeredServices.length () + 1); |
|---|
| 460 | _registeredServices[_registeredServices.length () - 1].serviceObject = registeringService; |
|---|
| 461 | _registeredServices[_registeredServices.length () - 1].serviceName = name; |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | //The registerService operation shall register the registeringService with the DomainManager |
|---|
| 465 | //when the DeviceManager has already registered to the DomainManager and the |
|---|
| 466 | //registeringService has been successfully added to the DeviceManagers registeredServices |
|---|
| 467 | //attribute. |
|---|
| 468 | if (_adminState == DEVMGR_REGISTERED) |
|---|
| 469 | { |
|---|
| 470 | _dmnMgr->registerService (registeringService, this->_this (), name); |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | //The registerService operation shall write a FAILURE_ALARM log record, upon unsuccessful |
|---|
| 474 | //registration of a Service to the DeviceManagers registeredServices. |
|---|
| 475 | //The registerService operation shall raise the CF InvalidObjectReference exception when the |
|---|
| 476 | //input registeringService is a nil CORBA object reference. |
|---|
| 477 | |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | void |
|---|
| 482 | DeviceManager_impl::unregisterService (CORBA::Object_ptr registeredService, |
|---|
| 483 | const char *name) |
|---|
| 484 | throw (CORBA::SystemException, CF::InvalidObjectReference) |
|---|
| 485 | { |
|---|
| 486 | DEBUG(6, DeviceManager, "Entering unRegisterService."); |
|---|
| 487 | if (CORBA::is_nil (registeredService)) |
|---|
| 488 | { |
|---|
| 489 | /*writeLogRecord(FAILURE_ALARM,invalid reference input parameter.); */ |
|---|
| 490 | |
|---|
| 491 | throw (CF:: |
|---|
| 492 | InvalidObjectReference |
|---|
| 493 | ("Cannot unregister Service. registeringService is a nil reference.")); |
|---|
| 494 | return; |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | //The unregisterService operation shall remove the input registeredService from the |
|---|
| 498 | //DeviceManagers registeredServices attribute. The unregisterService operation shall unregister |
|---|
| 499 | //the input registeredService from the DomainManager when the input registeredService is |
|---|
| 500 | //registered with the DeviceManager and the DeviceManager is not in the shutting down state. |
|---|
| 501 | |
|---|
| 502 | //Look for registeredService in _registeredServices |
|---|
| 503 | for (unsigned int i = 0; i < _registeredServices.length (); i++) |
|---|
| 504 | { |
|---|
| 505 | if (strcmp (_registeredServices[i].serviceName, name) == 0) |
|---|
| 506 | { |
|---|
| 507 | //when the appropiater device is found, remove it from the _registeredDevices sequence |
|---|
| 508 | if (_adminState == DEVMGR_REGISTERED) |
|---|
| 509 | { |
|---|
| 510 | _dmnMgr->unregisterService (registeredService, name); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | for (unsigned int j = i; j < _registeredServices.length ()-1; j++) |
|---|
| 514 | { |
|---|
| 515 | |
|---|
| 516 | CORBA::release (registeredService); |
|---|
| 517 | _registeredServices[j] = _registeredServices[j+1]; |
|---|
| 518 | } |
|---|
| 519 | _registeredServices.length (_registeredServices.length () - 1); |
|---|
| 520 | return; |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | //If it didn't find registeredDevice, then throw an exception |
|---|
| 525 | /*writeLogRecord(FAILURE_ALARM,invalid reference input parameter.);*/ |
|---|
| 526 | throw (CF:: |
|---|
| 527 | InvalidObjectReference |
|---|
| 528 | ("Cannot unregister Service. registeringService was not registered.")); |
|---|
| 529 | //The unregisterService operation shall write a FAILURE_ALARM log record, when it cannot |
|---|
| 530 | //successfully remove a registeredService from the DeviceManagers registeredServices. |
|---|
| 531 | //The unregisterService operation shall raise the CF InvalidObjectReference when the input |
|---|
| 532 | //registeredService is a nil CORBA object reference or does not exist in the DeviceManagers |
|---|
| 533 | //registeredServices attribute. |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | char * |
|---|
| 538 | DeviceManager_impl:: |
|---|
| 539 | getComponentImplementationId (const char *componentInstantiationId) |
|---|
| 540 | throw (CORBA::SystemException) |
|---|
| 541 | { |
|---|
| 542 | DEBUG(6, DeviceManager, "Entering getComponentImplementationId."); |
|---|
| 543 | //The getComponentImplementationId operation shall return the SPD implementation elements |
|---|
| 544 | //ID attribute that matches the SPD implementation element used to create the component |
|---|
| 545 | //identified by the input componentInstantiationId parameter. |
|---|
| 546 | |
|---|
| 547 | #if 0 |
|---|
| 548 | DCDParser _DCDParser (_deviceConfigurationProfile); |
|---|
| 549 | std::vector < char *>*LocalComponentsVector = |
|---|
| 550 | _DCDParser.getLocalComponents (); |
|---|
| 551 | #endif |
|---|
| 552 | |
|---|
| 553 | cout << "If this appears look at DeviceManager_impl.cpp line 572" << endl; |
|---|
| 554 | /*for (int i = 0; i<localComponentsVector->size();i++) |
|---|
| 555 | { |
|---|
| 556 | //get componentInstatiationId from each loal component |
|---|
| 557 | std::vector<ComponentInstantiation*> instantiations = LocalComponentsVector[i].getInstantiations(); |
|---|
| 558 | //assuming only one instantiation |
|---|
| 559 | if( strcmp(componentInstantiationId, instantiations[0]->getID()) == 0) |
|---|
| 560 | { |
|---|
| 561 | SPDParser spdParser ( LocalComponentsVector[i].getSPDFile() ); |
|---|
| 562 | std::vector<SPDImplementation*> implementations = spdParser.getImplementations(); |
|---|
| 563 | return implementations[0]->getID(); |
|---|
| 564 | } |
|---|
| 565 | } */ |
|---|
| 566 | return ""; |
|---|
| 567 | |
|---|
| 568 | //The getComponentImplementationId operation shall return an empty string when the input |
|---|
| 569 | //componentInstantiationId parameter does not match the ID attribute of any SPD implementation |
|---|
| 570 | //element used to create the component. |
|---|
| 571 | } |
|---|
| 572 | |
|---|
| 573 | #ifdef AUTOMATIC_TEST |
|---|
| 574 | |
|---|
| 575 | void DeviceManager_impl::displayRegisteredDevices (void) |
|---|
| 576 | { |
|---|
| 577 | |
|---|
| 578 | CF::Device_ptr myDev_ptr; |
|---|
| 579 | if(_registeredDevices.length() > 0) |
|---|
| 580 | { |
|---|
| 581 | std::cout << "Devices registered in "<< this->label() <<" Device Manager"<< std::endl; |
|---|
| 582 | for (unsigned int i = 0; i < _registeredDevices.length(); i++) |
|---|
| 583 | { |
|---|
| 584 | myDev_ptr=CF::Device::_narrow(_registeredDevices[i]); |
|---|
| 585 | std::cout<< "\n "<< myDev_ptr->label()<<std::endl; |
|---|
| 586 | //cout<<( "\n %s\n",_registeredDevices[i]->label() ); |
|---|
| 587 | } |
|---|
| 588 | } |
|---|
| 589 | else |
|---|
| 590 | { |
|---|
| 591 | std::cout<<"\nThere are no registered devices in "<<this->label()<<" Device Manager"<<std::endl; |
|---|
| 592 | } |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | void DeviceManager_impl::displayRegisteredServices (void) |
|---|
| 596 | { |
|---|
| 597 | if( _registeredServices.length() > 0 ) |
|---|
| 598 | { |
|---|
| 599 | std::cout<<"\nServices registered in "<<this->label() <<"Device Manager"<<std::endl; |
|---|
| 600 | for (unsigned int i = 0; i < _registeredServices.length(); i++) |
|---|
| 601 | { |
|---|
| 602 | if( CORBA::is_nil(_registeredServices[i].serviceObject) ) |
|---|
| 603 | std::cout<<"\nInvalid object reference for "<<_registeredServices[i].serviceName<<std::endl; |
|---|
| 604 | else |
|---|
| 605 | std::cout<<"\n"<<_registeredServices[i].serviceName<<std::endl; |
|---|
| 606 | } |
|---|
| 607 | } |
|---|
| 608 | else |
|---|
| 609 | { |
|---|
| 610 | std::cout<<"\nThere are no registered services in "<<this->label()<<" Device Manager"<<std::endl; |
|---|
| 611 | } |
|---|
| 612 | } |
|---|
| 613 | #endif |
|---|