File: fwdattrdesc.cpp

package info (click to toggle)
tango 9.3.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 95,792 kB
  • sloc: cpp: 138,382; sh: 8,009; ansic: 1,083; makefile: 996; java: 800; python: 264; xml: 54
file content (759 lines) | stat: -rw-r--r-- 21,082 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
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
//+==================================================================================================================
//
// file :               fwdattrdesc.cpp
//
// description :        C++ source code for the FwdAttrDesc classes
//
// project :            TANGO
//
// author(s) :          A.Gotz + E.Taurel
//
// Copyright (C) :      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$
//
//-==================================================================================================================

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

#include <tango.h>
#include <fwdattrdesc.h>

#include <fwdattribute.tpp>
#include <fwdattribute_spec.tpp>

namespace Tango
{

//--------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::FwdAttr
//
// description :
//		Constructor for the FwdAttr class. Initialize data with default value for a wrongly configured
//		forwarded attribute
//
// argument :
//		in :
//			- att_name : The attribute name
//			- root_attribute : The root attribute name
//
//--------------------------------------------------------------------------------------------------------------------


FwdAttr::FwdAttr(const string &att_name,const string &root_attribute):
ImageAttr(att_name.c_str()),full_root_att(root_attribute),fwd_wrongly_conf(false),err_kind(FWD_ERR_UNKNOWN),ext(Tango_nullptr)
{
	writable = Tango::READ;			// Difficult to switch it to WT_UNKNOWN
//	type = DATA_TYPE_UNKNOWN;
	type = DEV_DOUBLE;
	format = Tango::FMT_UNKNOWN;
//	disp_level = DL_UNKNOWN;
	assoc_name = AssocWritNotSpec;

	max_x = 0;
	max_y = 0;

	mem = false;
	mem_init = false;

    fire_change_event = false;
    fire_archive_event = false;
    check_change_event = false;
    check_archive_event = false;
    fire_dr_event = false;

    set_cl_name("FwdAttr");
    set_err_kind(FWD_NO_ERROR);
}

FwdAttr::FwdAttr(const FwdAttr &sou):ImageAttr(sou)
{
	full_root_att = sou.full_root_att;
	fwd_dev_name = sou.fwd_dev_name;
	fwd_root_att = sou.fwd_root_att;
	fwd_wrongly_conf = sou.fwd_wrongly_conf;
	err_kind = sou.err_kind;
}

//--------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::validate_fwd_att
//
// description :
//		Validate that we have the knowledge of the root attribute.
//
// argument :
//		in :
//			- prop_list : The attribute property list
//			- dev_name : The device name
//
// return:
//		True if we have the required info to build a forwarded attribute
//
//--------------------------------------------------------------------------------------------------------------------

bool FwdAttr::validate_fwd_att(vector<AttrProperty> &prop_list,const string &dev_name)
{
	bool ret = true;

//
// Check if root attribute is defined in DB (then in received prop list)
// If it's the case, check its syntax
//

	string root_att_db;
	bool root_att_db_defined = false;
	bool is_full_root_att_set = false;

    Util *tg = Util::instance();
    Database *db = tg->get_database();

	try
	{
#ifdef HAS_LAMBDA_FUNC
		auto pos = find_if(prop_list.begin(),prop_list.end(),
					[] (AttrProperty &ap) -> bool
					{
						return ap.get_name() == RootAttrPropName;
					});
#else
		vector<AttrProperty>::iterator pos;
		for (pos = prop_list.begin();pos != prop_list.end();++pos)
		{
			if (pos->get_name() == RootAttrPropName)
				break;
		}
#endif
		if (pos != prop_list.end())
		{
			root_att_db = pos->get_value();
			root_att_db_defined = true;
		}
		else
        {

//
// Write something in DB to help user to create the right entry except if the root att name is hard coded
//

            if (full_root_att == RootAttNotDef)
            {
                DbDatum att(get_name());
                att << (DevShort)1;
                DbDatum root_name(RootAttrPropName);
                root_name << RootAttNotDef;

                DbData db_dat;
                db_dat.push_back(att);
                db_dat.push_back(root_name);

                try
                {
                    if (db != Tango_nullptr)
                        db->put_device_attribute_property(dev_name,db_dat);
                }
                catch(...) {}
            }
        }
	}
	catch (...) {}

	//check if full_root_att is already set
	is_full_root_att_set = full_root_att.size()!=0 && full_root_att.compare(RootAttNotDef)!=0;

	if(!is_full_root_att_set) {
		if (root_att_db_defined)
			full_root_att = root_att_db;
		else
			full_root_att = RootAttNotDef;
	}

//
// Check root att syntax and add TANGO_HOST info in root device name of not given
// Also add dns suffix if not defined in provided TANGO_HOST host name
//

	string fq;
	if (db != Tango_nullptr)
	{
		fq = "tango://";
		string &h = db->get_db_host();
		string &p = db->get_db_port();
		fq = fq + h + ':' + p + '/';
	}
	transform(fq.begin(),fq.end(),fq.begin(),::tolower);

	if (full_root_att != RootAttNotDef)
	{
		int nb_sep = count(full_root_att.begin(),full_root_att.end(),'/');

		if (nb_sep == 3)
		{
			full_root_att.insert(0,fq);
		}
		else if (nb_sep == 6)
		{
			string::size_type pos = full_root_att.find("tango://");
			if (pos != 0)
				ret = false;
			else
			{
				pos = full_root_att.find(':',8);
				string ho = full_root_att.substr(8,pos - 8);
				string::size_type pos1 = ho.find('.');
				size_t old_size = ho.size();
				if (pos1 == string::npos)
					Connection::get_fqdn(ho);
				string dom = ho.substr(old_size);
				full_root_att.insert(pos,dom);
			}
		}
		else
		{
			fwd_wrongly_conf = true;
			err_kind = FWD_WRONG_SYNTAX;
			ret = false;
		}

		if (ret == true)
		{
			string::size_type pos = full_root_att.find_last_of('/');
			fwd_root_att = full_root_att.substr(pos + 1);
			fwd_dev_name = full_root_att.substr(0,pos);

			transform(fwd_dev_name.begin(),fwd_dev_name.end(),fwd_dev_name.begin(),::tolower);
			transform(fwd_root_att.begin(),fwd_root_att.end(),fwd_root_att.begin(),::tolower);
		}
	}
	else
	{
		fwd_wrongly_conf = true;
		err_kind = FWD_MISSING_ROOT;
		ret = false;
	}

//
// Check that the root device is not the local device
//

	string local_dev_name(dev_name);
	local_dev_name.insert(0,fq);

	if (fwd_dev_name == local_dev_name)
	{
		fwd_wrongly_conf = true;
		err_kind = FWD_ROOT_DEV_LOCAL_DEV;
		ret = false;
	}

	return ret;
}

//--------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::get_root_conf
//
// description :
//		Get the root attribute configuration
//
// argument :
//		in :
//			- dev_name : The local device name
//			- dev : Device pointer
//
//--------------------------------------------------------------------------------------------------------------------

void FwdAttr::get_root_conf(string &dev_name,DeviceImpl *dev)
{
	try
	{
		RootAttRegistry &dps = Tango::Util::instance()->get_root_att_reg();
		dps.add_root_att(fwd_dev_name,fwd_root_att,dev_name,name,this,dev);
	}
	catch (Tango::DevFailed &)
	{
		fwd_wrongly_conf = true;
		throw;
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::read
//
// description :
//		Read method for forwarded attribute
//
// argument :
//		in :
//			- dev : The device
//			- attr : The attribute object
//
//--------------------------------------------------------------------------------------------------------------------

void FwdAttr::read(DeviceImpl *dev,Attribute &attr)
{
//
// Throw exception in case of fwd att wrongly configured or if the root device is not yet accessible
//

	if (attr.get_data_type() == DATA_TYPE_UNKNOWN)
	{
		string desc("Attribute ");
		desc = desc + name + " is a forwarded attribute and its root device (";
		desc = desc + fwd_dev_name;
		desc = desc + ") is not yet available";
		Tango::Except::throw_exception(API_AttrConfig,desc,"FwdAttr::read");
	}

//
// Retrieve root attribute device proxy object
//

	FwdAttribute &fwd_attr = static_cast<FwdAttribute &>(attr);
	RootAttRegistry &rar = Util::instance()->get_root_att_reg();
	DeviceProxy *root_att_dev;
	try
	{
		root_att_dev = rar.get_root_att_dp(fwd_attr.get_fwd_dev_name());
	}
	catch (Tango::DevFailed &e)
	{
		string desc("Attribute ");
		desc = desc + name + " is a forwarded attribute.\n";
		desc = desc + "Check device status to get more info";
		Tango::Except::re_throw_exception(e,API_AttrConfig,desc,"FwdAttr::read()");
	}

//
// Read the ŕoot attribute
//

	try
	{
		root_att_dev->set_source(dev->get_call_source());
		DeviceAttribute da = root_att_dev->read_attribute(fwd_attr.get_fwd_att_name());

//
// Set the local attribute from the result of the previous read
//

		switch(fwd_attr.get_data_type())
		{
		case DEV_SHORT:
		case DEV_ENUM:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().sh_seq);
			break;

		case DEV_LONG:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().lg_seq);
			break;

		case DEV_FLOAT:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().fl_seq);
			break;

		case DEV_DOUBLE:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().db_seq);
			break;

		case DEV_STRING:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().str_seq);
			break;

