1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
|
static const char *RcsId = "$Id: basiccommand.cpp 15556 2011-02-11 08:25:58Z taurel $\n$Name$";
//+============================================================================
//
// file : BasicCommand.cpp
//
// description : C++ source code for commands which are automatically
// installed for every devices
// Three commands are :
// DevState, DevStatus, DevRestart
//
// project : TANGO
//
// author(s) : A.Gotz + E.Taurel
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2010,2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Revision: 15556 $
//
// $Log$
// Revision 3.16 2010/09/09 13:44:46 taurel
// - Add year 2010 in Copyright notice
//
// Revision 3.15 2009/03/13 09:33:29 taurel
// - Small changes to fix Windows VC8 warnings in Warning level 3
//
// Revision 3.14 2009/02/03 15:10:07 jensmeyer
// Added cleaning of the sub device list in DevInitCmd::execute().
//
// Revision 3.13 2009/01/21 12:49:04 taurel
// - Change CopyRights for 2009
//
// Revision 3.12 2008/10/06 15:00:36 taurel
// - Changed the licensing info from GPL to LGPL
//
// Revision 3.11 2008/10/03 06:51:36 taurel
// - Add some licensing info in each files
//
// Revision 3.10 2008/09/04 07:37:05 taurel
// - Fix bug in memorized attributes
// - Changes for the new IDL 4
//
// Revision 3.9 2008/05/20 12:44:09 taurel
// - Commit after merge with release 7 branch
//
// Revision 3.8 2008/02/29 12:50:27 taurel
// - Fix bug in Init command for the admin device
// Revision 3.7.2.1 2008/02/07 15:58:12 taurel
// - First implementation of the Controlled Access done
//
// Revision 3.7 2007/11/08 12:03:44 taurel
// - Start implementing user interceptors
// - Fix bug in poll thread pproperty management when removing polling object
// - Set a database timeout to 6 sec
//
// Revision 3.6 2007/10/26 11:25:25 taurel
// - Memorized attributes now applied even for the Init command
//
// Revision 3.5 2006/11/20 16:28:43 taurel
// - Re-configure the polling thread if the Init command is done on the admin
// device
//
// Revision 3.4 2006/05/18 08:52:37 taurel
// - Miscellaneous changes due to Python device server ported to Windows
// - Fix some bugs discovered by Windows VC8 using the test suite
// - Update Windows resource file include path
// - Fix some Windows VC8 warnings
//
// Revision 3.3 2005/01/13 09:27:52 taurel
// Fix some bugs :
// - R/W attribute : W value not returned when read if set by set_write_value
// - Core dumped when retrieving attribute polling history for Device_2Impl device which
// has stored an exception
// - Remove device_name in lib default attribute label property
// - Lib default value for label not store in db any more
// - Size of the DaData used by the Database::get_device_attribute_property() and
// Database::get_class_attribute_property()
// - R/W attribute: W part not returned when read for Device_2Impl device
// Some changes :
// - Improvement of the -file option error management (now throw exception in case of
// error)
// - Reset "string" attribute property to the default value (lib or user) when new
// value is an empty string
//
// Revision 3.2 2003/05/28 14:55:07 taurel
// Add the include (conditionally) of the include files generated by autoconf
//
// Revision 3.1 2003/05/16 08:46:15 taurel
// Many changes for release 3.0.1. The most important ones are :
// - Timeout are backs
// - Multiple db servers (change in TANGO_HOST syntax)
// - Added methods to print DeviceData, DeviceDataHistory, DeviceAttribute and DeviceAttributeHistory instances
// - Attributes name stored in blackbox
// - Remove check if a class is created without any device
// - It's now possible to create a DeviceProxy from its alias name
// - Command, attribute names are case insensitive
// - Change parameters of some DeviceProxy logging methods
// - Change parameters of DeviceProxy asynchronous replies calls
// - New serialization model in device server (no serialization model)
// - Win32 (2000) device server service does not exit at loggoff anymore
// - Miscellaneous bug fixes
//
// Revision 3.0 2003/03/25 16:41:57 taurel
// Many changes for Tango release 3.0 including
// - Added full logging features
// - Added asynchronous calls
// - Host name of clients now stored in black-box
// - Three serialization model in DS
// - Fix miscellaneous bugs
// - Ported to gcc 3.2
// - Added ApiUtil::cleanup() and destructor methods
// - Some internal cleanups
// - Change the way how TangoMonitor class is implemented. It's a recursive
// mutex
//
// Revision 2.9 2003/01/09 12:03:15 taurel
// - Ported to gcc 3.2
// - Added ApiUtil::cleanup() and ApiUtil::~ApiUtil() methods
// - Replace some ORB * by ORB_ptr
// - Use CORBA::ORB::is_nil() instead of comparing to NULL
//
// Revision 2.8 2002/12/16 12:06:21 taurel
// No change in code at all but only forgot th emost important line in
// list of updates in the previous release :
// - Change underlying ORB from ORBacus to omniORB
//
// Revision 2.7 2002/12/16 10:15:35 taurel
// - New method get_device_list() in Util class
// - Util::get_class_list takes DServer device into account
// - Util::get_device_by_name() takes DServer device into account
// - Util::get_device_list_by_class() takes DServer device into account
// - New parameter to the attribute::set_value() method to enable CORBA to free
// memory allocated for the attribute
//
// Revision 2.6 2002/10/17 07:43:05 taurel
// Fix bug in history stored by the polling thread :
// - We need one copy of the attribute data to build an history!!! It is true
// also for command which return data created by the DeviceImpl::create_xxx
// methods. Chnage in pollring.cpp/pollring.h/dserverpoll.cpp/pollobj.cpp
// and pollobj.h
//
// Revision 2.5 2002/10/15 11:27:18 taurel
// Fix bugs in device.cpp file :
// - Protect the state and status CORBA attribute with the device monitor
// Add the "TgLibVers" string as a #define in tango_config.h
//
// Revision 2.4 2002/08/12 15:06:53 taurel
// Several big fixes and changes
// - Remove HP-UX specific code
// - Fix bug in polling alogorithm which cause the thread to enter an infinite
// loop (pollthread.cpp)
// - For bug for Win32 device when trying to set attribute config
// (attribute.cpp)
//
// Revision 2.3 2002/07/02 15:22:23 taurel
// Miscellaneous small changes/bug fixes for Tango CPP release 2.1.0
// - classes reference documentation now generated using doxygen instead of doc++
// - A little file added to the library which summarizes version number.
// The RCS/CVS "ident" command will now tells you that release library x.y.z is composed
// by C++ client classes set release a.b and C++ server classes set release c.d
// - Fix incorrect field setting for DevFailed exception re-thrown from a CORBA exception
// - It's now not possible to poll the Init command
// - It's now possible to define a default class doc. per control system
// instance (using property)
// - The test done to check if attribute value has been set before it is
// returned to caller is done only if the attribute quality is set to VALID
// - The JTCInitialize object is now stored in the Util
// - Windows specific : The tango.h file now also include winsock.h
//
// Revision 2.2 2002/04/30 10:50:40 taurel
// Don't check alarm on attribute if attribute quality factor is INVALID
//
// Revision 2.1 2002/04/29 12:24:02 taurel
// Fix bug in attribute::set_value method and on the check against min and max value when writing attributes
//
// Revision 2.0 2002/04/09 14:45:08 taurel
// See Tango WEB pages for list of changes
//
// Revision 1.6 2001/10/08 09:03:10 taurel
// See tango WEB pages for list of changes
//
// Revision 1.5 2001/07/04 12:27:09 taurel
// New methods re_throw_exception(). Read_attributes supports AllAttr mnemonic A new add_attribute()method in DeviceImpl class New way to define attribute properties New pattern to prevent full re-compile For multi-classes DS, it is now possible to use the Util::get_device_by_name() method in device constructor Adding << operator ovebloading Fix devie CORBA ref. number when device constructor sends an excep.
//
// Revision 1.4 2001/05/04 09:28:12 taurel
// Fix bugs in DServer::restart() method and in Util::get_device_by_name() method
//
// Revision 1.3 2001/03/30 08:03:44 taurel
// Fix bugs in attributes. For linux, add signal_handler in its own thread, change the way to kill server. For all system, change DevRestart philosophy.
//
// Revision 1.2 2001/03/09 08:20:14 taurel
// Fix bug in the MultiClassAttribute::init_class_attribute() method. Also remove the DbErr_DeviceNotDefined define.
//
// Revision 1.1.1.1 2001/02/27 08:46:20 taurel
// Imported sources
//
// Revision 1.3 2000/04/13 10:40:39 taurel
// Added attribute support
//
// Revision 1.2 2000/02/04 11:00:12 taurel
// Just update revision number
//
// Revision 1.1.1.1 2000/02/04 10:58:27 taurel
// Imported sources
//
//-============================================================================
#if HAVE_CONFIG_H
#include <ac_config.h>
#endif
#include <tango.h>
#include <basiccommand.h>
extern omni_thread::key_t key_py_data;
namespace Tango
{
//+-------------------------------------------------------------------------
//
// method : DevStatusCmd::DevStatusCmd
//
// description : constructor for Command class Status
//
//--------------------------------------------------------------------------
DevStatusCmd::DevStatusCmd(const char *name,Tango::CmdArgType in,Tango::CmdArgType out)
:Command(name,in,out)
{
}
//+-------------------------------------------------------------------------
//
// method : DevStatusCmd::execute
//
// description : return status as string
//
//--------------------------------------------------------------------------
CORBA::Any *DevStatusCmd::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
cout4 << "DevStatus::execute(): arrived " << endl;
//
// return status string as Any
//
CORBA::Any *out_any;
try
{
out_any = new CORBA::Any();
}
catch (bad_alloc)
{
Except::throw_exception((const char *)"API_MemoryAllocation",
(const char *)"Can't allocate memory in server",
(const char *)"DevStatus::execute");
}
try
{
(*out_any) <<= device->dev_status();
}
catch(...)
{
delete out_any;
throw;
}
cout4 << "Leaving DevStatus::execute()" << endl;
return out_any;
}
//+-------------------------------------------------------------------------
//
// method : DevStateCmd::DevStateCmd
//
// description : constructor for Command class State
//
//--------------------------------------------------------------------------
DevStateCmd::DevStateCmd(const char *name,Tango::CmdArgType in, Tango::CmdArgType out)
:Command(name,in,out)
{
}
//+-------------------------------------------------------------------------
//
// method : StateCmd::execute
//
// description : return state as enumerated type
//
//--------------------------------------------------------------------------
CORBA::Any *DevStateCmd::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
cout4 << "DevState::execute(): arrived" << endl;
//
// return state as Any
//
CORBA::Any *out_any;
try
{
out_any = new CORBA::Any();
}
catch (bad_alloc)
{
Except::throw_exception((const char *)"API_MemoryAllocation",
(const char *)"Can't allocate memory in server",
(const char *)"DevStatus::execute");
}
try
{
(*out_any) <<= device->dev_state();
}
catch(...)
{
delete out_any;
throw;
}
cout4 << "Leaving DevState::execute()" << endl;
return out_any;
}
//+-------------------------------------------------------------------------
//
// method : DevStateCmd::DevInitCmd
//
// description : constructor for Command class Init
//
//--------------------------------------------------------------------------
DevInitCmd::DevInitCmd(const char *name,Tango::CmdArgType in, Tango::CmdArgType out)
:Command(name,in,out)
{
}
//+-------------------------------------------------------------------------
//
// method : InitCmd::execute
//
// description : Initialize a device
//
//--------------------------------------------------------------------------
CORBA::Any *DevInitCmd::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
cout4 << "Init::execute(): arrived" << endl;
//
// Init device
//
Tango::Util *tg = Tango::Util::instance();
omni_thread *th;
PyLock *lock_ptr = NULL;
try
{
NoSyncModelTangoMonitor mon(device);
if (tg->is_py_ds())
{
th = omni_thread::self();
omni_thread::value_t *tmp_py_data = th->get_value(key_py_data);
lock_ptr = (static_cast<PyData *>(tmp_py_data))->PerTh_py_lock;
lock_ptr->Get();
}
// clean the sub-device list for this device
tg->get_sub_dev_diag().remove_sub_devices (device->get_name());
tg->get_sub_dev_diag().set_associated_device(device->get_name());
device->delete_device();
device->init_device();
//
// Re-configure polling in device on which the Init cmd been done is the admin
// device but only if the Init is not called during the DS startup sequence
//
DeviceImpl *admin_dev = NULL;
try
{
admin_dev = tg->get_dserver_device();
}
catch (Tango::DevFailed &) {}
if (admin_dev == device)
tg->polling_configure();
if (tg->is_py_ds())
lock_ptr->Release();
//
// Apply memorized values for memorized attributes (if any)
// For Py DS, if some attributes are memorized, the write_attributes
// call will take the Python lock
//
Tango::DeviceClass *dc = device->get_device_class();
vector<Tango::DeviceImpl *> dev_v = dc->get_device_list();
unsigned int loop;
for (loop = 0;loop < dev_v.size();loop++)
{
if (dev_v[loop] == device)
break;
}
if (loop != dev_v.size())
dc->set_memorized_values(false,loop,true);
else
{
Tango::Except::throw_exception((const char *)"API_DeviceNotFound",
(const char *)"Can't find new device in device list",
(const char *)"DevInitCmd::execute()");
}
}
catch (Tango::DevFailed &e)
{
if ((tg->is_py_ds() == true) && (lock_ptr != NULL))
{
lock_ptr->Release();
}
TangoSys_OMemStream o;
o << "Init command failed!!";
o << "\nHINT: RESTART device with the Restart command of the device server adm. device";
o << "\nDevice server adm. device name = dserver/";
o << tg->get_ds_name().c_str() << ends;
Except::re_throw_exception(e,(const char *)"API_InitThrowsException",o.str(),
(const char *)"DevInitCmd::execute()");
}
//
// return to the caller
//
CORBA::Any *ret = return_empty_any("InitCmd");
return ret;
}
} // End of Tango namespace
|