Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
* Upgrade to libcluon v0.0.108
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berger <christian.berger@gu.se>
  • Loading branch information
chrberger committed Aug 13, 2018
1 parent 94ad592 commit 23c99f0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ project(opendlv-device-camera-opencv)

################################################################################
# Defining the relevant version of libcluon.
set(CLUON_COMPLETE cluon-complete-v0.0.105.hpp)
set(CLUON_COMPLETE cluon-complete-v0.0.108.hpp)

################################################################################
# Set the search path for .cmake files.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To run this microservice using our pre-built Docker multi-arch images to open
an OpenCV-encapsulated camera, simply start it as follows:

```
docker run --rm -ti --init --ipc=host -e DISPLAY=$DISPLAY --device /dev/video0 -v /tmp:/tmp chalmersrevere/opendlv-device-camera-opencv-multi:v0.0.9 --camera=/dev/video0 --width=640 --height=480 --freq=20
docker run --rm -ti --init --ipc=host -e DISPLAY=$DISPLAY --device /dev/video0 -v /tmp:/tmp chalmersrevere/opendlv-device-camera-opencv-multi:v0.0.10 --camera=/dev/video0 --width=640 --height=480 --freq=20
```

If you want to display the captured frames, simply append `--verbose` to the
Expand Down
80 changes: 51 additions & 29 deletions src/cluon-complete-v0.0.105.hpp → src/cluon-complete-v0.0.108.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is an auto-generated header-only single-file distribution of libcluon.
// Date: Thu, 19 Jul 2018 20:35:46 +0200
// Version: 0.0.105
// Date: Mon, 13 Aug 2018 19:56:15 +0200
// Version: 0.0.108
//
//
// Implementation of N4562 std::experimental::any (merged into C++17) for C++11 compilers.
Expand Down Expand Up @@ -7222,6 +7222,21 @@ class LIBCLUON_API EnvelopeConverter {
*/
std::string getProtoEncodedEnvelopeFromJSONWithoutTimeStamps(const std::string &json, int32_t messageIdentifier, uint32_t senderStamp) noexcept;

/**
* This method transforms a given JSON representation into a Proto-encoded Envelope
* including the prepended OD4-header and setting cluon::time::now() as sampleTimeStamp.
*
* @param json representation according to the given message specification.
* @param messageIdentifier The given JSON representation shall be interpreted
* as the specified message.
* @param senderStamp to be used in the Envelope.
* @return Proto-encoded Envelope including OD4-header or empty string.
*/
std::string getProtoEncodedEnvelopeFromJSON(const std::string &json, int32_t messageIdentifier, uint32_t senderStamp) noexcept;

private:
std::string getProtoEncodedEnvelopeFromJSON(const std::string &json, int32_t messageIdentifier, uint32_t senderStamp, cluon::data::TimeStamp sampleTimeStamp) noexcept;

private:
std::vector<cluon::MetaMessage> m_listOfMetaMessages{};
std::map<int32_t, cluon::MetaMessage> m_scopeOfMetaMessages{};
Expand Down Expand Up @@ -13288,6 +13303,7 @@ inline void ToODVDVisitor::visit(uint32_t id, std::string &&typeName, std::strin
//#include "cluon/MessageParser.hpp"
//#include "cluon/ToJSONVisitor.hpp"
//#include "cluon/ToProtoVisitor.hpp"
//#include "cluon/Time.hpp"
//#include "cluon/any/any.hpp"

#include <algorithm>
Expand Down Expand Up @@ -13391,6 +13407,18 @@ inline std::string EnvelopeConverter::getJSONFromEnvelope(cluon::data::Envelope

// clang-format off
inline std::string EnvelopeConverter::getProtoEncodedEnvelopeFromJSONWithoutTimeStamps(const std::string &json, int32_t messageIdentifier, uint32_t senderStamp) noexcept {
// clang-format on
return getProtoEncodedEnvelopeFromJSON(json, messageIdentifier, senderStamp, cluon::data::TimeStamp());
}

// clang-format off
inline std::string EnvelopeConverter::getProtoEncodedEnvelopeFromJSON(const std::string &json, int32_t messageIdentifier, uint32_t senderStamp) noexcept {
// clang-format on
return getProtoEncodedEnvelopeFromJSON(json, messageIdentifier, senderStamp, cluon::time::now());
}

// clang-format off
inline std::string EnvelopeConverter::getProtoEncodedEnvelopeFromJSON(const std::string &json, int32_t messageIdentifier, uint32_t senderStamp, cluon::data::TimeStamp sampleTimeStamp) noexcept {
// clang-format on
std::string retVal;
if (0 < m_scopeOfMetaMessages.count(messageIdentifier)) {
Expand All @@ -13414,7 +13442,10 @@ inline std::string EnvelopeConverter::getProtoEncodedEnvelopeFromJSONWithoutTime
gm.accept(protoEncoder);

cluon::data::Envelope env;
env.dataType(messageIdentifier).serializedData(protoEncoder.encodedData()).senderStamp(senderStamp);
env.dataType(messageIdentifier)
.serializedData(protoEncoder.encodedData())
.senderStamp(senderStamp)
.sampleTimeStamp(sampleTimeStamp);

retVal = cluon::serializeEnvelope(std::move(env));
}
Expand Down Expand Up @@ -14456,9 +14487,7 @@ inline void SharedMemory::initSysV() noexcept {
// set of semaphores and shared memory areas.
std::fstream tokenFile(m_name.c_str(), std::ios::in);
if (tokenFile.good()) {
std::cerr << "[cluon::SharedMemory (SysV)] Token file '" << m_name << "' already exists; need to clean up existing SysV-based shared memory."
<< std::endl;
// Cleaning up will be tried in the code below.
// Existing tokenFile found. Cleaning up will be tried in the code below.
}
tokenFile.close();

Expand Down Expand Up @@ -14494,19 +14523,16 @@ inline void SharedMemory::initSysV() noexcept {
// IPC_CREAT flag. On a clean environment, this call must fail
// as there should not be any shared memory segments left.
{
int orphanedSharedMemoryIDSysV = ::shmget(m_shmKeySysV, 0, S_IRUSR | S_IWUSR);
int orphanedSharedMemoryIDSysV = ::shmget(m_shmKeySysV, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (!(orphanedSharedMemoryIDSysV < 0)) {
std::cerr << "[cluon::SharedMemory (SysV)] Existing shared memory (0x" << std::hex << m_shmKeySysV << std::dec << ") found; ";
if (::shmctl(orphanedSharedMemoryIDSysV, IPC_RMID, 0)) {
std::cerr << "removing failed." << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
} else {
std::cerr << "successfully removed." << std::endl;
std::cerr << "[cluon::SharedMemory (SysV)] Existing shared memory (0x" << std::hex << m_shmKeySysV << std::dec << ") found; removing failed." << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
}
}
}

// Now, create the shared memory segment.
m_sharedMemoryIDSysV = ::shmget(m_shmKeySysV, m_size, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
m_sharedMemoryIDSysV = ::shmget(m_shmKeySysV, m_size, IPC_CREAT | IPC_EXCL | S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (-1 != m_sharedMemoryIDSysV) {
m_sharedMemory = reinterpret_cast<char *>(::shmat(m_sharedMemoryIDSysV, nullptr, 0));
#pragma GCC diagnostic push
Expand All @@ -14524,7 +14550,7 @@ inline void SharedMemory::initSysV() noexcept {
}
} else {
// The caller wants to attach to an existing shared memory segment.
m_sharedMemoryIDSysV = ::shmget(m_shmKeySysV, 0, S_IRUSR | S_IWUSR);
m_sharedMemoryIDSysV = ::shmget(m_shmKeySysV, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (-1 != m_sharedMemoryIDSysV) {
struct shmid_ds info;
if (-1 != ::shmctl(m_sharedMemoryIDSysV, IPC_STAT, &info)) {
Expand Down Expand Up @@ -14562,22 +14588,18 @@ inline void SharedMemory::initSysV() noexcept {

// First, try to remove the orphaned one.
{
int orphanedMutexIDSysV = ::semget(m_mutexKeySysV, 0, S_IRUSR | S_IWUSR);
int orphanedMutexIDSysV = ::semget(m_mutexKeySysV, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (!(orphanedMutexIDSysV < 0)) {
std::cerr << "[cluon::SharedMemory (SysV)] Existing semaphore (0x" << std::hex << m_mutexKeySysV << std::dec
<< ", intended to use as mutex) found; ";
if (::semctl(orphanedMutexIDSysV, 0, IPC_RMID)) {
std::cerr << "removing failed." << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
} else {
std::cerr << "successfully removed." << std::endl;
std::cerr << "[cluon::SharedMemory (SysV)] Existing semaphore (0x" << std::hex << m_mutexKeySysV << std::dec << ", intended to use as mutex) found; removing failed." << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
}
}
}

// Next, create the correct semaphore used as mutex.
{
constexpr int NSEMS{1};
m_mutexIDSysV = ::semget(m_mutexKeySysV, NSEMS, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
m_mutexIDSysV = ::semget(m_mutexKeySysV, NSEMS, IPC_CREAT | IPC_EXCL | S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (-1 != m_mutexIDSysV) {
constexpr int NUMBER_OF_SEMAPHORE_TO_CONTROL{0};
constexpr int INITIAL_VALUE{1};
Expand All @@ -14598,7 +14620,7 @@ inline void SharedMemory::initSysV() noexcept {
}
}
} else {
m_mutexIDSysV = ::semget(m_mutexKeySysV, 0, S_IRUSR | S_IWUSR);
m_mutexIDSysV = ::semget(m_mutexKeySysV, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (-1 == m_mutexIDSysV) {
std::cerr << "[cluon::SharedMemory (SysV)] Failed to get semaphore (0x" << std::hex << m_mutexKeySysV << std::dec // LCOV_EXCL_LINE
<< ", intended to use as mutex): " << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
Expand All @@ -14618,22 +14640,18 @@ inline void SharedMemory::initSysV() noexcept {

// First, try to remove the orphaned one.
{
int orphanedConditionIDSysV = ::semget(m_conditionKeySysV, 0, S_IRUSR | S_IWUSR);
int orphanedConditionIDSysV = ::semget(m_conditionKeySysV, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (!(orphanedConditionIDSysV < 0)) {
std::cerr << "[cluon::SharedMemory (SysV)] Existing semaphore (0x" << std::hex << m_conditionKeySysV << std::dec
<< ", intended to use as condition variable) found; ";
if (::semctl(orphanedConditionIDSysV, 0, IPC_RMID)) {
std::cerr << "removing failed." << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
} else {
std::cerr << "successfully removed." << std::endl;
std::cerr << "[cluon::SharedMemory (SysV)] Existing semaphore (0x" << std::hex << m_conditionKeySysV << std::dec << ", intended to use as condition variable) found; removing failed." << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
}
}
}

// Next, create the correct semaphore used as condition variable.
{
constexpr int NSEMS{1};
m_conditionIDSysV = ::semget(m_conditionKeySysV, NSEMS, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
m_conditionIDSysV = ::semget(m_conditionKeySysV, NSEMS, IPC_CREAT | IPC_EXCL | S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (-1 != m_conditionIDSysV) {
constexpr int NUMBER_OF_SEMAPHORE_TO_CONTROL{0};
constexpr int INITIAL_VALUE{1};
Expand All @@ -14654,7 +14672,7 @@ inline void SharedMemory::initSysV() noexcept {
}
}
} else {
m_conditionIDSysV = ::semget(m_conditionKeySysV, 0, S_IRUSR | S_IWUSR);
m_conditionIDSysV = ::semget(m_conditionKeySysV, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (-1 == m_conditionIDSysV) {
std::cerr << "[cluon::SharedMemory (SysV)] Failed to get semaphore (0x" << std::hex << m_conditionKeySysV << std::dec // LCOV_EXCL_LINE
<< ", intended to use as condition variable): " << ::strerror(errno) << " (" << errno << ")" << std::endl; // LCOV_EXCL_LINE
Expand Down Expand Up @@ -16673,6 +16691,10 @@ inline int32_t cluon_replay(int32_t argc, char **argv) {
if (od4 && !od4->isRunning()) {
break;
}
// If we are at the end of the playback file, simply wait a little to avoid excessive system load.
if (!player.hasMoreData() && keepRunning) {
std::this_thread::sleep_for(std::chrono::duration<int32_t, std::milli>(200)); // LCOV_EXCL_LINE
}
// Check for broadcasting status updates.
if (playerStatusUpdate) {
std::string s;
Expand Down

0 comments on commit 23c99f0

Please sign in to comment.