		case DEV_USHORT:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().ush_seq);
			break;

		case DEV_BOOLEAN:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().boo_seq);
			break;

		case DEV_UCHAR:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().cha_seq);
			break;

		case DEV_LONG64:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().lg64_seq);
			break;

		case DEV_ULONG:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().ulg_seq);
			break;

		case DEV_ULONG64:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().ulg64_seq);
			break;

		case DEV_STATE:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().state_seq);
			break;

		case DEV_ENCODED:
			fwd_attr.set_local_attribute(da,fwd_attr.get_root_ptr().enc_seq);
			break;

		default:
			break;
		}
	}
	catch (Tango::DevFailed &e)
	{
		stringstream ss;
		ss << "Reading root attribute " << fwd_root_att << " on device " << fwd_dev_name << " failed!";
		Tango::Except::re_throw_exception(e,API_AttributeFailed,ss.str(),"FwdAttr::read");
	}

}

//--------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::write
//
// description :
//		Write method for forwarded attribute
//
// argument :
//		in :
//			- dev : The device
//			- attr : The attribute object
//
//--------------------------------------------------------------------------------------------------------------------

void FwdAttr::write(TANGO_UNUSED(DeviceImpl *dev),WAttribute &attr)
{

//
// Throw exception in case of fwd att wrongly configured or if the root device is not yet accessible
//

	if (attr.get_data_type() == DATA_TYPE_UNKNOWN)
	{
		string desc("Attribute ");
		desc = desc + name + " is a forwarded attribute and its root device (";
		desc = desc + fwd_dev_name;
		desc = desc + ") is not yet available";
		Tango::Except::throw_exception(API_AttrConfig,desc,"FwdAttr::write");
	}

//
// Retrieve root attribute device proxy object
//

	FwdAttribute &fwd_attr = static_cast<FwdAttribute &>(attr);
	RootAttRegistry &rar = Util::instance()->get_root_att_reg();
	DeviceProxy *root_att_dev;
	try
	{
		root_att_dev = rar.get_root_att_dp(fwd_attr.get_fwd_dev_name());
	}
	catch (Tango::DevFailed &e)
	{
		string desc("Attribute ");
		desc = desc + name + " is a forwarded attribute.\n";
		desc = desc + "Check device status to get more info";
		Tango::Except::re_throw_exception(e,API_AttrConfig,desc,"FwdAttr::write()");
	}

//
// Write the ŕoot attribute
//

	DeviceAttribute da;
	da.set_name(fwd_attr.get_fwd_att_name());

	switch(fwd_attr.get_data_type())
	{
	case DEV_SHORT:
	case DEV_ENUM:
		DevShort *ptr_sh;
		fwd_attr.propagate_writen_data(da,attr,ptr_sh,fwd_attr.get_root_ptr().sh_seq);
		break;

	case DEV_LONG:
		DevLong *ptr_lo;
		fwd_attr.propagate_writen_data(da,attr,ptr_lo,fwd_attr.get_root_ptr().lg_seq);
		break;

	case DEV_FLOAT:
		DevFloat *ptr_fl;
		fwd_attr.propagate_writen_data(da,attr,ptr_fl,fwd_attr.get_root_ptr().fl_seq);
		break;

	case DEV_DOUBLE:
		DevDouble *ptr_db;
		fwd_attr.propagate_writen_data(da,attr,ptr_db,fwd_attr.get_root_ptr().db_seq);
		break;

	case DEV_STRING:
		ConstDevString *ptr_str;
		fwd_attr.propagate_writen_data(da,attr,ptr_str,fwd_attr.get_root_ptr().str_seq);
		break;

	case DEV_USHORT:
		DevUShort *ptr_ush;
		fwd_attr.propagate_writen_data(da,attr,ptr_ush,fwd_attr.get_root_ptr().ush_seq);
		break;

	case DEV_BOOLEAN:
		DevBoolean *ptr_bo;
		fwd_attr.propagate_writen_data(da,attr,ptr_bo,fwd_attr.get_root_ptr().boo_seq);
		break;

	case DEV_UCHAR:
		DevUChar *ptr_uch;
		fwd_attr.propagate_writen_data(da,attr,ptr_uch,fwd_attr.get_root_ptr().cha_seq);
		break;

	case DEV_LONG64:
		DevLong64 *ptr_lg64;
		fwd_attr.propagate_writen_data(da,attr,ptr_lg64,fwd_attr.get_root_ptr().lg64_seq);
		break;

	case DEV_ULONG:
		DevULong *ptr_ulg;
		fwd_attr.propagate_writen_data(da,attr,ptr_ulg,fwd_attr.get_root_ptr().ulg_seq);
		break;

	case DEV_ULONG64:
		DevULong64 *ptr_ulg64;
		fwd_attr.propagate_writen_data(da,attr,ptr_ulg64,fwd_attr.get_root_ptr().ulg64_seq);
		break;

	case DEV_STATE:
		DevState *ptr_sta;
		fwd_attr.propagate_writen_data(da,attr,ptr_sta,fwd_attr.get_root_ptr().state_seq);
		break;

	case DEV_ENCODED:
		DevEncoded *ptr_enc;
		fwd_attr.propagate_writen_data(da,attr,ptr_enc,fwd_attr.get_root_ptr().enc_seq);
		break;

	default:
		break;
	}

	try
	{
		 root_att_dev->write_attribute(da);
	}
	catch (Tango::DevFailed &e)
	{
		stringstream ss;
		ss << "Writing root attribute " << fwd_root_att << " on device " << fwd_dev_name << " failed!";
		Tango::Except::re_throw_exception(e,API_AttributeFailed,ss.str(),"FwdAttr::write");
	}
}

