Skip to content

Commit

Permalink
CommonAPI-D-Bus 3.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed Jun 19, 2017
1 parent 4410394 commit 5f694be
Show file tree
Hide file tree
Showing 26 changed files with 583 additions and 409 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Changes
=======
v3.1.12
- Support DBus type DBUS_TYPE_UNIX_FD as deployment for ints
- DBus deployment: IsObjectPath for all string locations

v3.1.11.2
- Fixed availability problems when deleting and recreating proxies multiple times

v3.1.11.1
- Support deployment for anonymous arrays
- Fixed concurrency problem / segfault in unregisterStub()
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PROJECT(libcommonapi-dbus)
# version of CommonAPI-DBus
SET( LIBCOMMONAPI_DBUS_MAJOR_VERSION 3 )
SET( LIBCOMMONAPI_DBUS_MINOR_VERSION 1 )
SET( LIBCOMMONAPI_DBUS_PATCH_VERSION 11 )
SET( LIBCOMMONAPI_DBUS_PATCH_VERSION 12 )

message(STATUS "Project name: ${PROJECT_NAME}")

Expand Down Expand Up @@ -123,9 +123,9 @@ message(STATUS "CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}")
FIND_PACKAGE(PkgConfig)
FIND_PACKAGE(Threads REQUIRED)
if ("${USE_INSTALLED_COMMONAPI}" STREQUAL "ON")
FIND_PACKAGE(CommonAPI 3.1.11 REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY)
FIND_PACKAGE(CommonAPI 3.1.12 REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY)
else()
FIND_PACKAGE(CommonAPI 3.1.11 REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
FIND_PACKAGE(CommonAPI 3.1.12 REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
endif()

message(STATUS "CommonAPI_CONSIDERED_CONFIGS: ${CommonAPI_CONSIDERED_CONFIGS}")
Expand Down
17 changes: 15 additions & 2 deletions include/CommonAPI/DBus/DBusConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class DBusConnection
COMMONAPI_EXPORT virtual bool addObjectManagerSignalMemberHandler(const std::string& dbusBusName,
std::weak_ptr<DBusSignalHandler> dbusSignalHandler);
COMMONAPI_EXPORT virtual bool removeObjectManagerSignalMemberHandler(const std::string& dbusBusName,
DBusSignalHandler* dbusSignalHandler);
const DBusSignalHandler* dbusSignalHandler);

COMMONAPI_EXPORT DBusSignalHandlerToken addSignalMemberHandler(const std::string& objectPath,
const std::string& interfaceName,
Expand Down Expand Up @@ -223,6 +223,16 @@ class DBusConnection
inline std::weak_ptr<DBusMainloop> getLoop() { return loop_; }
#endif

COMMONAPI_EXPORT virtual void addSignalStateHandler(
std::shared_ptr<DBusProxyConnection::DBusSignalHandler> _handler,
const uint32_t _subscription);

COMMONAPI_EXPORT virtual void removeSignalStateHandler(
std::shared_ptr<DBusProxyConnection::DBusSignalHandler> _handler,
const uint32_t _tag, bool _remove_all);

COMMONAPI_EXPORT virtual void handleSignalStates();

typedef std::tuple<std::string, std::string, std::string> DBusSignalMatchRuleTuple;
typedef std::pair<uint32_t, std::string> DBusSignalMatchRuleMapping;
typedef std::unordered_map<DBusSignalMatchRuleTuple, DBusSignalMatchRuleMapping> DBusSignalMatchRulesMap;
Expand Down Expand Up @@ -386,7 +396,7 @@ class DBusConnection
mutable std::mutex enforceTimeoutMutex_;
mutable std::condition_variable_any enforceTimeoutCondition_;

mutable std::shared_ptr<std::thread> enforcerThread_;
mutable std::thread* enforcerThread_;
mutable std::recursive_mutex enforcerThreadMutex_;
bool enforcerThreadCancelled_;
ConnectionId_t connectionId_;
Expand All @@ -409,6 +419,9 @@ class DBusConnection

std::vector<DBusMessageReplyAsyncHandler*> asyncHandlersToDelete_;
std::mutex asyncHandlersToDeleteMutex_;

std::map<std::shared_ptr<DBusProxyConnection::DBusSignalHandler>, std::set<uint32_t>> signalStateHandlers_;
std::mutex signalStateHandlersMutex_;
};

template<class Function, class... Arguments>
Expand Down
7 changes: 7 additions & 0 deletions include/CommonAPI/DBus/DBusDeployment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ struct StringDeployment : CommonAPI::Deployment<> {
bool isObjectPath_;
};

struct IntegerDeployment : CommonAPI::Deployment<> {
IntegerDeployment(bool _isUnixFD)
: isUnixFD_(_isUnixFD) {};

bool isUnixFD_;
};

template<typename... Types_>
struct StructDeployment : CommonAPI::Deployment<Types_...> {
StructDeployment(Types_*... t)
Expand Down
43 changes: 32 additions & 11 deletions include/CommonAPI/DBus/DBusEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DBusEvent: public Event_ {
const std::string &_name, const std::string &_signature,
std::tuple<Arguments_...> _arguments)
: proxy_(_proxy),
signalHandler_(std::make_shared<SignalHandler>(_proxy, this)),
signalHandler_(),
name_(_name), signature_(_signature),
getMethodName_(""),
arguments_(_arguments) {
Expand All @@ -45,7 +45,7 @@ class DBusEvent: public Event_ {
const std::string &_path, const std::string &_interface,
std::tuple<Arguments_...> _arguments)
: proxy_(_proxy),
signalHandler_(std::make_shared<SignalHandler>(_proxy, this)),
signalHandler_(),
name_(_name), signature_(_signature),
path_(_path), interface_(_interface),
getMethodName_(""),
Expand All @@ -58,7 +58,7 @@ class DBusEvent: public Event_ {
const std::string &_getMethodName,
std::tuple<Arguments_...> _arguments)
: proxy_(_proxy),
signalHandler_(std::make_shared<SignalHandler>(_proxy, this)),
signalHandler_(),
name_(_name),
signature_(_signature),
getMethodName_(_getMethodName),
Expand All @@ -69,6 +69,7 @@ class DBusEvent: public Event_ {
}

virtual ~DBusEvent() {
proxy_.removeSignalStateHandler(signalHandler_, 0, true);
proxy_.removeSignalMemberHandler(subscription_, signalHandler_.get());
}

Expand All @@ -77,8 +78,7 @@ class DBusEvent: public Event_ {
}

virtual void onSpecificError(const CommonAPI::CallStatus status, const uint32_t tag) {
(void)status;
(void)tag;
this->notifySpecificError(tag, status);
}

virtual void setSubscriptionToken(const DBusProxyConnection::DBusSignalHandlerToken token, const uint32_t tag) {
Expand All @@ -93,34 +93,43 @@ class DBusEvent: public Event_ {
public:
SignalHandler(DBusProxyBase&_proxy,
DBusEvent<Event_, Arguments_ ...>* _dbusEvent) :
proxy_(_proxy),
proxy_(_proxy.getWeakPtr()),
dbusEvent_(_dbusEvent) {

}

virtual void onSignalDBusMessage(const DBusMessage &_message) {
dbusEvent_->handleSignalDBusMessage(_message, typename make_sequence<sizeof...(Arguments_)>::type());
if(auto itsProxy = proxy_.lock()) {
dbusEvent_->handleSignalDBusMessage(_message, typename make_sequence<sizeof...(Arguments_)>::type());
}
}

virtual void onInitialValueSignalDBusMessage(const DBusMessage&_message, const uint32_t tag) {
dbusEvent_->handleSignalDBusMessage(tag, _message, typename make_sequence<sizeof...(Arguments_)>::type());
if(auto itsProxy = proxy_.lock()) {
dbusEvent_->handleSignalDBusMessage(tag, _message, typename make_sequence<sizeof...(Arguments_)>::type());
}
}

virtual void onSpecificError(const CommonAPI::CallStatus status, const uint32_t tag) {
dbusEvent_->onSpecificError(status, tag);
if(auto itsProxy = proxy_.lock()) {
dbusEvent_->onSpecificError(status, tag);
}
}

virtual void setSubscriptionToken(const DBusProxyConnection::DBusSignalHandlerToken token, const uint32_t tag) {
dbusEvent_->setSubscriptionToken(token, tag);
if(auto itsProxy = proxy_.lock()) {
dbusEvent_->setSubscriptionToken(token, tag);
}
}

private :
DBusProxyBase& proxy_;
std::weak_ptr<DBusProxyBase> proxy_;
DBusEvent<Event_, Arguments_ ...>* dbusEvent_;
};

virtual void onFirstListenerAdded(const Listener &_listener) {
(void)_listener;
init();
subscription_ = proxy_.addSignalMemberHandler(
path_, interface_, name_, signature_, getMethodName_, signalHandler_, false);
}
Expand All @@ -130,6 +139,12 @@ class DBusEvent: public Event_ {
if ("" != getMethodName_) {
proxy_.getCurrentValueForSignalListener(getMethodName_, signalHandler_, subscription);
}
proxy_.addSignalStateHandler(signalHandler_, subscription);
}

virtual void onListenerRemoved(const Listener &_listener, const Subscription _subscription) {
(void)_listener;
proxy_.removeSignalStateHandler(signalHandler_, _subscription);
}

virtual void onLastListenerRemoved(const Listener&) {
Expand Down Expand Up @@ -160,6 +175,12 @@ class DBusEvent: public Event_ {
}
}

virtual void init() {
if (!signalHandler_) {
signalHandler_ = std::make_shared<SignalHandler>(proxy_, this);
}
}

DBusProxyBase &proxy_;
std::shared_ptr<SignalHandler> signalHandler_;

Expand Down
29 changes: 18 additions & 11 deletions include/CommonAPI/DBus/DBusInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ class DBusInputStream
(void)_depl;
return readValue(_value, static_cast<EmptyDeployment *>(nullptr));
}

COMMONAPI_EXPORT InputStream &readValue(int32_t &_value, const CommonAPI::DBus::IntegerDeployment* _depl) {
(void)_depl;
return readValue(_value, static_cast<EmptyDeployment *>(nullptr));
}
COMMONAPI_EXPORT InputStream &readValue(uint32_t &_value, const CommonAPI::DBus::IntegerDeployment* _depl) {
(void)_depl;
return readValue(_value, static_cast<EmptyDeployment *>(nullptr));
}
COMMONAPI_EXPORT InputStream &readValue(Version &_value, const EmptyDeployment *_depl);

COMMONAPI_EXPORT void beginReadMapOfSerializableStructs() {
Expand All @@ -81,7 +88,7 @@ class DBusInputStream
}

COMMONAPI_EXPORT bool readMapCompleted() {
return (sizes_.top() <= (current_ - positions_.top()));
return (sizes_.back() <= (current_ - positions_.back()));
}

COMMONAPI_EXPORT void endReadMapOfSerializableStructs() {
Expand All @@ -93,8 +100,8 @@ class DBusInputStream
uint32_t itsSize(0);
_readValue(itsSize);
align(8); /* skip padding (if any) */
if (itsSize > (sizes_.top() + positions_.top() - current_)) {
COMMONAPI_ERROR(std::string(__FUNCTION__) + ": size ", itsSize, " exceeds remaining ", (sizes_.top() + positions_.top() - current_));
if (itsSize > (sizes_.back() + positions_.back() - current_)) {
COMMONAPI_ERROR(std::string(__FUNCTION__) + ": size ", itsSize, " exceeds remaining ", (sizes_.back() + positions_.back() - current_));
}
_readRaw(itsSize);
return (*this);
Expand Down Expand Up @@ -177,7 +184,7 @@ class DBusInputStream

if (_depl != nullptr && _depl->isDBus_) {
// Read signature
uint8_t signatureLength;
uint8_t signatureLength(0);
readValue(signatureLength, static_cast<EmptyDeployment *>(nullptr));
char * raw = _readRaw(signatureLength+1);
if (hasError()) {
Expand Down Expand Up @@ -233,7 +240,7 @@ class DBusInputStream
pushPosition();

_value.clear();
while (sizes_.top() > current_ - positions_.top()) {
while (sizes_.back() > current_ - positions_.back()) {
ElementType_ itsElement;
readValue(itsElement, static_cast<EmptyDeployment *>(nullptr));

Expand Down Expand Up @@ -279,7 +286,7 @@ class DBusInputStream
pushPosition();

_value.clear();
while (sizes_.top() > current_ - positions_.top()) {
while (sizes_.back() > current_ - positions_.back()) {
ElementType_ itsElement;
readValue(itsElement, (_depl ? _depl->elementDepl_ : nullptr));

Expand Down Expand Up @@ -310,7 +317,7 @@ class DBusInputStream
pushPosition();

_value.clear();
while (sizes_.top() > current_ - positions_.top()) {
while (sizes_.back() > current_ - positions_.back()) {
KeyType_ itsKey;
ValueType_ itsValue;

Expand Down Expand Up @@ -345,7 +352,7 @@ class DBusInputStream
pushPosition();

_value.clear();
while (sizes_.top() > current_ - positions_.top()) {
while (sizes_.back() > current_ - positions_.back()) {
KeyType_ itsKey;
ValueType_ itsValue;

Expand Down Expand Up @@ -514,8 +521,8 @@ class DBusInputStream
CommonAPI::DBus::DBusError* exception_;
CommonAPI::DBus::DBusMessage message_;

std::stack<uint32_t> sizes_;
std::stack<size_t> positions_;
std::vector<uint32_t> sizes_;
std::vector<size_t> positions_;
};

} // namespace DBus
Expand Down
2 changes: 2 additions & 0 deletions include/CommonAPI/DBus/DBusMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class COMMONAPI_EXPORT DBusMessage {

void setSerial(const unsigned int serial) const;

void setNoReplyExpected(const uint32_t replyNotExpected) const;

private:
::DBusMessage *message_;

Expand Down
14 changes: 9 additions & 5 deletions include/CommonAPI/DBus/DBusOutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ class DBusOutputStream: public OutputStream<DBusOutputStream> {
(void)_depl;
return _writeValue(_value);
}

COMMONAPI_EXPORT OutputStream &writeValue(const int32_t &_value, const CommonAPI::DBus::IntegerDeployment* _depl) {
(void)_depl;
return _writeValue(_value);
}
COMMONAPI_EXPORT OutputStream &writeValue(const int64_t &_value, const EmptyDeployment *_depl) {
(void)_depl;
return _writeValue(_value);
}

COMMONAPI_EXPORT OutputStream &writeValue(const uint8_t &_value, const EmptyDeployment *_depl) {
(void)_depl;
return _writeValue(_value);
Expand All @@ -101,12 +103,14 @@ class DBusOutputStream: public OutputStream<DBusOutputStream> {
(void)_depl;
return _writeValue(_value);
}

COMMONAPI_EXPORT OutputStream &writeValue(const uint32_t &_value, const CommonAPI::DBus::IntegerDeployment* _depl) {
(void)_depl;
return _writeValue(_value);
}
COMMONAPI_EXPORT OutputStream &writeValue(const uint64_t &_value, const EmptyDeployment *_depl) {
(void)_depl;
return _writeValue(_value);
}

COMMONAPI_EXPORT OutputStream &writeValue(const float &_value, const EmptyDeployment *_depl) {
(void)_depl;
return _writeValue(static_cast<double>(_value));
Expand Down Expand Up @@ -458,7 +462,7 @@ class DBusOutputStream: public OutputStream<DBusOutputStream> {
DBusError dbusError_;
DBusMessage dbusMessage_;

std::stack<size_t> positions_;
std::vector<size_t> positions_;
};

} // namespace DBus
Expand Down
2 changes: 2 additions & 0 deletions include/CommonAPI/DBus/DBusProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class COMMONAPI_EXPORT_CLASS_EXPLICIT DBusProxy
std::promise<AvailabilityStatus>
> AvailabilityTimeout_t;
mutable std::list<AvailabilityTimeout_t> timeouts_;

std::atomic<bool> everAvailable_;
};


Expand Down
10 changes: 10 additions & 0 deletions include/CommonAPI/DBus/DBusProxyBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ class COMMONAPI_EXPORT_CLASS_EXPLICIT DBusProxyBase

COMMONAPI_EXPORT virtual void init() = 0;

COMMONAPI_EXPORT void addSignalStateHandler(
std::shared_ptr<DBusProxyConnection::DBusSignalHandler> _handler,
const uint32_t _subscription);

COMMONAPI_EXPORT void removeSignalStateHandler(
std::shared_ptr<DBusProxyConnection::DBusSignalHandler> _handler,
const uint32_t _tag, bool _remove_all = false);

COMMONAPI_EXPORT std::weak_ptr<DBusProxyBase> getWeakPtr();

protected:
COMMONAPI_EXPORT DBusProxyBase(const DBusProxyBase &) = delete;

Expand Down
Loading

0 comments on commit 5f694be

Please sign in to comment.