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
|
/*
* SPDX-FileCopyrightText: All Contributors to the PyTango project
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef _DEVICE_CLASS_H_
#define _DEVICE_CLASS_H_
#include <boost/python.hpp>
#include <tango/tango.h>
class CppDeviceClass : public Tango::DeviceClass
{
public:
CppDeviceClass(const std::string &);
virtual ~CppDeviceClass();
/**
* Export a device.
* Associate the servant to a CORBA object and send device network parameter
* to TANGO database.
* The main parameter sent to database is the CORBA object stringified device IOR.
*
* @param[in] dev The device to be exported (CORBA servant)
* @param[in] corba_dev_name The name to be used in the CORBA object key.
* This parameter does not need to be set in most of
* cases and has a default value. It is used for special
* device server like the database device server.
*/
inline void export_device(Tango::DeviceImpl *dev, const char *corba_dev_nam = "Unused")
{
Tango::DeviceClass::export_device(dev, corba_dev_nam);
}
/**
* Returns the python interpreter state
*
* @return python interpreter state pointer
*/
inline PyInterpreterState *get_py_interp()
{
return interp;
}
/**
* Sets the python interpreter state
*
* @param[in] in python interpreter state
*/
inline void set_py_interp(PyInterpreterState *in)
{
interp = in;
}
/**
* Creates an attribute and adds it to the att_list.
* This method is intended to be called by python to register a new
* attribute.
*/
void create_attribute(std::vector<Tango::Attr *> &att_list,
const std::string &attr_name,
Tango::CmdArgType attr_type,
Tango::AttrDataFormat attr_format,
Tango::AttrWriteType attr_write,
long dim_x,
long dim_y,
Tango::DispLevel display_level,
long polling_period,
bool memorized,
bool hw_memorized,
const std::string &read_method_name,
const std::string &write_method_name,
const std::string &is_allowed_name,
Tango::UserDefaultAttrProp *att_prop);
void create_fwd_attribute(std::vector<Tango::Attr *> &att_list,
const std::string &attr_name,
Tango::UserDefaultFwdAttrProp *att_prop);
/**
* Creates an pipe and adds it to the att_list.
* This method is intended to be called by python to register a new
* pipe.
*/
void create_pipe(std::vector<Tango::Pipe *> &pipe_list,
const std::string &name,
Tango::PipeWriteType access,
Tango::DispLevel display_level,
const std::string &read_method_name,
const std::string &write_method_name,
const std::string &is_allowed_name,
Tango::UserDefaultPipeProp *prop);
/**
* Creates a command.
* This method is intended to be called by python to register a new
* command.
*/
void create_command(const std::string &cmd_name,
Tango::CmdArgType param_type,
Tango::CmdArgType result_type,
const std::string ¶m_desc,
const std::string &result_desc,
Tango::DispLevel display_level,
bool default_command,
long polling_period,
const std::string &is_allowed);
protected:
PyInterpreterState *interp;
};
class CppDeviceClassWrap : public CppDeviceClass
{
public:
/** a reference to itself */
PyObject *m_self;
/**
* Constructor
*
* @param[in] self A reference to the python device class object
* @param[in] name the class name
*/
CppDeviceClassWrap(PyObject *self, const std::string &name);
/**
* Destructor
*/
virtual ~CppDeviceClassWrap();
/**
* This method forward a C++ call to the device_factory method to the
* Python method
*
* @param[in] dev_list The device name list
*/
virtual void device_factory(const Tango::DevVarStringArray *dev_list);
/**
* This method forward a C++ call to the attribute_factory method to the
* Python method
*
* @param[in] att_list attribute list
*/
virtual void attribute_factory(std::vector<Tango::Attr *> &att_list);
/**
* This method forward a C++ call to the pipe_factory method to the
* Python method
*
* @param[in] pipe_list pipe list
*/
virtual void pipe_factory();
/**
* This method forward a C++ call to the command_factory method to the
* Python method
*/
virtual void command_factory();
/**
* This method forward a C++ call to the device_name_factory method to the
* Python method
*/
virtual void device_name_factory(std::vector<std::string> &dev_list);
/**
* This method forward a C++ call to the signal_handler method to the
* Python method or executes default signal handler if no signal handler
* is defined in python
*
* @param[in] signo signal identifier
*/
virtual void signal_handler(long signo);
/**
* Default signal handler implementation
*
* @param[in] signo signal identifier
*/
void default_signal_handler(long signo);
protected:
/**
* Initializes the class. Registers as a python DeviceClass to tango,
* determines existence of a signal handler among other things
*/
void init_class();
/**
* flag containing the information about the existence of a signal_handler
* method in the python class
*/
bool signal_handler_defined;
};
#endif // _DEVICE_CLASS_H_
|