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 #include "protocolplugininstance.h"
24 
25 #include <licq/plugin/protocolpluginfactory.h>
26 #include <licq/plugin/protocolplugininterface.h>
27 
28 using namespace LicqDaemon;
29 
nullDeleter(void *)30 static void nullDeleter(void*) { /* Empty */ }
31 
ProtocolPluginInstance(int id,const Licq::UserId & ownerId,ProtocolPlugin::Ptr plugin,PluginThread::Ptr thread)32 ProtocolPluginInstance::ProtocolPluginInstance(
33     int id, const Licq::UserId& ownerId, ProtocolPlugin::Ptr plugin,
34     PluginThread::Ptr thread)
35   : PluginInstance(id, thread),
36     myOwnerId(ownerId),
37     myPlugin(plugin)
38 {
39   // Empty
40 }
41 
~ProtocolPluginInstance()42 ProtocolPluginInstance::~ProtocolPluginInstance()
43 {
44   if (myInterface)
45     myPlugin->protocolFactory()->destroyPlugin(myInterface.get());
46 }
47 
run(void (* startCallback)(const PluginInstance &),void (* exitCallback)(const PluginInstance &))48 void ProtocolPluginInstance::run(void (*startCallback)(const PluginInstance&),
49                                  void (*exitCallback)(const PluginInstance&))
50 {
51   PluginInstance::run(startCallback, exitCallback);
52 }
53 
plugin() const54 boost::shared_ptr<Licq::ProtocolPlugin> ProtocolPluginInstance::plugin() const
55 {
56   return myPlugin;
57 }
58 
pushSignal(boost::shared_ptr<const Licq::ProtocolSignal> signal)59 void ProtocolPluginInstance::pushSignal(
60     boost::shared_ptr<const Licq::ProtocolSignal> signal)
61 {
62   if (isRunning())
63     myInterface->pushSignal(signal);
64 }
65 
createInterface()66 void ProtocolPluginInstance::createInterface()
67 {
68   assert(!myInterface);
69   myInterface.reset(myPlugin->protocolFactory()->createPlugin(), &nullDeleter);
70 }
71 
interface()72 boost::shared_ptr<Licq::PluginInterface> ProtocolPluginInstance::interface()
73 {
74   return myInterface;
75 }
76 
77 boost::shared_ptr<const Licq::PluginInterface>
interface() const78 ProtocolPluginInstance::interface() const
79 {
80   return myInterface;
81 }
82