CARMA C++
Session.h
Go to the documentation of this file.
1 
10 #ifndef SESSION_H
11 #define SESSION_H
12 
13 // System includes
14 #include <netinet/in.h>
15 #include <pthread.h>
16 #include <sys/socket.h>
17 
18 #include <vector>
19 
20 namespace log4cpp {
21  class Category;
22 }
23 
24 namespace carma {
25 namespace canbus {
26 
27 // Forward declaration
28 class Message;
29 
30 namespace canoverip {
31 
32 
38 class Session {
39 public:
40 
46  Session(int readSock, int writeSock);
47 
51  ~Session();
52 
56  typedef struct {
57  unsigned int aCode; // CAN id filter acceptance codes
58  unsigned int aMask; // CAN id filter acceptance masks
59  unsigned short busFilter; // Bus Id Filter
60  } FilterType;
61 
65  void addFilter(FilterType filter);
66 
70  void clearFilters( );
71 
75  bool matchesFilter(const carma::canbus::Message & msg);
76 
81  inline int getReadSock( ) { return rsd_; };
82 
87  inline int getWriteSock( ) { return wsd_; };
88 
89 protected:
90 
91 
92 private:
93 
94  typedef union {
95  struct sockaddr_in sa_in; // Server addresses
96  struct sockaddr sa;
97  } SockAddressUnion;
98 
99  int rsd_; // Read Socket Descriptor.
100  int wsd_; // Write Socket Descriptor.
101  SockAddressUnion ra_; // Read socket address
102  SockAddressUnion wa_; // Write socket address
103  pthread_mutex_t mutex_; // Mutex for data structure access.
104  std::vector<FilterType> filters_; // Vector to hold filters.
105  log4cpp::Category &log_;
106 
107  Session &operator=(const Session &);
108  Session(const Session &);
109 
110 };
111 }}} // namespace carma::canbus::canoverip
112 #endif
bool matchesFilter(const carma::canbus::Message &msg)
Check to see if a CAN Message Id matches a filter for this Session.
void clearFilters()
Clear existing filters.
void addFilter(FilterType filter)
Add a filter to this Session.
Class to encapsulate a CAN message.
Definition: Message.h:21
Class to encompass a CAN over IP session.
Definition: Session.h:38
int getReadSock()
Get read sock.
Definition: Session.h:81
Session(int readSock, int writeSock)
Constructor.
int getWriteSock()
Get write sock.
Definition: Session.h:87