File: StarterClass.cpp

package info (click to toggle)
tango 10.0.2%2Bdfsg1-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 89,480 kB
  • sloc: cpp: 201,245; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 269; sql: 72; ruby: 24
file content (1210 lines) | stat: -rw-r--r-- 40,367 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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
/*----- PROTECTED REGION ID(StarterClass.cpp) ENABLED START -----*/
//=============================================================================
//
// file :        StarterClass.cpp
//
// description : C++ source for the StarterClass. A singleton
//               class derived from DeviceClass. It implements the
//               command list and all properties and methods required
//               by the �name� once per process.
//
// project :     Starter for Tango Administration.
//
// $Author$
//
// 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 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango.  If not, see <http://www.gnu.org/licenses/>.
//
// $Revision$
// $Date$
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#include <tango/tango.h>
#include "Starter.h"
#include "StarterClass.h"

#include "Logging.h"

/*----- PROTECTED REGION END -----*/	//	StarterClass.cpp

//-------------------------------------------------------------------
/**
 *	Create StarterClass singleton and
 *	return it in a C function for Python usage
 */
//-------------------------------------------------------------------
extern "C" {
#ifdef _TG_WINDOWS_

__declspec(dllexport)

#endif

	Tango::DeviceClass *_create_Starter_class(const char *name) {
		return Starter_ns::StarterClass::init(name);
	}
}

