2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief AMB plug-in communication I/F
13 #ifndef _ICO_VIC_AMBPICOMM_H_
14 #define _ICO_VIC_AMBPICOMM_H_
18 #include "ico-util/ico_uws.h"
20 const int MsgQueueMaxMsgSize = 128;
22 struct KeyEventOptMsg_t
24 char KeyEventType[64];
25 struct timeval recordtime;
36 char KeyEventType[64];
37 struct timeval recordtime;
45 class AmbpiCommRecvQueue
49 AmbpiCommRecvQueue(int queuesize);
50 ~AmbpiCommRecvQueue();
51 bool push(char *data, int datasize);
52 bool front(char *buf) const;
57 static const int maxdatasize = sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize;
63 char (*mdata)[maxdatasize];
71 AmbpiCommIF(const char* uri, const char* protocolName);
73 bool start(const char* uri, const char* protocolName);
74 bool send(const char *msg, const int size);
75 bool recv(char *msg, bool fbolcking);
77 static void *loop(void *arg);
78 bool isContextMatch(const ico_uws_context* context) const;
79 // bool threadCondWait();
80 void event_cb(const ico_uws_evt_e event, const void *id,
81 const ico_uws_detail *detail, void *user_data);
88 bool init(const char* uri, const char* protocolName);
91 ico_uws_context* m_context;
93 pthread_mutex_t m_mutex;
94 pthread_cond_t m_cond;
95 char m_sendbuf[AmbpiCommRecvQueue::maxdatasize];
96 AmbpiCommRecvQueue m_queue;
97 std::string m_uri; // URI
98 std::string m_pNm; // protocol name
99 ico_uws_error_e m_ercode;
104 * @brief context compare
106 * @return true:agree / false:not agree
108 inline bool AmbpiCommIF::isContextMatch(const ico_uws_context* context) const
110 if (context == m_context) {
118 * @return true:success / false:fail
120 inline bool AmbpiCommIF::threadCondWait()
122 if (0 != pthread_cond_wait(&m_cond, &m_mutex)) {
129 * @brief reset error code
131 inline void AmbpiCommIF::reset_ercode()
133 m_ercode = ICO_UWS_ERR_UNKNOWN;
136 #endif //#ifndef _ICO_VIC_AMBPICOMM_H_