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

RFC: Add SetRuntimeEnvironment call for NI-DCPower #962

Closed
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
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ if(WIN32)
)
endif()

# Generate version header file
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
# This file requires product name and version info that mako does not know, but CMake does
configure_file(
source/server/version.h.in
${service_output_dir}/version.h
@ONLY)

target_sources(ni_grpc_device_server
PUBLIC "${service_output_dir}/version.h"
)


if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_sources(ni_grpc_device_server
PRIVATE "source/server/linux/syslog_logging.cpp"
Expand Down
14 changes: 14 additions & 0 deletions generated/nidcpower/nidcpower_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Service implementation for the NI-DCPower Metadata
//---------------------------------------------------------------------
#include "nidcpower_library.h"
#include "version.h"

#if defined(_MSC_VER)
static const char* kLibraryName = "nidcpower_64.dll";
Expand Down Expand Up @@ -169,6 +170,11 @@ NiDCPowerLibrary::NiDCPowerLibrary() : shared_library_(kLibraryName)
function_pointers_.UnlockSession = reinterpret_cast<UnlockSessionPtr>(shared_library_.get_function_pointer("niDCPower_UnlockSession"));
function_pointers_.WaitForEvent = reinterpret_cast<WaitForEventPtr>(shared_library_.get_function_pointer("niDCPower_WaitForEvent"));
function_pointers_.WaitForEventWithChannels = reinterpret_cast<WaitForEventWithChannelsPtr>(shared_library_.get_function_pointer("niDCPower_WaitForEventWithChannels"));
function_pointers_.SetRuntimeEnvironment = reinterpret_cast<SetRuntimeEnvironmentPtr>(shared_library_.get_function_pointer("niDCPower_SetRuntimeEnvironment"));

if (function_pointers_.SetRuntimeEnvironment) {
this->SetRuntimeEnvironment(nidevice_grpc::kNiDeviceGrpcOriginalFileName, nidevice_grpc::kNiDeviceGrpcFileVersion, "", "");
}
}

NiDCPowerLibrary::~NiDCPowerLibrary()
Expand Down Expand Up @@ -1366,4 +1372,12 @@ ViStatus NiDCPowerLibrary::WaitForEventWithChannels(ViSession vi, ViConstString
return function_pointers_.WaitForEventWithChannels(vi, channelName, eventId, timeout);
}

ViStatus NiDCPowerLibrary::SetRuntimeEnvironment(ViConstString environment, ViConstString environmentVersion, ViConstString reserved1, ViConstString reserved2)
{
if (!function_pointers_.SetRuntimeEnvironment) {
throw nidevice_grpc::LibraryLoadException("Could not find niDCPower_SetRuntimeEnvironment.");
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
}
return function_pointers_.SetRuntimeEnvironment(environment, environmentVersion, reserved1, reserved2);
}

} // namespace nidcpower_grpc
3 changes: 3 additions & 0 deletions generated/nidcpower/nidcpower_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class NiDCPowerLibrary : public nidcpower_grpc::NiDCPowerLibraryInterface {
ViStatus UnlockSession(ViSession vi, ViBoolean* callerHasLock);
ViStatus WaitForEvent(ViSession vi, ViInt32 eventId, ViReal64 timeout);
ViStatus WaitForEventWithChannels(ViSession vi, ViConstString channelName, ViInt32 eventId, ViReal64 timeout);
ViStatus SetRuntimeEnvironment(ViConstString environment, ViConstString environmentVersion, ViConstString reserved1, ViConstString reserved2);
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved

private:
using AbortPtr = decltype(&niDCPower_Abort);
Expand Down Expand Up @@ -316,6 +317,7 @@ class NiDCPowerLibrary : public nidcpower_grpc::NiDCPowerLibraryInterface {
using UnlockSessionPtr = ViStatus (*)(ViSession vi, ViBoolean* callerHasLock);
using WaitForEventPtr = decltype(&niDCPower_WaitForEvent);
using WaitForEventWithChannelsPtr = decltype(&niDCPower_WaitForEventWithChannels);
using SetRuntimeEnvironmentPtr = ViStatus (*)(ViConstString environment, ViConstString environmentVersion, ViConstString reserved1, ViConstString reserved2);

typedef struct FunctionPointers {
AbortPtr Abort;
Expand Down Expand Up @@ -466,6 +468,7 @@ class NiDCPowerLibrary : public nidcpower_grpc::NiDCPowerLibraryInterface {
UnlockSessionPtr UnlockSession;
WaitForEventPtr WaitForEvent;
WaitForEventWithChannelsPtr WaitForEventWithChannels;
SetRuntimeEnvironmentPtr SetRuntimeEnvironment;
} FunctionLoadStatus;

nidevice_grpc::SharedLibrary shared_library_;
Expand Down
1 change: 1 addition & 0 deletions generated/nidcpower/nidcpower_library_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class NiDCPowerLibraryInterface {
virtual ViStatus UnlockSession(ViSession vi, ViBoolean* callerHasLock) = 0;
virtual ViStatus WaitForEvent(ViSession vi, ViInt32 eventId, ViReal64 timeout) = 0;
virtual ViStatus WaitForEventWithChannels(ViSession vi, ViConstString channelName, ViInt32 eventId, ViReal64 timeout) = 0;
virtual ViStatus SetRuntimeEnvironment(ViConstString environment, ViConstString environmentVersion, ViConstString reserved1, ViConstString reserved2) = 0;
};

} // namespace nidcpower_grpc
Expand Down
1 change: 1 addition & 0 deletions generated/nidcpower/nidcpower_mock_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class NiDCPowerMockLibrary : public nidcpower_grpc::NiDCPowerLibraryInterface {
MOCK_METHOD(ViStatus, UnlockSession, (ViSession vi, ViBoolean* callerHasLock), (override));
MOCK_METHOD(ViStatus, WaitForEvent, (ViSession vi, ViInt32 eventId, ViReal64 timeout), (override));
MOCK_METHOD(ViStatus, WaitForEventWithChannels, (ViSession vi, ViConstString channelName, ViInt32 eventId, ViReal64 timeout), (override));
MOCK_METHOD(ViStatus, SetRuntimeEnvironment, (ViConstString environment, ViConstString environmentVersion, ViConstString reserved1, ViConstString reserved2), (override));
};

} // namespace unit
Expand Down
11 changes: 11 additions & 0 deletions generated/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef NIDEVICE_GRPC_VERSION_H
#define NIDEVICE_GRPC_VERSION_H

namespace nidevice_grpc {

static constexpr const char* kNiDeviceGrpcFileVersion = "2.3.0.0";
static constexpr const char* kNiDeviceGrpcOriginalFileName = "ni_grpc_device_server.exe";

}

#endif // NIDEVICE_GRPC_VERSION_H
9 changes: 8 additions & 1 deletion source/codegen/metadata/nidcpower/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from .functions import functions
from .functions_addon import functions_override_metadata
from .attributes import attributes
from .attributes_addon import attributes_override_metadata
from .enums import enums
from .enums_addon import enums_override_metadata
from .config import config

metadata = {
"functions" : functions,
"attributes" : attributes,
"enums" : enums,
"config" : config
}
}