namespace Starter_ns
{
//===================================================================
//	Initialize pointer for singleton pattern
//===================================================================
StarterClass *StarterClass::_instance = NULL;

//--------------------------------------------------------
/**
 * method : 		StarterClass::StarterClass(std::string &s)
 * description : 	constructor for the StarterClass
 *
 * @param s	The class name
 */
//--------------------------------------------------------
StarterClass::StarterClass(std::string &s):Tango::DeviceClass(s)
{
	TANGO_LOG_INFO << "Entering StarterClass constructor" << std::endl;
	set_default_property();
	get_class_property();
	write_class_property();

	/*----- PROTECTED REGION ID(StarterClass::constructor) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::constructor

	TANGO_LOG_INFO << "Leaving StarterClass constructor" << std::endl;
}

//--------------------------------------------------------
/**
 * method : 		StarterClass::~StarterClass()
 * description : 	destructor for the StarterClass
 */
//--------------------------------------------------------
StarterClass::~StarterClass()
{
	/*----- PROTECTED REGION ID(StarterClass::destructor) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::destructor

	_instance = NULL;
}


//--------------------------------------------------------
/**
 * method : 		StarterClass::init
 * description : 	Create the object if not already done.
 *                  Otherwise, just return a pointer to the object
 *
 * @param	name	The class name
 */
//--------------------------------------------------------
StarterClass *StarterClass::init(const char *name)
{
	if (_instance == NULL)
	{
		try
		{
			std::string s(name);
			_instance = new StarterClass(s);
		}
		catch (std::bad_alloc &)
		{
			throw;
		}
	}
	return _instance;
}

//--------------------------------------------------------
/**
 * method : 		StarterClass::instance
 * description : 	Check if object already created,
 *                  and return a pointer to the object
 */
//--------------------------------------------------------
StarterClass *StarterClass::instance()
{
	if (_instance == NULL)
	{
		std::cerr << "Class is not initialised !!" << std::endl;
		exit(-1);
	}
	return _instance;
}



//===================================================================
//	Command execution method calls
//===================================================================
//--------------------------------------------------------
/**
 * method : 		DevStartClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevStartClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevStartClass::execute(): arrived" << std::endl;
	Tango::DevString argin;
	extract(in_any, argin);
	((static_cast<Starter *>(device))->dev_start(argin));
	return new CORBA::Any();
}

//--------------------------------------------------------
/**
 * method : 		DevStopClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevStopClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevStopClass::execute(): arrived" << std::endl;
	Tango::DevString argin;
	extract(in_any, argin);
	((static_cast<Starter *>(device))->dev_stop(argin));
	return new CORBA::Any();
}

//--------------------------------------------------------
/**
 * method : 		DevStartAllClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevStartAllClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevStartAllClass::execute(): arrived" << std::endl;
	Tango::DevShort argin;
	extract(in_any, argin);
	((static_cast<Starter *>(device))->dev_start_all(argin));
	return new CORBA::Any();
}

//--------------------------------------------------------
/**
 * method : 		DevStopAllClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevStopAllClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevStopAllClass::execute(): arrived" << std::endl;
	Tango::DevShort argin;
	extract(in_any, argin);
	((static_cast<Starter *>(device))->dev_stop_all(argin));
	return new CORBA::Any();
}

//--------------------------------------------------------
/**
 * method : 		DevGetRunningServersClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevGetRunningServersClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevGetRunningServersClass::execute(): arrived" << std::endl;
	Tango::DevBoolean argin;
	extract(in_any, argin);
	return insert((static_cast<Starter *>(device))->dev_get_running_servers(argin));
}

//--------------------------------------------------------
/**
 * method : 		DevGetStopServersClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevGetStopServersClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevGetStopServersClass::execute(): arrived" << std::endl;
	Tango::DevBoolean argin;
	extract(in_any, argin);
	return insert((static_cast<Starter *>(device))->dev_get_stop_servers(argin));
}

//--------------------------------------------------------
/**
 * method : 		DevReadLogClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *DevReadLogClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "DevReadLogClass::execute(): arrived" << std::endl;
	Tango::DevString argin;
	extract(in_any, argin);
	return insert((static_cast<Starter *>(device))->dev_read_log(argin));
}

//--------------------------------------------------------
/**
 * method : 		HardKillServerClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *HardKillServerClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
	TANGO_LOG_INFO << "HardKillServerClass::execute(): arrived" << std::endl;
	Tango::DevString argin;
	extract(in_any, argin);
	((static_cast<Starter *>(device))->hard_kill_server(argin));
	return new CORBA::Any();
}

//--------------------------------------------------------
/**
 * method : 		ResetStatisticsClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *ResetStatisticsClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
	TANGO_LOG_INFO << "ResetStatisticsClass::execute(): arrived" << std::endl;
	((static_cast<Starter *>(device))->reset_statistics());
	return new CORBA::Any();
}

//--------------------------------------------------------
/**
 * method : 		UpdateServersInfoClass::execute()
 * description : 	method to trigger the execution of the command.
 *
 * @param	device	The device on which the command must be executed
 * @param	in_any	The command input data
 *
 *	returns The command output data (packed in the Any object)
 */
//--------------------------------------------------------
CORBA::Any *UpdateServersInfoClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
	TANGO_LOG_INFO << "UpdateServersInfoClass::execute(): arrived" << std::endl;
	((static_cast<Starter *>(device))->update_servers_info());
	return new CORBA::Any();
}


//===================================================================
//	Properties management
//===================================================================
//--------------------------------------------------------
/**
 *	Method      : StarterClass::get_class_property()
 *	Description : Get the class property for specified name.
 */
//--------------------------------------------------------
Tango::DbDatum StarterClass::get_class_property(std::string &prop_name)
{
	for (unsigned int i=0 ; i<cl_prop.size() ; i++)
		if (cl_prop[i].name == prop_name)
			return cl_prop[i];
	//	if not found, returns  an empty DbDatum
	return Tango::DbDatum(prop_name);
}

//--------------------------------------------------------
/**
 *	Method      : StarterClass::get_default_device_property()
 *	Description : Return the default value for device property.
 */
//--------------------------------------------------------
Tango::DbDatum StarterClass::get_default_device_property(std::string &prop_name)
{
	for (unsigned int i=0 ; i<dev_def_prop.size() ; i++)
		if (dev_def_prop[i].name == prop_name)
			return dev_def_prop[i];
	//	if not found, return  an empty DbDatum
	return Tango::DbDatum(prop_name);
}

//--------------------------------------------------------
/**
 *	Method      : StarterClass::get_default_class_property()
 *	Description : Return the default value for class property.
 */
//--------------------------------------------------------
Tango::DbDatum StarterClass::get_default_class_property(std::string &prop_name)
{
	for (unsigned int i=0 ; i<cl_def_prop.size() ; i++)
		if (cl_def_prop[i].name == prop_name)
			return cl_def_prop[i];
	//	if not found, return  an empty DbDatum
	return Tango::DbDatum(prop_name);
}

//--------------------------------------------------------
/**
 *	Method      : StarterClass::get_class_property()
 *	Description : Read database to initialize class property data members.
 */
//--------------------------------------------------------
void StarterClass::get_class_property()
{
	/*----- PROTECTED REGION ID(StarterClass::get_class_property_before) ENABLED START -----*/

	//	Initialize class property data members
	readInfoDbPeriod  = 4;
	nbStartupLevels   = 5;
	logFileHome = LOG_HOME;

	/*----- PROTECTED REGION END -----*/	//	StarterClass::get_class_property_before
	//	Read class properties from database.
	cl_prop.push_back(Tango::DbDatum("AutoRestartDuration"));
	cl_prop.push_back(Tango::DbDatum("LogFileHome"));
	cl_prop.push_back(Tango::DbDatum("NbStartupLevels"));
	cl_prop.push_back(Tango::DbDatum("ReadInfoDbPeriod"));
	cl_prop.push_back(Tango::DbDatum("ServerStartupTimeout"));
	cl_prop.push_back(Tango::DbDatum("StartServersAtStartup"));
	cl_prop.push_back(Tango::DbDatum("MovingMaxDuration"));
	
	//	Call database and extract values
	if (Tango::Util::instance()->_UseDb==true)
		get_db_class()->get_property(cl_prop);
	Tango::DbDatum	def_prop;
	int	i = -1;

	//	Try to extract AutoRestartDuration value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  autoRestartDuration;
	else
	{
		//	Check default value for AutoRestartDuration
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  autoRestartDuration;
			cl_prop[i]  <<  autoRestartDuration;
		}
	}
	//	Try to extract LogFileHome value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  logFileHome;
	else
	{
		//	Check default value for LogFileHome
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  logFileHome;
			cl_prop[i]  <<  logFileHome;
		}
	}
	//	Try to extract NbStartupLevels value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  nbStartupLevels;
	else
	{
		//	Check default value for NbStartupLevels
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  nbStartupLevels;
			cl_prop[i]  <<  nbStartupLevels;
		}
	}
	//	Try to extract ReadInfoDbPeriod value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  readInfoDbPeriod;
	else
	{
		//	Check default value for ReadInfoDbPeriod
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  readInfoDbPeriod;
			cl_prop[i]  <<  readInfoDbPeriod;
		}
	}
	//	Try to extract ServerStartupTimeout value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  serverStartupTimeout;
	else
	{
		//	Check default value for ServerStartupTimeout
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  serverStartupTimeout;
			cl_prop[i]  <<  serverStartupTimeout;
		}
	}
	//	Try to extract StartServersAtStartup value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  startServersAtStartup;
	else
	{
		//	Check default value for StartServersAtStartup
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  startServersAtStartup;
			cl_prop[i]  <<  startServersAtStartup;
		}
	}
	//	Try to extract MovingMaxDuration value
	if (cl_prop[++i].is_empty()==false)	cl_prop[i]  >>  movingMaxDuration;
	else
	{
		//	Check default value for MovingMaxDuration
		def_prop = get_default_class_property(cl_prop[i].name);
		if (def_prop.is_empty()==false)
		{
			def_prop    >>  movingMaxDuration;
			cl_prop[i]  <<  movingMaxDuration;
		}
	}
	/*----- PROTECTED REGION ID(StarterClass::get_class_property_after) ENABLED START -----*/

	//	Check class property data members init
	TANGO_LOG_INFO << "readInfoDbPeriod  = " << readInfoDbPeriod << std::endl;
	TANGO_LOG_INFO << "nbStartupLevels   = " << nbStartupLevels << std::endl;
	TANGO_LOG_INFO << "logFileHome       = " << logFileHome   << std::endl;

	//	Put the value (depends on OS) in cl_prop to be set as default value for device property..
	for (auto & i : cl_prop)
		if (i.name == "LogFileHome")
			i  <<  logFileHome;

	/*----- PROTECTED REGION END -----*/	//	StarterClass::get_class_property_after

}

