Skip to content

Commit

Permalink
Merge pull request #58 from ifm/develop
Browse files Browse the repository at this point in the history
Version 1.0.9
  • Loading branch information
cwiede authored Nov 17, 2023
2 parents 77d5d2a + d0da916 commit dff42c7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
6 changes: 5 additions & 1 deletion nexxT/include/nexxT/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#ifndef NEXXT_LOGGER_HPP
#define NEXXT_LOGGER_HPP

#include "nexxT/Services.hpp"
#include "nexxT/NexxTLinkage.hpp"
#include "SharedPointerTypes.hpp"
#include <QtCore/QMetaObject>

//! @cond Doxygen_Suppress
Expand Down Expand Up @@ -71,9 +71,13 @@ namespace nexxT
class DLLEXPORT Logging
{
static unsigned int loglevel;
static SharedQObjectPtr loggingService;
static void _log(unsigned int level, const QString &message, const QString &file, unsigned int line);
public:
static void setLogLevel(unsigned int level);
/* this function is introduced to avoid having to call getService(...) for every log call. getService(...)
acquires a mutex and therefore all functions using logging would be required to allow threads */
static void setLoggingService(const SharedQObjectPtr &loggingService);
static inline void log(unsigned int level, const QString &message, const QString &file, unsigned int line)
{
if( level >= loglevel )
Expand Down
10 changes: 1 addition & 9 deletions nexxT/include/nexxT/Services.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,12 @@
#include <QtCore/QSharedPointer>

#include "nexxT/NexxTLinkage.hpp"
#include "nexxT/SharedPointerTypes.hpp"

namespace nexxT
{
struct ServicesD;

/*!
A typedef for a QObject handled by a shared pointer.
In principle it is not really necessary to use a shared pointer to handle QObjects, because of the parent/child
ownership principle. However for consistency, the design decision has been made to also wrap the services in a
smart pointer just like datasamples, filters and ports.
*/
typedef QSharedPointer<QObject> SharedQObjectPtr;

/*!
This class is the C++ variant of \verbatim embed:rst:inline :py:class:`nexxT.interface.Services.Services`
\endverbatim
Expand Down
11 changes: 11 additions & 0 deletions nexxT/include/nexxT/SharedPointerTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QtCore/QSharedPointer>

class QObject;

namespace nexxT
{
class Port;
Expand Down Expand Up @@ -34,6 +36,15 @@ namespace nexxT
A typedef for a list of ports.
*/
typedef QList<QSharedPointer<Port> > PortList;

/*!
A typedef for a QObject handled by a shared pointer.
In principle it is not really necessary to use a shared pointer to handle QObjects, because of the parent/child
ownership principle. However for consistency, the design decision has been made to also wrap the services in a
smart pointer just like datasamples, filters and ports.
*/
typedef QSharedPointer<QObject> SharedQObjectPtr;
}

#endif
4 changes: 4 additions & 0 deletions nexxT/interface/DataSamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def getContent(self):
Get the contents of this sample as a QByteArray. Note that this is an efficient operation due to the copy on
write semantics of QByteArray. It also asserts that the original contents cannot be modified.
In C++, make sure to keep an instance of the QByteArray until done with processing. Moreover, consider to use
`QByteArray::constData()` for a pointer-to-memory access rather than `QByteArray::data()`, since the latter
will eventually make an unnecessary deep copy of the encapsulated data.
:return: QByteArray instance copy
"""
return QByteArray(self._content)
Expand Down
8 changes: 7 additions & 1 deletion nexxT/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ using namespace nexxT;
namespace nexxT
{
unsigned int Logging::loglevel;
SharedQObjectPtr Logging::loggingService;

void Logging::setLogLevel(unsigned int level)
{
loglevel = level;
}

void Logging::setLoggingService(const SharedQObjectPtr &service)
{
loggingService = service;
}

void Logging::_log(unsigned int level, const QString &message, const QString &file, unsigned int line)
{
SharedQObjectPtr logger = Services::getService("Logging");
SharedQObjectPtr logger = loggingService;
if( !logger.isNull() )
{
bool res = QMetaObject::invokeMethod(logger.get(), "log", Qt::DirectConnection, Q_ARG(int, level), Q_ARG(const QString &, message), Q_ARG(const QString &, file), Q_ARG(int, line));
Expand Down
9 changes: 9 additions & 0 deletions nexxT/src/Services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ void Services::_addService(const QString &name, const SharedQObjectPtr &service)
{
NEXXT_LOG_INFO(QString("adding service %1").arg(name));
d->map[name] = service;
if( name == "Logging" )
{
Logging::setLoggingService(service);
}
}
}

Expand All @@ -85,6 +89,10 @@ void Services::_removeService(const QString &name)
QMetaObject::invokeMethod(d->map[name].data(), "detach", Qt::DirectConnection);
}
d->map.remove(name);
if( name == "Logging" )
{
Logging::setLoggingService(SharedQObjectPtr());
}
}
}

Expand All @@ -96,6 +104,7 @@ void Services::_removeAll()
{
_removeService(key);
}
Logging::setLoggingService(SharedQObjectPtr());
}

Services *Services::singleton()
Expand Down
2 changes: 1 addition & 1 deletion nexxT/src/cnexxT.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<object-type name="InterThreadConnection" allow-thread="true">
</object-type>

<object-type name="Services">
<object-type name="Services" allow-thread="true">
<modify-function signature="addService(const QString &amp;,QObject*)">
<modify-argument index="2">
<define-ownership owner="c++"/>
Expand Down

0 comments on commit dff42c7

Please sign in to comment.