//---------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::init_conf()
//
// description :
//		This method initialize FwdAttr class data member in case of forwarded attribute from the root attribute
//		configuration received during the attribute change event subscription
//
// argument :
//		in :
//			- ev_data : The event data
//
//--------------------------------------------------------------------------------------------------------------------

void FwdAttr::init_conf(AttrConfEventData *ev_data)
{

//
// Set main data
//

	type = ev_data->attr_conf->data_type;
	writable = ev_data->attr_conf->writable;
	format = ev_data->attr_conf->data_format;
	max_x = ev_data->attr_conf->max_dim_x;
	max_y = ev_data->attr_conf->max_dim_y;
	assoc_name = ev_data->attr_conf->writable_attr_name;
	if (writable == READ_WRITE)
		assoc_name = name;
	disp_level = ev_data->attr_conf->disp_level;
	switch (ev_data->attr_conf->memorized)
	{
	case NOT_KNOWN:
	case NONE:
		mem = false;
		mem_init = false;
		break;

	case MEMORIZED:
		mem = true;
		mem_init = false;
		break;

	case MEMORIZED_WRITE_INIT:
		mem = true;
		mem_init = true;
		break;

	default:
		break;
	}

//
// Set configuration
// If we already have a label in our conf, save it and reapply it
//

	string local_label;
	try
	{
		local_label = get_label_from_default_properties();
	}
	catch (Tango::DevFailed &e) {}

	UserDefaultAttrProp udap;
	if (local_label.empty() == false)
		udap.set_label(local_label.c_str());
	udap.set_description(ev_data->attr_conf->description.c_str());
	udap.set_unit(ev_data->attr_conf->unit.c_str());
	udap.set_standard_unit(ev_data->attr_conf->standard_unit.c_str());
	udap.set_display_unit(ev_data->attr_conf->display_unit.c_str());
	udap.set_format(ev_data->attr_conf->format.c_str());
	udap.set_min_value(ev_data->attr_conf->min_value.c_str());
	udap.set_max_value(ev_data->attr_conf->max_value.c_str());
	udap.set_enum_labels(ev_data->attr_conf->enum_labels);

	udap.set_min_alarm(ev_data->attr_conf->alarms.min_alarm.c_str());
	udap.set_max_alarm(ev_data->attr_conf->alarms.max_alarm.c_str());
	udap.set_min_warning(ev_data->attr_conf->alarms.min_warning.c_str());
	udap.set_max_warning(ev_data->attr_conf->alarms.max_warning.c_str());
	udap.set_delta_val(ev_data->attr_conf->alarms.delta_val.c_str());
	udap.set_delta_t(ev_data->attr_conf->alarms.delta_t.c_str());

	udap.set_event_abs_change(ev_data->attr_conf->events.ch_event.abs_change.c_str());
	udap.set_event_rel_change(ev_data->attr_conf->events.ch_event.rel_change.c_str());
	udap.set_event_period(ev_data->attr_conf->events.per_event.period.c_str());
	udap.set_archive_event_abs_change(ev_data->attr_conf->events.arch_event.archive_abs_change.c_str());
	udap.set_archive_event_rel_change(ev_data->attr_conf->events.arch_event.archive_rel_change.c_str());
	udap.set_archive_event_period(ev_data->attr_conf->events.arch_event.archive_period.c_str());

	this->Attr::set_default_properties(udap);
}

