Skip to content

Commit

Permalink
Initial VNA Service Files
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulNagaraju15 committed Aug 5, 2024
1 parent 08d1ae3 commit 1b19afd
Show file tree
Hide file tree
Showing 17 changed files with 2,944 additions and 54 deletions.
3 changes: 2 additions & 1 deletion generated/nirfmxvna/nirfmxvna.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ message InitializeResponse {
int32 status = 1;
nidevice_grpc.Session instrument = 2;
int32 is_new_session = 3;
}
}

2 changes: 1 addition & 1 deletion generated/nirfmxvna/nirfmxvna_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ initialize(const StubPtr& stub, const std::string& resource_name, const std::str
}


} // namespace nirfmxvna_grpc::experimental::client
} // namespace nirfmxvna_grpc::experimental::client
2 changes: 1 addition & 1 deletion generated/nirfmxvna/nirfmxvna_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ InitializeResponse initialize(const StubPtr& stub, const std::string& resource_n

} // namespace nirfmxvna_grpc::experimental::client

#endif /* NIRFMXVNA_GRPC_CLIENT_H */
#endif /* NIRFMXVNA_GRPC_CLIENT_H */
2 changes: 1 addition & 1 deletion generated/nirfmxvna/nirfmxvna_compilation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ int32 Initialize(char resourceName[], char optionString[], niRFmxInstrHandle* ha
return RFmxVNA_Initialize(resourceName, optionString, handleOut, isNewSession);
}

} // namespace nirfmxvna_grpc
} // namespace nirfmxvna_grpc
24 changes: 15 additions & 9 deletions generated/nirfmxvna/nirfmxvna_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// Service implementation for the NI-rfmxvna Metadata
//---------------------------------------------------------------------
#include "nirfmxvna_library.h"
#include <server/shared_library.h>

#include <memory>

#if defined(_MSC_VER)
static const char* kLibraryName = "niRFmxVNA.dll";
Expand All @@ -13,18 +16,21 @@ static const char* kLibraryName = "libnirfmxvna.so.1";

namespace nirfmxvna_grpc {

NiRFmxVNALibrary::NiRFmxVNALibrary() : shared_library_(kLibraryName)
NiRFmxVNALibrary::NiRFmxVNALibrary() : NiRFmxVNALibrary(std::make_shared<nidevice_grpc::SharedLibrary>()) {}

NiRFmxVNALibrary::NiRFmxVNALibrary(std::shared_ptr<nidevice_grpc::SharedLibraryInterface> shared_library) : shared_library_(shared_library)
{
shared_library_.load();
bool loaded = shared_library_.is_loaded();
shared_library_->set_library_name(kLibraryName);
shared_library_->load();
bool loaded = shared_library_->is_loaded();
memset(&function_pointers_, 0, sizeof(function_pointers_));
if (!loaded) {
return;
}
function_pointers_.Close = reinterpret_cast<ClosePtr>(shared_library_.get_function_pointer("RFmxVNA_Close"));
function_pointers_.GetError = reinterpret_cast<GetErrorPtr>(shared_library_.get_function_pointer("RFmxVNA_GetError"));
function_pointers_.GetErrorString = reinterpret_cast<GetErrorStringPtr>(shared_library_.get_function_pointer("RFmxVNA_GetErrorString"));
function_pointers_.Initialize = reinterpret_cast<InitializePtr>(shared_library_.get_function_pointer("RFmxVNA_Initialize"));
function_pointers_.Close = reinterpret_cast<ClosePtr>(shared_library_->get_function_pointer("RFmxVNA_Close"));
function_pointers_.GetError = reinterpret_cast<GetErrorPtr>(shared_library_->get_function_pointer("RFmxVNA_GetError"));
function_pointers_.GetErrorString = reinterpret_cast<GetErrorStringPtr>(shared_library_->get_function_pointer("RFmxVNA_GetErrorString"));
function_pointers_.Initialize = reinterpret_cast<InitializePtr>(shared_library_->get_function_pointer("RFmxVNA_Initialize"));
}

NiRFmxVNALibrary::~NiRFmxVNALibrary()
Expand All @@ -33,7 +39,7 @@ NiRFmxVNALibrary::~NiRFmxVNALibrary()

::grpc::Status NiRFmxVNALibrary::check_function_exists(std::string functionName)
{
return shared_library_.function_exists(functionName.c_str())
return shared_library_->function_exists(functionName.c_str())
? ::grpc::Status::OK
: ::grpc::Status(::grpc::NOT_FOUND, "Could not find the function " + functionName);
}
Expand Down Expand Up @@ -70,4 +76,4 @@ int32 NiRFmxVNALibrary::Initialize(char resourceName[], char optionString[], niR
return function_pointers_.Initialize(resourceName, optionString, handleOut, isNewSession);
}

} // namespace nirfmxvna_grpc
} // namespace nirfmxvna_grpc
17 changes: 10 additions & 7 deletions generated/nirfmxvna/nirfmxvna_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

