Updated comments and fixed tabbing
[profile/ivi/automotive-message-broker.git] / plugins / common / cansocketraw.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #ifndef CANSOCKETRAW_H
20 #define CANSOCKETRAW_H
21
22 /**
23  *  \addtogroup libcanbus
24  *  @{
25  */
26
27 #include <net/if.h>
28 #include <sys/poll.h>
29 #include <string>
30 #include <linux/can/raw.h>
31
32 #include "cansocket.h"
33
34 /**
35 * \brief CAN Socket wrapper.
36 * @class CANSocket
37 */
38 class CANSocketRaw : public CANSocket
39 {
40 public:
41     CANSocketRaw();
42
43     /**
44     * Opens and initializes CAN socket
45     * @fn start
46     * @param ifName Name of the CAN bus network interface.
47     * @return True if no error occurs.
48     */
49     virtual bool start(const char* ifName);
50     /**
51     * Closes socket
52     * @fn stop
53     */
54     virtual void stop();
55     /**
56     * Writes CAN frame using the socket
57     * @fn write
58     * @param message CAN frame with additional information
59     * @return True if no error occurs.
60     */
61     virtual bool write(const struct CANFrameInfo &message);
62     /**
63     * Try to read CAN frame
64     * @fn read
65     * @param message Buffer for CAN frame with additional information
66     * @param timeout Timeout for reading in [ms].
67     * @return Reading operation status code.
68     */
69     virtual CANSocket::CANSocketReadSuccess read(struct CANFrameInfo& message, unsigned int timeout = 1000);
70
71 private:
72     /**
73     * @internal
74     */
75     bool createSocket();
76     bool enableCANErrors(can_err_mask_t errorMask);
77     bool enableTimestamps();
78     bool locateInterfaceIndex(struct ifreq& ifr);
79     bool bindSocket(struct sockaddr_can &addr);
80     bool closeSocket();
81     int waitData(unsigned int timeout);
82     bool writeFrame(const struct can_frame &frame);
83     ssize_t readFrame(can_frame& frame, double &timestamp);
84
85 private:
86     /**
87     * Socket file descriptor.
88     * @property mSocket
89     * @private
90     */
91     int mSocket;
92     /**
93     * Data structure describing a polling request.
94     * @property mPoll
95     * @private
96     */
97     struct pollfd mPoll;
98 };
99
100 #endif // CANSOCKETRAW_H
101
102 /** @} */