Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #15

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.24)

project(JetModule
VERSION 1.0.0
DESCRIPTION "Library for using JetPeer alongside with openDAQ"
project(JetModule
DESCRIPTION "Library for publishing openDAQ device structure as Jet states"
LANGUAGES C CXX)

##### Variables
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Jet module is an integration of Jet protocol with openDAQ SDK. It publishes devi
- After a device has been instantiated, create `JetServer` object:

```c++
daq::modules::jet_module::JetServer jetServer = JetServer(opendaqInstance);
jet_module::JetServer jetServer = jet_module::JetServer(opendaqInstance);
```

- Call `JetServer::publishJetStates()` to publish device structure as Jet states:
Expand Down Expand Up @@ -38,7 +38,4 @@ cmake --build .
### TODO

- Add Support for all property types.
- ref_dev0/MethodSet/GetErrorInformation (Decide whether methods like these habe to be turned into Jet methods).
- Verify that Jet methods for FunctionProperty is created properly.
- Support parameter passing to Jet methods
- Rethink how to handle SelectionProperties
- Exception handling and error logging has to be reworked from ground-up.
2 changes: 1 addition & 1 deletion app/ref_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>

using namespace daq;
using namespace daq::modules::jet_module;
using namespace jet_module;

int main() {

Expand Down
10 changes: 7 additions & 3 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/
#pragma once
#include <coretypes/common.h>

#define BEGIN_NAMESPACE_JET_MODULE BEGIN_NAMESPACE_OPENDAQ_MODULE(jet_module)
#define END_NAMESPACE_JET_MODULE END_NAMESPACE_OPENDAQ_MODULE
#define BEGIN_NAMESPACE_JET_MODULE \
namespace jet_module \
{

#define END_NAMESPACE_JET_MODULE \
}

1 change: 0 additions & 1 deletion include/component_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class ComponentConverter
JetEventHandler jetEventHandler;

InstancePtr opendaqInstance;
LoggerComponentPtr logger;
private:
};

Expand Down
2 changes: 0 additions & 2 deletions include/jet_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class JetEventHandler

JetPeerWrapper& jetPeerWrapper;
PropertyConverter propertyConverter;

LoggerComponentPtr logger;
};

END_NAMESPACE_JET_MODULE
20 changes: 18 additions & 2 deletions include/jet_module_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,34 @@
* limitations under the License.
*/
#pragma once
#include "common.h"
#include <opendaq/device_impl.h>
#include <json/value.h>
#include <opendaq/logger_component_factory.h>

BEGIN_NAMESPACE_JET_MODULE

extern daq::LoggerComponentPtr jetModuleLogger;

enum JetModuleException : int
{
JM_INCOMPATIBLE_TYPES = 0,
JM_UNSUPPORTED_JSON_TYPE,
JM_UNSUPPORTED_DAQ_TYPE,
JM_UNSUPPORTED_ITEM
JM_UNSUPPORTED_ITEM,
JM_FUNCTION_INCOMPATIBLE_ARGUMENT_TYPES,
JM_FUNCTION_INCORRECT_ARGUMENT_NUMBER,
JM_FUNCTION_UNSUPPORTED_ARGUMENT_TYPE,
JM_FUNCTION_UNSUPPORTED_ARGUMENT_FORMAT,
JM_FUNCTION_UNSUPPORTED_RETURN_TYPE,
JM_UNEXPECTED_TYPE
};

bool checkTypeCompatibility(Json::ValueType jsonValueType, daq::CoreType daqValueType);
void throwJetModuleException(JetModuleException jmException);
void throwJetModuleException(JetModuleException jmException, std::string propertyName);
void throwJetModuleException(JetModuleException jmException, Json::ValueType jsonValueType, std::string propertyName, std::string globalId);
void throwJetModuleException(JetModuleException jmException, Json::ValueType jsonValueType, std::string propertyName, std::string globalId);
std::string jetModuleExceptionToString(const JetModuleException& jmException);


END_NAMESPACE_JET_MODULE
33 changes: 0 additions & 33 deletions include/jet_module_impl.h

