File: classpipe.cpp

package info (click to toggle)
tango 9.2.5a%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 21,624 kB
  • ctags: 11,597
  • sloc: cpp: 135,480; sh: 21,772; makefile: 1,103; ansic: 1,083; java: 215; python: 55
file content (223 lines) | stat: -rw-r--r-- 6,329 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

static const char *RcsId = "$Id: classpipe.cpp 27410 2015-01-27 05:46:17Z taurel $\n$Name$";

//+=================================================================================================================
//
// file :               ClassPipe.cpp
//
// description :        C++ source code for the MultiClassPipe
//
// project :            TANGO
//
// author(s) :          E.Taurel
//
// Copyright (C) :      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: 27410 $
//
//-==================================================================================================================

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

#include <tango.h>
#include <classpipe.h>

namespace Tango
{

//+------------------------------------------------------------------------------------------------------------------
//
// method :
//		MultiClassPipe::MultiClassPipe
//
// description :
//		destructor for the MultiClassPipe class
//
//-------------------------------------------------------------------------------------------------------------------

MultiClassPipe::~MultiClassPipe()
{
/*	long nb_attr = attr_list.size();
	for (int i = 0;i < nb_attr;i++)
		delete attr_list[i];*/
}


//+-------------------------------------------------------------------------------------------------------------------
//
// method :
//		MultiClassPipe::MultiClassPipe
//
// description :
//		Constructor for the MultiClassPipe class
//
//--------------------------------------------------------------------------------------------------------------------

MultiClassPipe::MultiClassPipe()
{
	cout4 << "Entering MultiClassPipe constructor" << endl;
}

//+-------------------------------------------------------------------------------------------------------------------
//
// method :
//		MultiClassPipe::init_class_pipe
//
// description :
//		Ask the database for properties defined at class level and build the ClassPipe object for each pipe
//		with defined properties
//
// argument :
//		in :
//			- cl_ptr : The device class object pointer
//
//-------------------------------------------------------------------------------------------------------------------

void MultiClassPipe::init_class_pipe(DeviceClass *cl_ptr)
{
	cout4 << "Entering MultiClassPipe::init_class_pipe" << endl;

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

	vector<Pipe *> &pi_list = cl_ptr->get_pipe_list();
	size_t nb_pipe = pi_list.size();

//
// Get class attribute(s) properties stored in DB. No need to implement a retry here (in case of db server restart)
// because the db reconnection is forced by the get_property call executed during xxxClass construction
// before we reach this code.
//

	if ((nb_pipe != 0) && (Tango::Util::_UseDb == true))
	{
		size_t i;
		Tango::DbData db_list;
		string &class_name = cl_ptr->get_name();
		size_t nb_db_requested_pipe = 0;

//
// Ask for class default prop in DB only for pipe with label or desc not already set to some user default value
//

		for(i = 0;i < nb_pipe;i++)
		{
			Pipe *pi_ptr = pi_list[i];
			string &pi_name = pi_ptr->get_name();
			if (pi_ptr->get_label() == pi_name || pi_ptr->get_desc() == DescNotSpec)
			{
				db_list.push_back(DbDatum(pi_name));
				nb_db_requested_pipe++;
			}
		}

		try
		{
			tg->get_database()->get_class_pipe_property(class_name,db_list,tg->get_db_cache());
		}
		catch (Tango::DevFailed &e)
		{
			stringstream ss;
			ss << "Can't get class pipe properties for class " << class_name;

			Except::re_throw_exception(e,API_DatabaseAccess,ss.str(),
				                "MultiClassPipe::init_class_pipe");
		}

//
// Sort property for each pipe
//

		long ind = 0;
		for (i = 0;i < nb_db_requested_pipe;i++)
		{
			vector<PipeProperty> prop_list;

			string pipe_name = db_list[ind].name;
			long nb_prop = 0;
			db_list[ind] >> nb_prop;

			ind++;
			for (long j = 0;j < nb_prop;j++)
			{
				if (db_list[ind].size() > 1)
				{
					string tmp(db_list[ind].value_string[0]);
					long nb = db_list[ind].size();
					for (int k = 1;k < nb;k++)
					{
						tmp = tmp + " ";
						tmp = tmp + db_list[ind].value_string[k];
					}
					prop_list.push_back(PipeProperty(db_list[ind].name,tmp));
				}
				else
					prop_list.push_back(PipeProperty(db_list[ind].name,db_list[ind].value_string[0]));
				ind++;
			}

			if (nb_prop != 0)
			{
#ifdef INIT_LIST
				pipe_prop_list.insert({pipe_name,prop_list});
#else
				pipe_prop_list.insert(make_pair(pipe_name,prop_list));
#endif
			}
		}
	}

	cout4 << "Leaving MultiClassPipe::init_class_pipe" << endl;
}


//+-------------------------------------------------------------------------------------------------------------------
//
// method :
//		MultiClassPipe::get_prop_list
//
// description :
//		Get list of pipe property (defined at class level) for the pipe specified as input arg
//
// argument :
// 		in :
//			- pipe_name : The pipe name
//
// return :
//		Reference to the vector of pipe properties or throw an exception if the pipe is not found
//
//--------------------------------------------------------------------------------------------------------------------

vector<Tango::PipeProperty> &MultiClassPipe::get_prop_list(const string &pipe_name)
{
	map<string,vector<PipeProperty> >::iterator ite;
	ite = pipe_prop_list.find(pipe_name);
	if (ite == pipe_prop_list.end())
	{
		stringstream ss;
		ss << "Pipe " << pipe_name << " not found in class pipe(s) properties" << ends;

		Except::throw_exception(API_PipeNotFound,ss.str(),"MultiClassPipe::get_prop_list");
	}

	return ite->second;
}

} // End of Tango namespace