//--------------------------------------------------------
/**
 *	Method      : StarterClass::set_default_property()
 *	Description : Set default property (class and device) for wizard.
 *                For each property, add to wizard property name and description.
 *                If default value has been set, add it to wizard property and
 *                store it in a DbDatum.
 */
//--------------------------------------------------------
void StarterClass::set_default_property()
{
	std::string	prop_name;
	std::string	prop_desc;
	std::string	prop_def;
	std::vector<std::string>	vect_data;

	//	Set Default Class Properties
	prop_name = "AutoRestartDuration";
	prop_desc = "If this property is greater than 0, if a server has been running more than the specified value (in minutes), and has failed, it will be restart automatically.";
	prop_def  = "0";
	vect_data.clear();
	vect_data.push_back("0");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);
	prop_name = "LogFileHome";
	prop_desc = "The home directory to log servers traces.\nFor Linux the default value is /var/tmp\nFor Win32 it is c:\temp";
	prop_def  = "";
	vect_data.clear();
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);
	prop_name = "NbStartupLevels";
	prop_desc = "Number of startup levels managed by starter.";
	prop_def  = "5";
	vect_data.clear();
	vect_data.push_back("5");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);
	prop_name = "ReadInfoDbPeriod";
	prop_desc = "Period to read database for new info if not fired from Database server.";
	prop_def  = "";
	vect_data.clear();
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);
	prop_name = "ServerStartupTimeout";
	prop_desc = "Timeout on device server startup in seconds.";
	prop_def  = "1";
	vect_data.clear();
	vect_data.push_back("1");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);
	prop_name = "StartServersAtStartup";
	prop_desc = "Skip starting servers at startup if false. It a way to do not have a big re-start of many servers after a power cut.";
	prop_def  = "true";
	vect_data.clear();
	vect_data.push_back("true");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);
	prop_name = "MovingMaxDuration";
	prop_desc = "If a server is moving during a period more than this value,\nthe Starter will be switched from MOVING to STANDBY";
	prop_def  = "120";
	vect_data.clear();
	vect_data.push_back("120");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		cl_def_prop.push_back(data);
		add_wiz_class_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_class_prop(prop_name, prop_desc);

	//	Set Default device Properties
	prop_name = "AutoRestartDuration";
	prop_desc = "If this property is greater than 0, if a server has been running more than the specified value (in minutes), and has failed, it will be restart automatically.";
	prop_def  = "0";
	vect_data.clear();
	vect_data.push_back("0");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "InterStartupLevelWait";
	prop_desc = "Time to wait before two startup levels in seconds.";
	prop_def  = "1";
	vect_data.clear();
	vect_data.push_back("1");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "KeepLogFiles";
	prop_desc = "Number of log file kept.";
	prop_def  = "3";
	vect_data.clear();
	vect_data.push_back("3");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "LogFileHome";
	prop_desc = "The home directory to log servers traces.\nFor Linux the default value is /var/tmp\nFor Win32 it is c:\temp";
	prop_def  = "";
	vect_data.clear();
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "ServerStartupTimeout";
	prop_desc = "Timeout on device server startup in seconds.";
	prop_def  = "5";
	vect_data.clear();
	vect_data.push_back("5");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "StartDsPath";
	prop_desc = "Path to find executable files\nto start device servers";
	prop_def  = "";
	vect_data.clear();
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "StartServersAtStartup";
	prop_desc = "Skip starting servers at startup if false.";
	prop_def  = "true";
	vect_data.clear();
	vect_data.push_back("true");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "WaitForDriverStartup";
	prop_desc = "The Starter will wait a bit before starting servers, to be sure than the drivers\nare started.This time is in seconds.";
	prop_def  = "0";
	vect_data.clear();
	vect_data.push_back("0");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "MovingMaxDuration";
	prop_desc = "If a server is moving during a period more than this value,\nthe Starter will be switched from MOVING to STANDBY";
	prop_def  = "120";
	vect_data.clear();
	vect_data.push_back("120");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
}

