Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / utils / ActorProtocol.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21 #pragma once
22
23 #include "threads/Thread.h"
24 #include "utils/log.h"
25 #include <queue>
26 #include "memory.h"
27
28 #define MSG_INTERNAL_BUFFER_SIZE 32
29
30 namespace Actor
31 {
32
33 class Protocol;
34
35 class Message
36 {
37   friend class Protocol;
38 public:
39   int signal;
40   bool isSync;
41   bool isSyncFini;
42   bool isOut;
43   bool isSyncTimeout;
44   int payloadSize;
45   uint8_t buffer[MSG_INTERNAL_BUFFER_SIZE];
46   uint8_t *data;
47   Message *replyMessage;
48   Protocol *origin;
49   CEvent *event;
50
51   void Release();
52   bool Reply(int sig, void *data = NULL, int size = 0);
53
54 private:
55   Message() {isSync = false; data = NULL; event = NULL; replyMessage = NULL;};
56 };
57
58 class Protocol
59 {
60 public:
61   Protocol(std::string name, CEvent* inEvent, CEvent *outEvent)
62     : portName(name), inDefered(false), outDefered(false) {containerInEvent = inEvent; containerOutEvent = outEvent;};
63   virtual ~Protocol();
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);
71   void Purge();
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();};
78   std::string portName;
79
80 protected:
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;
87 };
88
89 }