File: DataBase.h

package info (click to toggle)
tango 7.2.6%2Bdfsg-14
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 20,720 kB
  • sloc: cpp: 122,899; sh: 11,304; ansic: 1,079; makefile: 843; java: 215; python: 55
file content (945 lines) | stat: -rw-r--r-- 27,927 bytes parent folder | download
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
/*----- PROTECTED REGION ID(DataBase.h) ENABLED START -----*/
//=============================================================================
//
// file :        DataBase.h
//
// description : Include for the DataBase class.
//
// project :     TANGO Database server.
//
// $Author: pascal_verdier $
//
// Copyright (C) :      2004,2005,2006,2007,2008,2009,2010
//						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: 16032 $
// $Date: 2011-03-14 09:58:00 +0100 (Mon, 14 Mar 2011) $
//
// $HeadURL:$
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#ifndef DATABASE_H
#define DATABASE_H


#include <tango.h>
#ifdef WIN32
#include <my_global.h>
#endif
#include <mysql.h>
#include <update_starter.h>


#define DB_SQLError 				"DB_SQLError"
#define DB_IncorrectArguments		"DB_IncorrectArguments"
#define DB_IncorrectDeviceName		"DB_IncorrectDeviceName"
#define DB_IncorrectServerName		"DB_IncorrectServerName"
#define DB_DeviceNotDefined			"DB_DeviceNotDefined"
#define DB_AliasNotDefined			"DB_AliasNotDefined"
#define	DB_NoFreeMySQLConnection	"DB_NoFreeMySQLConnection"
#define	DB_MySQLLibNotThreadSafe	"DB_MySQLLibNotThreadSafe"

#define	STARTER_DEVNAME_HEADER		"tango/admin/"

#define	DEFAULT_CONN_POOL_SIZE		20

//	Define time measuremnt type (depends on OS)
#ifndef WIN32

#	define	TimeVal	struct timeval
#	define	GetTime(t)	gettimeofday(&t, NULL);
#	define	Elapsed(before, after)	\
		1000.0*(after.tv_sec-before.tv_sec) + \
		((double)after.tv_usec-before.tv_usec) / 1000

#else

static LARGE_INTEGER	cpu_freq;
#	define	TimeVal	LARGE_INTEGER
#	define	GetTime(t)	w_gettimeofday(&t);
#	define	Elapsed(before, after)		\
		(cpu_freq.QuadPart==0) ? 0.0 :	\
			(double) (after.QuadPart - before.QuadPart)/cpu_freq.QuadPart * 1000;

#endif	/*	WIN32		*/




/*----- PROTECTED REGION END -----*/


/**
 *	DataBase class Description:
 *	This class manage the TANGO database.
 */

namespace DataBase_ns
{
	/*----- PROTECTED REGION ID(DataBase::Additional Class Declarations) ENABLED START -----*/

		//		Additional Class Declarations
class DummyDev: public Tango::Connection
{
public:
	DummyDev():Tango::Connection(true) {};

	virtual string get_corba_name(bool) {string str;return str;}
	virtual string build_corba_name() {string str;return str;}
	virtual int get_lock_ctr() {return 0;}
	virtual void set_lock_ctr(int) {};

	virtual string dev_name() {string str;return str;}

	int get_env_var(const char *cc,string &str_ref) {return Tango::Connection::get_env_var(cc,str_ref);}
};

	/*----- PROTECTED REGION END -----*/	//	DataBase::Additional Class Declarations


class DataBase : public Tango::Device_4Impl
{


	/*----- PROTECTED REGION ID(DataBase::Data Members) ENABLED START -----*/

	//		Add your own data members
public:
	/**
	 *	current incarnation of database
	 */
	static string db_name;

	/**
	 *	Will be set by property of Default object
	 */
	bool	fireToStarter;
	
	/**
	 *	Database value history depth
	 */
	int	historyDepth;
	
	/**
	 *	Shared data for update starter thread
	 */
	UpdStarterData	*starter_shared;
	/**
	 *	update starter thread instance
	 */
	UpdateStarter	*upd_starter_thread;

	/*
	 * timing related variables
	 */
	typedef struct timing_stats_struct
	{
		double calls;
		double total_elapsed;
		double average;
		double minimum;
		double maximum;
	} TimingStatsStruct;

	map<std::string,TimingStatsStruct*> timing_stats_map; 

	int timing_stats_size;
	double *timing_stats_average;
	double *timing_stats_minimum;
	double *timing_stats_maximum;
	double *timing_stats_calls;
	char **timing_stats_index;