This file was deleted.

3 changes: 1 addition & 2 deletions include/jet_peer_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class JetPeerWrapper

void publishJetState(const std::string& path, const Json::Value& jetState, JetStateCallback callback);
void publishJetMethod(const std::string& path, JetMethodCallback callback);
void removeJetMethod(const std::string& path);
Json::Value readJetState(const std::string& path);
Json::Value readAllJetStates();
void updateJetState(const std::string& path, const Json::Value newValue);
Expand All @@ -74,8 +75,6 @@ class JetPeerWrapper
hbk::sys::EventLoop jetEventloop;
bool jetEventloopRunning;
std::thread jetEventloopThread;

LoggerComponentPtr logger;
};

END_NAMESPACE_JET_MODULE
19 changes: 0 additions & 19 deletions include/module_dll.h

This file was deleted.

3 changes: 1 addition & 2 deletions include/opendaq_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class OpendaqEventHandler
void updateSimpleProperty(const ComponentPtr& component, const DictPtr<IString, IBaseObject>& eventParameters);
void updateListProperty(const ComponentPtr& component, const DictPtr<IString, IBaseObject>& eventParameters);
void updateDictProperty(const ComponentPtr& component, const DictPtr<IString, IBaseObject>& eventParameters);
void updateFunctionProperty(const ComponentPtr& component, const DictPtr<IString, IBaseObject>& eventParameters);
void updateActiveStatus(const ComponentPtr& component, const DictPtr<IString, IBaseObject>& eventParameters);

void addProperty(const ComponentPtr& component, const DictPtr<IString, IBaseObject>& eventParameters);
Expand All @@ -52,8 +53,6 @@ class OpendaqEventHandler
JetPeerWrapper& jetPeerWrapper;
PropertyManager propertyManager;
PropertyConverter propertyConverter;

LoggerComponentPtr logger;
};

END_NAMESPACE_JET_MODULE
2 changes: 0 additions & 2 deletions include/property_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class PropertyConverter

template <typename DictItemType>
Json::Value fillJsonDict_BasicType(const DictPtr<IString, IBaseObject>& opendaqDict);

LoggerComponentPtr logger;
};

END_NAMESPACE_JET_MODULE
18 changes: 12 additions & 6 deletions include/property_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <opendaq/device_impl.h>
#include "property_converter.h"
#include "jet_peer_wrapper.h"
#include "jet_module_exceptions.h"

using namespace daq;

Expand Down Expand Up @@ -57,13 +58,18 @@ class PropertyManager
void createJetMethod(const ComponentPtr& propertyPublisher, const PropertyPtr& property);

private:
BaseObjectPtr convertJsonValueToDaqValue(const Json::Value& jsonVal);
Json::Value convertDaqValueToJsonValue(const BaseObjectPtr& daqVal, const CoreType& coretype);
bool hasUnsupportedArgument(const CallableInfoPtr& callableInfo, const std::string& propertyName);
bool hasUnsupportedReturnType(const CoreType& returnType, const std::string& propertyName);
bool hasCompatibleArgumentTypes(CoreType daqType, const Json::Value& jsonVal);

PropertyConverter propertyConverter;
JetPeerWrapper& jetPeerWrapper;
LoggerComponentPtr logger;
};


