Skip to content

Commit

Permalink
Split protobuf_util namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 27, 2025
1 parent 1a90c74 commit 50bd61a
Show file tree
Hide file tree
Showing 35 changed files with 508 additions and 462 deletions.
6 changes: 3 additions & 3 deletions api/s2p_interface.proto → api/target_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2021-2024 Uwe Seimet
// Copyright (C) 2021-2025 Uwe Seimet
//
//---------------------------------------------------------------------------

Expand All @@ -13,8 +13,8 @@
// All operations accept an optional access token, specified by the "token" parameter.
// All operations also accept an optional locale, specified with the "locale" parameter. If there is
// a localized error message it is returned, with English being the fallback language.
// This interface is backwards compatible with PiSCSI. Numbers 100 and higher are used for messages
// and fields not known by PISCSI 23.11.01 and newer.
// This interface is backwards compatible with PiSCSI 24.04.01. Numbers 100 and higher are used for
// messages and fields not supported by PiSCSI.
//

syntax = "proto3";
Expand Down
28 changes: 14 additions & 14 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ DIR_CONTROLLERS := controllers
DIR_DEVICES := devices
DIR_PI := pi

SRC_PROTOC := ../api/s2p_interface.proto
PROTO_TARGET_API := ../api/target_api.proto

SRC_GENERATED = $(GENERATED_DIR)/s2p_interface.pb.cpp
SRC_TARGET_API = $(GENERATED_DIR)/target_api.pb.cpp

