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

Improve code sharing and dependencies, address code duplication #976

Merged
merged 33 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3a17595
Moved files
uweseimet Nov 9, 2022
88e551f
Updated dependencies
uweseimet Nov 9, 2022
6e1efbd
Dependency update
uweseimet Nov 9, 2022
6cab252
Updated error handling
uweseimet Nov 9, 2022
ed3560d
Unified optional LUN argument handling
uweseimet Nov 9, 2022
d459671
Added comment
uweseimet Nov 9, 2022
22571f4
Removed duplicate constant
uweseimet Nov 9, 2022
17b2816
Renaming
uweseimet Nov 9, 2022
76bfe96
Dependency update
uweseimet Nov 9, 2022
7f3731f
Removed duplicate code
uweseimet Nov 9, 2022
4f0af97
Message update
uweseimet Nov 9, 2022
23ac6c4
Updated error handling
uweseimet Nov 9, 2022
79379d3
Fixed issues
uweseimet Nov 9, 2022
cc433cd
Updated baanner handling
uweseimet Nov 9, 2022
deefa3a
Removed unused code
uweseimet Nov 9, 2022
f5ba98f
Removed commented out code
uweseimet Nov 9, 2022
e8e8998
Extraced method
uweseimet Nov 9, 2022
35597be
Dependency update
uweseimet Nov 9, 2022
fe12d98
Dependency update
uweseimet Nov 9, 2022
b310219
Fixed data type issues
uweseimet Nov 9, 2022
97f97e6
Fixed issue
uweseimet Nov 9, 2022
50034a1
Revert "Fixed issue"
uweseimet Nov 9, 2022
b807d3c
Fixed issue
uweseimet Nov 9, 2022
3d14498
Cleanup
uweseimet Nov 9, 2022
3fb7445
Updated TODO
uweseimet Nov 9, 2022
8c1c426
Updated error handling
uweseimet Nov 9, 2022
566d3e8
Comment update
uweseimet Nov 9, 2022
037fd7e
Comment update
uweseimet Nov 9, 2022
bc16f79
Updated optargs handling and renamed type (it is not a queue anymore)
uweseimet Nov 9, 2022
958f467
Fixed typo
uweseimet Nov 9, 2022
e9f5c99
Updated error handling
uweseimet Nov 9, 2022
be26429
Error message update
uweseimet Nov 9, 2022
c74cc91
Fixed issue
uweseimet Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ rascsi.dat
obj
bin
coverage
/rascsi_interface.pb.cpp
/rascsi_interface.pb.h
generated
.project
.cproject
.settings
85 changes: 43 additions & 42 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,30 @@ RSYSLOG_LOG = /var/log/rascsi.log
USR_LOCAL_BIN = /usr/local/bin
MAN_PAGE_DIR = /usr/local/man/man1
DOC_DIR = ../doc
COVERAGE_DIR = ./coverage
COVERAGE_DIR = coverage
COVERAGE_FILE = rascsi.dat
OS_FILES = ./os_integration
OS_FILES = os_integration

OBJDIR := ./obj/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]')
BINDIR := ./bin/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]')
OBJDIR := obj/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]')
BINDIR := bin/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]')

BIN_ALL = \
$(BINDIR)/$(RASCSI) \
$(BINDIR)/$(RASCTL) \
$(BINDIR)/$(SCSIMON) \
$(BINDIR)/$(RASDUMP)

SRC_PROTOC = \
rascsi_interface.proto
SRC_PROTOC = rascsi_interface.proto

SRC_GENERATED = $(GENERATED_DIR)/rascsi_interface.pb.cpp

SRC_PROTOBUF = \
rascsi_interface.pb.cpp
shared/protobuf_util.cpp \
shared/protobuf_serializer.cpp

SRC_SHARED = \
rascsi_version.cpp \
rasutil.cpp \
protobuf_util.cpp \
protobuf_serializer.cpp
shared/rascsi_version.cpp \
shared/rasutil.cpp

SRC_RASCSI_CORE = $(shell find ./rascsi -name '*.cpp')
SRC_RASCSI_CORE += $(shell find ./controllers -name '*.cpp')
Expand All @@ -98,28 +98,24 @@ SRC_RASCSI_CORE += $(shell find ./hal -name '*.cpp')

