aboutsummaryrefslogtreecommitdiffstats
path: root/alljoyn_core/inc/alljoyn/AutoPinger.h
blob: 402708bdc566e26b5ace9f2a2da2f195e52a8571 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
 * @file
 *
 * AutoPinger
 */

/******************************************************************************
 * Copyright AllSeen Alliance. All rights reserved.
 *
 *    Permission to use, copy, modify, and/or distribute this software for any
 *    purpose with or without fee is hereby granted, provided that the above
 *    copyright notice and this permission notice appear in all copies.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************************/

#ifndef _ALLJOYN_AUTOPINGER_H_
#define _ALLJOYN_AUTOPINGER_H_

#ifndef __cplusplus
#error Only include AutoPinger.h in C++ code.
#endif

#include <map>
#include <qcc/String.h>
#include <qcc/Debug.h>
#include <alljoyn/Status.h>
#include <alljoyn/PingListener.h>

namespace ajn {
/// @cond ALLJOYN_DEV
/** @internal Forward references */
class AutoPingerInternal;
class BusAttachment;
/// @endcond

/**
 * AutoPinger class
 */
class AutoPinger {
  public:

    /**
     * Create instance of autopinger
     *
     * @param busAttachment reference to the BusAttachment associated with this
     *                      autopinger.
     *
     */
    AutoPinger(BusAttachment& busAttachment);

    /**
     * Destructor.
     *
     * Do not destroy an AutoPinger instance from within a PingListener
     * callback. This will cause a deadlock.
     */
    ~AutoPinger();

    /**
     * Pause all ping actions
     */
    void Pause();

    /**
     * Resume ping actions
     */
    void Resume();

    /**
     * Define new ping group
     *
     * @param  group Ping group name
     * @param  listener Listener called when a change was detected in the reachability of a destination
     * @param  pingInterval Ping interval in seconds
     */
    void AddPingGroup(const qcc::String& group, PingListener& listener, uint32_t pingInterval = 5);

    /**
     * Remove complete ping group, including all destinations
     *
     * Do not invoke this method from within a PingListener callback. This will
     * cause a deadlock.
     *
     * @param  group Ping group name
     */
    void RemovePingGroup(const qcc::String& group);

    /**
     * Set ping interval of the specified group
     *
     * @param  group Ping group name
     * @param  pingInterval Ping interval in seconds
     * @return
     *  - #ER_OK: Interval updated
     *  - #ER_BUS_PING_GROUP_NOT_FOUND: group did not exist
     */
    QStatus SetPingInterval(const qcc::String& group, uint32_t pingInterval);

    /**
     * Add a destination to the specified ping group
     * Destinations are refcounted and must be removed N times if they were added N times
     *
     * @param  group Ping group name
     * @param  destination Destination name to be pinged
     * @return
     *  - #ER_OK: destination added
     *  - #ER_BUS_PING_GROUP_NOT_FOUND: group did not exist
     */
    QStatus AddDestination(const qcc::String& group, const qcc::String& destination);

    /**
     * Remove a destination from the specified ping group
     * This will lower the refcount by one and only remove the destination when the refcount reaches zero
     *
     * @param  group Ping group name
     * @param  destination Destination name to be removed
     * @param  removeAll Rather than decrementing the refcount by one, set refcount to zero and remove
     * @return
     *  - #ER_OK: destination removed or was not present
     *  - #ER_BUS_PING_GROUP_NOT_FOUND: group did not exist
     */
    QStatus RemoveDestination(const qcc::String& group, const qcc::String& destination, bool removeAll = false);

  private:
    AutoPinger(const AutoPinger&);
    void operator=(const AutoPinger&);

    AutoPingerInternal* internal;

};

}
#endif /* AUTOPINGER_H_ */