metadata['functions'].update(functions_override_metadata)
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
metadata['attributes'].update(attributes_override_metadata)
metadata['enums'].update(enums_override_metadata)
34 changes: 34 additions & 0 deletions source/codegen/metadata/nidcpower/functions_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,38 @@
# Changes to the metadata should be made here, because functions.py is generated thus any changes get overwritten.

functions_override_metadata = {
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
'SetRuntimeEnvironment': {
'codegen_method': 'private',
'parameters': [
{
'cppName': 'environment',
'direction': 'in',
'grpc_type': 'string',
'name': 'environment',
'type': 'ViConstString'
},
{
'cppName': 'environmentVersion',
'direction': 'in',
'grpc_type': 'string',
'name': 'environmentVersion',
'type': 'ViConstString'
},
{
'cppName': 'reserved1',
'direction': 'in',
'grpc_type': 'string',
'name': 'reserved1',
'type': 'ViConstString'
},
{
'cppName': 'reserved2',
'direction': 'in',
'grpc_type': 'string',
'name': 'reserved2',
'type': 'ViConstString'
}
],
'returns': 'ViStatus'
},
}
9 changes: 9 additions & 0 deletions source/codegen/templates/library.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ windows_library_name = windows_library_info['name']
// Service implementation for the ${config["driver_name"]} Metadata
//---------------------------------------------------------------------
#include "${module_name}_library.h"
% if 'SetRuntimeEnvironment' in service_helpers.filter_api_functions(functions, only_mockable_functions=False):
#include "version.h"
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
% endif

#if defined(_MSC_VER)
static const char* kLibraryName = "${windows_library_name}";
Expand All @@ -44,6 +47,12 @@ ${service_class_prefix}Library::${service_class_prefix}Library() : shared_librar
%>\
function_pointers_.${method_name} = reinterpret_cast<${method_name}Ptr>(shared_library_.get_function_pointer("${c_name}"));
% endfor
% if 'SetRuntimeEnvironment' in service_helpers.filter_api_functions(functions, only_mockable_functions=False):

if (function_pointers_.SetRuntimeEnvironment) {
this->SetRuntimeEnvironment(nidevice_grpc::kNiDeviceGrpcOriginalFileName, nidevice_grpc::kNiDeviceGrpcFileVersion, "", "");
}
% endif
}

${service_class_prefix}Library::~${service_class_prefix}Library()
Expand Down
11 changes: 11 additions & 0 deletions source/server/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef NIDEVICE_GRPC_VERSION_H
#define NIDEVICE_GRPC_VERSION_H

namespace nidevice_grpc {

static constexpr const char* kNiDeviceGrpcFileVersion = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@[email protected]";
static constexpr const char* kNiDeviceGrpcOriginalFileName = "ni_grpc_device_server.exe";

}

#endif // NIDEVICE_GRPC_VERSION_H