ambd: remove redundant code in core
[profile/ivi/automotive-message-broker.git] / plugins / common / cansocketadapter.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 CANSOCKETADAPTER_H
20 #define CANSOCKETADAPTER_H
21
22 /**
23  *  \addtogroup libcanbus
24  *  @{
25  */
26
27 #include "canadapter.h"
28
29 class CANObserver;
30 class CANSocket;
31 class CANSocketReader;
32
33 /**
34 * \brief Socket CAN device implementation based on <a href="http://developer.berlios.de/projects/socketcan">BerliOS Socket CAN</a> API.
35 *
36 * @class CANSocketAdapter
37 */
38 class CANSocketAdapter : public CANAdapter
39 {
40 public:
41     /**
42     * @param observer @link CANObserver Observer @endlink that will receives CAN bus frames
43     */
44     CANSocketAdapter(CANObserver& observer);
45     virtual ~CANSocketAdapter();
46
47     /**
48     * Creates connection the specified network interface and starts listening on it.
49     * @fn start
50     * @param ifName Name of the CAN bus network interface
51     * @return True if no error occurs.
52     */
53     virtual bool start(const char* ifName);
54     /**
55     * Closes socket connection and exits listening thread.
56     * @fn stop
57     */
58     virtual void stop();
59     /**
60     * Sends CAN frame over the socket CAN interface
61     * @fn sendFrame
62     * @param frame CAN frame to be sent
63     * @return True if frame was sent
64     */
65     virtual bool sendFrame(const can_frame& frame);
66     /**
67     * Registers CAN ID of a cyclic message for receiving
68     * @fn registerCyclicMessageForReceive
69     * @param canId CAN ID of the message.
70     * @param minCycleTime Minimal interval between messages in seconds. Set to 0 if not used.
71     * @param maxCycleTime Maximum interval between messages for timeout detection in seconds. Set to 0 if no timeout detection is necessary.
72     * @return True if registration succeeds.
73     */
74     virtual bool registerCyclicMessageForReceive(int canId, double minCycleTime, double maxCycleTime);
75     /**
76     * Unregisters CAN ID for receiving
77     * @fn unregisterMessageForReceive
78     * @param canId CAN ID of the message.
79     * @return True if de-registration succeeds.
80     */
81     virtual bool unregisterMessageForReceive(int canId);
82
83 protected:
84     /**
85     * Socket initialization and starts reading thread
86     * @fn init
87     * @protected
88     */
89     virtual void init();
90
91 private:
92     /**
93     * @link CANSocket CAN Socket wrapper @endlink instance reference
94     * @property mSocket
95     * @protected
96     */
97     CANSocket* mSocket;
98     /**
99     * @link CANSocketReader CANSocket reader @endlink instance reference
100     * @property mReader
101     * @protected
102     */
103     CANSocketReader* mReader;
104 };
105
106 #endif // CANSOCKETADAPTER_H
107
108 /** @} */