//--------------------------------------------------------
/**
 *	Method      : StarterClass::write_class_property()
 *	Description : Set class description fields as property in database
 */
//--------------------------------------------------------
void StarterClass::write_class_property()
{
	//	First time, check if database used
	if (Tango::Util::_UseDb == false)
		return;

	Tango::DbData	data;
	std::string	classname = get_name();
	std::string	header;

	//	Put title
	Tango::DbDatum	title("ProjectTitle");
	std::string	str_title("Starter for Tango Administration");
	title << str_title;
	data.push_back(title);

	//	Put Description
	Tango::DbDatum	description("Description");
	std::vector<std::string>	str_desc;
	str_desc.push_back("This device server is able to control <b>Tango</b> components (database, device servers, clients...).");
	str_desc.push_back("It is able to start or stop and to report the status of these components.");
	description << str_desc;
	data.push_back(description);

	//  Put inheritance
	Tango::DbDatum	inher_datum("InheritedFrom");
	std::vector<std::string> inheritance;
	inheritance.push_back("TANGO_BASE_CLASS");
	inher_datum << inheritance;
	data.push_back(inher_datum);

	//	Call database and and values
	get_db_class()->put_property(data);
}

//===================================================================
//	Factory methods
//===================================================================

//--------------------------------------------------------
/**
 *	Method      : StarterClass::device_factory()
 *	Description : Create the device object(s)
 *                and store them in the device list
 */
