/usr/include/tango/ApiUtil.h is in libtango-dev 9.2.5a+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | //////////////////////////////////////////////////////////////////
//
// ApiUtil.h - include file for TANGO device api class ApiUtil
//
//
// Copyright (C) : 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 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: 20437 $
//
///////////////////////////////////////////////////////////////
#ifndef _APIUTIL_H
#define _APIUTIL_H
/****************************************************************************************
* *
* The ApiUtil class *
* ----------------- *
* *
***************************************************************************************/
/**
* Miscellaneous utility methods usefull in a Tango client.
*
* This class is a singleton. Therefore, it is not necessary to create it. It will be automatically done. A static
* method allows a user to retrieve the instance
*
* $Author: taurel $
* $Revision: 1 $
*
* @headerfile tango.h
* @ingroup Client
*/
class ApiUtil
{
public:
/**
* Retrieve the ApiUtil instance
*
* Return the ApiUtil singleton instance
*
* @return The singleton instance
*/
TANGO_IMP_EXP static ApiUtil *instance();
/**
* Destroy the ApiUtil instance
*
* Destroy the ApiUtil singleton instance.
*/
TANGO_IMP_EXP static inline void cleanup()
{if (_instance != NULL){delete _instance;_instance=NULL;}}
/**
* Get environment variable
*
* Get environment variable. On Unixes OS, this call tries to get the variable in the caller environment then
* in a file @e .tangorc in the user home directory and finally in a file @e /etc/tangorc. On Windows, this call looks
* in the user environment then in a file stored in %TANGO_HOME%/tangorc. This method returns 0 of the
* environment variable is found. Otherwise, it returns -1.
*
* @param [in] name The environment variable name
* @param [out] value The environment variable value
* @return Set to -1 if the environment varaibel is not found
*/
TANGO_IMP_EXP static int get_env_var(const char *name,string &value);
/**
* Get pending asynchronous requets number
*
* Return number of asynchronous pending requests (any device).
*
* @param [in] ty Asynchronous request type
* @return Pending asynchronous request number
*/
size_t pending_asynch_call(asyn_req_type ty)
{if (ty==POLLING)return asyn_p_table->get_request_nb();
else if (ty==CALL_BACK)return asyn_p_table->get_cb_request_nb();
else return (asyn_p_table->get_request_nb()+asyn_p_table->get_cb_request_nb());}
/**
* Fire callback methods for asynchronous request(s)
*
* Fire callback methods for all (any device) asynchronous requests (command and attribute) with already
* arrived replied. Returns immediately if there is no replies already arrived or if there is no asynchronous
* requests.
*/
void get_asynch_replies();
/**
* Fire callback methods for asynchronous request(s) with timeout
*
* Fire callback methods for all (any device) asynchronous requests (command and attributes) with already
* arrived replied. Wait and block the caller for timeout milliseconds if they are some device asynchronous
* requests which are not yet arrived. Returns immediately if there is no asynchronous request. If timeout is
* set to 0, the call waits until all the asynchronous requests sent has received a reply.
*
* @param [in] timeout The timeout value
*/
void get_asynch_replies(long timeout);
/**
* Set asynchronous callback sub-model
*
* Set the asynchronous callback sub-model between the pull and push sub-model. See Tango book chapter 4.5 to read
* the definition of these sub-models.
* By default, all Tango client using asynchronous callback model are in pull sub-model. This call must be
* used to switch to the push sub-model. NOTE that in push sub-model, a separate thread is spawned to deal
* with server replies.
*
* @param [in] csm The asynchronous callback sub-model
*/
void set_asynch_cb_sub_model(cb_sub_model csm);
/**
* Get asynchronous callback sub-model
*
* Get the asynchronous callback sub-model
*
* @return The asynchronous callback sub-model
*/
cb_sub_model get_asynch_cb_sub_model() {return auto_cb;}
/// @privatesection
CORBA::ORB_ptr get_orb() {return CORBA::ORB::_duplicate(_orb);}
void set_orb(CORBA::ORB_ptr orb_in) {_orb = orb_in;}
void create_orb();
int get_db_ind();
int get_db_ind(string &host,int port);
vector<Database *> &get_db_vect() {return db_vect;}
bool in_server() {return in_serv;}
void in_server(bool serv) {in_serv = serv;}
TangoSys_Pid get_client_pid() {return cl_pid;}
void clean_locking_threads(bool clean=true);
bool is_lock_exit_installed() {omni_mutex_lock guard(lock_th_map);return exit_lock_installed;}
void set_lock_exit_installed(bool in) {omni_mutex_lock guard(lock_th_map);exit_lock_installed = in;}
bool need_reset_already_flag() {return reset_already_executed_flag;}
void need_reset_already_flag(bool in) {reset_already_executed_flag = in;}
TANGO_IMP_EXP static inline bool _is_instance_null()
{return _instance == NULL;}
//
// Utilities methods
//
int get_user_connect_timeout() {return user_connect_timeout;}
DevLong get_user_sub_hwm() {return user_sub_hwm;}
void set_event_buffer_hwm(DevLong val) {if (user_sub_hwm == -1)user_sub_hwm=val;}
void get_ip_from_if(vector<string> &);
void print_error_message(const char *);
void set_sig_handler();
//
// EventConsumer related methods
//
void create_notifd_event_consumer();
void create_zmq_event_consumer();
bool is_notifd_event_consumer_created() {return notifd_event_consumer != NULL;}
NotifdEventConsumer *get_notifd_event_consumer();
bool is_zmq_event_consumer_created() {return zmq_event_consumer != NULL;}
ZmqEventConsumer *get_zmq_event_consumer();
//
// Asynchronous methods
//
AsynReq *get_pasyn_table() {return asyn_p_table;}
//
// Conv. between AttributeValuexxx and DeviceAttribute
//
static void attr_to_device(const AttributeValue *,const AttributeValue_3 *,long,DeviceAttribute *);
static void attr_to_device(const AttributeValue_4 *,long,DeviceAttribute *);
static void attr_to_device(const AttributeValue_5 *,long,DeviceAttribute *);
static void device_to_attr(const DeviceAttribute &,AttributeValue_4 &);
static void device_to_attr(const DeviceAttribute &,AttributeValue &,string &);
//
// Conv. between AttributeConfig and AttributeInfoEx
//
static void AttributeInfoEx_to_AttributeConfig(const AttributeInfoEx *,AttributeConfig_5 *);
protected:
/// @privatesection
ApiUtil();
virtual ~ApiUtil();
vector<Database *> db_vect;
omni_mutex the_mutex;
CORBA::ORB_ptr _orb;
bool in_serv;
cb_sub_model auto_cb;
CbThreadCmd cb_thread_cmd;
CallBackThread *cb_thread_ptr;
AsynReq *asyn_p_table;
public:
/// @privatesection
omni_mutex lock_th_map;
map<string,LockingThread> lock_threads;
private:
class ApiUtilExt
{
public:
ApiUtilExt() {};
};
TANGO_IMP static ApiUtil *_instance;
static omni_mutex inst_mutex;
bool exit_lock_installed;
bool reset_already_executed_flag;
#ifdef HAS_UNIQUE_PTR
unique_ptr<ApiUtilExt> ext;
#else
ApiUtilExt *ext; // Class extension
#endif
NotifdEventConsumer *notifd_event_consumer;
TangoSys_Pid cl_pid;
int user_connect_timeout;
ZmqEventConsumer *zmq_event_consumer;
vector<string> host_ip_adrs;
DevLong user_sub_hwm;
template <typename T> static void attr_to_device_base(const T *,DeviceAttribute *);
};
class _KillProc_: public omni_thread
{
public:
void run(void *) {::exit(-1);}
};
#endif /* _APIUTIL_H */
|