Skip to content

Commit 008f6c1

Browse files
CommonAPI 3.1.12
1 parent 66de998 commit 008f6c1

File tree

11 files changed

+125
-66
lines changed

11 files changed

+125
-66
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changes
22
=======
33

4+
v3.1.12
5+
- Add possibility to be notified on proxy destruction via
6+
Proxy::getCompletionFuture method
7+
- set CommonAPI CallStatus to INVALID_VALUE for wrong CRC values
8+
- fixed code sonar warnings
9+
410
v3.1.11
511
- console logging - log to standard error stream instead of standard output stream
612
- Runtime::initFactories() made public

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PROJECT(libcommonapi)
1010
# version of CommonAPI
1111
SET( LIBCOMMONAPI_MAJOR_VERSION 3 )
1212
SET( LIBCOMMONAPI_MINOR_VERSION 1 )
13-
SET( LIBCOMMONAPI_PATCH_VERSION 11 )
13+
SET( LIBCOMMONAPI_PATCH_VERSION 12 )
1414

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

include/CommonAPI/Deployable.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ template<typename Type_, typename TypeDepl_>
1919
struct Deployable : DeployableBase
2020
{
2121
Deployable(const TypeDepl_ *_depl = nullptr)
22-
: depl_(const_cast<TypeDepl_ *>(_depl)) {
22+
: value_(),
23+
depl_(const_cast<TypeDepl_ *>(_depl)) {
2324
}
2425

2526
Deployable(const Type_ &_value, const TypeDepl_ *_depl)

include/CommonAPI/Event.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Event {
7272
void notifyListeners(const Arguments_&... _eventArguments);
7373
void notifySpecificListener(const Subscription _subscription, const Arguments_&... _eventArguments);
7474
void notifySpecificError(const Subscription _subscription, const CallStatus status);
75+
void notifyErrorListeners(const CallStatus status);
7576

7677
virtual void onFirstListenerAdded(const Listener &_listener) {
7778
(void)_listener;
@@ -267,6 +268,37 @@ void Event<Arguments_...>::notifySpecificError(const Subscription subscription,
267268
}
268269
}
269270

271+
template<typename ... Arguments_>
272+
void Event<Arguments_...>::notifyErrorListeners(const CallStatus status) {
273+
subscriptionMutex_.lock();
274+
notificationMutex_.lock();
275+
for (auto iterator = pendingUnsubscriptions_.begin();
276+
iterator != pendingUnsubscriptions_.end();
277+
iterator++) {
278+
subscriptions_.erase(*iterator);
279+
}
280+
pendingUnsubscriptions_.clear();
281+
282+
for (auto iterator = pendingSubscriptions_.begin();
283+
iterator != pendingSubscriptions_.end();
284+
iterator++) {
285+
subscriptions_.insert(*iterator);
286+
}
287+
pendingSubscriptions_.clear();
288+
289+
subscriptionMutex_.unlock();
290+
291+
for (auto iterator = subscriptions_.begin(); iterator != subscriptions_.end(); iterator++) {
292+
ErrorListener listener = std::get<1>(iterator->second);
293+
if (listener) {
294+
listener(status);
295+
}
296+
}
297+
298+
notificationMutex_.unlock();
299+
}
300+
301+
270302
} // namespace CommonAPI
271303

272304
#endif // COMMONAPI_EVENT_HPP_

include/CommonAPI/Proxy.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cstdint>
1414
#include <memory>
1515
#include <type_traits>
16+
#include <future>
1617

1718
#include <CommonAPI/Address.hpp>
1819
#include <CommonAPI/Attribute.hpp>
@@ -24,22 +25,25 @@ namespace CommonAPI {
2425
typedef Event<AvailabilityStatus> ProxyStatusEvent;
2526
typedef ReadonlyAttribute<Version> InterfaceVersionAttribute;
2627

27-
class Proxy {
28+
class COMMONAPI_EXPORT Proxy {
2829
public:
29-
COMMONAPI_EXPORT virtual ~Proxy() {}
30+
virtual ~Proxy();
3031

31-
COMMONAPI_EXPORT const Address &getAddress() const;
32+
const Address &getAddress() const;
3233

33-
COMMONAPI_EXPORT virtual bool isAvailable() const = 0;
34+
std::future<void> getCompletionFuture();
3435

35-
COMMONAPI_EXPORT virtual bool isAvailableBlocking() const = 0;
36+
virtual bool isAvailable() const = 0;
3637

37-
COMMONAPI_EXPORT virtual ProxyStatusEvent& getProxyStatusEvent() = 0;
38+
virtual bool isAvailableBlocking() const = 0;
3839

39-
COMMONAPI_EXPORT virtual InterfaceVersionAttribute& getInterfaceVersionAttribute() = 0;
40+
virtual ProxyStatusEvent& getProxyStatusEvent() = 0;
41+
42+
virtual InterfaceVersionAttribute& getInterfaceVersionAttribute() = 0;
4043

4144
protected:
4245
Address address_;
46+
std::promise<void> completed_;
4347
};
4448

4549
} // namespace CommonAPI

src/CommonAPI/Address.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ Address::getAddress() const {
7575
void
7676
Address::setAddress(const std::string &_address) {
7777
std::string itsDomain, itsInterface, itsVersion, itsInstance;
78-
std::size_t itsDomainPos, itsInterfacePos, itsVersionPos, itsInstancePos;
78+
std::size_t itsDomainPos(0);
79+
std::size_t itsInterfacePos(0);
80+
std::size_t itsVersionPos(0);
81+
std::size_t itsInstancePos(0);
7982
bool isValid(true);
8083

8184
itsDomainPos = _address.find(':');
@@ -114,7 +117,7 @@ Address::setAddress(const std::string &_address) {
114117
isValid = false;
115118
if(isValid) {
116119
for (auto it = itsVersion.begin()+1; it != itsVersion.end(); ++it) {
117-
if (!isdigit(*it) && *it != '_') {
120+
if (!isdigit(static_cast<unsigned char>(*it)) && *it != '_') {
118121
isValid = false;
119122
break;
120123
}

src/CommonAPI/IniFileReader.cpp

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -29,65 +29,66 @@ IniFileReader::Section::getValue(const std::string &_key) const {
2929
bool
3030
IniFileReader::load(const std::string &_path) {
3131
std::ifstream configStream(_path);
32-
if (configStream.is_open()) {
33-
//COMMONAPI_INFO("Loading ini file from ", _path);
32+
if (!configStream.is_open()) {
33+
COMMONAPI_ERROR("Failed to load ini file: ", _path);
34+
return false;
35+
}
3436

35-
int lineCounter(0);
36-
std::string currentSectionName;
37-
std::shared_ptr<Section> currentSection;
37+
int lineCounter(0);
38+
std::string currentSectionName;
39+
std::shared_ptr<Section> currentSection;
3840

39-
while (!configStream.eof()) {
40-
std::string line;
41-
std::getline(configStream, line);
42-
lineCounter++;
41+
while (!configStream.eof()) {
42+
std::string line;
43+
std::getline(configStream, line);
44+
lineCounter++;
4345

44-
trim(line);
46+
trim(line);
4547

46-
std::size_t start = line.find('[');
47-
if (start == 0) {
48-
std::size_t end = line.find(']');
49-
if (end != line.npos) {
50-
currentSectionName = line.substr(++start, --end);
51-
if (sections_.end() == sections_.find(currentSectionName)) {
52-
currentSection = std::make_shared<Section>();
53-
if (currentSection) {
54-
sections_[currentSectionName] = currentSection;
55-
}
56-
} else {
57-
COMMONAPI_ERROR("Double definition of section \'",
58-
currentSectionName,
59-
"\' ignoring definition (line ",
60-
lineCounter,
61-
")");
62-
currentSection = nullptr;
48+
std::size_t start = line.find('[');
49+
if (start == 0) {
50+
std::size_t end = line.find(']');
51+
if (end != line.npos) {
52+
currentSectionName = line.substr(++start, --end);
53+
if (sections_.end() == sections_.find(currentSectionName)) {
54+
currentSection = std::make_shared<Section>();
55+
if (currentSection) {
56+
sections_[currentSectionName] = currentSection;
6357
}
6458
} else {
65-
COMMONAPI_ERROR("Missing \']\' in section definition (line ",
66-
lineCounter, ")");
59+
COMMONAPI_ERROR("Double definition of section \'",
60+
currentSectionName,
61+
"\' ignoring definition (line ",
62+
lineCounter,
63+
")");
64+
currentSection = nullptr;
6765
}
68-
} else if (currentSection) {
69-
std::size_t pos = line.find('=');
70-
if (pos != line.npos) {
71-
std::string key = line.substr(0, pos);
72-
trim(key);
73-
if (currentSection->mappings_.end()
74-
!= currentSection->mappings_.find(key)) {
75-
COMMONAPI_ERROR("Double definition for key \'",
76-
key,
77-
"'\' in section \'",
78-
currentSectionName,
79-
"\' (line ",
80-
lineCounter,
81-
")");
82-
} else {
83-
std::string value = line.substr(pos+1);
84-
trim(value);
85-
currentSection->mappings_[key] = value;
86-
}
87-
} else if (line.size() > 0) {
88-
COMMONAPI_ERROR("Missing \'=\' in key=value definition (line ",
89-
lineCounter, ")");
66+
} else {
67+
COMMONAPI_ERROR("Missing \']\' in section definition (line ",
68+
lineCounter, ")");
69+
}
70+
} else if (currentSection) {
71+
std::size_t pos = line.find('=');
72+
if (pos != line.npos) {
73+
std::string key = line.substr(0, pos);
74+
trim(key);
75+
if (currentSection->mappings_.end()
76+
!= currentSection->mappings_.find(key)) {
77+
COMMONAPI_ERROR("Double definition for key \'",
78+
key,
79+
"'\' in section \'",
80+
currentSectionName,
81+
"\' (line ",
82+
lineCounter,
83+
")");
84+
} else {
85+
std::string value = line.substr(pos+1);
86+
trim(value);
87+
currentSection->mappings_[key] = value;
9088
}
89+
} else if (line.size() > 0) {
90+
COMMONAPI_ERROR("Missing \'=\' in key=value definition (line ",
91+
lineCounter, ")");
9192
}
9293
}
9394
}

src/CommonAPI/Logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <CommonAPI/Logger.hpp>
77
#include <CommonAPI/Runtime.hpp>
88

9-
namespace CommonAPI {;
9+
namespace CommonAPI {
1010
void
1111
Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt, const std::string &_level) {
1212
LoggerImpl::init(_useConsole, _fileName, _useDlt, _level);

src/CommonAPI/LoggerImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <CommonAPI/Runtime.hpp>
1111
#endif
1212

13-
namespace CommonAPI {;
13+
namespace CommonAPI {
1414

1515
#if defined(USE_CONSOLE) || defined(USE_FILE)
1616
std::mutex LoggerImpl::mutex_;

src/CommonAPI/Proxy.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77

88
namespace CommonAPI {
99

10+
Proxy::~Proxy() {
11+
completed_.set_value();
12+
}
13+
1014
const Address &
1115
Proxy::getAddress() const {
1216
return address_;
1317
}
1418

19+
std::future<void> Proxy::getCompletionFuture() {
20+
return completed_.get_future();
21+
}
22+
1523
} // namespace CommonAPI

0 commit comments

Comments
 (0)