//--------------------------------------------------------
void StarterClass::device_factory(const Tango::DevVarStringArray *devlist_ptr)
{
	/*----- PROTECTED REGION ID(StarterClass::device_factory_before) ENABLED START -----*/

	//	Add your own code


	/*----- PROTECTED REGION END -----*/	//	StarterClass::device_factory_before

	//	Create devices and add it into the device list
	for (unsigned long i=0 ; i<devlist_ptr->length() ; i++)
	{
		TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << std::endl;
		device_list.push_back(new Starter(this, (*devlist_ptr)[i]));
	}

	//	Manage dynamic attributes if any
	erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list());

	//	Export devices to the outside world
	for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++)
	{
		//	Add dynamic attributes if any
		Starter *dev = static_cast<Starter *>(device_list[device_list.size()-i]);
		dev->add_dynamic_attributes();

		//	Check before if database used.
		if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false))
			export_device(dev);
		else
			export_device(dev, dev->get_name().c_str());
	}

	/*----- PROTECTED REGION ID(StarterClass::device_factory_after) ENABLED START -----*/

	//	Add your own code


	/*----- PROTECTED REGION END -----*/	//	StarterClass::device_factory_after
}
//--------------------------------------------------------
/**
 *	Method      : StarterClass::attribute_factory()
 *	Description : Create the attribute object(s)
 *                and store them in the attribute list
 */
