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
|
static const char *RcsId = "$Id: basiccommand.cpp 28853 2015-12-07 13:38:45Z 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,2012,2013,2014,2015
// 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: 28853 $
//
//-==================================================================================================================
#if HAVE_CONFIG_H
#include <ac_config.h>
#endif
#include <tango.h>
#include <basiccommand.h>
#include <devintr.h>
#include <eventsupplier.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, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout4 << "DevStatus::execute(): arrived " << endl;
//
// return status string as Any
//
CORBA::Any *out_any = NULL;
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
{
if (device->is_alarm_state_forced() == true)
(*out_any) <<= device->DeviceImpl::dev_status();
else
(*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, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout4 << "DevState::execute(): arrived" << endl;
//
// return state as Any
//
CORBA::Any *out_any = NULL;
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
{
if (device->is_alarm_state_forced() == true)
(*out_any) <<= device->DeviceImpl::dev_state();
else
(*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
//
// argument :
// in :
// - device : Pointer to the device on which the command must be excuted
// - in_any : Input data packed in a CORBA Any object
//
//--------------------------------------------------------------------------------------------------------------------
CORBA::Any *DevInitCmd::execute(DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout4 << "Init::execute(): arrived" << endl;
//
// Get device interface only if necessary (some client(s) listening on device interface change event)
//
ZmqEventSupplier *event_supplier_zmq = Tango_nullptr;
event_supplier_zmq = Util::instance()->get_zmq_event_supplier();
DevIntr di;
bool ev_client = false;
if (event_supplier_zmq != Tango_nullptr)
{
ev_client = event_supplier_zmq->any_dev_intr_client(device);
}
if (device->get_dev_idl_version() >= MIN_IDL_DEV_INTR && ev_client == true)
{
di.get_interface(device);
device->disable_intr_change_ev();
}
//
// Init device
//
omni_thread *th;
PyLock *lock_ptr = NULL;
Tango::Util *tg;
try
{
NoSyncModelTangoMonitor mon(device);
tg = Tango::Util::instance();
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();
}
device->enable_intr_change_ev();
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()");
}
//
// Check if device interface has changed and eventually fire device interface change event
//
if (device->get_dev_idl_version() >= MIN_IDL_DEV_INTR && ev_client == true)
{
device->enable_intr_change_ev();
if (di.has_changed(device) == true)
{
Device_5Impl *dev_5 = static_cast<Device_5Impl *>(device);
DevCmdInfoList_2 *cmds_list = dev_5->command_list_query_2();
DevVarStringArray dvsa(1);
dvsa.length(1);
dvsa[0] = Tango::string_dup(AllAttr_3);
AttributeConfigList_5 *atts_list = dev_5->get_attribute_config_5(dvsa);
event_supplier_zmq->push_dev_intr_change_event(device,false,cmds_list,atts_list);
}
}
//
// return to the caller
//
CORBA::Any *ret = return_empty_any("InitCmd");
return ret;
}
} // End of Tango namespace
|