//! Template functions definitions have to be in the header file so that derived classes are able to use them.
//! Template function definitions have to be in the header file so that derived classes are able to use them.
/*
* Unlike regular functions and methods, template definitions (including template member functions of a class) must be visible
* to a translation unit that uses them. This is because the compiler needs to instantiate the template with the specific type
Expand Down Expand Up @@ -134,9 +140,9 @@ void PropertyManager::determinePropertyType(const PropertyHolder& propertyHolder
default:
{
std::string message = "Unsupported value type of Property: " + propertyName + '\n';
logger.logMessage(SourceLocation{__FILE__, __LINE__, OPENDAQ_CURRENT_FUNCTION}, message.c_str(), LogLevel::Warn);
DAQLOG_W(jetModuleLogger, message.c_str());
message = "\"std::string\" will be used to store property value.\n";
logger.logMessage(SourceLocation{__FILE__, __LINE__, OPENDAQ_CURRENT_FUNCTION}, message.c_str(), LogLevel::Info);
DAQLOG_I(jetModuleLogger, message.c_str());
std::string propertyValue = propertyHolder.getPropertyValue(propertyName);
parentJsonValue[propertyName] = propertyValue;
}
Expand Down Expand Up @@ -306,7 +312,7 @@ void PropertyManager::appendStructProperty(const PropertyHolderType& propertyHol
default:
{
// std::string message = "Unsupported list item type: " + listItemType + '\n';
// jetPeerWrapper.logger.logMessage(SourceLocation{__FILE__, __LINE__, OPENDAQ_CURRENT_FUNCTION}, message.c_str(), LogLevel::Error);
// jetPeerWrapper.jetModuleLogger.logMessage(SourceLocation{__FILE__, __LINE__, OPENDAQ_CURRENT_FUNCTION}, message.c_str(), LogLevel::Error);
}
break;
}
Expand All @@ -324,7 +330,7 @@ void PropertyManager::appendStructProperty(const PropertyHolderType& propertyHol
default:
{
// std::string message = "Unsupported struct field type: " + structfieldType + '\n';
// jetPeerWrapper.logger.logMessage(SourceLocation{__FILE__, __LINE__, OPENDAQ_CURRENT_FUNCTION}, message.c_str(), LogLevel::Info);
// jetPeerWrapper.jetModuleLogger.logMessage(SourceLocation{__FILE__, __LINE__, OPENDAQ_CURRENT_FUNCTION}, message.c_str(), LogLevel::Info);
}
}
}
Expand Down
20 changes: 0 additions & 20 deletions include/version.h

This file was deleted.

19 changes: 0 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set(MODULE_HEADERS_DIR "${PROJECT_SOURCE_DIR}/include")
# Header files
set(SRC_Include
common.h
module_dll.h
jet_module_impl.h
jet_peer_wrapper.h
jet_server.h
jet_module_exceptions.h
Expand All @@ -19,13 +17,10 @@ set(SRC_Include
input_port_converter.h
opendaq_event_handler.h
jet_event_handler.h
version.h
)

# Source files
set(SRC_Srcs
module_dll.cpp
jet_module_impl.cpp
jet_peer_wrapper.cpp
jet_server.cpp
jet_module_exceptions.cpp
Expand All @@ -44,31 +39,17 @@ set(SRC_Srcs
# Prepend path to header files
list(TRANSFORM SRC_Include PREPEND "${MODULE_HEADERS_DIR}/")

source_group("module" FILES
${MODULE_HEADERS_DIR}/module_dll.h
${MODULE_HEADERS_DIR}/jet_module_impl.h
${MODULE_HEADERS_DIR}/jet.h
module_dll.cpp
jet_module_impl.cpp
jet.cpp
)

# Library creation
add_library(${LIB_NAME} SHARED
${SRC_Include}
${SRC_Srcs}
)
add_library(${SDK_TARGET_NAMESPACE}::${LIB_NAME} ALIAS ${LIB_NAME})
target_include_directories(${LIB_NAME} PUBLIC ${MODULE_HEADERS_DIR})
target_link_libraries(${LIB_NAME} PUBLIC daq::opendaq hbk jetpeer jetpeerasync jsoncpp_lib pugixml)

target_compile_definitions(${LIB_NAME} PUBLIC OPENDAQ_THREAD_SAFE)
target_include_directories(${LIB_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${LIB_NAME}>
$<INSTALL_INTERFACE:${LIB_NAME}>
)

set(OPENDAQ_MODULE_SUFFIX ".module${CMAKE_SHARED_LIBRARY_SUFFIX}")
opendaq_set_module_properties(${LIB_NAME} ${PROJECT_VERSION_MAJOR})

file(GLOB MODULE_HEADERS "${MODULE_HEADERS_DIR}/*.h")
install(FILES ${MODULE_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIB_NAME}")
Loading
Loading