	/*----- PROTECTED REGION END -----*/	//	DataBase::Data Members


//	Device property data members
public:	

//	Attribute data members
public:
	Tango::DevString	*attr_StoredProcedureRelease_read;
	Tango::DevDouble	*attr_Timing_average_read;
	Tango::DevDouble	*attr_Timing_minimum_read;
	Tango::DevDouble	*attr_Timing_maximum_read;
	Tango::DevDouble	*attr_Timing_calls_read;
	Tango::DevString	*attr_Timing_index_read;
	Tango::DevString	*attr_Timing_info_read;



//	Constructors and destructors
public:
	/**
	 * Constructs a newly allocated Command object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	DataBase(Tango::DeviceClass *cl,string &s);
	/**
	 * Constructs a newly allocated Command object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	DataBase(Tango::DeviceClass *cl,const char *s);
	/**
	 * Constructs a newly allocated Command object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device name
	 *	@param d	Device description.
	 */
	DataBase(Tango::DeviceClass *cl,const char *s,const char *d);
	/**
	 * The object destructor.
	 */	
	~DataBase() {delete_device();};



//	Miscellaneous methods
public:
	/**
	 *	will be called at device destruction or at init command.
	 */
	void delete_device();
	/**
	 *	Initialize the device
	 */
	virtual void init_device();
	/**
	 *	Read the device properties from database
	 */
	 void get_device_property();
	/**
	 *	Always executed method before execution command method.
	 */
	virtual void always_executed_hook();


//	Attribute methods
public:
	/**
	 *	Method      : DataBase::read_attr_hardware()
	 *	Description : Hardware acquisition for attributes.
	 */
	virtual void read_attr_hardware(vector<long> &attr_list);


	/**
	 *	StoredProcedureRelease attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevString
	 *	Attr type:	Scalar 
	 */
	virtual void read_StoredProcedureRelease(Tango::Attribute &attr);
	virtual bool is_StoredProcedureRelease_allowed(Tango::AttReqType type);



	/**
	 *	Timing_average attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevDouble
	 *	Attr type:	Spectrum  max = 64
	 */
	virtual void read_Timing_average(Tango::Attribute &attr);
	virtual bool is_Timing_average_allowed(Tango::AttReqType type);



	/**
	 *	Timing_minimum attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevDouble
	 *	Attr type:	Spectrum  max = 64
	 */
	virtual void read_Timing_minimum(Tango::Attribute &attr);
	virtual bool is_Timing_minimum_allowed(Tango::AttReqType type);



	/**
	 *	Timing_maximum attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevDouble
	 *	Attr type:	Spectrum  max = 64
	 */
	virtual void read_Timing_maximum(Tango::Attribute &attr);
	virtual bool is_Timing_maximum_allowed(Tango::AttReqType type);



	/**
	 *	Timing_calls attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevDouble
	 *	Attr type:	Spectrum  max = 64
	 */
	virtual void read_Timing_calls(Tango::Attribute &attr);
	virtual bool is_Timing_calls_allowed(Tango::AttReqType type);



	/**
	 *	Timing_index attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevString
	 *	Attr type:	Spectrum  max = 64
	 */
	virtual void read_Timing_index(Tango::Attribute &attr);
	virtual bool is_Timing_index_allowed(Tango::AttReqType type);



	/**
	 *	Timing_info attribute related methods.
	 *	Description: 
	 *
	 *	Data type:	Tango::DevString
	 *	Attr type:	Spectrum  max = 64
	 */
	virtual void read_Timing_info(Tango::Attribute &attr);
	virtual bool is_Timing_info_allowed(Tango::AttReqType type);



	/**
	 *	Method      : DataBase::add_dynamic_attributes()
	 *	Description : Add dynamic attributes if any.
	 */
		void add_dynamic_attributes();

//	Command related methods
public: 
	/**
	 *	Command State related methods.
	 */
	Tango::DevState dev_state();


