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
|
// NOLINTBEGIN(*)
#include "old_common.h"
/*
* Small utility program to help testing locking features.
*
* Possible return code:
* -1 : major error
* 0 : success
* 1 : Exception API_DeviceLocked
* 2 : All other exceptions
* 3 : State or Status command failed
*/
int main(int argc, char **argv)
{
DeviceProxy *device;
if((argc == 1) || (argc > 3))
{
TEST_LOG << "usage: %s device" << endl;
exit(-1);
}
string device_name = argv[1];
try
{
device = new DeviceProxy(device_name);
}
catch(CORBA::Exception &)
{
// Except::print_exception(e);
exit(-1);
}
// Try state or status on a locked device
try
{
device->command_inout("State");
device->command_inout("Status");
}
catch(Tango::DevFailed &)
{
return 3;
}
// Try a command on the device
DeviceData din, dout;
din << (short) 2;
try
{
dout = device->command_inout("IOShort", din);
}
catch(Tango::DevFailed &e)
{
// Except::print_exception(e);
if(::strcmp(e.errors[0].reason.in(), API_DeviceLocked) != 0)
{
return 2;
}
}
// Try a command asynchronously
long id;
id = device->command_inout_asynch("IOShort", din);
bool finish = false;
while(finish == false)
{
try
{
dout = device->command_inout_reply(id);
finish = true;
}
catch(AsynReplyNotArrived &)
{
finish = false;
TEST_LOG << "Command not yet arrived" << endl;
}
catch(DevFailed &e)
{
// Except::print_exception(e);
if(::strcmp(e.errors[0].reason.in(), API_DeviceLocked) != 0)
{
return 2;
}
else
{
finish = true;
}
}
if(finish == false)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
// Try a write attribute
try
{
DeviceAttribute da("Long64_attr_rw", (DevLong64) 10);
device->write_attribute(da);
}
catch(Tango::DevFailed &e)
{
// Except::print_exception(e);
if(::strcmp(e.errors[0].reason.in(), API_DeviceLocked) != 0)
{
return 2;
}
}
// Try a write attribute asynchronously
DeviceAttribute da("Long64_attr_rw", (DevLong64) 10);
id = device->write_attribute_asynch(da);
finish = false;
while(finish == false)
{
try
{
device->write_attribute_reply(id);
finish = true;
}
catch(AsynReplyNotArrived &)
{
finish = false;
TEST_LOG << "Attribute not yet written" << endl;
}
catch(DevFailed &e)
{
// Except::print_exception(e);
if(::strcmp(e.errors[0].reason.in(), API_DeviceLocked) != 0)
{
return 2;
}
else
{
finish = true;
}
}
if(finish == false)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
// Try a attribute set_config
try
{
string att_name("Long64_attr_rw");
AttributeInfoEx ai = device->get_attribute_config(att_name);
AttributeInfoListEx ail;
ail.push_back(ai);
device->set_attribute_config(ail);
}
catch(Tango::DevFailed &e)
{
// Except::print_exception(e);
if(::strcmp(e.errors[0].reason.in(), API_DeviceLocked) != 0)
{
return 2;
}
else
{
return 1;
}
}
delete device;
return 0;
}
// NOLINTEND(*)
|