CPPMyth
Library to interoperate with MythTV server
mytheventhandler.h
1 /*
2  * Copyright (C) 2014 Jean-Luc Barriere
3  *
4  * This Program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This Program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #ifndef MYTHEVENTHANDLER_H
23 #define MYTHEVENTHANDLER_H
24 
25 #include "mythtypes.h"
26 
27 #include <string>
28 
29 #define EVENTHANDLER_CONNECTED "CONNECTED"
30 #define EVENTHANDLER_DISCONNECTED "DISCONNECTED"
31 #define EVENTHANDLER_STOPPED "STOPPED"
32 #define EVENTHANDLER_NOTCONNECTED "NOTCONNECTED"
33 #define EVENTHANDLER_TIMEOUT 1 // 1 sec
34 
35 namespace Myth
36 {
37 
39  {
40  public:
41  virtual ~EventSubscriber() {};
42  virtual void HandleBackendMessage(EventMessagePtr msg) = 0;
43  };
44 
46  {
47  public:
48  EventHandler(const std::string& server, unsigned port);
49 
50  bool Start() { return m_imp->Start(); }
51  void Stop() { m_imp->Stop(); }
52  void Reset() { m_imp->Reset(); }
53  std::string GetServer() const { return m_imp->GetServer(); }
54  unsigned GetPort() const { return m_imp->GetPort(); }
55  bool IsRunning() { return m_imp->IsRunning(); }
56  bool IsConnected() { return m_imp->IsConnected(); }
57 
58  unsigned CreateSubscription(EventSubscriber *sub) { return m_imp->CreateSubscription(sub); }
59  bool SubscribeForEvent(unsigned subid, EVENT_t event) { return m_imp->SubscribeForEvent(subid, event);}
60  void RevokeSubscription(unsigned subid) { m_imp->RevokeSubscription(subid); }
61  void RevokeAllSubscriptions(EventSubscriber *sub) { m_imp->RevokeAllSubscriptions(sub); }
62 
64  {
65  friend class EventHandler;
66  public:
67  EventHandlerThread(const std::string& server, unsigned port);
68  virtual ~EventHandlerThread();
69  virtual std::string GetServer() const { return m_server; }
70  virtual unsigned GetPort() const { return m_port; }
71  virtual bool Start() = 0;
72  virtual void Stop() = 0;
73  virtual void Reset() = 0;
74  virtual bool IsRunning() = 0;
75  virtual bool IsConnected() = 0;
76  virtual unsigned CreateSubscription(EventSubscriber *sub) = 0;
77  virtual bool SubscribeForEvent(unsigned subid, EVENT_t event) = 0;
78  virtual void RevokeSubscription(unsigned subid) = 0;
79  virtual void RevokeAllSubscriptions(EventSubscriber *sub) = 0;
80 
81  protected:
82  std::string m_server;
83  unsigned m_port;
84  };
85 
86  typedef MYTH_SHARED_PTR<EventHandlerThread> EventHandlerThreadPtr;
87 
88  private:
89  EventHandlerThreadPtr m_imp;
90  };
91 
92 }
93 
94 #endif /* MYTHEVENTHANDLER_H */
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29