| 1 |
/* |
| 2 |
* This program is free software; you can redistribute it and/or modify |
| 3 |
* it under the terms of the GNU General Public License as published by |
| 4 |
* the Free Software Foundation; either version 2 of the License, or |
| 5 |
* (at your option) any later version. |
| 6 |
* |
| 7 |
* This program is distributed in the hope that it will be useful, |
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
* GNU Library General Public License for more details. |
| 11 |
* |
| 12 |
* You should have received a copy of the GNU General Public License |
| 13 |
* along with this program; if not, write to the Free Software |
| 14 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 15 |
* |
| 16 |
* PluginAdaptor.cpp |
| 17 |
* Provides a wrapper for the DeviceManager and SelectServer objects so that |
| 18 |
* the plugins can register devices and file handles for events |
| 19 |
* Copyright (C) 2005 Simon Newton |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <string> |
| 23 |
#include "ola/Callback.h" |
| 24 |
#include "olad/PluginAdaptor.h" |
| 25 |
#include "olad/PortBroker.h" |
| 26 |
#include "olad/Preferences.h" |
| 27 |
#include "olad/plugin_api/DeviceManager.h" |
| 28 |
|
| 29 |
namespace ola { |
| 30 |
|
| 31 |
using ola::io::SelectServerInterface; |
| 32 |
using ola::thread::timeout_id; |
| 33 |
using std::string; |
| 34 |
|
| 35 |
PluginAdaptor::PluginAdaptor(DeviceManager *device_manager, |
| 36 |
SelectServerInterface *select_server, |
| 37 |
ExportMap *export_map, |
| 38 |
PreferencesFactory *preferences_factory, |
| 39 |
PortBrokerInterface *port_broker, |
| 40 |
const std::string *instance_name): |
| 41 |
m_device_manager(device_manager), |
| 42 |
m_ss(select_server), |
| 43 |
m_export_map(export_map), |
| 44 |
m_preferences_factory(preferences_factory), |
| 45 |
m_port_broker(port_broker), |
| 46 |
m_instance_name(instance_name) { |
| 47 |
} |
| 48 |
|
| 49 |
bool PluginAdaptor::AddReadDescriptor( |
| 50 |
ola::io::ReadFileDescriptor *descriptor) { |
| 51 |
return m_ss->AddReadDescriptor(descriptor); |
| 52 |
} |
| 53 |
|
| 54 |
bool PluginAdaptor::AddReadDescriptor( |
| 55 |
ola::io::ConnectedDescriptor *descriptor, |
| 56 |
bool delete_on_close) { |
| 57 |
return m_ss->AddReadDescriptor(descriptor, delete_on_close); |
| 58 |
} |
| 59 |
|
| 60 |
void PluginAdaptor::RemoveReadDescriptor( |
| 61 |
ola::io::ReadFileDescriptor *descriptor) { |
| 62 |
m_ss->RemoveReadDescriptor(descriptor); |
| 63 |
} |
| 64 |
|
| 65 |
void PluginAdaptor::RemoveReadDescriptor( |
| 66 |
ola::io::ConnectedDescriptor *descriptor) { |
| 67 |
m_ss->RemoveReadDescriptor(descriptor); |
| 68 |
} |
| 69 |
|
| 70 |
bool PluginAdaptor::AddWriteDescriptor( |
| 71 |
ola::io::WriteFileDescriptor *descriptor) { |
| 72 |
return m_ss->AddWriteDescriptor(descriptor); |
| 73 |
} |
| 74 |
|
| 75 |
void PluginAdaptor::RemoveWriteDescriptor( |
| 76 |
ola::io::WriteFileDescriptor *descriptor) { |
| 77 |
m_ss->RemoveWriteDescriptor(descriptor); |
| 78 |
} |
| 79 |
|
| 80 |
timeout_id PluginAdaptor::RegisterRepeatingTimeout( |
| 81 |
unsigned int ms, |
| 82 |
Callback0<bool> *closure) { |
| 83 |
return m_ss->RegisterRepeatingTimeout(ms, closure); |
| 84 |
} |
| 85 |
|
| 86 |
timeout_id PluginAdaptor::RegisterRepeatingTimeout( |
| 87 |
const TimeInterval &interval, |
| 88 |
Callback0<bool> *closure) { |
| 89 |
return m_ss->RegisterRepeatingTimeout(interval, closure); |
| 90 |
} |
| 91 |
|
| 92 |
timeout_id PluginAdaptor::RegisterSingleTimeout( |
| 93 |
unsigned int ms, |
| 94 |
SingleUseCallback0<void> *closure) { |
| 95 |
return m_ss->RegisterSingleTimeout(ms, closure); |
| 96 |
} |
| 97 |
|
| 98 |
timeout_id PluginAdaptor::RegisterSingleTimeout( |
| 99 |
const TimeInterval &interval, |
| 100 |
SingleUseCallback0<void> *closure) { |
| 101 |
return m_ss->RegisterSingleTimeout(interval, closure); |
| 102 |
} |
| 103 |
|
| 104 |
void PluginAdaptor::RemoveTimeout(timeout_id id) { |
| 105 |
m_ss->RemoveTimeout(id); |
| 106 |
} |
| 107 |
|
| 108 |
void PluginAdaptor::Execute(ola::BaseCallback0<void> *closure) { |
| 109 |
m_ss->Execute(closure); |
| 110 |
} |
| 111 |
|
| 112 |
void PluginAdaptor::DrainCallbacks() { |
| 113 |
m_ss->DrainCallbacks(); |
| 114 |
} |
| 115 |
|
| 116 |
bool PluginAdaptor::RegisterDevice(AbstractDevice *device) const { |
| 117 |
return m_device_manager->RegisterDevice(device); |
| 118 |
} |
| 119 |
|
| 120 |
bool PluginAdaptor::UnregisterDevice(AbstractDevice *device) const { |
| 121 |
return m_device_manager->UnregisterDevice(device); |
| 122 |
} |
| 123 |
|
| 124 |
Preferences *PluginAdaptor::NewPreference(const string &name) const { |
| 125 |
return m_preferences_factory->NewPreference(name); |
| 126 |
} |
| 127 |
|
| 128 |
const TimeStamp *PluginAdaptor::WakeUpTime() const { |
| 129 |
return m_ss->WakeUpTime(); |
| 130 |
} |
| 131 |
|
| 132 |
const std::string PluginAdaptor::InstanceName() { |
| 133 |
if (m_instance_name) { |
| 134 |
return *m_instance_name; |
| 135 |
} else { |
| 136 |
return ""; |
| 137 |
} |
| 138 |
} |
| 139 |
} // namespace ola |