SRC_RASCSI = rascsi.cpp

SRC_SCSIMON = \
scsimon.cpp \
rascsi_version.cpp
SRC_SCSIMON = scsimon.cpp
SRC_SCSIMON += $(shell find ./monitor -name '*.cpp')
SRC_SCSIMON += $(shell find ./hal -name '*.cpp')

SRC_RASCTL_CORE = $(shell find ./rasctl -name '*.cpp')

SRC_RASCTL = rasctl.cpp

SRC_RASDUMP = \
rasdump.cpp \
rascsi_version.cpp
SRC_RASDUMP = rasdump.cpp
SRC_RASDUMP += $(shell find ./rasdump -name '*.cpp')
SRC_RASDUMP += $(shell find ./hal -name '*.cpp')

SRC_RASCSI_TEST = $(shell find ./test -name '*.cpp')
SRC_RASCSI_TEST += $(shell find ./rasdump -name '*.cpp')
SRC_RASCSI_TEST += $(shell find ./monitor -name '*.cpp')

vpath %.h ./ ./controllers ./devices ./monitor ./hal ./rascsi ./rasctl ./rasdump
vpath %.cpp ./ ./controllers ./devices ./monitor ./hal ./rascsi ./rasctl ./rasdump ./test
vpath %.h ./ ./shared ./controllers ./devices ./monitor ./hal ./rascsi ./rasctl ./rasdump
vpath %.cpp ./ ./shared ./controllers ./devices ./monitor ./hal ./rascsi ./rasctl ./rasdump ./test
vpath %.o ./$(OBJDIR)
vpath ./$(BINDIR)

Expand All @@ -133,26 +129,31 @@ OBJ_SCSIMON := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIMON:%.cpp=%.o)))
OBJ_RASCSI_TEST := $(addprefix $(OBJDIR)/,$(notdir $(SRC_RASCSI_TEST:%.cpp=%.o)))
OBJ_SHARED := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SHARED:%.cpp=%.o)))
OBJ_PROTOBUF := $(addprefix $(OBJDIR)/,$(notdir $(SRC_PROTOBUF:%.cpp=%.o)))
OBJ_GENERATED := $(addprefix $(OBJDIR)/,$(notdir $(SRC_GENERATED:%.cpp=%.o)))

GEN_PROTOBUF := $(SRC_PROTOBUF) rascsi_interface.pb.h
GENERATED_DIR := generated


# The following will include all of the auto-generated dependency files (*.d)
# if they exist. This will trigger a rebuild of a source file if a header changes
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_RASCSI_CORE) $(OBJ_RASCTL_CORE) $(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_SCSIMON) $(OBJ_RASCSI_TEST))
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_RASCSI_CORE) $(OBJ_RASCTL_CORE) $(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_RASDUMP) $(OBJ_SCSIMON) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_RASCSI_TEST))
-include $(ALL_DEPS)

$(OBJDIR) $(BINDIR):
echo "-- Creating directory $@"
@echo "-- Creating directory $@"
mkdir -p $@

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

$(SRC_PROTOBUF): $(SRC_PROTOC)
echo "-- Generating protobuf-based source files"
protoc --cpp_out=. $(SRC_PROTOC)
mv rascsi_interface.pb.cc $@
$(SRC_GENERATED) : $(SRC_PROTOC)
@echo "-- Generating protobuf-based source files"
mkdir -p $(GENERATED_DIR)
protoc --cpp_out=$(GENERATED_DIR) $(SRC_PROTOC)
mv $(GENERATED_DIR)/rascsi_interface.pb.cc $@

$(OBJ_GENERATED) : $(SRC_GENERATED)
$(CXX) $(CXXFLAGS) -c $< -o $@

## Build Targets:
## all : Rebuild all of the executable files and re-generate
Expand Down Expand Up @@ -180,37 +181,37 @@ lcov: test

docs: $(DOC_DIR)/rascsi_man_page.txt $(DOC_DIR)/rasctl_man_page.txt $(DOC_DIR)/scsimon_man_page.txt $(DOC_DIR)/rasdump_man_page.txt