//+-------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::set_default_properties
//
// description :
//		This method set the default user properties in the Attr object. At this level, each attribute property is
//		represented by one instance of the Attrproperty class.
//
//--------------------------------------------------------------------------------------------------------------------

void FwdAttr::set_default_properties(UserDefaultFwdAttrProp &prop_list)
{
	if ((prop_list.label.empty() == false) &&
		(TG_strcasecmp(prop_list.label.c_str(),AlrmValueNotSpec) != 0) &&
		(TG_strcasecmp(prop_list.label.c_str(),NotANumber) != 0))
		user_default_properties.push_back(AttrProperty("label",prop_list.label));
}

//+-------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttr::get_label_from_default_properties
//
// description :
//		Get the label property from the user default properties list. Throw exception if not in list
//
// return :
//		The label property value
//
//--------------------------------------------------------------------------------------------------------------------

string &FwdAttr::get_label_from_default_properties()
{
	size_t nb_prop = user_default_properties.size();
	size_t ctr;
	for (ctr = 0;ctr < nb_prop;ctr++)
	{
		if (user_default_properties[ctr].get_name() == "label")
			break;
	}

	if (ctr == nb_prop)
	{
		Except::throw_exception(API_AttrOptProp,"Property label not defined in list",
								"FwdAttr::get_label_from_default_properties");
	}

	return user_default_properties[ctr].get_value();
}

