summaryrefslogtreecommitdiff
path: root/cpp/src/IceBT/Engine.h
blob: ec6b29959fabd351eeabec23c167df8bcff911c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// **********************************************************************
//
// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_BT_ENGINE_H
#define ICE_BT_ENGINE_H

#include <IceBT/EngineF.h>
#include <IceBT/Config.h>
#include <IceBT/Plugin.h>
#include <IceBT/Types.h>
#include <Ice/CommunicatorF.h>

namespace IceBT
{

//
// Notifies the transport about a new incoming connection.
//
class ProfileCallback
#ifndef ICE_CPP11_MAPPING
    : public virtual IceUtil::Shared
#endif
{
public:

    virtual void newConnection(int) = 0;
};
ICE_DEFINE_PTR(ProfileCallbackPtr, ProfileCallback);

//
// Represents an outgoing (client) connection. The transport must keep a reference to this object
// and call close() when no longer needed.
//
class Connection : public IceUtil::Shared
{
public:

    virtual void close() = 0;

};
typedef IceUtil::Handle<Connection> ConnectionPtr;

//
// Callback API for an outgoing connection attempt.
//
class ConnectCallback
#ifndef ICE_CPP11_MAPPING
    : public virtual IceUtil::Shared
#endif
{
public:

    virtual void completed(int, const ConnectionPtr&) = 0;
    virtual void failed(const Ice::LocalException&) = 0;
};
ICE_DEFINE_PTR(ConnectCallbackPtr, ConnectCallback);

//
// Engine encapsulates all Bluetooth activities.
//
class Engine : public IceUtil::Shared
{
public:

    Engine(const Ice::CommunicatorPtr&);

    Ice::CommunicatorPtr communicator() const;

    void initialize();
    bool initialized() const;

    std::string getDefaultAdapterAddress() const;
    bool adapterExists(const std::string&) const;

    bool deviceExists(const std::string&) const;

    std::string registerProfile(const std::string&, const std::string&, int, const ProfileCallbackPtr&);
    void unregisterProfile(const std::string&);

    void connect(const std::string&, const std::string&, const ConnectCallbackPtr&);

#ifdef ICE_CPP11_MAPPING
    void startDiscovery(const std::string&, std::function<void(const std::string&, const PropertyMap&)>);
#else
    void startDiscovery(const std::string&, const DiscoveryCallbackPtr&);
#endif
    void stopDiscovery(const std::string&);

    DeviceMap getDevices() const;

    void destroy();

private:

    const Ice::CommunicatorPtr _communicator;
    bool _initialized;
    IceUtil::Monitor<IceUtil::Mutex> _lock;
    BluetoothServicePtr _service;
};

}

#endif