$(SRC_SHARED) $(SRC_RASCSI_CORE) $(SRC_RASCTL_CORE): $(OBJ_PROTOBUF)
$(SRC_RASCSI_CORE) $(SRC_RASCTL_CORE) : $(OBJ_GENERATED)

$(BINDIR)/$(RASCSI): $(SRC_PROTOBUF) $(OBJ_RASCSI_CORE) $(OBJ_RASCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCSI_CORE) $(OBJ_RASCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) -lpthread -lpcap -lprotobuf -lstdc++fs
$(BINDIR)/$(RASCSI): $(SRC_GENERATED) $(OBJ_RASCSI_CORE) $(OBJ_RASCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCSI_CORE) $(OBJ_RASCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs

$(BINDIR)/$(RASCTL): $(SRC_PROTOBUF) $(OBJ_RASCTL_CORE) $(OBJ_RASCTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCTL_CORE) $(OBJ_RASCTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) -lpthread -lprotobuf
$(BINDIR)/$(RASCTL): $(SRC_GENERATED) $(OBJ_RASCTL_CORE) $(OBJ_RASCTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCTL_CORE) $(OBJ_RASCTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lprotobuf

$(BINDIR)/$(RASDUMP): $(OBJ_RASDUMP) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASDUMP)
$(BINDIR)/$(RASDUMP): $(OBJ_RASDUMP) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASDUMP) $(OBJ_SHARED)

$(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSIMON) -lpthread
$(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSIMON) $(OBJ_SHARED)

$(BINDIR)/$(RASCSI_TEST): $(SRC_PROTOBUF) $(OBJ_RASCSI_CORE) $(OBJ_RASCTL_CORE) $(OBJ_RASCSI_TEST) $(OBJ_RASCTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCSI_CORE) $(OBJ_RASCTL_CORE) $(OBJ_RASCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) -lpthread -lpcap -lprotobuf -lstdc++fs -lgmock -lgtest
$(BINDIR)/$(RASCSI_TEST): $(SRC_GENERATED) $(OBJ_RASCSI_CORE) $(OBJ_RASCTL_CORE) $(OBJ_RASCSI_TEST) $(OBJ_RASCTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCSI_CORE) $(OBJ_RASCTL_CORE) $(OBJ_RASCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs -lgmock -lgtest


# Phony rules for building individual utilities
.PHONY: $(RASCSI) $(RASCTL) $(RASDUMP) $(SCSIMON)
$(RASCSI) : $(BINDIR)/$(RASCSI)
$(RASCTL) : $(BINDIR)/$(RASCTL)
.PHONY: $(RASCSI) $(RASCTL) $(RASDUMP) $(SCSIMON) $(RASCSI_TEST)
$(RASCSI) : $(BINDIR)/$(RASCSI)
$(RASCTL) : $(BINDIR)/$(RASCTL)
$(RASDUMP) : $(BINDIR)/$(RASDUMP)
$(SCSIMON) : $(BINDIR)/$(SCSIMON)

$(RASCSI_TEST): $(BINDIR)/$(RASCSI_TEST)

## clean : Remove all of the object files, intermediate
## compiler files and executable files
.PHONY: clean
clean:
rm -rf $(OBJDIR) $(BINDIR) $(GEN_PROTOBUF) $(COVERAGE_DIR) $(COVERAGE_FILE)
rm -rf $(OBJDIR) $(BINDIR) $(GENERATED_DIR) $(COVERAGE_DIR) $(COVERAGE_FILE)

## install : Copies all of the man pages to the correct location
## Copies the binaries to a global install location
Expand Down
4 changes: 2 additions & 2 deletions cpp/controllers/abstract_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "rascsi_exceptions.h"
#include "shared/log.h"
#include "shared/rascsi_exceptions.h"
#include "devices/primary_device.h"
#include "abstract_controller.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/controllers/abstract_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#pragma once

#include "scsi.h"
#include "shared/scsi.h"
#include "hal/bus.h"
#include "phase_handler.h"
#include "controller_manager.h"
Expand Down
2 changes: 1 addition & 1 deletion cpp/controllers/phase_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "scsi.h"
#include "shared/scsi.h"

class PhaseHandler
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/controllers/scsi_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "shared/log.h"
#include "shared/rascsi_exceptions.h"
#include "hal/gpiobus.h"
#include "hal/systimer.h"
#include "rascsi_exceptions.h"
#include "devices/interfaces/byte_writer.h"
#include "devices/mode_page_device.h"
#include "devices/disk.h"
Expand Down
6 changes: 4 additions & 2 deletions cpp/controllers/scsi_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

#pragma once

#include "shared/scsi.h"
#include "controller_manager.h"
#include "abstract_controller.h"
#include "scsi.h"
#include <array>

using namespace std;

class PrimaryDevice;

class ScsiController : public AbstractController
Expand Down Expand Up @@ -46,7 +48,7 @@ class ScsiController : public AbstractController
// ATN message
bool atnmsg;
int msc;
std::array<uint8_t, 256> msb;
array<uint8_t, 256> msb;
};