#include "nirfmxvna_library_interface.h"

#include <server/shared_library.h>
#include <server/shared_library_interface.h>

#include <memory>

namespace nirfmxvna_grpc {

class NiRFmxVNALibrary : public nirfmxvna_grpc::NiRFmxVNALibraryInterface {
public:
NiRFmxVNALibrary();
explicit NiRFmxVNALibrary(std::shared_ptr<nidevice_grpc::SharedLibraryInterface> shared_library);
virtual ~NiRFmxVNALibrary();

::grpc::Status check_function_exists(std::string functionName);
int32 Close(niRFmxInstrHandle instrumentHandle, int32 forceDestroy);
int32 GetError(niRFmxInstrHandle instrumentHandle, int32* errorCode, int32 errorDescriptionBufferSize, char errorDescription[]);
int32 GetErrorString(niRFmxInstrHandle instrumentHandle, int32 errorCode, int32 errorDescriptionBufferSize, char errorDescription[]);
int32 Initialize(char resourceName[], char optionString[], niRFmxInstrHandle* handleOut, int32* isNewSession);
int32 Close(niRFmxInstrHandle instrumentHandle, int32 forceDestroy) override;
int32 GetError(niRFmxInstrHandle instrumentHandle, int32* errorCode, int32 errorDescriptionBufferSize, char errorDescription[]) override;
int32 GetErrorString(niRFmxInstrHandle instrumentHandle, int32 errorCode, int32 errorDescriptionBufferSize, char errorDescription[]) override;
int32 Initialize(char resourceName[], char optionString[], niRFmxInstrHandle* handleOut, int32* isNewSession) override;

private:
using ClosePtr = decltype(&RFmxVNA_Close);
Expand All @@ -36,10 +39,10 @@ class NiRFmxVNALibrary : public nirfmxvna_grpc::NiRFmxVNALibraryInterface {
InitializePtr Initialize;
} FunctionLoadStatus;

nidevice_grpc::SharedLibrary shared_library_;
std::shared_ptr<nidevice_grpc::SharedLibraryInterface> shared_library_;
FunctionPointers function_pointers_;
};

} // namespace nirfmxvna_grpc

#endif // NIRFMXVNA_GRPC_LIBRARY_H
#endif // NIRFMXVNA_GRPC_LIBRARY_H
2 changes: 1 addition & 1 deletion generated/nirfmxvna/nirfmxvna_library_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class NiRFmxVNALibraryInterface {
};

} // namespace nirfmxvna_grpc
#endif // NIRFMXVNA_GRPC_LIBRARY_WRAPPER_H
#endif // NIRFMXVNA_GRPC_LIBRARY_WRAPPER_H
2 changes: 1 addition & 1 deletion generated/nirfmxvna/nirfmxvna_mock_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class NiRFmxVNAMockLibrary : public nirfmxvna_grpc::NiRFmxVNALibraryInterface {
} // namespace unit
} // namespace tests
} // namespace ni
#endif // NIRFMXVNA_GRPC_MOCK_LIBRARY_H
#endif // NIRFMXVNA_GRPC_MOCK_LIBRARY_H
9 changes: 6 additions & 3 deletions generated/nirfmxvna/nirfmxvna_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace nirfmxvna_grpc {
const auto kWarningCAPIStringTruncatedToFitBuffer = 200026;

NiRFmxVNAService::NiRFmxVNAService(
NiRFmxVNALibraryInterface* library,
LibrarySharedPtr library,
ResourceRepositorySharedPtr resource_repository,
const NiRFmxVNAFeatureToggles& feature_toggles)
: library_(library),
Expand Down Expand Up @@ -177,7 +177,9 @@ namespace nirfmxvna_grpc {
return std::make_tuple(status, instrument);
};
std::string grpc_device_session_name = request->session_name();
auto cleanup_lambda = [&] (niRFmxInstrHandle id) { library_->Close(id, RFMXVNA_VAL_FALSE); };
// Capture the library shared_ptr by value. Do not capture `this` or any references.
LibrarySharedPtr library = library_;
auto cleanup_lambda = [library] (niRFmxInstrHandle id) { library->Close(id, RFMXVNA_VAL_FALSE); };
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForNiRFmxInstrHandle(context, status, 0);
Expand All @@ -199,4 +201,5 @@ namespace nirfmxvna_grpc {
feature_toggles.is_feature_enabled("nirfmxvna", CodeReadiness::kNextRelease))
{
}
} // namespace nirfmxvna_grpc
} // namespace nirfmxvna_grpc

11 changes: 6 additions & 5 deletions generated/nirfmxvna/nirfmxvna_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@ struct NiRFmxVNAFeatureToggles

