summaryrefslogtreecommitdiff
path: root/include/CommonAPI/DBus/DBusSelectiveEvent.hpp
blob: 65c61f94b38efec9fe34a5b808515d7232c9a9dd (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
// Copyright (C) 2013-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#if !defined (COMMONAPI_INTERNAL_COMPILATION)
#error "Only <CommonAPI/CommonAPI.hpp> can be included directly, this file may disappear or change contents."
#endif

#ifndef COMMONAPI_DBUS_DBUSSELECTIVEEVENT_HPP_
#define COMMONAPI_DBUS_DBUSSELECTIVEEVENT_HPP_

#include <CommonAPI/DBus/DBusEvent.hpp>

namespace CommonAPI {
namespace DBus {

template<typename _EventType, typename... _Arguments>
class DBusSelectiveEvent: public DBusEvent<_EventType, _Arguments...> {
public:
    typedef typename DBusEvent<_EventType, _Arguments...>::Listener Listener;
    typedef DBusEvent<_EventType, _Arguments...> DBusEventBase;

    DBusSelectiveEvent(DBusProxy &_proxy,
    				   const char *_name, const char *_signature,
    				   std::tuple<_Arguments...> _arguments)
    	: DBusEventBase(_proxy, _name, _signature, _arguments) {
    }

    DBusSelectiveEvent(DBusProxy &_proxy,
    				   const char *_name, const char *_signature,
                       const char *_path, const char *_interface,
                       std::tuple<_Arguments...> _arguments)
    	: DBusEventBase(_proxy, _name, _signature, _path, _interface, _arguments) {
    }

    virtual ~DBusSelectiveEvent() {}

protected:
    void onFirstListenerAdded(const Listener &) {
    	bool success;
		this->subscription_
			= static_cast<DBusProxy&>(this->proxy_).subscribeForSelectiveBroadcastOnConnection(
				success, this->path_, this->interface_, this->name_, this->signature_, this);
    }

    void onLastListenerRemoved(const Listener &) {
    	static_cast<DBusProxy&>(this->proxy_).unsubscribeFromSelectiveBroadcast(
                        this->name_, this->subscription_, this);
    }
};

} // namespace DBus
} // namespace CommonAPI

#endif // COMMONAPI_DBUS_DBUSSELECTIVEEVENT_HPP_