File: dserverlock.cpp

package info (click to toggle)
tango 8.1.2c%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,964 kB
  • ctags: 14,286
  • sloc: cpp: 133,954; sh: 14,704; ansic: 1,083; makefile: 944; java: 215; python: 55
file content (341 lines) | stat: -rw-r--r-- 9,041 bytes parent folder | download | duplicates (2)
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
static const char *RcsId = "$Id: dserverlock.cpp 22213 2013-03-07 14:32:56Z taurel $\n$Name$";

//+=============================================================================
//
// file :               dserverlock.cpp
//
// description :        C++ source for the DServer class and its commands.
//			The class is derived from Device. It represents the
//			CORBA servant object which will be accessed from the
//			network. All commands which can be executed on a
//			DServer object are implemented in this file.
//
// project :            TANGO
//
// author(s) :          E.Taurel
//
// Copyright (C) :      2004,2005,2006,2007,2008,2009,2010,2011,2012,2013
//						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: 22213 $
//
//-=============================================================================

#if HAVE_CONFIG_H
#include <ac_config.h>
#endif

#include <tango.h>


namespace Tango
{

//+----------------------------------------------------------------------------
//
// method : 		DServer::lock_device()
//
// description : 	command to lock device
//
// args: - in_data : Pointer to a structure with:
//						1 - Name of the device(s) to be locked
//		 				2 - Lock validity
//
//-----------------------------------------------------------------------------

void DServer::lock_device(const Tango::DevVarLongStringArray *in_data)
{
	NoSyncModelTangoMonitor mon(this);

	string dev_name(in_data->svalue[0]);
	int lock_validity = in_data->lvalue[0];

	cout4 << "In lock_device command for device " << dev_name << ", lock validity = " << lock_validity << endl;

//
// Get client identification
//

	Tango::client_addr *cl = get_client_ident();
	if (cl == NULL)
	{
		Except::throw_exception((const char*)API_CantGetClientIdent,
					       	(const char*)"Cannot retrieve client identification",
					        (const char*)"DServer::lock_device");
	}

	cout4 << "Client identification = " << *cl << endl;

	if (cl->client_ident == false)
	{
		Except::throw_exception((const char*)"API_ClientTooOld",
					       	(const char*)"Your client cannot lock devices. You are using a too old Tango release. Please, update to tango V7 or more",
					        (const char*)"DServer::lock_device");
	}

//
// Transform device name to lower case
//

	Tango::Util *tg = Tango::Util::instance();

	string local_dev_name(get_name());
	transform(local_dev_name.begin(),local_dev_name.end(),local_dev_name.begin(),::tolower);

	string d_name_lower(dev_name);
	transform(d_name_lower.begin(),d_name_lower.end(),d_name_lower.begin(),::tolower);

//
// Refuse to lock the admin device
//

	if (d_name_lower == local_dev_name)
	{
		Except::throw_exception((const char *)API_DeviceUnlockable,
								(const char *)"Impossible to lock device server administration device",
								(const char *)"DServer::lock_device");
	}

//
// Get device ptr
//

	DeviceImpl *the_dev;
	the_dev = tg->get_device_by_name(dev_name);

//
// Refuse to lock database device
//

	string &cl_name = the_dev->get_device_class()->get_name();
	if (::strcmp(cl_name.c_str(),DATABASE_CLASS) == 0)
	{
		Except::throw_exception((const char *)API_DeviceUnlockable,
								(const char *)"Impossible to lock database device",
								(const char *)"DServer::lock_device");
	}

//
// Mark the device as locked
//

	the_dev->lock(cl,lock_validity);

}


//+----------------------------------------------------------------------------
//
// method : 		DServer::un_lock_device()
//
// description : 	command to un lock a device
//
// args: - dev_name : The device name
//
//-----------------------------------------------------------------------------

Tango::DevLong DServer::un_lock_device(const Tango::DevVarLongStringArray *in_data)
{
	NoSyncModelTangoMonitor mon(this);

	cout4 << "In un_lock_device command for device " << in_data->svalue[0] << endl;

//
// Get client identification
//

	Tango::client_addr *cl = get_client_ident();
	if (cl == NULL)
	{
		Except::throw_exception((const char*)API_CantGetClientIdent,
					       	(const char*)"Cannot retrieve client identification",
					        (const char*)"DServer::un_lock_device");
	}

	cout4 << "Client identification = " << *cl << endl;

	if ((cl->client_ident == false) && (in_data->lvalue[0] == 0))
	{
		Except::throw_exception((const char*)"API_ClientTooOld",
					       	(const char*)"Your client cannot un-lock devices. You are using a too old Tango release. Please, update to tango V7 or more",
					        (const char*)"DServer::un_lock_device");
	}

//
// Get the device and unlock it
//

	DevLong ctr = 0;
	Tango::Util *tg = Tango::Util::instance();

	for (unsigned int loop = 0;loop < in_data->svalue.length();++loop)
	{
		string d_name(in_data->svalue[loop]);

		if (d_name == get_name())
			ctr = ext->lock_ctr;
		else
		{
			DeviceImpl *the_dev = tg->get_device_by_name(d_name);
			ctr = the_dev->unlock((bool)in_data->lvalue[0]);
		}

		if (loop > 0)
			ctr = 0;
	}

	return ctr;
}

//+----------------------------------------------------------------------------
//
// method : 		DServer::re_lock_devices()
//
// description : 	command to re-lock devices
//
// args: - dev_name_list : Name of the device(s) to be re-locked
//
//-----------------------------------------------------------------------------

void DServer::re_lock_devices(const Tango::DevVarStringArray *dev_name_list)
{
	NoSyncModelTangoMonitor mon(this);

	cout4 << "In re_lock_devices command" << endl;
	CORBA::ULong loop;
	CORBA::ULong nb_dev = dev_name_list->length();

	for (loop = 0;loop < nb_dev;loop++)
		cout4 << "Device to re-lock: " << (*dev_name_list)[loop] << endl;

//
// Get client identification
//

	Tango::client_addr *cl = get_client_ident();
	if (cl == NULL)
	{
		Except::throw_exception((const char*)API_CantGetClientIdent,
					       	(const char*)"Cannot retrieve client identification",
					        (const char*)"DServer::re_lock_devices");
	}

	cout4 << "Client identification = " << *cl << endl;

	if (cl->client_ident == false)
	{
		Except::throw_exception((const char*)"API_ClientTooOld",
					       	(const char*)"Your client cannot re_lock devices. You are using a too old Tango release. Please, update to tango V7 or more",
					        (const char*)"DServer::re_lock_devices");
	}

//
// ReLock the devices
// If we have an error in this loop, memorize it and throw the exception at the
// end of the loop
//

	Tango::Util *tg = Tango::Util::instance();

	DevErrorList errors;
	long nb_error = 0;

	for (loop = 0;loop < nb_dev;loop++)
	{
		string d_name((*dev_name_list)[loop]);

//
// Get device ptr
//

		DeviceImpl *the_dev = NULL;
		try
		{
			the_dev = tg->get_device_by_name(d_name);
		}
		catch (Tango::DevFailed &e)
		{
			errors.length(nb_error + 1);
			errors[nb_error].desc = CORBA::string_dup(e.errors[0].desc.in());
			errors[nb_error].reason = CORBA::string_dup(e.errors[0].reason.in());
			errors[nb_error].origin = CORBA::string_dup(e.errors[0].origin.in());
			errors[nb_error].severity = e.errors[0].severity;
			nb_error++;
		}

//
// ReLock the device
//

		try
		{
			the_dev->relock(cl);
		}
		catch (Tango::DevFailed &e)
		{
			errors.length(nb_error + 1);
			errors[nb_error].desc = CORBA::string_dup(e.errors[0].desc.in());
			errors[nb_error].reason = CORBA::string_dup(e.errors[0].reason.in());
			errors[nb_error].origin = CORBA::string_dup(e.errors[0].origin.in());
			errors[nb_error].severity = e.errors[0].severity;
			nb_error++;
		}
	}

//
// Throw the exception if we had one during the loop
//

	if (nb_error != 0)
	{
		throw Tango::DevFailed(errors);
	}
}

//+----------------------------------------------------------------------------
//
// method : 		DServer::dev_lock_status()
//
// description : 	command to get device lock status
//
// args: - dev_name : The device name
//
//-----------------------------------------------------------------------------

Tango::DevVarLongStringArray *DServer::dev_lock_status(Tango::ConstDevString dev_name)
{
	NoSyncModelTangoMonitor mon(this);

	cout4 << "In dev_lock_status command for device " << dev_name << endl;

//
// Get the device and get its lock status
//

	string d_name(dev_name);

	Tango::Util *tg = Tango::Util::instance();
	DeviceImpl *the_dev = tg->get_device_by_name(d_name);
	return the_dev->lock_status();
}


} // End of Tango namespace