Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cs
cls
socket2client
Commits
c0d71c76
Commit
c0d71c76
authored
May 20, 2020
by
Alessio Igor Bogani
Browse files
Initial commit
parents
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/Socket2Client.cpp
0 → 100644
View file @
c0d71c76
/*----- PROTECTED REGION ID(Socket2Client.cpp) ENABLED START -----*/
static
const
char
*
RcsId
=
"$Id: Socket2Client.cpp,v 1.5 2018-07-09 13:58:00 alessio Exp $"
;
//=============================================================================
//
// file : Socket2Client.cpp
//
// description : C++ source for the Socket2Client class and its commands.
// The class is derived from Device. It represents the
// CORBA servant object which will be accessed from the
// network. All commands which can be executed on the
// Socket2Client are implemented in this file.
//
// project :
//
// This file is part of Tango device class.
//
// 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/>.
//
// $Author: alessio $
//
// $Revision: 1.5 $
// $Date: 2018-07-09 13:58:00 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <Socket2Client.h>
#include <Socket2ClientClass.h>
#include <iomanip>
/*----- PROTECTED REGION END -----*/
// Socket2Client.cpp
/**
* Socket2Client class description:
*
*/
//================================================================
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//================================================================
// State | Inherited (no method)
// Status | Inherited (no method)
//================================================================
//================================================================
// Attributes managed is:
//================================================================
//================================================================
namespace
Socket2Client_ns
{
/*----- PROTECTED REGION ID(Socket2Client::namespace_starting) ENABLED START -----*/
// static initializations
/*----- PROTECTED REGION END -----*/
// Socket2Client::namespace_starting
//--------------------------------------------------------
/**
* Method : Socket2Client::Socket2Client()
* Description : Constructors for a Tango device
* implementing the classSocket2Client
*/
//--------------------------------------------------------
Socket2Client
::
Socket2Client
(
Tango
::
DeviceClass
*
cl
,
string
&
s
)
:
TANGO_BASE_CLASS
(
cl
,
s
.
c_str
())
{
/*----- PROTECTED REGION ID(Socket2Client::constructor_1) ENABLED START -----*/
init_device
();
/*----- PROTECTED REGION END -----*/
// Socket2Client::constructor_1
}
//--------------------------------------------------------
Socket2Client
::
Socket2Client
(
Tango
::
DeviceClass
*
cl
,
const
char
*
s
)
:
TANGO_BASE_CLASS
(
cl
,
s
)
{
/*----- PROTECTED REGION ID(Socket2Client::constructor_2) ENABLED START -----*/
init_device
();
/*----- PROTECTED REGION END -----*/
// Socket2Client::constructor_2
}
//--------------------------------------------------------
Socket2Client
::
Socket2Client
(
Tango
::
DeviceClass
*
cl
,
const
char
*
s
,
const
char
*
d
)
:
TANGO_BASE_CLASS
(
cl
,
s
,
d
)
{
/*----- PROTECTED REGION ID(Socket2Client::constructor_3) ENABLED START -----*/
init_device
();
/*----- PROTECTED REGION END -----*/
// Socket2Client::constructor_3
}
//--------------------------------------------------------
/**
* Method : Socket2Client::delete_device()
* Description : will be called at device destruction or at init command
*/
//--------------------------------------------------------
void
Socket2Client
::
delete_device
()
{
DEBUG_STREAM
<<
"Socket2Client::delete_device() "
<<
device_name
<<
endl
;
/*----- PROTECTED REGION ID(Socket2Client::delete_device) ENABLED START -----*/
// Delete device allocated objects
if
(
device_proxy
)
{
delete
device_proxy
;
device_proxy
=
NULL
;
}
/*----- PROTECTED REGION END -----*/
// Socket2Client::delete_device
}
//--------------------------------------------------------
/**
* Method : Socket2Client::init_device()
* Description : will be called at device initialization.
*/
//--------------------------------------------------------
void
Socket2Client
::
init_device
()
{
DEBUG_STREAM
<<
"Socket2Client::init_device() create device "
<<
device_name
<<
endl
;
/*----- PROTECTED REGION ID(Socket2Client::init_device_before) ENABLED START -----*/
// Initialization before get_device_property() call
device_proxy
=
NULL
;
init_error
.
clear
();
/*----- PROTECTED REGION END -----*/
// Socket2Client::init_device_before
// Get the device properties from database
get_device_property
();
// No longer if mandatory property not set.
if
(
mandatoryNotDefined
)
return
;
/*----- PROTECTED REGION ID(Socket2Client::init_device) ENABLED START -----*/
// Initialize device
try
{
device_proxy
=
new
Tango
::
DeviceProxy
(
deviceName
);
}
catch
(
Tango
::
DevFailed
&
e
)
{
init_error
=
"Initialization failed: "
+
string
(
e
.
errors
[
0
].
desc
);
}
catch
(
...
)
{
init_error
=
"Initialization failed: unknown reason"
;
}
/*----- PROTECTED REGION END -----*/
// Socket2Client::init_device
}
//--------------------------------------------------------
/**
* Method : Socket2Client::get_device_property()
* Description : Read database to initialize property data members.
*/
//--------------------------------------------------------
void
Socket2Client
::
get_device_property
()
{
/*----- PROTECTED REGION ID(Socket2Client::get_device_property_before) ENABLED START -----*/
// Initialize property data members
/*----- PROTECTED REGION END -----*/
// Socket2Client::get_device_property_before
mandatoryNotDefined
=
false
;
// Read device properties from database.
Tango
::
DbData
dev_prop
;
dev_prop
.
push_back
(
Tango
::
DbDatum
(
"DeviceName"
));
// is there at least one property to be read ?
if
(
dev_prop
.
size
()
>
0
)
{
// Call database and extract values
if
(
Tango
::
Util
::
instance
()
->
_UseDb
==
true
)
get_db_device
()
->
get_property
(
dev_prop
);
// get instance on Socket2ClientClass to get class property
Tango
::
DbDatum
def_prop
,
cl_prop
;
Socket2ClientClass
*
ds_class
=
(
static_cast
<
Socket2ClientClass
*>
(
get_device_class
()));
int
i
=
-
1
;
// Try to initialize DeviceName from class property
cl_prop
=
ds_class
->
get_class_property
(
dev_prop
[
++
i
].
name
);
if
(
cl_prop
.
is_empty
()
==
false
)
cl_prop
>>
deviceName
;
else
{
// Try to initialize DeviceName from default device value
def_prop
=
ds_class
->
get_default_device_property
(
dev_prop
[
i
].
name
);
if
(
def_prop
.
is_empty
()
==
false
)
def_prop
>>
deviceName
;
}
// And try to extract DeviceName value from database
if
(
dev_prop
[
i
].
is_empty
()
==
false
)
dev_prop
[
i
]
>>
deviceName
;
// Property StartDsPath is mandatory, check if has been defined in database.
check_mandatory_property
(
cl_prop
,
dev_prop
[
i
]);
}
/*----- PROTECTED REGION ID(Socket2Client::get_device_property_after) ENABLED START -----*/
// Check device property data members init
/*----- PROTECTED REGION END -----*/
// Socket2Client::get_device_property_after
}
//--------------------------------------------------------
/**
* Method : Socket2Client::check_mandatory_property()
* Description : For mandatory properties check if defined in database.
*/
//--------------------------------------------------------
void
Socket2Client
::
check_mandatory_property
(
Tango
::
DbDatum
&
class_prop
,
Tango
::
DbDatum
&
dev_prop
)
{
// Check if all properties are empty
if
(
class_prop
.
is_empty
()
&&
dev_prop
.
is_empty
())
{
TangoSys_OMemStream
tms
;
tms
<<
endl
<<
"Property
\'
"
<<
dev_prop
.
name
;
if
(
Tango
::
Util
::
instance
()
->
_UseDb
==
true
)
tms
<<
"
\'
is mandatory but not defined in database"
;
else
tms
<<
"
\'
is mandatory but cannot be defined without database"
;
string
status
(
get_status
());
status
+=
tms
.
str
();
set_status
(
status
);
mandatoryNotDefined
=
true
;
/*----- PROTECTED REGION ID(Socket2Client::check_mandatory_property) ENABLED START -----*/
cerr
<<
tms
.
str
()
<<
" for "
<<
device_name
<<
endl
;
/*----- PROTECTED REGION END -----*/
// Socket2Client::check_mandatory_property
}
}
//--------------------------------------------------------
/**
* Method : Socket2Client::always_executed_hook()
* Description : method always executed before any command is executed
*/
//--------------------------------------------------------
void
Socket2Client
::
always_executed_hook
()
{
DEBUG_STREAM
<<
"Socket2Client::always_executed_hook() "
<<
device_name
<<
endl
;
if
(
mandatoryNotDefined
)
{
string
status
(
get_status
());
Tango
::
Except
::
throw_exception
(
(
const
char
*
)
"PROPERTY_NOT_SET"
,
status
.
c_str
(),
(
const
char
*
)
"Socket2Client::always_executed_hook()"
);
}
/*----- PROTECTED REGION ID(Socket2Client::always_executed_hook) ENABLED START -----*/
// code always executed before all requests
if
(
!
init_error
.
empty
())
{
set_state
(
Tango
::
FAULT
);
set_status
(
init_error
);
}
/*----- PROTECTED REGION END -----*/
// Socket2Client::always_executed_hook
}
//--------------------------------------------------------
/**
* Method : Socket2Client::read_attr_hardware()
* Description : Hardware acquisition for attributes
*/
//--------------------------------------------------------
void
Socket2Client
::
read_attr_hardware
(
TANGO_UNUSED
(
vector
<
long
>
&
attr_list
))
{
DEBUG_STREAM
<<
"Socket2Client::read_attr_hardware(vector<long> &attr_list) entering... "
<<
endl
;
/*----- PROTECTED REGION ID(Socket2Client::read_attr_hardware) ENABLED START -----*/
// Add your own code
check_init
();
/*----- PROTECTED REGION END -----*/
// Socket2Client::read_attr_hardware
}
//--------------------------------------------------------
/**
* Method : Socket2Client::add_dynamic_attributes()
* Description : Create the dynamic attributes if any
* for specified device.
*/
//--------------------------------------------------------
void
Socket2Client
::
add_dynamic_attributes
()
{
/*----- PROTECTED REGION ID(Socket2Client::add_dynamic_attributes) ENABLED START -----*/
// Add your own code to create and add dynamic attributes if any
/*----- PROTECTED REGION END -----*/
// Socket2Client::add_dynamic_attributes
}
//--------------------------------------------------------
/**
* Method : Socket2Client::add_dynamic_commands()
* Description : Create the dynamic commands if any
* for specified device.
*/
//--------------------------------------------------------
void
Socket2Client
::
add_dynamic_commands
()
{
/*----- PROTECTED REGION ID(Socket2Client::add_dynamic_commands) ENABLED START -----*/
// Add your own code to create and add dynamic commands if any
/*----- PROTECTED REGION END -----*/
// Socket2Client::add_dynamic_commands
}
/*----- PROTECTED REGION ID(Socket2Client::namespace_ending) ENABLED START -----*/
// Additional Methods
void
Socket2Client
::
check_init
()
{
if
(
!
init_error
.
empty
())
Tango
::
Except
::
throw_exception
(
""
,
init_error
.
c_str
(),
"Socket2Client::check_init()"
);
}
void
Socket2Client
::
write_
(
const
vector
<
unsigned
char
>
&
data_to_write
)
{
check_init
();
vector
<
unsigned
char
>
*
data_to_write_
=
const_cast
<
vector
<
unsigned
char
>*
>
(
&
data_to_write
);
Tango
::
DeviceData
dtw
;
dtw
<<
*
data_to_write_
;
device_proxy
->
command_inout
(
"Write"
,
dtw
);
}
void
Socket2Client
::
read_
(
const
Tango
::
DevLong
len
,
vector
<
unsigned
char
>
&
data_to_read
)
{
check_init
();
Tango
::
DeviceData
dtr
,
dtr_len
;
dtr_len
<<
len
;
dtr
=
device_proxy
->
command_inout
(
"Read"
,
dtr_len
);
dtr
>>
data_to_read
;
}
void
Socket2Client
::
read_until_
(
const
unsigned
char
delim
,
vector
<
unsigned
char
>
&
data_to_read
)
{
check_init
();
vector
<
unsigned
char
>
delim_
;
delim_
.
push_back
(
delim
);
Tango
::
DeviceData
dtr
,
dtr_delim
;
dtr_delim
<<
delim_
;
dtr
=
device_proxy
->
command_inout
(
"ReadUntil"
,
dtr_delim
);
dtr
>>
data_to_read
;
}
void
Socket2Client
::
write
(
const
vector
<
unsigned
char
>
&
data_to_write
)
{
write_
(
data_to_write
);
DEBUG_STREAM
<<
"Written "
<<
data_to_write
.
size
()
<<
" byte(s): "
<<
dump_hex
(
data_to_write
)
<<
endl
;
}
void
Socket2Client
::
read
(
const
Tango
::
DevLong
len
,
vector
<
unsigned
char
>
&
data_to_read
)
{
read_
(
len
,
data_to_read
);
DEBUG_STREAM
<<
"Readed "
<<
data_to_read
.
size
()
<<
" byte(s): "
<<
dump_hex
(
data_to_read
)
<<
endl
;
}
void
Socket2Client
::
read_until
(
const
unsigned
char
delim
,
vector
<
unsigned
char
>
&
data_to_read
)
{
read_until_
(
delim
,
data_to_read
);
DEBUG_STREAM
<<
"Readed "
<<
data_to_read
.
size
()
<<
" byte(s): "
<<
dump_hex
(
data_to_read
)
<<
endl
;
}
void
Socket2Client
::
write
(
const
string
&
data_to_write
)
{
vector
<
unsigned
char
>
data
;
for
(
unsigned
int
i
=
0
;
i
<
data_to_write
.
size
();
++
i
)
data
.
push_back
(
data_to_write
[
i
]);
write_
(
data
);
DEBUG_STREAM
<<
"Written "
<<
data
.
size
()
<<
" byte(s): "
<<
dump_ascii
(
data
)
<<
endl
;
}
void
Socket2Client
::
read
(
const
Tango
::
DevLong
len
,
string
&
data_readed
)
{
vector
<
unsigned
char
>
data
;
read_
(
len
,
data
);
data_readed
=
""
;
for
(
unsigned
int
i
=
0
;
i
<
data
.
size
();
++
i
)
data_readed
+=
data
[
i
];
DEBUG_STREAM
<<
"Readed "
<<
data
.
size
()
<<
" byte(s): "
<<
dump_ascii
(
data
)
<<
endl
;
}
void
Socket2Client
::
read_until
(
const
char
delim
,
string
&
data_readed
)
{
vector
<
unsigned
char
>
data
;
read_until_
(
delim
,
data
);
data_readed
=
""
;
for
(
unsigned
int
i
=
0
;
i
<
data
.
size
();
++
i
)
data_readed
+=
data
[
i
];
DEBUG_STREAM
<<
"Readed "
<<
data
.
size
()
<<
" byte(s): "
<<
dump_ascii
(
data
)
<<
endl
;
}
int
Socket2Client
::
output_length
()
{
check_init
();
Tango
::
DevLong
ret
;
device_proxy
->
read_attribute
(
"OutputLength"
)
>>
ret
;
return
ret
;
}
int
Socket2Client
::
input_length
()
{
check_init
();
Tango
::
DevLong
ret
;
device_proxy
->
read_attribute
(
"InputLength"
)
>>
ret
;
return
ret
;
}
Tango
::
DevState
Socket2Client
::
get_state2
()
{
check_init
();
Tango
::
DevState
state
;
device_proxy
->
read_attribute
(
"State"
)
>>
state
;
return
state
;
}
string
Socket2Client
::
get_status2
()
{
check_init
();
string
status
;
device_proxy
->
read_attribute
(
"Status"
)
>>
status
;
return
status
;
}
/*
void StreamClient::read(Tango::DeviceProxy &dp, const Tango::DevLong len,
Tango::DevVarCharArray &data_readed)
{
Tango::DeviceData dtr, dtr_len;
dtr_len << len;
dtr = dp.command_inout("Read", dtr_len);
const Tango::DevVarCharArray *dvca;
dtr >> dvca;
data_readed.length(dvca->length());
for (unsigned int i=0; i<dvca->length(); ++i)
data_readed[i] = (*dvca)[i];
}
void StreamClient::read_until(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &delim,
Tango::DevVarCharArray &data_readed)
{
Tango::DeviceData dtr, d;
Tango::DevVarCharArray *temp = new Tango::DevVarCharArray();
temp->length(delim.length());
for (unsigned int i=0; i<delim.length(); ++i)
(*temp)[i] = delim[i];
d << temp;
dtr = dp.command_inout("ReadUntil", d);
const Tango::DevVarCharArray *dvca;
dtr >> dvca;
data_readed.length(dvca->length());
for (unsigned int i=0; i<dvca->length(); ++i)
data_readed[i] = (*dvca)[i];
}
*/
/*
void Socket2Client::write(const Tango::DevVarCharArray *data_to_write)
{
Tango::DeviceData dtw;
dtw << data_to_write;
device_proxy->command_inout("Write", dtw);
}
*/
/*
void StreamClient::write(const Tango::DevString *data_to_write)
{
}
void StreamClient::write_and_read(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &data_to_write,
const Tango::DevLong len, Tango::DevVarCharArray &data_readed)
{
write(dp, data_to_write);
read(dp, len, data_readed);
}
void StreamClient::write_and_read(Tango::DeviceProxy &dp,
const string &data_to_write, const Tango::DevLong len,
string &data_readed)
{
write(dp, data_to_write);
read(dp, len, data_readed);
}
void StreamClient::write_and_read_until(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &data_to_write,
const Tango::DevVarCharArray &delim,
Tango::DevVarCharArray &data_readed)
{
write(dp, data_to_write);
read_until(dp, delim, data_readed);
}
void StreamClient::write_and_read_until(Tango::DeviceProxy &dp,
const string &data_to_write, const string &delim,
string &data_readed)
{
write(dp, data_to_write);
read_until(dp, delim, data_readed);
}
*/
string
Socket2Client
::
dump_ascii
(
const
vector
<
unsigned
char
>
&
data
)
{
stringstream
mesg_ascii
;
for
(
unsigned
int
i
=
0
;
i
<
data
.
size
();
++
i
)
{
if
(
isspace
((
char
)
data
[
i
]))
{
if
((
int
)
data
[
i
]
==
0x20
)
mesg_ascii
<<
(
char
)
data
[
i
];
}
else
mesg_ascii
<<
(
char
)
data
[
i
];
}
return
mesg_ascii
.
str
();
}
string
Socket2Client
::
dump_hex
(
const
vector
<
unsigned
char
>
&
data
)
{
stringstream
mesg_hex
;
for
(
unsigned
int
i
=
0
;
i
<
data
.
size
();
++
i
)
{
mesg_hex
<<
setw
(
2
)
<<
setfill
(
'0'
)
<<
hex
<<
(
int
)
data
[
i
]
<<
" "
;
}
return
mesg_hex
.
str
();
}
/*----- PROTECTED REGION END -----*/
// Socket2Client::namespace_ending
}
// namespace
src/Socket2Client.h
0 → 100644
View file @
c0d71c76
/*----- PROTECTED REGION ID(Socket2Client.h) ENABLED START -----*/
//=============================================================================
//
// file : Socket2Client.h
//
// description : Include file for the Socket2Client class
//
// project :
//
// This file is part of Tango device class.
//
// 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/>.
//
// $Author: alessio $
//
// $Revision: 1.4 $
// $Date: 2018-01-08 10:32:23 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef Socket2Client_H
#define Socket2Client_H
#include <tango.h>
/*----- PROTECTED REGION END -----*/
// Socket2Client.h