1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #include <IceBT/PluginI.h>
6 #include <IceBT/EndpointI.h>
7 #include <IceBT/Engine.h>
8 #include <IceBT/Instance.h>
9 #include <IceBT/Util.h>
10 
11 #include <Ice/LocalException.h>
12 #include <Ice/ProtocolPluginFacade.h>
13 #include <Ice/ProtocolInstance.h>
14 
15 using namespace std;
16 using namespace Ice;
17 using namespace IceBT;
18 
19 void
ice_print(ostream & out) const20 IceBT::BluetoothException::ice_print(ostream& out) const
21 {
22     Exception::ice_print(out);
23     out << ":\nbluetooth exception: `" << reason << "'";
24 }
25 
26 //
27 // Plug-in factory function.
28 //
29 extern "C"
30 {
31 
32 ICEBT_API Ice::Plugin*
createIceBT(const CommunicatorPtr & communicator,const string &,const StringSeq &)33 createIceBT(const CommunicatorPtr& communicator, const string& /*name*/, const StringSeq& /*args*/)
34 {
35     return new PluginI(communicator);
36 }
37 
38 }
39 
40 namespace Ice
41 {
42 
43 ICEBT_API void
registerIceBT(bool loadOnInitialize)44 registerIceBT(bool loadOnInitialize)
45 {
46     Ice::registerPluginFactory("IceBT", createIceBT, loadOnInitialize);
47 }
48 
49 }
50 
51 //
52 // Plugin implementation.
53 //
PluginI(const Ice::CommunicatorPtr & com)54 IceBT::PluginI::PluginI(const Ice::CommunicatorPtr& com) :
55     _engine(new Engine(com))
56 {
57     IceInternal::ProtocolPluginFacadePtr f = IceInternal::getProtocolPluginFacade(com);
58 
59     //
60     // Register the endpoint factory. We have to do this now, rather
61     // than in initialize, because the communicator may need to
62     // interpret proxies before the plug-in is fully initialized.
63     //
64     InstancePtr bt = new Instance(_engine, BTEndpointType, "bt");
65     f->addEndpointFactory(new EndpointFactoryI(bt));
66 
67     InstancePtr bts = new Instance(_engine, BTSEndpointType, "bts");
68     f->addEndpointFactory(new IceInternal::UnderlyingEndpointFactory(bts, SSLEndpointType, BTEndpointType));
69 }
70 
71 void
initialize()72 IceBT::PluginI::initialize()
73 {
74     _engine->initialize();
75 }
76 
77 void
destroy()78 IceBT::PluginI::destroy()
79 {
80     _engine->destroy();
81 }
82 
83 void
84 #ifdef ICE_CPP11_MAPPING
startDiscovery(const string & address,function<void (const string &,const PropertyMap &)> cb)85 IceBT::PluginI::startDiscovery(const string& address, function<void(const string&, const PropertyMap&)> cb)
86 #else
87 IceBT::PluginI::startDiscovery(const string& address, const DiscoveryCallbackPtr& cb)
88 #endif
89 {
90     _engine->startDiscovery(address, cb);
91 }
92 
93 void
stopDiscovery(const string & address)94 IceBT::PluginI::stopDiscovery(const string& address)
95 {
96     _engine->stopDiscovery(address);
97 }
98 
99 IceBT::DeviceMap
getDevices() const100 IceBT::PluginI::getDevices() const
101 {
102     return _engine->getDevices();
103 }
104