1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2013 Licq Developers <licq-dev@googlegroups.com>
4  *
5  * Please refer to the COPYRIGHT file distributed with this source
6  * distribution for the names of the individual contributors.
7  *
8  * Licq is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Licq is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Licq; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22 
23 #ifndef LICQ_PROTOCOLPLUGINHELPER_H
24 #define LICQ_PROTOCOLPLUGINHELPER_H
25 
26 #include "protocolplugininterface.h"
27 #include "../macro.h"
28 
29 namespace Licq
30 {
31 
32 /**
33  * Implements part of the ProtocolPluginInterface to help make the
34  * implementation of a protocol plugin easier.
35  */
36 class ProtocolPluginHelper : public ProtocolPluginInterface
37 {
38 public:
39   // Notification that protocols can get via its pipe
40   static const char PipeShutdown = 'X';
41   static const char PipeSignal = 'S';
42 
43   /// Returns true without doing anything
44   bool init(int argc, char** argv);
45 
46   /// Writes PipeShutdown to the pipe
47   void shutdown();
48 
49   /// Queues the signal and writes PipeSignal to the pipe
50   void pushSignal(boost::shared_ptr<const ProtocolSignal> signal);
51 
52 protected:
53   ProtocolPluginHelper();
54 
55   virtual ~ProtocolPluginHelper();
56 
57   /**
58    * Get read end of pipe used to communicate with the plugin.
59    *
60    * @return A file descriptor that can be polled for new signals.
61    */
62   int getReadPipe() const;
63 
64   /**
65    * Get a signal from the signal queue
66    * Called from protocol plugin
67    *
68    * The plugin must call this function to fetch a signal after getting
69    * notified via its pipe.
70    *
71    * @return The oldest signal on the queue, or NULL if queue is empty
72    */
73   boost::shared_ptr<const ProtocolSignal> popSignal();
74 
75 private:
76   LICQ_DECLARE_PRIVATE();
77 };
78 
79 } // namespace Licq
80 
81 #endif
82