Skip to content

Commit

Permalink
[O2B-1010] Hide protobuf dependency from the c++ library
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed May 3, 2024
1 parent 21d7edc commit 5c99837
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 394 deletions.
33 changes: 2 additions & 31 deletions cxx-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protobuf_generate(
add_library(BookkeepingApi SHARED
src/grpc/GrpcBkpClient.cxx
src/grpc/services/GrpcFlpServiceClient.cxx
src/grpc/services/GrpcDplProcessExecutionClient.cxx
src/BkpClientFactory.cxx
)

Expand All @@ -74,28 +75,6 @@ target_link_libraries(BookkeepingApi

target_compile_features(BookkeepingApi PUBLIC cxx_std_17)

add_library(BookkeepingProtoApi SHARED
src/BkpProtoClientFactory.cxx
src/grpc/GrpcBkpProtoClient.cxx
src/grpc/services/GrpcRunProtoClient.cxx
src/grpc/services/GrpcDplProcessExecutionProtoClient.cxx
)

target_include_directories(BookkeepingProtoApi
PUBLIC $<INSTALL_INTERFACE:include> # public header once installed
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> # to build it
PRIVATE $<BUILD_INTERFACE:${PROTO_OUT_DIR}> # because of the proto generated files
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> # private headers
)

target_link_libraries(BookkeepingProtoApi
PUBLIC BookkeepingProtos
PUBLIC protobuf::libprotobuf
PRIVATE gRPC::grpc++
)

target_compile_features(BookkeepingProtoApi PUBLIC cxx_std_17)

### EXAMPLES

add_executable(exampleSpecificService example/exampleSpecificServices.cxx)
Expand All @@ -104,14 +83,6 @@ target_link_libraries(exampleSpecificService
PUBLIC BookkeepingApi
)

add_executable(exampleProtoService example/exampleProtoServices.cxx)

target_link_libraries(exampleProtoService
PUBLIC BookkeepingProtoApi
)

target_include_directories(exampleProtoService PRIVATE $<BUILD_INTERFACE:${PROTO_OUT_DIR}>)

# PACKAGE INFO

include(CMakePackageConfigHelpers)
Expand All @@ -134,7 +105,7 @@ install(FILES
DESTINATION "include"
)

install(TARGETS BookkeepingProtos BookkeepingApi BookkeepingProtoApi
install(TARGETS BookkeepingProtos BookkeepingApi
EXPORT BookkeepingApiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
12 changes: 0 additions & 12 deletions cxx-client/cmake/BookkeepingProtoApiConfig.cmake.in

This file was deleted.

69 changes: 0 additions & 69 deletions cxx-client/example/exampleProtoServices.cxx

This file was deleted.

5 changes: 5 additions & 0 deletions cxx-client/example/exampleSpecificServices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ int main(int argc, char** argv)
}

try {
// Test of FLP counters update
auto client = BkpClientFactory::create(argv[1]);
client->flp()->updateReadoutCountersByFlpNameAndRunNumber("FLP-TPC-1", 1, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF);
std::cout << "FLP counters have been successfully updated" << std::endl;


// Test of DPL process execution
client->dplProcessExecution()->registerProcessExecution(106, o2::bkp::DplProcessType::QC_CHECKER, "SECOND-HOSTNAME", "PROCESS-NAME", "", "DEFAUlT");
} catch (std::runtime_error& error) {
std::cerr << "An error occurred: " << error.what() << std::endl;
exit(2);
Expand Down
4 changes: 4 additions & 0 deletions cxx-client/include/BookkeepingApi/BkpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <memory>
#include "FlpServiceClient.h"
#include "DplProcessExecutionClient.h"

namespace o2::bkp::api
{
Expand All @@ -25,6 +26,9 @@ class BkpClient

/// Return the client for FLP service
virtual const std::unique_ptr<FlpServiceClient>& flp() const = 0;

/// Returns the implementation of the DPL process execution service defined in dpl-process-execution.proto
virtual const std::unique_ptr<DplProcessExecutionClient>& dplProcessExecution() const = 0;
};
} // namespace o2::bkp::api

Expand Down
32 changes: 0 additions & 32 deletions cxx-client/include/BookkeepingApi/BkpProtoClient.h

This file was deleted.

22 changes: 0 additions & 22 deletions cxx-client/include/BookkeepingApi/BkpProtoClientFactory.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONPROTOCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONPROTOCLIENT_H
#ifndef CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONCLIENT_H

#include <memory>
#include "dplProcessExecution.pb.h"
#include "DplProcessType.h"

namespace o2::bkp::api::proto
namespace o2::bkp::api
{
class DplProcessExecutionProtoClient
class DplProcessExecutionClient
{
public:
virtual ~DplProcessExecutionProtoClient() = default;

/// Returns the implementation of the DPL process execution service defined in dplProcessExecution.proto
virtual std::shared_ptr<o2::bookkeeping::DplProcessExecution> Create(std::shared_ptr<o2::bookkeeping::DplProcessExecutionCreationRequest> request) = 0;
virtual ~DplProcessExecutionClient() = default;

/// Register the execution fo a DPL process
virtual void registerProcessExecution(
int runNumber,
o2::bookkeeping::DplProcessType type,
o2::bkp::DplProcessType type,
std::string hostname,
std::string deviceId,
std::string args,
Expand All @@ -37,4 +34,4 @@ class DplProcessExecutionProtoClient
};
} // namespace o2::bkp::api::proto

#endif // CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONPROTOCLIENT_H
#endif // CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONCLIENT_H
22 changes: 22 additions & 0 deletions cxx-client/include/BookkeepingApi/DplProcessType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by mboulais on 22/04/24.
//

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSTYPE_H
#define CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSTYPE_H

namespace o2::bkp
{
// Enum values map the proto values, and will map to pb generated file without need for conversion
enum class DplProcessType {
_NULL = 0,
QC_TASK = 1,
QC_CHECKER = 2,
QC_AGGREGATOR = 3,
QC_POSTPROCESSING = 4,
DISPATCHER = 5,
MERGER = 6,
};
} // namespace o2::bkp

#endif // CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSTYPE_H
6 changes: 3 additions & 3 deletions cxx-client/include/BookkeepingApi/FlpServiceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// Created by martin on 12/01/23.
//

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H_
#define CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H_
#ifndef CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H

#include <string>
#include <cstdint>
Expand All @@ -37,4 +37,4 @@ class FlpServiceClient
};
} // namespace o2::bkp::api

#endif // CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H_
#endif // CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H
26 changes: 0 additions & 26 deletions cxx-client/include/BookkeepingApi/RunProtoClient.h

This file was deleted.

10 changes: 0 additions & 10 deletions cxx-client/src/BkpProtoClientFactory.cxx

This file was deleted.

8 changes: 7 additions & 1 deletion cxx-client/src/grpc/GrpcBkpClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "GrpcBkpClient.h"
#include <memory>
#include <grpc++/grpc++.h>
#include "flp.grpc.pb.h"

using grpc::Channel;

Expand All @@ -28,15 +27,22 @@ using std::unique_ptr;
namespace o2::bkp::api::grpc
{
using services::GrpcFlpServiceClient;
using services::GrpcDplProcessExecutionClient;

GrpcBkpClient::GrpcBkpClient(const string& uri)
{
auto channel = CreateChannel(uri, InsecureChannelCredentials());
mFlpClient = make_unique<GrpcFlpServiceClient>(channel);
mDplProcessExecutionClient = make_unique<GrpcDplProcessExecutionClient>(channel);
}

const unique_ptr<FlpServiceClient>& GrpcBkpClient::flp() const
{
return mFlpClient;
}

const std::unique_ptr<DplProcessExecutionClient>& GrpcBkpClient::dplProcessExecution() const
{
return mDplProcessExecutionClient;
}
} // namespace o2::bkp::api::grpc
Loading

0 comments on commit 5c99837

Please sign in to comment.