Updated comments and fixed tabbing
[profile/ivi/automotive-message-broker.git] / plugins / common / cansocket.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 CANSOCKET_H
20 #define CANSOCKET_H
21
22 /**
23  *  \addtogroup libcanbus
24  *  @{
25  */
26
27 #include <linux/can.h>
28
29 #include "canbus.h"
30
31 /**
32 * \brief Wrapper around different implementations of SocketCAN.
33 * @class CANSocket
34 */
35 class CANSocket
36 {
37 public:
38
39     /**
40     * CAN bus socket error.
41     * @enum CANSocketReadSuccess
42     * @public
43     */
44     enum CANSocketReadSuccess {
45         READING_FAILED = -1,
46         READING_TIMED_OUT,
47         READING_SUCCEEDED,
48     };
49
50 public:
51     CANSocket();
52     virtual ~CANSocket();
53
54     /**
55     * Opens and initializes CAN socket
56     * @fn start
57     * @param ifName Name of the CAN bus network interface.
58     * @return True if no error occurs.
59     */
60     virtual bool start(const char* ifName) = 0;
61     /**
62     * Closes the socket
63     * @fn stop
64     */
65     virtual void stop();
66     /**
67     * Writes CAN frame using the socket
68     * @fn write
69     * @param message CAN frame with additional information
70     * @param bytesWritten Number of written bytes.
71     * @return True if no error occurs.
72     */
73     virtual bool write(const struct CANFrameInfo &message);
74     /**
75     * Try to read CAN frame
76     * @fn read
77     * @param message Buffer for CAN frame with additional information
78     * @param timeout Timeout for reading in [ms].
79     * @return Reading operation status code.
80     */
81     virtual CANSocket::CANSocketReadSuccess read(struct CANFrameInfo& message, unsigned int timeout = 1000);
82     /**
83      * Registers CAN ID of a cyclic message for receiving
84      * @fn registerCyclicMessageForReceive
85      * @param canId CAN ID of the message.
86      * @param minCycleTime Minimal interval between messages in seconds. Set to 0 if not used.
87      * @param maxCycleTime Maximum interval between messages for timeout detection in seconds. Set to 0 if no timeout detection is necessary.
88      * @return True if registration succeeds.
89      */
90     virtual bool registerCyclicMessageForReceive(int canId, double minCycleTime, double maxCycleTime);
91     /**
92      * Un-registers CAN ID of a message used of receiving. Valid for cyclic and sporadic messages.
93      * @fn unregisterMessageForReceive
94      * @param canId CAN ID of the message.
95      * @return True if de-registration succeeds.
96      */
97     virtual bool unregisterMessageForReceive(int canId);
98 };
99
100 #endif // CANSOCKET_H
101
102 /** @} */