public:
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/cfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "shared/log.h"
#include "cfilesystem.h"
#include <dirent.h>
#include <iconv.h>
Expand Down
8 changes: 4 additions & 4 deletions cpp/devices/ctapdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
//
//---------------------------------------------------------------------------

#include "shared/log.h"
#include "shared/rasutil.h"
#include "shared/rascsi_exceptions.h"
#include <unistd.h>
#include <poll.h>
#include <arpa/inet.h>
#include "ctapdriver.h"
#include "log.h"
#include "rasutil.h"
#include "rascsi_exceptions.h"
#include <net/if.h>
#include <sys/ioctl.h>
#include <sstream>
Expand Down Expand Up @@ -236,7 +236,7 @@ bool CTapDriver::Init(const unordered_map<string, string>& const_params)
address = inet.substr(0, separatorPos);

int m;
if (!GetAsInt(inet.substr(separatorPos + 1), m) || m < 8 || m > 32) {
if (!GetAsUnsignedInt(inet.substr(separatorPos + 1), m) || m < 8 || m > 32) {
LOGERROR("Invalid CIDR netmask notation '%s'", inet.substr(separatorPos + 1).c_str())

close(m_hTAP);
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
//---------------------------------------------------------------------------

#include "rascsi_version.h"
#include "log.h"
#include "shared/log.h"
#include "shared/rascsi_version.h"
#include "device.h"
#include <cassert>
#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "rascsi_interface.pb.h"
#include "generated/rascsi_interface.pb.h"
#include <unordered_map>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/device_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
//---------------------------------------------------------------------------

#include "shared/rasutil.h"
#include "scsihd.h"
#include "scsihd_nec.h"
#include "scsimo.h"
Expand All @@ -15,7 +16,6 @@
#include "scsi_host_bridge.h"
#include "scsi_daynaport.h"
#include "host_services.h"
#include "rasutil.h"
#include "device_factory.h"
#include <ifaddrs.h>
#include <sys/ioctl.h>
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/device_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include "rascsi_interface.pb.h"
#include "generated/rascsi_interface.pb.h"

using namespace std;
using namespace rascsi_interface;
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "rascsi_exceptions.h"
#include "shared/log.h"
#include "shared/rascsi_exceptions.h"
#include "scsi_command_util.h"
#include "disk.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#pragma once

#include "scsi.h"
#include "shared/scsi.h"
#include "device_factory.h"
#include "disk_track.h"
#include "disk_cache.h"
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/disk_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "shared/log.h"
#include "disk_track.h"
#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/host_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// c) start && load (LOAD): Reboot the Raspberry Pi
//

#include "shared/rascsi_exceptions.h"
#include "controllers/scsi_controller.h"
#include "rascsi_exceptions.h"
#include "scsi_command_util.h"
#include "host_services.h"
#include <algorithm>
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/mode_page_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "rascsi_exceptions.h"
#include "shared/log.h"
#include "shared/rascsi_exceptions.h"
#include "scsi_command_util.h"
#include "mode_page_device.h"
#include <cstddef>
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/primary_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
//---------------------------------------------------------------------------

#include "log.h"
#include "rascsi_exceptions.h"
#include "shared/log.h"
#include "shared/rascsi_exceptions.h"
#include "scsi_command_util.h"
#include "primary_device.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/primary_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#pragma once

#include "scsi.h"
#include "shared/scsi.h"
#include "interfaces/scsi_primary_commands.h"
#include "controllers/abstract_controller.h"
#include "device.h"
Expand Down