Updated comments and fixed tabbing
[profile/ivi/automotive-message-broker.git] / plugins / common / canadapter.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3 Copyright (C) 2015 Cogent Embedded Inc.
4 Copyright (C) 2015 Renesas Electronics Corporation
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21 #ifndef CANADAPTER_H
22 #define CANADAPTER_H
23
24 /**
25  *  \addtogroup libcanbus
26  *  @{
27  */
28
29 #include <linux/can.h>
30
31 class CANObserver;
32
33 /**
34 * \brief Abstracts CAN hardware object representation.
35 * Has protected constructor.
36 * Instance of the object has to be done via CANAdapter#createCANAdapter method.
37 *
38 *       @code CANAdapter* pAdapter = CANAdapter::createCANAdapter(this); @endcode
39 *
40 * @class CANAdapter
41 */
42 class CANAdapter
43 {
44 public:
45     virtual ~CANAdapter();/*LCOV_EXCL_LINE*/
46     /**
47     * Creates and initializes CANAdapter instance
48     * @fn createCANAdapter
49     * @param observer @link CANObserver Observer @endlink that will receives CAN bus frames
50     * @return Pointer to CANAdapter instance
51     * @static
52     */
53     static CANAdapter* createCANAdapter(CANObserver& observer);
54     /**
55     * Starts listening to CAN bus on the specified interface
56     * @fn start
57     * @param name Name of the CAN bus interface
58     * @return True if no error occurs.
59     */
60     virtual bool start(const char* name) = 0;
61     /**
62     * Stops listening to CAN bus
63     * @fn stop
64     */
65     virtual void stop() = 0;
66     /**
67     * Sends CAN frame over the bus
68     * @fn sendFrame
69     * @param frame CAN frame to be sent
70     * @return True if frame was sent
71     */
72     virtual bool sendFrame(const can_frame& frame) = 0;
73     /**
74      * Registers CAN ID of a cyclic message for receiving
75      * @fn registerCyclicMessageForReceive
76      * @param canId CAN ID of the message.
77      * @param minCycleTime Minimal interval between messages in seconds. Set to 0 if not used.
78      * @param maxCycleTime Maximum interval between messages for timeout detection in seconds. Set to 0 if no timeout detection is necessary.
79      * @return True if registration succeeds.
80      */
81     virtual bool registerCyclicMessageForReceive(int canId, double minCycleTime, double maxCycleTime) = 0;
82     /**
83      * Un-registers CAN ID of a message used of receiving. Valid for cyclic and sporadic messages.
84      * @fn unregisterMessageForReceive
85      * @param canId CAN ID of the message.
86      * @return True if de-registration succeeds.
87      */
88     virtual bool unregisterMessageForReceive(int canId) = 0;
89
90 protected:
91     /**
92     * @param observer @link CANObserver Observer @endlink that will receives CAN bus frames
93     */
94     CANAdapter(CANObserver& observer);
95
96 protected:
97     /**
98     * #CANObserver instance reference
99     * @property mObserver
100     * @protected
101     */
102     CANObserver& mObserver;
103
104 };
105
106 #endif // CANADAPTER_H
107
108 /** @} */