Skip to content

Commit

Permalink
Merge pull request #41 from NaturalSelect/master
Browse files Browse the repository at this point in the history
Refacor project and add interfaces
  • Loading branch information
NaturalSelect authored Dec 30, 2022
2 parents 34fcd93 + 2dc1db9 commit 43970c5
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 421 deletions.
47 changes: 35 additions & 12 deletions .github/workflows/cmake.yml → .github/workflows/AutoTest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake
name: AutoTest

on: [push]

Expand All @@ -7,7 +7,7 @@ env:
BUILD_TYPE: Debug

jobs:
build:
build-ubuntu:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
Expand All @@ -16,31 +16,54 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Get latest CMake and Ninja
uses: lukka/get-cmake@latest
with:
cmakeVersion: latest
ninjaVersion: latest

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -C $BUILD_TYPE -VV
build-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Get latest CMake and Ninja
uses: lukka/get-cmake@latest
with:
cmakeVersion: latest
ninjaVersion: latest

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE -VV
2 changes: 1 addition & 1 deletion include/sharpen/Broadcaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace sharpen
this->actors_.rehash(sz);
while (begin != end)
{
std::uint64_t id{begin->GetId()};
std::uint64_t id{(*begin)->GetId()};
this->actors_.emplace(id,std::move(*begin));
++begin;
}
Expand Down
6 changes: 3 additions & 3 deletions include/sharpen/IMailReceiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace sharpen
using Self = sharpen::IMailReceiver;
protected:

virtual void NviReceiveMail(sharpen::Mail mail,std::uint64_t actorId) = 0;
virtual void NviReceive(sharpen::Mail mail,std::uint64_t actorId) = 0;
public:

IMailReceiver() noexcept = default;
Expand All @@ -36,10 +36,10 @@ namespace sharpen
return *this;
}

inline void ReceiveMail(sharpen::Mail mail,std::uint64_t actorId)
inline void Receive(sharpen::Mail mail,std::uint64_t actorId)
{
assert(!mail.Header().Empty() || !mail.Content().Empty());
this->NviReceiveMail(std::move(mail),actorId);
this->NviReceive(std::move(mail),actorId);
}
};
}
Expand Down
83 changes: 83 additions & 0 deletions include/sharpen/IQuorum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma once
#ifndef _SHARPEN_IQUORUMMAP_HPP
#define _SHARPEN_IQUORUMMAP_HPP

#include <cassert>

#include "IRemoteActorBuilder.hpp"
#include "Broadcaster.hpp"

namespace sharpen
{
class IQuorum
{
private:
using Self = sharpen::IQuorum;
protected:

virtual sharpen::IRemoteActorBuilder *NviLookup(std::uint64_t actorId) noexcept = 0;

virtual const sharpen::IRemoteActorBuilder *NviLookup(std::uint64_t actorId) const noexcept = 0;

virtual void NviRegister(std::uint64_t actorId,std::unique_ptr<sharpen::IRemoteActorBuilder> builder) = 0;
public:

IQuorum() noexcept = default;

IQuorum(const Self &other) noexcept = default;

IQuorum(Self &&other) noexcept = default;

Self &operator=(const Self &other) noexcept = default;

Self &operator=(Self &&other) noexcept = default;

virtual ~IQuorum() noexcept = default;

inline const Self &Const() const noexcept
{
return *this;
}

virtual std::unique_ptr<sharpen::Broadcaster> CreateBroadcaster() const = 0;

inline sharpen::IRemoteActorBuilder *Lookup(std::uint64_t actorId)
{
return this->NviLookup(actorId);
}

inline const sharpen::IRemoteActorBuilder *Lookup(std::uint64_t actorId) const
{
return this->NviLookup(actorId);
}

inline sharpen::IRemoteActorBuilder &Get(std::uint64_t actorId) noexcept
{
sharpen::IRemoteActorBuilder *builder{this->NviLookup(actorId)};
assert(builder != nullptr);
return *builder;
}

inline const sharpen::IRemoteActorBuilder &Get(std::uint64_t actorId) const noexcept
{
const sharpen::IRemoteActorBuilder *builder{this->NviLookup(actorId)};
assert(builder != nullptr);
return *builder;
}

inline void Register(std::uint64_t actorId,std::unique_ptr<sharpen::IRemoteActorBuilder> builder)
{
assert(builder != nullptr);
this->NviRegister(actorId,std::move(builder));
}

virtual void Remove(std::uint64_t actorId) noexcept = 0;

inline bool Exist(std::uint64_t actorId) const noexcept
{
return this->NviLookup(actorId) != nullptr;
}
};
}

#endif
4 changes: 2 additions & 2 deletions include/sharpen/IRemoteActorBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace sharpen
return *this;
}

virtual std::unique_ptr<sharpen::IRemoteActor> Build() = 0;
virtual std::unique_ptr<sharpen::IRemoteActor> Build() const = 0;

virtual std::shared_ptr<sharpen::IRemoteActor> BuildShared() = 0;
virtual std::shared_ptr<sharpen::IRemoteActor> BuildShared() const = 0;
};
}

Expand Down
4 changes: 2 additions & 2 deletions include/sharpen/IpTcpActorBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ namespace sharpen

void SetParserFactory(std::shared_ptr<sharpen::IMailParserFactory> parserFactory) noexcept;

virtual std::unique_ptr<sharpen::IRemoteActor> Build() override;
virtual std::unique_ptr<sharpen::IRemoteActor> Build() const override;

virtual std::shared_ptr<sharpen::IRemoteActor> BuildShared() override;
virtual std::shared_ptr<sharpen::IRemoteActor> BuildShared() const override;
};
}

Expand Down
4 changes: 2 additions & 2 deletions include/sharpen/Ipv6TcpActorBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ namespace sharpen

void SetParserFactory(std::shared_ptr<sharpen::IMailParserFactory> parserFactory) noexcept;

virtual std::unique_ptr<sharpen::IRemoteActor> Build() override;
virtual std::unique_ptr<sharpen::IRemoteActor> Build() const override;

virtual std::shared_ptr<sharpen::IRemoteActor> BuildShared() override;
virtual std::shared_ptr<sharpen::IRemoteActor> BuildShared() const override;
};
}

Expand Down
Loading

0 comments on commit 43970c5

Please sign in to comment.