//--------------------------------------------------------------------------------------------------------------------
//
// method :
//		FwdAttribute::remove_useless_prop
//
// description :
//		Remove classical attribute property(ies) if found in prop_list input argument. For forwarded attribute,
//      the configuration is taken from the root att and should not be taken from the DB. If we found some
//      useless properties, remove them from the prop list and inform the user to clean up the database.
//
// argument :
//		in :
//			- prop_list : The property list
//          - dev_name : The device name
//
//--------------------------------------------------------------------------------------------------------------------

void FwdAttr::remove_useless_prop(vector<AttrProperty> &prop_list,string &dev_name,MultiAttribute *m_attr)
{
    vector<AttrProperty>::iterator ite;

    for (ite = prop_list.begin();ite != prop_list.end();)
    {
        if (ite->get_name() == "label" || ite->get_name() == "__root_att")
        {
            ++ite;
            continue;
        }

        if (m_attr->is_opt_prop(ite->get_name()) == true)
        {
            cerr << "Warning: The forwarded attribute " << get_name()  << " belonging to device "  << dev_name;
            cerr << "  has the property " << ite->get_name() << " defined in DB.\n";
            cerr << "This property will not be taken into account. Please clean up your DB." << endl;
            ite = prop_list.erase(ite);
        }
        else
            ++ite;
    }
}

} // End of Tango namespace