session.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SESSION_H
27 #define ODVA_ETHERNETIP_SESSION_H
28 
29 #include <string>
30 #include <gtest/gtest_prod.h>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/make_shared.hpp>
33 #include <boost/asio.hpp>
34 
42 #include "odva_ethernetip/path.h"
44 
45 using std::string;
46 using boost::shared_ptr;
47 using boost::make_shared;
48 
49 namespace eip {
50 
51 using serialization::Serializable;
52 using serialization::SerializablePrimitive;
53 using socket::Socket;
54 
55 #define DEFAULT_VENDOR_ID 0x1234
56 #define DEFAULT_SERIAL_NUM 0x6789
57 
61 class Session
62 {
63 public:
64 
72  Session(shared_ptr<Socket> socket, shared_ptr<Socket> io_socket,
73  EIP_UINT vendor_id = DEFAULT_VENDOR_ID, EIP_UDINT serial_num = DEFAULT_SERIAL_NUM);
74 
75  virtual ~Session();
76 
83  void open(string hostname, string port = "44818", string io_port = "2222");
84 
88  void close();
89 
95  {
96  return session_id_;
97  }
98 
106  void getSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id,
107  EIP_USINT attribute_id, Serializable& result);
108 
116  template <typename T>
117  T getSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
118  {
120  getSingleAttributeSerializable(class_id, instance_id, attribute_id, data);
121  return data.data;
122  }
123 
131  void setSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id,
132  EIP_USINT attribute_id, shared_ptr<Serializable> data);
133 
141  template <typename T>
142  void setSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id,
143  EIP_USINT attribute_id, T v)
144  {
145  shared_ptr< SerializablePrimitive<T> > data =
146  make_shared< SerializablePrimitive<T> > (v);
147  setSingleAttributeSerializable(class_id, instance_id, attribute_id, data);
148  }
149 
155  int createConnection(const EIP_CONNECTION_INFO_T& o_to_t,
156  const EIP_CONNECTION_INFO_T& t_to_o);
157 
162  void closeConnection(size_t n);
163 
168  inline EIP_UINT getVendorID() const
169  {
170  return my_vendor_id_;
171  }
172 
177  inline EIP_UDINT getSerialNum() const
178  {
179  return my_serial_num_;
180  }
181 
187  const Connection& getConnection(size_t n)
188  {
189  return connections_[n];
190  }
191 
199 
204  void sendIOPacket(CPFPacket& pkt);
205 
206 private:
207  FRIEND_TEST(SessionTest, test_create_connection);
208 
209  shared_ptr<Socket> socket_;
210  shared_ptr<Socket> io_socket_;
213 
218 
219  vector<Connection> connections_;
220 
226  void check_packet(EncapPacket& pkt, EIP_UINT exp_cmd);
227 
235 
245  RRDataResponse sendRRDataCommand(EIP_USINT service, const Path& path,
246  shared_ptr<Serializable> data);
247 };
248 
249 } // namespace eip
250 
251 #endif // ODVA_ETHERNETIP_SESSION_H
eip::Session::next_connection_id_
EIP_UDINT next_connection_id_
Definition: session.h:217
eip::Session::my_serial_num_
EIP_UDINT my_serial_num_
Definition: session.h:215
eip::CPFPacket
Definition: cpf_packet.h:49
path.h
eip_types.h
EIP_CONNECTION_INFO_T
Definition: eip_types.h:97
eip::serialization::SerializablePrimitive
Definition: serializable_primitive.h:41
eip::Session
Definition: session.h:61
eip::Session::~Session
virtual ~Session()
Definition: session.cpp:65
eip
Definition: connection.h:41
eip::Session::getConnection
const Connection & getConnection(size_t n)
Definition: session.h:187
EIP_BYTE
uint8_t EIP_BYTE
Definition: eip_types.h:35
eip::Session::Session
Session(shared_ptr< Socket > socket, shared_ptr< Socket > io_socket, EIP_UINT vendor_id=DEFAULT_VENDOR_ID, EIP_UDINT serial_num=DEFAULT_SERIAL_NUM)
Definition: session.cpp:51
EIP_UINT
uint16_t EIP_UINT
Definition: eip_types.h:39
eip::Session::connections_
vector< Connection > connections_
Definition: session.h:219
eip::Session::check_packet
void check_packet(EncapPacket &pkt, EIP_UINT exp_cmd)
Definition: session.cpp:188
eip::Session::getVendorID
EIP_UINT getVendorID() const
Definition: session.h:168
eip::Session::sendCommand
EncapPacket sendCommand(EncapPacket &req)
Definition: session.cpp:166
eip::Session::io_socket_
shared_ptr< Socket > io_socket_
Definition: session.h:210
eip::Session::setSingleAttribute
void setSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
Definition: session.h:142
EIP_USINT
uint8_t EIP_USINT
Definition: eip_types.h:36
eip::Session::socket_
shared_ptr< Socket > socket_
Definition: session.h:209
eip::serialization::SerializablePrimitive::data
T data
Data as the primitive type to be serialized or deserialized.
Definition: serializable_primitive.h:46
eip::Session::getSingleAttribute
T getSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
Definition: session.h:117
eip::serialization::Serializable
Definition: serializable.h:38
eip::Session::recv_buffer_
EIP_BYTE recv_buffer_[4 *1024]
Definition: session.h:212
eip::Session::sendRRDataCommand
RRDataResponse sendRRDataCommand(EIP_USINT service, const Path &path, shared_ptr< Serializable > data)
Definition: session.cpp:240
eip::Session::createConnection
int createConnection(const EIP_CONNECTION_INFO_T &o_to_t, const EIP_CONNECTION_INFO_T &t_to_o)
Definition: session.cpp:296
eip::RRDataResponse
Definition: rr_data_response.h:56
eip::Session::sendIOPacket
void sendIOPacket(CPFPacket &pkt)
Definition: session.cpp:353
eip::Session::next_connection_sn_
EIP_UINT next_connection_sn_
Definition: session.h:216
connection.h
DEFAULT_SERIAL_NUM
#define DEFAULT_SERIAL_NUM
Definition: session.h:56
eip::Session::setSingleAttributeSerializable
void setSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, shared_ptr< Serializable > data)
Definition: session.cpp:233
eip::Session::closeConnection
void closeConnection(size_t n)
Definition: session.cpp:320
eip::Session::open
void open(string hostname, string port="44818", string io_port="2222")
Definition: session.cpp:80
rr_data_response.h
DEFAULT_VENDOR_ID
#define DEFAULT_VENDOR_ID
Definition: session.h:55
eip::Connection
Definition: connection.h:46
serializable_primitive.h
eip::Session::session_id_
EIP_UDINT session_id_
Definition: session.h:211
socket.h
encap_packet.h
eip::Session::receiveIOPacket
CPFPacket receiveIOPacket()
Definition: session.cpp:335
eip::Session::my_vendor_id_
EIP_UINT my_vendor_id_
Definition: session.h:214
eip::Session::FRIEND_TEST
FRIEND_TEST(SessionTest, test_create_connection)
cpf_packet.h
eip::Session::close
void close()
Definition: session.cpp:150
eip::Session::getSingleAttributeSerializable
void getSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, Serializable &result)
Definition: session.cpp:223
eip::Session::getSerialNum
EIP_UDINT getSerialNum() const
Definition: session.h:177
eip::EncapPacket
Definition: encap_packet.h:50
EIP_UDINT
uint32_t EIP_UDINT
Definition: eip_types.h:42
eip::Session::getSessionID
EIP_UDINT getSessionID()
Definition: session.h:94
serializable.h
eip::Path
Definition: path.h:50


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:56