	/**
	 *	Command DbAddDevice related methods.
	 */
	void db_add_device(const Tango::DevVarStringArray *argin);
	virtual bool is_DbAddDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbAddServer related methods.
	 */
	void db_add_server(const Tango::DevVarStringArray *argin);
	virtual bool is_DbAddServer_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteAttributeAlias related methods.
	 */
	void db_delete_attribute_alias(Tango::DevString argin);
	virtual bool is_DbDeleteAttributeAlias_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteClassAttribute related methods.
	 */
	void db_delete_class_attribute(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteClassAttribute_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteClassAttributeProperty related methods.
	 */
	void db_delete_class_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteClassAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteClassProperty related methods.
	 */
	void db_delete_class_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteClassProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteDevice related methods.
	 */
	void db_delete_device(Tango::DevString argin);
	virtual bool is_DbDeleteDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteDeviceAlias related methods.
	 */
	void db_delete_device_alias(Tango::DevString argin);
	virtual bool is_DbDeleteDeviceAlias_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteDeviceAttribute related methods.
	 */
	void db_delete_device_attribute(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteDeviceAttribute_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteDeviceAttributeProperty related methods.
	 */
	void db_delete_device_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteDeviceAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteDeviceProperty related methods.
	 */
	void db_delete_device_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteDeviceProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteProperty related methods.
	 */
	void db_delete_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteServer related methods.
	 */
	void db_delete_server(Tango::DevString argin);
	virtual bool is_DbDeleteServer_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteServerInfo related methods.
	 */
	void db_delete_server_info(Tango::DevString argin);
	virtual bool is_DbDeleteServerInfo_allowed(const CORBA::Any &any);

	/**
	 *	Command DbExportDevice related methods.
	 */
	void db_export_device(const Tango::DevVarStringArray *argin);
	virtual bool is_DbExportDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbExportEvent related methods.
	 */
	void db_export_event(const Tango::DevVarStringArray *argin);
	virtual bool is_DbExportEvent_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetAliasDevice related methods.
	 */
	Tango::DevString db_get_alias_device(Tango::DevString argin);
	virtual bool is_DbGetAliasDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetAttributeAlias related methods.
	 */
	Tango::DevString db_get_attribute_alias(Tango::DevString argin);
	virtual bool is_DbGetAttributeAlias_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetAttributeAliasList related methods.
	 */
	Tango::DevVarStringArray *db_get_attribute_alias_list(Tango::DevString argin);
	virtual bool is_DbGetAttributeAliasList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassAttributeList related methods.
	 */
	Tango::DevVarStringArray *db_get_class_attribute_list(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetClassAttributeList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassAttributeProperty related methods.
	 */
	Tango::DevVarStringArray *db_get_class_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetClassAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassAttributeProperty2 related methods.
	 */
	Tango::DevVarStringArray *db_get_class_attribute_property2(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetClassAttributeProperty2_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassAttributePropertyHist related methods.
	 */
	Tango::DevVarStringArray *db_get_class_attribute_property_hist(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetClassAttributePropertyHist_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassForDevice related methods.
	 */
	Tango::DevString db_get_class_for_device(Tango::DevString argin);
	virtual bool is_DbGetClassForDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassInheritanceForDevice related methods.
	 */
	Tango::DevVarStringArray *db_get_class_inheritance_for_device(Tango::DevString argin);
	virtual bool is_DbGetClassInheritanceForDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassList related methods.
	 */
	Tango::DevVarStringArray *db_get_class_list(Tango::DevString argin);
	virtual bool is_DbGetClassList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassProperty related methods.
	 */
	Tango::DevVarStringArray *db_get_class_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetClassProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassPropertyHist related methods.
	 */
	Tango::DevVarStringArray *db_get_class_property_hist(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetClassPropertyHist_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetClassPropertyList related methods.
	 */
	Tango::DevVarStringArray *db_get_class_property_list(Tango::DevString argin);
	virtual bool is_DbGetClassPropertyList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceAlias related methods.
	 */
	Tango::DevString db_get_device_alias(Tango::DevString argin);
	virtual bool is_DbGetDeviceAlias_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceAliasList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_alias_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceAliasList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceAttributeList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_attribute_list(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDeviceAttributeList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceAttributeProperty related methods.
	 */
	Tango::DevVarStringArray *db_get_device_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDeviceAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceAttributeProperty2 related methods.
	 */
	Tango::DevVarStringArray *db_get_device_attribute_property2(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDeviceAttributeProperty2_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceAttributePropertyHist related methods.
	 */
	Tango::DevVarStringArray *db_get_device_attribute_property_hist(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDeviceAttributePropertyHist_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceClassList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_class_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceClassList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceDomainList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_domain_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceDomainList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceExportedList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_exported_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceExportedList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceFamilyList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_family_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceFamilyList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceInfo related methods.
	 */
	Tango::DevVarLongStringArray *db_get_device_info(Tango::DevString argin);
	virtual bool is_DbGetDeviceInfo_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_list(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDeviceList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceWideList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_wide_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceWideList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceMemberList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_member_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceMemberList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceProperty related methods.
	 */
	Tango::DevVarStringArray *db_get_device_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDeviceProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDevicePropertyHist related methods.
	 */
	Tango::DevVarStringArray *db_get_device_property_hist(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDevicePropertyHist_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDevicePropertyList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_property_list(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDevicePropertyList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDeviceServerClassList related methods.
	 */
	Tango::DevVarStringArray *db_get_device_server_class_list(Tango::DevString argin);
	virtual bool is_DbGetDeviceServerClassList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetExportdDeviceListForClass related methods.
	 */
	Tango::DevVarStringArray *db_get_exportd_device_list_for_class(Tango::DevString argin);
	virtual bool is_DbGetExportdDeviceListForClass_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetHostList related methods.
	 */
	Tango::DevVarStringArray *db_get_host_list(Tango::DevString argin);
	virtual bool is_DbGetHostList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetHostServerList related methods.
	 */
	Tango::DevVarStringArray *db_get_host_server_list(Tango::DevString argin);
	virtual bool is_DbGetHostServerList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetHostServersInfo related methods.
	 */
	Tango::DevVarStringArray *db_get_host_servers_info(Tango::DevString argin);
	virtual bool is_DbGetHostServersInfo_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetInstanceNameList related methods.
	 */
	Tango::DevVarStringArray *db_get_instance_name_list(Tango::DevString argin);
	virtual bool is_DbGetInstanceNameList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetObjectList related methods.
	 */
	Tango::DevVarStringArray *db_get_object_list(Tango::DevString argin);
	virtual bool is_DbGetObjectList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetProperty related methods.
	 */
	Tango::DevVarStringArray *db_get_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetPropertyHist related methods.
	 */
	Tango::DevVarStringArray *db_get_property_hist(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetPropertyHist_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetPropertyList related methods.
	 */
	Tango::DevVarStringArray *db_get_property_list(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetPropertyList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetServerInfo related methods.
	 */
	Tango::DevVarStringArray *db_get_server_info(Tango::DevString argin);
	virtual bool is_DbGetServerInfo_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetServerList related methods.
	 */
	Tango::DevVarStringArray *db_get_server_list(Tango::DevString argin);
	virtual bool is_DbGetServerList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetServerNameList related methods.
	 */
	Tango::DevVarStringArray *db_get_server_name_list(Tango::DevString argin);
	virtual bool is_DbGetServerNameList_allowed(const CORBA::Any &any);

	/**
	 *	Command DbImportDevice related methods.
	 */
	Tango::DevVarLongStringArray *db_import_device(Tango::DevString argin);
	virtual bool is_DbImportDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbImportEvent related methods.
	 */
	Tango::DevVarLongStringArray *db_import_event(Tango::DevString argin);
	virtual bool is_DbImportEvent_allowed(const CORBA::Any &any);

	/**
	 *	Command DbInfo related methods.
	 */
	Tango::DevVarStringArray *db_info();
	virtual bool is_DbInfo_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutAttributeAlias related methods.
	 */
	void db_put_attribute_alias(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutAttributeAlias_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutClassAttributeProperty related methods.
	 */
	void db_put_class_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutClassAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutClassAttributeProperty2 related methods.
	 */
	void db_put_class_attribute_property2(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutClassAttributeProperty2_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutClassProperty related methods.
	 */
	void db_put_class_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutClassProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutDeviceAlias related methods.
	 */
	void db_put_device_alias(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutDeviceAlias_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutDeviceAttributeProperty related methods.
	 */
	void db_put_device_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutDeviceAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutDeviceAttributeProperty2 related methods.
	 */
	void db_put_device_attribute_property2(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutDeviceAttributeProperty2_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutDeviceProperty related methods.
	 */
	void db_put_device_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutDeviceProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutProperty related methods.
	 */
	void db_put_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbPutServerInfo related methods.
	 */
	void db_put_server_info(const Tango::DevVarStringArray *argin);
	virtual bool is_DbPutServerInfo_allowed(const CORBA::Any &any);

	/**
	 *	Command DbUnExportDevice related methods.
	 */
	void db_un_export_device(Tango::DevString argin);
	virtual bool is_DbUnExportDevice_allowed(const CORBA::Any &any);

	/**
	 *	Command DbUnExportEvent related methods.
	 */
	void db_un_export_event(Tango::DevString argin);
	virtual bool is_DbUnExportEvent_allowed(const CORBA::Any &any);

	/**
	 *	Command DbUnExportServer related methods.
	 */
	void db_un_export_server(Tango::DevString argin);
	virtual bool is_DbUnExportServer_allowed(const CORBA::Any &any);

	/**
	 *	Command ResetTimingValues related methods.
	 */
	void reset_timing_values();
	virtual bool is_ResetTimingValues_allowed(const CORBA::Any &any);

	/**
	 *	Command DbGetDataForServerCache related methods.
	 */
	Tango::DevVarStringArray *db_get_data_for_server_cache(const Tango::DevVarStringArray *argin);
	virtual bool is_DbGetDataForServerCache_allowed(const CORBA::Any &any);

	/**
	 *	Command DbDeleteAllDeviceAttributeProperty related methods.
	 */
	void db_delete_all_device_attribute_property(const Tango::DevVarStringArray *argin);
	virtual bool is_DbDeleteAllDeviceAttributeProperty_allowed(const CORBA::Any &any);

	/**
	 *	Command DbMySqlSelect related methods.
	 */
	Tango::DevVarLongStringArray *db_my_sql_select(Tango::DevString argin);
	virtual bool is_DbMySqlSelect_allowed(const CORBA::Any &any);



	/*----- PROTECTED REGION ID(DataBase::Additional Method prototypes) ENABLED START -----*/

	//	Additional Method prototypes
protected :	
	unsigned long	mysql_svr_version;
	
	bool check_device_name(string &);
	bool device_name_to_dfm(string &device_name, char domain[], char family[], char member[]);
	string replace_wildcard(const char*);
	Tango::DevString db_get_device_host(Tango::DevString,int con_nb=-1);
	string escape_string(const char *string_c_str);
	void init_timing_stats();
	unsigned int get_id(const char *name,int con_nb=-1);
	void check_history_tables();
	void purge_property(const char *table,const char *field,const char *object,const char *name,int con_nb=-1);
	void purge_att_property(const char *table,const char *field,const char *object,const char *attribute,const char *name,int con_nb=-1);

	typedef struct
	{
		MYSQL 			*db;
		omni_semaphore 	the_sema;
	}DbConnection;
	DbConnection	*conn_pool;
	int				last_sem_wait;
	static int		conn_pool_size;
	char 			*stored_release_ptr;
	char			stored_release[128];

	omni_mutex		timing_stats_mutex;
	omni_mutex		starter_mutex;
	omni_mutex		sem_wait_mutex;
				
	void create_connection_pool(const char *,const char *);
	void base_connect(int);

	inline void update_timing_stats(TimeVal before, TimeVal after, std::string command)
	{
		double time_elapsed = Elapsed(before, after);
		timing_stats_mutex.lock();
		TimingStatsStruct *timing_stats = timing_stats_map[command];
		if (timing_stats != NULL)
		{
			timing_stats->calls++;
			timing_stats->total_elapsed = timing_stats->total_elapsed+time_elapsed;
			timing_stats->average = timing_stats->total_elapsed/timing_stats->calls;
			if (time_elapsed > timing_stats->maximum) timing_stats->maximum = time_elapsed;
			if (time_elapsed < timing_stats->minimum || timing_stats->minimum == 0.0) timing_stats->minimum = time_elapsed;
		}
		timing_stats_mutex.unlock();
	}
	
#ifdef WIN32
	inline static void w_gettimeofday(LARGE_INTEGER *t)
	{
		static int				status = 0;
		if (status==0)
			//	Initialize
			status = QueryPerformanceFrequency(&cpu_freq);

		if (status!=0)
			QueryPerformanceCounter(t);		//	Get micro-second time
		else
			t->QuadPart = 0;
	}
#endif

public:
	
	void simple_query(string sql_query,const char *method,int con_nb=-1);
	MYSQL_RES *query(string sql_query,const char *method,int con_nb=-1);
	static void set_conn_pool_size(int si) {conn_pool_size = si;}
	
	int get_connection();
	void release_connection(int con_nb) {conn_pool[con_nb].the_sema.post();}

	/*----- PROTECTED REGION END -----*/	//	DataBase::Additional Method prototypes

};

	/*----- PROTECTED REGION ID(DataBase::Additional Classes Definitions) ENABLED START -----*/

	//	Additional Classes definitions
class AutoLock
{
public:
	AutoLock(const char *,DataBase *);
	~AutoLock();
	
	int get_con_nb() {return con_nb;}
	
private:
	DataBase	*the_db;
	int 		con_nb;
};

class DbInter: public Tango::Interceptors
{
public:
	DbInter() {}
	~DbInter() {}
	
	virtual void create_thread() 
	{
		if (Tango::Util::instance()->is_svr_starting() == false)
			mysql_thread_init();
	}
	virtual void delete_thread()
	{
		if (Tango::Util::instance()->is_svr_starting() == false)
			mysql_thread_end();
	}
};

	/*----- PROTECTED REGION END -----*/	//	DataBase::Additional Classes Definitions

} //	namespace

#endif	//	DATABASE_H