diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8dad48f..18ee10aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -139,12 +139,13 @@ set_target_properties(yaze LINK_FLAGS "${CMAKE_CURRENT_SOURCE_DIR}/yaze.res" ) -# +add_subdirectory(app/delta) add_executable( yaze_delta app/delta/delta.cc app/delta/viewer.cc + app/delta/client.cc app/rom.cc ${YAZE_APP_ASM_SRC} ${YAZE_APP_CORE_SRC} @@ -176,6 +177,7 @@ target_link_libraries( ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES} ${CMAKE_DL_LIBS} + delta-service ImGui ) diff --git a/src/app/delta/CMakeLists.txt b/src/app/delta/CMakeLists.txt new file mode 100644 index 00000000..087dd9f7 --- /dev/null +++ b/src/app/delta/CMakeLists.txt @@ -0,0 +1,32 @@ + +add_library(delta-service delta.proto) +target_link_libraries(delta-service + PUBLIC + protobuf::libprotobuf + gRPC::grpc + gRPC::grpc++ +) + +target_include_directories(delta-service + PUBLIC + ${CMAKE_CURRENT_BINARY_DIR} + ${PROTOBUF_INCLUDE_PATH} +) + +get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) + +# compile the message types +protobuf_generate(TARGET delta-service LANGUAGE cpp) + +# compile the GRPC services +protobuf_generate( + TARGET + delta-service + LANGUAGE + grpc + GENERATE_EXTENSIONS + .grpc.pb.h + .grpc.pb.cc + PLUGIN + "protoc-gen-grpc=${grpc_cpp_plugin_location}" +) \ No newline at end of file diff --git a/src/app/delta/client.cc b/src/app/delta/client.cc new file mode 100644 index 00000000..b90f5e20 --- /dev/null +++ b/src/app/delta/client.cc @@ -0,0 +1,53 @@ +#include "client.h" + +#include +#include +#include +#include +#include + +#include "absl/status/status.h" +#include "src/app/delta/delta.grpc.pb.h" +#include "src/app/delta/delta.pb.h" + +namespace yaze { +namespace app { +namespace delta { + +using grpc::Channel; +using grpc::ClientAsyncResponseReader; +using grpc::ClientContext; +using grpc::CompletionQueue; +using grpc::Server; +using grpc::ServerBuilder; +using grpc::Status; + +void Client::CreateChannel() { + auto channel = grpc::CreateChannel("localhost:50051", + grpc::InsecureChannelCredentials()); + stub_ = ::YazeDelta::NewStub(channel); +} + +absl::Status Client::InitRepo(std::string author_name, + std::string project_name) { + Repository new_repo; + new_repo.set_author_name(author_name); + new_repo.set_project_name(project_name); + + InitRequest request; + request.set_allocated_repo(&new_repo); + + InitResponse response; + Status status = stub_->Init(&rpc_context, request, &response); + + if (!status.ok()) { + std::cerr << status.error_code() << ": " << status.error_message() + << std::endl; + return absl::InternalError(status.error_message()); + } + return absl::OkStatus(); +} + +} // namespace delta +} // namespace app +} // namespace yaze diff --git a/src/app/delta/client.h b/src/app/delta/client.h new file mode 100644 index 00000000..0c5cb0c2 --- /dev/null +++ b/src/app/delta/client.h @@ -0,0 +1,44 @@ +#ifndef YAZE_APP_DELTA_CLIENT_H +#define YAZE_APP_DELTA_CLIENT_H + +#include +#include +#include +#include +#include + +#include + +#include "absl/status/status.h" +#include "src/app/delta/delta.grpc.pb.h" +#include "src/app/delta/delta.pb.h" + + +namespace yaze { +namespace app { +namespace delta { + +using grpc::Channel; +using grpc::ClientAsyncResponseReader; +using grpc::ClientContext; +using grpc::CompletionQueue; +using grpc::Server; +using grpc::ServerBuilder; +using grpc::Status; + +class Client { + public: + void CreateChannel(); + absl::Status InitRepo(std::string author_name, std::string project_name); + + private: + ClientContext rpc_context; + std::vector repos_; + std::unique_ptr stub_; +}; + +} // namespace delta +} // namespace app +} // namespace yaze + +#endif \ No newline at end of file diff --git a/src/app/delta/delta.cc b/src/app/delta/delta.cc index 39e604d1..4a413d67 100644 --- a/src/app/delta/delta.cc +++ b/src/app/delta/delta.cc @@ -18,7 +18,6 @@ int main(int argc, char** argv) { auto entry_status = controller.onEntry(); if (!entry_status.ok()) { - // TODO(@scawful): log the specific error return EXIT_FAILURE; } diff --git a/src/app/delta/delta.proto b/src/app/delta/delta.proto index fc67285d..4ed2fd66 100644 --- a/src/app/delta/delta.proto +++ b/src/app/delta/delta.proto @@ -4,9 +4,13 @@ option cc_enable_arenas = true; service YazeDelta { rpc Init(InitRequest) returns (InitResponse) {} + rpc Clone(CloneRequest) returns (CloneResponse) {} + rpc Push(PushRequest) returns (PushResponse) {} rpc Pull(PullRequest) returns (PullResponse) {} + rpc Sync(stream SyncRequest) returns (stream SyncResponse) {} + rpc CreateBranch(CreateBranchRequest) returns (CreateBranchResponse) {} rpc DeleteBranch(DeleteBranchRequest) returns (DeleteBranchResponse) {} @@ -14,19 +18,55 @@ service YazeDelta { rpc UndoMerge(UndoMergeRequest) returns (UndoMergeResponse) {} } -message InitRequest { - string project_name = 1; - repeated uint16_t bytes = 2; +message Commit { + int64 commit_id = 1; + int64 parent_commit_id = 2; + string author_name = 3; + string message_header = 4; + optional string message_body = 5; + bytes data = 6; + int64 signature = 7; } +message Branch { + string branch_name = 1; + optional string parent_name = 2; + repeated Commit commits = 3; +} + +message Repository { + string project_name = 1; + string author_name = 2; + int64 signature = 3; + optional bool locked = 4; + optional string password = 5; + repeated Branch tree = 6; +} + +message InitRequest { + Repository repo = 1; +} + +message InitResponse { + int32 response = 1; +} + +message CloneRequest {} + +message CloneResponse {} + message PushRequest { - string username = 1; + string author_name = 1; } message PushResponse {} message PullRequest {} message PullResponse {} +message SyncRequest {} + +message SyncResponse {} + message CreateBranchRequest {} message CreateBranchResponse {} diff --git a/src/app/delta/service.cc b/src/app/delta/service.cc new file mode 100644 index 00000000..b88d3f33 --- /dev/null +++ b/src/app/delta/service.cc @@ -0,0 +1,42 @@ +#include "service.h" + +#include +#include +#include +#include +#include + +#include "absl/status/status.h" +#include "src/app/delta/delta.grpc.pb.h" +#include "src/app/delta/delta.pb.h" + +namespace yaze { +namespace app { +namespace delta { + +using grpc::Channel; +using grpc::ClientAsyncResponseReader; +using grpc::ClientContext; +using grpc::CompletionQueue; +using grpc::Server; +using grpc::ServerBuilder; +using grpc::Status; + +Status DeltaService::Init(grpc::ServerContext* context, + const InitRequest* request, InitResponse* reply) { + return Status::OK; +} + +Status DeltaService::Push(grpc::ServerContext* context, + const PushRequest* request, PushResponse* reply) { + return Status::OK; +} + +Status DeltaService::Pull(grpc::ServerContext* context, + const PullRequest* request, PullResponse* reply) { + return Status::OK; +} + +} // namespace delta +} // namespace app +} // namespace yaze diff --git a/src/app/delta/service.h b/src/app/delta/service.h new file mode 100644 index 00000000..1bf1ab35 --- /dev/null +++ b/src/app/delta/service.h @@ -0,0 +1,37 @@ +#ifndef YAZE_APP_DELTA_SERVICE_H +#define YAZE_APP_DELTA_SERVICE_H + +#include +#include +#include +#include +#include + +#include + +#include "absl/status/status.h" +#include "src/app/delta/delta.grpc.pb.h" +#include "src/app/delta/delta.pb.h" + +namespace yaze { +namespace app { +namespace delta { + +class DeltaService final : public ::YazeDelta::Service { + public: + Status Init(grpc::ServerContext* context, const InitRequest* request, + InitResponse* reply) override; + + Status Push(grpc::ServerContext* context, const PushRequest* request, + PushResponse* reply) override; + + Status Pull(grpc::ServerContext* context, const PullRequest* request, + PullResponse* reply) override; + + private: + std::vector repos_; +}; + +} // namespace delta +} // namespace app +} // namespace yaze