//--------------------------------------------------------
void StarterClass::attribute_factory(std::vector<Tango::Attr *> &att_list)
{
	/*----- PROTECTED REGION ID(StarterClass::attribute_factory_before) ENABLED START -----*/

	//	Add your own code

	/*----- PROTECTED REGION END -----*/	//	StarterClass::attribute_factory_before
	//	Attribute : HostState
	HostStateAttrib	*hoststate = new HostStateAttrib();
	Tango::UserDefaultAttrProp	hoststate_prop;
	//	description	not set for HostState
	//	label	not set for HostState
	//	unit	not set for HostState
	//	standard_unit	not set for HostState
	//	display_unit	not set for HostState
	//	format	not set for HostState
	//	max_value	not set for HostState
	//	min_value	not set for HostState
	//	max_alarm	not set for HostState
	//	min_alarm	not set for HostState
	//	max_warning	not set for HostState
	//	min_warning	not set for HostState
	//	delta_t	not set for HostState
	//	delta_val	not set for HostState
	
	hoststate->set_default_properties(hoststate_prop);
	hoststate->set_polling_period(1000);
	hoststate->set_disp_level(Tango::OPERATOR);
	//	Not Memorized
	att_list.push_back(hoststate);

	//	Attribute : RunningServers
	RunningServersAttrib	*runningservers = new RunningServersAttrib();
	Tango::UserDefaultAttrProp	runningservers_prop;
	//	description	not set for RunningServers
	//	label	not set for RunningServers
	//	unit	not set for RunningServers
	//	standard_unit	not set for RunningServers
	//	display_unit	not set for RunningServers
	//	format	not set for RunningServers
	//	max_value	not set for RunningServers
	//	min_value	not set for RunningServers
	//	max_alarm	not set for RunningServers
	//	min_alarm	not set for RunningServers
	//	max_warning	not set for RunningServers
	//	min_warning	not set for RunningServers
	//	delta_t	not set for RunningServers
	//	delta_val	not set for RunningServers
	
	runningservers->set_default_properties(runningservers_prop);
	runningservers->set_polling_period(1000);
	runningservers->set_disp_level(Tango::OPERATOR);
	//	Not Memorized
	att_list.push_back(runningservers);

	//	Attribute : StoppedServers
	StoppedServersAttrib	*stoppedservers = new StoppedServersAttrib();
	Tango::UserDefaultAttrProp	stoppedservers_prop;
	stoppedservers_prop.set_description("Return all the Stopped servers.");
	stoppedservers_prop.set_label("All Stopped Servers");
	//	unit	not set for StoppedServers
	//	standard_unit	not set for StoppedServers
	//	display_unit	not set for StoppedServers
	//	format	not set for StoppedServers
	//	max_value	not set for StoppedServers
	//	min_value	not set for StoppedServers
	//	max_alarm	not set for StoppedServers
	//	min_alarm	not set for StoppedServers
	//	max_warning	not set for StoppedServers
	//	min_warning	not set for StoppedServers
	//	delta_t	not set for StoppedServers
	//	delta_val	not set for StoppedServers
	
	stoppedservers->set_default_properties(stoppedservers_prop);
	stoppedservers->set_polling_period(1000);
	stoppedservers->set_disp_level(Tango::OPERATOR);
	//	Not Memorized
	att_list.push_back(stoppedservers);

	//	Attribute : Servers
	ServersAttrib	*servers = new ServersAttrib();
	Tango::UserDefaultAttrProp	servers_prop;
	servers_prop.set_description("Return all registered servers for this host.\nServer names are followed by:   [states] [controlled] [level] [nb instances]\nIf nb instances >1 a warning will be displayed in Astor");
	servers_prop.set_label("Servers");
	//	unit	not set for Servers
	//	standard_unit	not set for Servers
	//	display_unit	not set for Servers
	//	format	not set for Servers
	//	max_value	not set for Servers
	//	min_value	not set for Servers
	//	max_alarm	not set for Servers
	//	min_alarm	not set for Servers
	//	max_warning	not set for Servers
	//	min_warning	not set for Servers
	//	delta_t	not set for Servers
	//	delta_val	not set for Servers
	
	servers->set_default_properties(servers_prop);
	servers->set_polling_period(1000);
	servers->set_disp_level(Tango::OPERATOR);
	//	Not Memorized
	att_list.push_back(servers);


	//	Create a list of static attributes
	create_static_attribute_list(get_class_attr()->get_attr_list());
	/*----- PROTECTED REGION ID(StarterClass::attribute_factory_after) ENABLED START -----*/

	//	Add your own code

	/*----- PROTECTED REGION END -----*/	//	StarterClass::attribute_factory_after
}
//--------------------------------------------------------
/**
 *	Method      : StarterClass::pipe_factory()
 *	Description : Create the pipe object(s)
 *                and store them in the pipe list
 */
