Skip to content

Commit

Permalink
capicxx-someip-runtime 3.1.12.12
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed May 22, 2018
1 parent f41fa77 commit 64f0cb0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
=======

v3.1.12.12
- Fix deregistration of events upon service deregistration
- Improve error handling on send errors

v3.1.12.11
- Set default build type to RelWithDebInfo when not specified
explicitly.
Expand Down
7 changes: 7 additions & 0 deletions include/CommonAPI/SomeIP/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ class Connection:
std::mutex subscriptionMutex_;

std::map<std::shared_ptr<vsomeip::message>, session_id_fake_t> errorResponses_;

// registered events from stubs
std::mutex registeredEventsMutex_;
std::map<vsomeip::service_t,
std::map<vsomeip::instance_t, std::set<vsomeip::event_t>>> registeredEvents_;

mutable session_id_t lastSessionId_;
};


Expand Down
67 changes: 64 additions & 3 deletions src/CommonAPI/SomeIP/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ Connection::Connection(const std::string &_name)
application_(vsomeip::runtime::get()->create_application(_name)),
asyncAnswersCleanupThread_(NULL),
cleanupCancelled_(false),
activeConnections_(0) {
activeConnections_(0),
lastSessionId_(0) {
std::string appId = Runtime::getProperty("LogApplication");
std::string contextId = Runtime::getProperty("LogContext");

Expand Down Expand Up @@ -497,13 +498,19 @@ bool Connection::sendMessageWithReplyAsync(
std::unique_ptr<MessageReplyAsyncHandler> messageReplyAsyncHandler,
const CommonAPI::CallInfo *_info) const {


if (!isConnected())
return false;


{
std::lock_guard<std::recursive_mutex> lock(sendReceiveMutex_);
application_->send(message.message_, true);
const vsomeip::session_t itsSession = message.getSessionId();
if (lastSessionId_ == itsSession) {
return false;
}
lastSessionId_ = itsSession;

if (_info->sender_ != 0) {
COMMONAPI_DEBUG("Message sent: SenderID: ", _info->sender_,
Expand All @@ -515,7 +522,7 @@ bool Connection::sendMessageWithReplyAsync(
(std::chrono::steady_clock::time_point) std::chrono::steady_clock::now()
+ std::chrono::milliseconds(_info->timeout_);

asyncAnswers_[message.getSessionId()] = std::make_tuple(
asyncAnswers_[itsSession] = std::make_tuple(
timeoutTime, message.message_,
std::move(messageReplyAsyncHandler));
}
Expand Down Expand Up @@ -546,10 +553,13 @@ Message Connection::sendMessageWithReplyAndBlock(
}

itsAnswer = sendAndBlockAnswers_.emplace(message.getSessionId(), Message());
Message itsResult;
if (!itsAnswer.second) {
return itsResult;
}

std::cv_status waitStatus = std::cv_status::no_timeout;

Message itsResult;

std::chrono::steady_clock::time_point elapsed(
std::chrono::steady_clock::now()
Expand Down Expand Up @@ -851,8 +861,27 @@ Connection::unregisterService(const Address &_address) {
major_version_t major = _address.getMajorVersion();
minor_version_t minor = _address.getMinorVersion();

std::set<vsomeip::event_t> itsEvents;
{
std::lock_guard<std::mutex> itsLock(registeredEventsMutex_);
const auto foundService = registeredEvents_.find(service);
if (foundService != registeredEvents_.end()) {
const auto foundInstance = foundService->second.find(instance);
if (foundInstance != foundService->second.end()) {
itsEvents = foundInstance->second;
foundService->second.erase(foundInstance);
if (!foundService->second.size()) {
registeredEvents_.erase(foundService);
}
}
}
}

application_->stop_offer_service(service, instance, major, minor);
application_->unregister_message_handler(service, instance, ANY_METHOD);
for (const auto e : itsEvents) {
application_->stop_offer_event(service, instance, e);
}
}

void
Expand Down Expand Up @@ -918,13 +947,45 @@ Connection::releaseService(const Address &_address) {
void
Connection::registerEvent(service_id_t _service, instance_id_t _instance,
event_id_t _event, const std::set<eventgroup_id_t> &_eventGroups, bool _isField) {
{
std::lock_guard<std::mutex> itsLock(registeredEventsMutex_);
bool found(false);
const auto foundService = registeredEvents_.find(_service);
if (foundService != registeredEvents_.end()) {
const auto foundInstance = foundService->second.find(_instance);
if (foundInstance != foundService->second.end()) {
foundInstance->second.insert(_event);
found = true;
}
}

if (!found) {
registeredEvents_[_service][_instance].insert(_event);
}
}
application_->offer_event(_service, _instance,
_event, _eventGroups, _isField);
}

void
Connection::unregisterEvent(service_id_t _service, instance_id_t _instance,
event_id_t _event) {
{
std::lock_guard<std::mutex> itsLock(registeredEventsMutex_);
const auto foundService = registeredEvents_.find(_service);
if (foundService != registeredEvents_.end()) {
const auto foundInstance = foundService->second.find(_instance);
if (foundInstance != foundService->second.end()) {
foundInstance->second.erase(_event);
if (!foundInstance->second.size()) {
foundService->second.erase(foundInstance);
if (!foundService->second.size()) {
registeredEvents_.erase(foundService);
}
}
}
}
}
application_->stop_offer_event(_service, _instance, _event);
}

Expand Down

0 comments on commit 64f0cb0

Please sign in to comment.