summaryrefslogtreecommitdiff
path: root/cpp/include/IceBT/Plugin.h
blob: 5cf5030edf0501985b823994c9729f7d135346eb (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
// **********************************************************************
//
// Copyright (c) 2003-present 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_PLUGIN_H
#define ICE_BT_PLUGIN_H

#include <Ice/Plugin.h>

#ifndef ICEBT_API
#   if defined(ICE_STATIC_LIBS)
#       define ICEBT_API /**/
#   elif defined(ICEBT_API_EXPORTS)
#       define ICEBT_API ICE_DECLSPEC_EXPORT
#   else
#       define ICEBT_API ICE_DECLSPEC_IMPORT
#   endif
#endif

namespace IceBT
{

/** A name-value map. */
typedef std::map<std::string, std::string> PropertyMap;

/** A collection of properties for each device. */
typedef std::map<std::string, PropertyMap> DeviceMap;

#ifndef ICE_CPP11_MAPPING
/**
 * An application can receive discovery notifications by implementing the DiscoveryCallback interface.
 * \headerfile IceBT/IceBT.h
 */
class ICEBT_API DiscoveryCallback : public IceUtil::Shared
{
public:

    /**
     * Called for each discovered device. The same device may be reported multiple times.
     * @param addr The discovered device's Bluetooth address.
     * @param props A map of device properties supplied by the system's Bluetooth stack.
     */
    virtual void discovered(const std::string& addr, const PropertyMap& props) = 0;
};
typedef IceUtil::Handle<DiscoveryCallback> DiscoveryCallbackPtr;
#endif

/**
 * Represents the IceBT plug-in object.
 * \headerfile IceBT/IceBT.h
 */
class ICEBT_API Plugin : public Ice::Plugin
{
public:

    /**
     * Start Bluetooth device discovery on the adapter with the specified address.
     * The given callback will be invoked for each discovered device. The same
     * device may be reported more than once. Discovery remains active until
     * explicitly stopped by a call to stopDiscovery(), or via other administrative means.
     * @param address The address associated with the Bluetooth adapter.
     * @param cb The callback to invoke when a device is discovered.
     */
#ifdef ICE_CPP11_MAPPING
    virtual void startDiscovery(const std::string& address,
                                std::function<void(const std::string& addr, const PropertyMap& props)> cb) = 0;
#else
    virtual void startDiscovery(const std::string& address, const DiscoveryCallbackPtr& cb) = 0;
#endif

    /**
     * Stops Bluetooth device discovery on the adapter with the specified address.
     * All discovery callbacks are removed when discovery stops.
     * @param address The address associated with the Bluetooth adapter.
     */
    virtual void stopDiscovery(const std::string& address) = 0;

    /**
     * Retrieve a snapshot of all known remote devices. The plug-in obtains a snapshot of the remote devices at
     * startup and then dynamically updates its map as the host adds and removes devices.
     * @return A map containing properties for each known device.
     */
    virtual DeviceMap getDevices() const = 0;
};
ICE_DEFINE_PTR(PluginPtr, Plugin);

}

#endif