//--------------------------------------------------------
void StarterClass::pipe_factory()
{
	/*----- PROTECTED REGION ID(StarterClass::pipe_factory_before) ENABLED START -----*/

	//	Add your own code

	/*----- PROTECTED REGION END -----*/	//	StarterClass::pipe_factory_before
	/*----- PROTECTED REGION ID(StarterClass::pipe_factory_after) ENABLED START -----*/

	//	Add your own code

	/*----- PROTECTED REGION END -----*/	//	StarterClass::pipe_factory_after
}
//--------------------------------------------------------
/**
 *	Method      : StarterClass::command_factory()
 *	Description : Create the command object(s)
 *                and store them in the command list
 */
//--------------------------------------------------------
void StarterClass::command_factory()
{
	/*----- PROTECTED REGION ID(StarterClass::command_factory_before) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::command_factory_before

	//	Set polling perod for command State
	Tango::Command	&stateCmd = get_cmd_by_name("State");
	stateCmd.set_polling_period(1000);
	

	//	Command DevStart
	DevStartClass	*pDevStartCmd =
		new DevStartClass("DevStart",
			Tango::DEV_STRING, Tango::DEV_VOID,
			"Server to be started.",
			"",
			Tango::OPERATOR);
	command_list.push_back(pDevStartCmd);

	//	Command DevStop
	DevStopClass	*pDevStopCmd =
		new DevStopClass("DevStop",
			Tango::DEV_STRING, Tango::DEV_VOID,
			"Servero be stopped.",
			"",
			Tango::OPERATOR);
	command_list.push_back(pDevStopCmd);

	//	Command DevStartAll
	DevStartAllClass	*pDevStartAllCmd =
		new DevStartAllClass("DevStartAll",
			Tango::DEV_SHORT, Tango::DEV_VOID,
			"Startup level.",
			"",
			Tango::OPERATOR);
	command_list.push_back(pDevStartAllCmd);

	//	Command DevStopAll
	DevStopAllClass	*pDevStopAllCmd =
		new DevStopAllClass("DevStopAll",
			Tango::DEV_SHORT, Tango::DEV_VOID,
			"Startup Level.",
			"",
			Tango::OPERATOR);
	command_list.push_back(pDevStopAllCmd);

	//	Command DevGetRunningServers
	DevGetRunningServersClass	*pDevGetRunningServersCmd =
		new DevGetRunningServersClass("DevGetRunningServers",
			Tango::DEV_BOOLEAN, Tango::DEVVAR_STRINGARRAY,
			"True for all servers. False for controlled servers only.",
			"List of the processes which are running.",
			Tango::OPERATOR);
	command_list.push_back(pDevGetRunningServersCmd);

	//	Command DevGetStopServers
	DevGetStopServersClass	*pDevGetStopServersCmd =
		new DevGetStopServersClass("DevGetStopServers",
			Tango::DEV_BOOLEAN, Tango::DEVVAR_STRINGARRAY,
			"True for all servers. False for controlled servers only.",
			"List of the processes which are not running.",
			Tango::OPERATOR);
	command_list.push_back(pDevGetStopServersCmd);

	//	Command DevReadLog
	DevReadLogClass	*pDevReadLogCmd =
		new DevReadLogClass("DevReadLog",
			Tango::DEV_STRING, Tango::CONST_DEV_STRING,
			"server name and domain (e.g. Starter/corvus)\nIf argin ==``Starter``     -> return Starter logg file content.\nIf argin ==``Statistics``  -> return Starter statistics file content.",
			"String found in log file.",
			Tango::OPERATOR);
	command_list.push_back(pDevReadLogCmd);

	//	Command HardKillServer
	HardKillServerClass	*pHardKillServerCmd =
		new HardKillServerClass("HardKillServer",
			Tango::DEV_STRING, Tango::DEV_VOID,
			"Server name",
			"",
			Tango::OPERATOR);
	command_list.push_back(pHardKillServerCmd);

	//	Command ResetStatistics
	ResetStatisticsClass	*pResetStatisticsCmd =
		new ResetStatisticsClass("ResetStatistics",
			Tango::DEV_VOID, Tango::DEV_VOID,
			"",
			"",
			Tango::EXPERT);
	command_list.push_back(pResetStatisticsCmd);

	//	Command UpdateServersInfo
	UpdateServersInfoClass	*pUpdateServersInfoCmd =
		new UpdateServersInfoClass("UpdateServersInfo",
			Tango::DEV_VOID, Tango::DEV_VOID,
			"",
			"",
			Tango::OPERATOR);
	command_list.push_back(pUpdateServersInfoCmd);

	/*----- PROTECTED REGION ID(StarterClass::command_factory_after) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::command_factory_after
}

//===================================================================
//	Dynamic attributes related methods
//===================================================================

//--------------------------------------------------------
/**
 * method : 		StarterClass::create_static_attribute_list
 * description : 	Create the a list of static attributes
 *
 * @param	att_list	the ceated attribute list
 */
//--------------------------------------------------------
void StarterClass::create_static_attribute_list(std::vector<Tango::Attr *> &att_list)
{
	for (unsigned long i=0 ; i<att_list.size() ; i++)
	{
		std::string att_name(att_list[i]->get_name());
		transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower);
		defaultAttList.push_back(att_name);
	}

	TANGO_LOG_INFO << defaultAttList.size() << " attributes in default list" << std::endl;

	/*----- PROTECTED REGION ID(StarterClass::create_static_att_list) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::create_static_att_list
}


//--------------------------------------------------------
/**
 * method : 		StarterClass::erase_dynamic_attributes
 * description : 	delete the dynamic attributes if any.
 *
 * @param	devlist_ptr	the device list pointer
 * @param	list of all attributes
 */
//--------------------------------------------------------
void StarterClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, std::vector<Tango::Attr *> &att_list)
{
	Tango::Util *tg = Tango::Util::instance();

	for (unsigned long i=0 ; i<devlist_ptr->length() ; i++)
	{
		Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((std::string)(*devlist_ptr)[i]).c_str());
		Starter *dev = static_cast<Starter *> (dev_impl);

		std::vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list();
		std::vector<Tango::Attribute *>::iterator ite_att;
		for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att)
		{
			std::string att_name((*ite_att)->get_name_lower());
			if ((att_name == "state") || (att_name == "status"))
				continue;
			std::vector<std::string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name);
			if (ite_str == defaultAttList.end())
			{
				TANGO_LOG_INFO << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << std::endl;
				Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str());
				dev->remove_attribute(att_list[att.get_attr_idx()], true, false);
				--ite_att;
			}
		}
	}
	/*----- PROTECTED REGION ID(StarterClass::erase_dynamic_attributes) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::erase_dynamic_attributes
}

//--------------------------------------------------------
/**
 *	Method      : StarterClass::get_attr_object_by_name()
 *	Description : returns Tango::Attr * object found by name
 */
//--------------------------------------------------------
Tango::Attr *StarterClass::get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname)
{
	std::vector<Tango::Attr *>::iterator it;
	for (it=att_list.begin() ; it<att_list.end() ; ++it)
		if ((*it)->get_name()==attname)
			return (*it);
	//	Attr does not exist
	return NULL;
}


/*----- PROTECTED REGION ID(StarterClass::Additional Methods) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	StarterClass::Additional Methods
} //	namespace