2 * Copyright (C) 2005-2013 Team XBMC
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "threads/Thread.h"
24 #include "utils/log.h"
28 #define MSG_INTERNAL_BUFFER_SIZE 32
37 friend class Protocol;
45 uint8_t buffer[MSG_INTERNAL_BUFFER_SIZE];
47 Message *replyMessage;
52 bool Reply(int sig, void *data = NULL, int size = 0);
55 Message() {isSync = false; data = NULL; event = NULL; replyMessage = NULL;};
61 Protocol(std::string name, CEvent* inEvent, CEvent *outEvent)
62 : portName(name), inDefered(false), outDefered(false) {containerInEvent = inEvent; containerOutEvent = outEvent;};
64 Message *GetMessage();
65 void ReturnMessage(Message *msg);
66 bool SendOutMessage(int signal, void *data = NULL, int size = 0, Message *outMsg = NULL);
67 bool SendInMessage(int signal, void *data = NULL, int size = 0, Message *outMsg = NULL);
68 bool SendOutMessageSync(int signal, Message **retMsg, int timeout, void *data = NULL, int size = 0);
69 bool ReceiveOutMessage(Message **msg);
70 bool ReceiveInMessage(Message **msg);
72 void PurgeIn(int signal);
73 void PurgeOut(int signal);
74 void DeferIn(bool value) {inDefered = value;};
75 void DeferOut(bool value) {outDefered = value;};
76 void Lock() {criticalSection.lock();};
77 void Unlock() {criticalSection.unlock();};
81 CEvent *containerInEvent, *containerOutEvent;
82 CCriticalSection criticalSection;
83 std::queue<Message*> outMessages;
84 std::queue<Message*> inMessages;
85 std::queue<Message*> freeMessageQueue;
86 bool inDefered, outDefered;