class NiRFmxVNAService final : public NiRFmxVNA::Service {
public:
using LibrarySharedPtr = std::shared_ptr<NiRFmxVNALibraryInterface>;
using ResourceRepositorySharedPtr = std::shared_ptr<nidevice_grpc::SessionResourceRepository<niRFmxInstrHandle>>;

NiRFmxVNAService(
NiRFmxVNALibraryInterface* library,
LibrarySharedPtr library,
ResourceRepositorySharedPtr resource_repository,
const NiRFmxVNAFeatureToggles& feature_toggles = {});
virtual ~NiRFmxVNAService();

::grpc::Status Close(::grpc::ServerContext* context, const CloseRequest* request, CloseResponse* response) override;
::grpc::Status GetError(::grpc::ServerContext* context, const GetErrorRequest* request, GetErrorResponse* response) override;
::grpc::Status GetErrorString(::grpc::ServerContext* context, const GetErrorStringRequest* request, GetErrorStringResponse* response) override;
::grpc::Status Initialize(::grpc::ServerContext* context, const InitializeRequest* request, InitializeResponse* response) override;
private:
NiRFmxVNALibraryInterface* library_;
LibrarySharedPtr library_;
ResourceRepositorySharedPtr session_repository_;
::grpc::Status ConvertApiErrorStatusForNiRFmxInstrHandle(::grpc::ServerContext* context, int32_t status, niRFmxInstrHandle instrumentHandle);
::grpc::Status ConvertApiErrorStatusForNiRFmxInstrHandle(::grpc::ServerContextBase* context, int32_t status, niRFmxInstrHandle instrumentHandle);

NiRFmxVNAFeatureToggles feature_toggles_;
};

} // namespace nirfmxvna_grpc

#endif // NIRFMXVNA_GRPC_SERVICE_H
#endif // NIRFMXVNA_GRPC_SERVICE_H
31 changes: 8 additions & 23 deletions generated/nirfmxvna/nirfmxvna_service_registrar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cdma2k

//---------------------------------------------------------------------
// This file is automatically generated. All manual edits will be lost.
//---------------------------------------------------------------------
Expand All @@ -13,40 +13,25 @@ cdma2k

namespace nirfmxvna_grpc {

namespace {
struct LibraryAndService {
LibraryAndService(
const std::shared_ptr<nidevice_grpc::SessionResourceRepository<niRFmxInstrHandle>>& resource_repository,
const NiRFmxVNAFeatureToggles& feature_toggles)
: library(),
service(
&library,
resource_repository,
feature_toggles) {
}
NiRFmxVNALibrary library;
NiRFmxVNAService service;
};
}

std::shared_ptr<void> register_service(
grpc::ServerBuilder& builder,
grpc::ServerBuilder& builder,
const std::shared_ptr<nidevice_grpc::SessionResourceRepository<niRFmxInstrHandle>>& resource_repository,
const nidevice_grpc::FeatureToggles& feature_toggles)
{
auto toggles = NiRFmxVNAFeatureToggles(feature_toggles);

if (toggles.is_enabled)
{
auto library_and_service_ptr = std::make_shared<LibraryAndService>(
auto library = std::make_shared<NiRFmxVNALibrary>();
auto service = std::make_shared<NiRFmxVNAService>(
library,
resource_repository,
toggles);
auto& service = library_and_service_ptr->service;
builder.RegisterService(&service);
return library_and_service_ptr;
builder.RegisterService(service.get());
return service;
}

return {};
}

} // nirfmxvna_grpc
} // nirfmxvna_grpc
2 changes: 1 addition & 1 deletion generated/nirfmxvna/nirfmxvna_service_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ std::shared_ptr<void> register_service(

} // nirfmxvna_grpc

#endif // NIRFMXVNA_GRPC_SERVICE_REGISTRAR_H
#endif // NIRFMXVNA_GRPC_SERVICE_REGISTRAR_H
10 changes: 10 additions & 0 deletions generated/register_all_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include "nirfmxtdscdma/nirfmxtdscdma_service_registrar.h"
#endif // defined(_MSC_VER)
#if defined(_MSC_VER)
#include "nirfmxvna/nirfmxvna_service_registrar.h"
#endif // defined(_MSC_VER)
#if defined(_MSC_VER)
#include "nirfmxwcdma/nirfmxwcdma_service_registrar.h"
#endif // defined(_MSC_VER)
#if defined(_MSC_VER)
Expand Down Expand Up @@ -224,6 +227,13 @@ std::shared_ptr<std::vector<std::shared_ptr<void>>> register_all_services(
vi_session_repository,
feature_toggles));
#endif // defined(_MSC_VER)
#if defined(_MSC_VER)
service_vector->push_back(
nirfmxvna_grpc::register_service(
server_builder,
ni_r_fmx_instr_handle_repository,
feature_toggles));
#endif // defined(_MSC_VER)
#if defined(_MSC_VER)
service_vector->push_back(
nirfmxwcdma_grpc::register_service(
Expand Down
Loading

0 comments on commit 1b19afd

Please sign in to comment.