SRC_SHARED = $(shell ls -1 $(DIR_SHARED)/*.cpp | grep -v sg_)
ifdef IS_LINUX
Expand Down Expand Up @@ -327,7 +327,7 @@ OBJ_S2PPROTO := $(call obj_files,$(SRC_S2PPROTO))
OBJ_S2PSIMH := $(call obj_files,$(SRC_S2PSIMH))
OBJ_S2PFORMAT := $(call obj_files,$(SRC_S2PFORMAT))
OBJ_S2PTOOL := $(call obj_files,$(SRC_S2PTOOL))
OBJ_GENERATED := $(call obj_files,$(SRC_GENERATED))
OBJ_TARGET_API := $(call obj_files,$(SRC_TARGET_API))
OBJ_S2P_TEST := $(call obj_files,$(SRC_S2P_TEST))

BINARIES = $(INSTALL_BIN)/$(S2PCTL) \
Expand All @@ -352,10 +352,10 @@ ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_S2P_CORE) $(OBJ_S2PCTL_CORE) $(OBJ_S2P) $(O
$(OBJ_SHARED_INITIATOR) $(OBJ_SHARED_COMMAND) $(OBJ_BASE) $(OBJ_BUSES) $(OBJ_CONTROLLERS) $(OBJ_DEVICES) $(OBJ_S2P_TEST))
-include $(ALL_DEPS)

$(OBJ_GENERATED): $(SRC_GENERATED)
$(OBJ_TARGET_API): $(SRC_TARGET_API)
$(LIB_SHARED): $(OBJ_SHARED)
$(LIB_SHARED_PROTOBUF): $(OBJ_GENERATED) $(OBJ_SHARED_PROTOBUF) $(OBJ_SHARED)
$(LIB_SHARED_COMMAND): $(OBJ_SHARED_COMMAND) $(OBJ_GENERATED) $(OBJ_SHARED_PROTOBUF) $(OBJ_SHARED)
$(LIB_SHARED_PROTOBUF): $(OBJ_TARGET_API) $(OBJ_SHARED_PROTOBUF) $(OBJ_SHARED)
$(LIB_SHARED_COMMAND): $(OBJ_SHARED_COMMAND) $(OBJ_TARGET_API) $(OBJ_SHARED_PROTOBUF) $(OBJ_SHARED)
$(LIB_SHARED_INITIATOR): $(OBJ_SHARED_INITIATOR)
$(LIB_BUS): $(OBJ_BUSES) $(OBJ_PI)
$(LIB_CONTROLLER): $(OBJ_CONTROLLERS)
Expand All @@ -367,15 +367,15 @@ $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENERATED_DIR):
$(LIB_SHARED) $(LIB_SHARED_PROTOBUF) $(LIB_SHARED_INITIATOR) $(LIB_SHARED_COMMAND) $(LIB_BUS) $(LIB_CONTROLLER) $(LIB_DEVICE): | $(LIBDIR)
$(AR) rcs $@ $^

$(OBJDIR)/%.o: %.cpp | $(OBJDIR) $(SRC_GENERATED)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR) $(SRC_TARGET_API)
$(CXX) $(CXXFLAGS) -c $< -o $@

$(OBJ_GENERATED): | $(OBJDIR)
$(OBJ_TARGET_API): | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c $< -o $@

$(SRC_GENERATED): $(SRC_PROTOC) | $(GENERATED_DIR)
protoc -I ../api --cpp_out=$(GENERATED_DIR) $(SRC_PROTOC)
mv $(GENERATED_DIR)/s2p_interface.pb.cc $@
$(SRC_TARGET_API): $(PROTO_TARGET_API) | $(GENERATED_DIR)
protoc -I ../api --cpp_out=$(GENERATED_DIR) $(PROTO_TARGET_API)
mv $(GENERATED_DIR)/target_api.pb.cc $@

## Build targets:
## all Buidl all executable files (default target)
Expand All @@ -395,7 +395,7 @@ test: $(BINDIR)/$(S2P_TEST)
coverage: CXXFLAGS += --coverage
coverage: test

$(SRC_S2P_CORE) $(SRC_S2PCTL_CORE) $(SRC_S2PPROTO) $(SRC_S2PTOOL): $(OBJ_GENERATED)
$(SRC_S2P_CORE) $(SRC_S2PCTL_CORE) $(SRC_S2PPROTO) $(SRC_S2PTOOL): $(OBJ_TARGET_API)

$(BINDIR)/$(S2P): $(LIB_SHARED_COMMAND) $(LIB_BUS) $(LIB_CONTROLLER) $(LIB_DEVICE) $(LIB_SHARED) $(OBJ_S2P_CORE) $(OBJ_S2P) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_S2P_CORE) $(OBJ_S2P) $(LIB_SHARED_COMMAND) $(LIB_BUS) $(LIB_CONTROLLER) \
Expand All @@ -410,9 +410,9 @@ $(BINDIR)/$(S2PDUMP): $(OBJ_S2PDUMP) $(LIB_SHARED_INITIATOR) $(LIB_BUS) $(LIB_SH
$(BINDIR)/$(S2PEXEC): $(OBJ_S2PEXEC) $(LIB_SHARED_INITIATOR) $(LIB_BUS) $(LIB_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_S2PEXEC) $(LIB_SHARED_INITIATOR) $(LIB_BUS) $(LIB_SHARED)

$(BINDIR)/$(S2PPROTO): $(OBJ_S2PPROTO) $(LIB_SHARED_INITIATOR) $(LIB_BUS) $(LIB_SHARED) $(OBJ_GENERATED) | $(BINDIR)
$(BINDIR)/$(S2PPROTO): $(OBJ_S2PPROTO) $(LIB_SHARED_INITIATOR) $(LIB_BUS) $(LIB_SHARED) $(OBJ_TARGET_API) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_S2PPROTO) $(LIB_SHARED_INITIATOR) $(LIB_BUS) $(LIB_SHARED) \
$(OBJ_GENERATED) $(ABSEIL_LIBS) -lprotobuf
$(OBJ_TARGET_API) $(ABSEIL_LIBS) -lprotobuf

$(BINDIR)/$(S2PSIMH): $(OBJ_S2PSIMH) $(LIB_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_S2PSIMH) $(LIB_SHARED)
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <spdlog/spdlog.h>
#include "shared/s2p_util.h"
#include "shared/s2p_version.h"
#include "generated/s2p_interface.pb.h"
#include "generated/target_api.pb.h"

using namespace spdlog;
using namespace s2p_interface;
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/device_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <unordered_map>
#include "shared/s2p_util.h"
#include "generated/s2p_interface.pb.h"
#include "generated/target_api.pb.h"

using namespace std;
using namespace s2p_interface;
Expand Down
2 changes: 1 addition & 1 deletion cpp/command/command_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <spdlog/spdlog.h>
#include "command_localizer.h"
#include "generated/s2p_interface.pb.h"
#include "generated/target_api.pb.h"

using namespace std;
using namespace spdlog;
Expand Down
4 changes: 2 additions & 2 deletions cpp/command/command_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "command_image_support.h"
#include "command_response.h"
#include "controllers/controller_factory.h"
#include "protobuf/protobuf_util.h"
#include "protobuf/target_api_util.h"
#include "base/property_handler.h"
#include "shared/s2p_exceptions.h"

using namespace command_response;
using namespace protobuf_util;
using namespace s2p_util;
using namespace target_api_util;

bool CommandDispatcher::DispatchCommand(const CommandContext &context, PbResult &result)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/command/command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include "controllers/controller_factory.h"
#include "devices/disk.h"
#include "devices/scsi_generic.h"
#include "protobuf/protobuf_util.h"
#include "protobuf/target_api_util.h"
#include "shared/s2p_exceptions.h"

using namespace protobuf_util;
using namespace s2p_util;
using namespace target_api_util;

bool CommandExecutor::ProcessDeviceCmd(const CommandContext &context, const PbDeviceDefinition &pb_device, bool dryRun)
{
Expand Down
6 changes: 3 additions & 3 deletions cpp/command/command_image_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2021-2024 Uwe Seimet
// Copyright (C) 2021-2025 Uwe Seimet
//
//---------------------------------------------------------------------------

Expand All @@ -12,10 +12,10 @@
#ifdef BUILD_STORAGE_DEVICE
#include "devices/storage_device.h"
#endif
#include "protobuf/protobuf_util.h"
#include "protobuf/target_api_util.h"

using namespace s2p_util;
using namespace protobuf_util;
using namespace target_api_util;

CommandImageSupport::CommandImageSupport()
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/command/command_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#include "command_image_support.h"
#include "devices/disk.h"
#include "devices/scsi_generic.h"
#include "protobuf/protobuf_util.h"
#include "protobuf/target_api_util.h"
#include "shared/network_util.h"
#include "shared/s2p_version.h"

using namespace network_util;
using namespace protobuf_util;
using namespace s2p_util;
using namespace target_api_util;

namespace
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/command/command_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string>
#include <unordered_set>
#include <spdlog/spdlog.h>
#include "generated/s2p_interface.pb.h"
#include "generated/target_api.pb.h"

class PrimaryDevice;

Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma once

#include "shared/s2p_defs.h"
#include "generated/s2p_interface.pb.h"
#include "generated/target_api.pb.h"

using namespace std;
using namespace s2p_interface;
Expand Down
6 changes: 3 additions & 3 deletions cpp/devices/host_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@
#include "command/command_context.h"
#include "command/command_dispatcher.h"
#include "controllers/abstract_controller.h"
#include "protobuf/protobuf_util.h"
#include "protobuf/target_api_util.h"
#include "shared/s2p_exceptions.h"
#include "page_handler.h"

using namespace std::chrono;
using namespace google::protobuf;
using namespace google::protobuf::util;
using namespace memory_util;
using namespace protobuf_util;
using namespace target_api_util;

HostServices::HostServices(int lun) : PrimaryDevice(SCHS, lun)
{
Expand Down Expand Up @@ -311,7 +311,7 @@ int HostServices::WriteData(cdb_t cdb, data_out_t buf, int, int l)

PbResult result;
CommandContext context(cmd, GetLogger());
context.SetLocale(protobuf_util::GetParam(cmd, "locale"));
context.SetLocale(target_api_util::GetParam(cmd, "locale"));
if (!dispatcher->DispatchCommand(context, result)) {
LogTrace("Failed to execute " + PbOperation_Name(cmd.operation()) + " operation");
throw ScsiException(SenseKey::ABORTED_COMMAND, Asc::INTERNAL_TARGET_FAILURE);
Expand Down
Loading

0 comments on commit 50bd61a

Please sign in to comment.