Code Monkey home page Code Monkey logo

Comments (4)

owent avatar owent commented on August 25, 2024
  1. 文档是不完善。https://github.com/atframework/atsf4g-co 这里有一些例子
  2. 是的。如果仅仅想使用连接通道,不想使用node管理节点关系的话也可以直接用 include/detail/libatbus_channel_export.h
  3. 不可以,因为这个库开发出来的目的是管理进程见通信和进程命令。进程内接收命令行工具的起/停命令或者其他自定义指令必须要有一个接收点。
  4. bus id的多层结构也可以用单层结构表达。这是个树形结构的通信库。不支持网状结构。单元测试里有多层级的测试。但是实际业务中还没有使用过多层级。
  5. https://github.com/atframework/atsf4g-co/tree/sample_solution
  6. id_prefix是为了设置父子关系(因为是树形结构)

from libatbus.

sidyhe avatar sidyhe commented on August 25, 2024

感谢指点, 已经测试成功单层结构的情况. 子节点自动直连的特性非常不错.
从了解到实验再到成功, 历时多天, 遇到了几个问题

  • win32
    在linux下基本一键编译, 而win32只能编译x86, x64会提示找不到库, 必须手动在cmake中指定变量
    也可能是cmake对windows支持还不够好, 各种缺工具和报错
    源码文件必须指定utf-8编码, 把atbus做成库才能避免编译选项传递

  • 依赖库
    核心文件与代码并不多, 但依赖多
    cmake构建时会下载很多库, 但用到的只有libuv, protobuf, tls

  • 代码耦合
    代码之间耦合较重
    提出这点的原因是当时无法编译, 想一个类一个类抄出来, 缺什么依赖补什么, 结果发现它们是一个整体, 囧


最终把atbus做成动态库(静态库不行)独立出去, 并通过纯C++接口的形式使用, 才能解耦

typedef std::uint64_t bus_id_t;

struct IAtBusNodeConf
{
	virtual void release() = 0;

	virtual void set_loop(uv_loop_t* loop) = 0;
	virtual void set_parent(const char* addr) = 0;
	virtual void add_subnet(bus_id_t prefix, std::uint32_t mask) = 0;
};

struct IAtBusNode
{
	virtual void release() = 0;
	virtual void set_handler(IAtBusNodeHandler* handler) = 0;

	virtual int init(bus_id_t id, IAtBusNodeConf* conf) = 0;
	virtual int start() = 0;
	virtual int reset() = 0;
	virtual int shutdown(int reason) = 0;
	virtual int proc(time_t sec, time_t usec) = 0;
	virtual int listen(const char* addr) = 0;
	virtual int connect(const char* addr) = 0;
	virtual int disconnect(bus_id_t id) = 0;
	virtual int send_data(bus_id_t id, int type, const void *buffer, size_t szbuffer) = 0;

	virtual bus_id_t get_id() = 0;
	virtual bool is_endpoint_available(bus_id_t id) = 0;
};

struct IAtBusNodeHandler
{
	virtual int on_shutdown(bus_id_t id, int reason) = 0;
	virtual int on_available(bus_id_t id, int status) = 0;
	virtual int on_log_info(bus_id_t id, const char* logstr) = 0;
	virtual int on_receive(bus_id_t src, int type, const void* buffer, size_t szbuffer) = 0;
};

struct IAtBusRegistry
{
	virtual IAtBusNode* new_node() = 0;
	virtual IAtBusNodeConf* new_node_conf() = 0;
};

IAtBusRegistry* GetAtBusRegistry();

from libatbus.

owent avatar owent commented on August 25, 2024

感谢指点, 已经测试成功单层结构的情况. 子节点自动直连的特性非常不错.
从了解到实验再到成功, 历时多天, 遇到了几个问题

  • win32
    在linux下基本一键编译, 而win32只能编译x86, x64会提示找不到库, 必须手动在cmake中指定变量
    也可能是cmake对windows支持还不够好, 各种缺工具和报错
    源码文件必须指定utf-8编码, 把atbus做成库才能避免编译选项传递
  • 依赖库
    核心文件与代码并不多, 但依赖多
    cmake构建时会下载很多库, 但用到的只有libuv, protobuf, tls
  • 代码耦合
    代码之间耦合较重
    提出这点的原因是当时无法编译, 想一个类一个类抄出来, 缺什么依赖补什么, 结果发现它们是一个整体, 囧

最终把atbus做成动态库(静态库不行)独立出去, 并通过纯C++接口的形式使用, 才能解耦

typedef std::uint64_t bus_id_t;

struct IAtBusNodeConf
{
	virtual void release() = 0;

	virtual void set_loop(uv_loop_t* loop) = 0;
	virtual void set_parent(const char* addr) = 0;
	virtual void add_subnet(bus_id_t prefix, std::uint32_t mask) = 0;
};

struct IAtBusNode
{
	virtual void release() = 0;
	virtual void set_handler(IAtBusNodeHandler* handler) = 0;

	virtual int init(bus_id_t id, IAtBusNodeConf* conf) = 0;
	virtual int start() = 0;
	virtual int reset() = 0;
	virtual int shutdown(int reason) = 0;
	virtual int proc(time_t sec, time_t usec) = 0;
	virtual int listen(const char* addr) = 0;
	virtual int connect(const char* addr) = 0;
	virtual int disconnect(bus_id_t id) = 0;
	virtual int send_data(bus_id_t id, int type, const void *buffer, size_t szbuffer) = 0;

	virtual bus_id_t get_id() = 0;
	virtual bool is_endpoint_available(bus_id_t id) = 0;
};

struct IAtBusNodeHandler
{
	virtual int on_shutdown(bus_id_t id, int reason) = 0;
	virtual int on_available(bus_id_t id, int status) = 0;
	virtual int on_log_info(bus_id_t id, const char* logstr) = 0;
	virtual int on_receive(bus_id_t src, int type, const void* buffer, size_t szbuffer) = 0;
};

struct IAtBusRegistry
{
	virtual IAtBusNode* new_node() = 0;
	virtual IAtBusNodeConf* new_node_conf() = 0;
};

IAtBusRegistry* GetAtBusRegistry();

感谢反馈。首先回答一下问题。

  • win32
    Windows下是可以编译64位库的,CI里的配置就是使用VS2019和VS2018编译64位版本。具体流程可以参考 .github/workflows/main.ymlci/do_ci.ps1
    也基本上可以一键编译。但是有几个特别的地方是:
  1. cmake 里使用VS2019是通过 -A x64 来指定64位库,默认情况下是32位。
  2. 不一定所有的安装方式都能被cmake自动找到工具链,可能需要手动去执行VC目录下的vcvars64.bat来加载工具链环境。这是VC本身的机制。
  3. 如果使用动态库,Windows下搜索dll没有想linux里会强制写完整路径进去,最简单的办法是把 third_party/install/*/bin 里的dll复制到可执行文件同目录。
  • 依赖库
    其实也不依赖tls。其他的都是atframe_utils里的依赖,而且是可以通过编译选项排除掉的。

  • 代码耦合
    其实atbus里主要就两组组件,一组是通信的channel层(提供C Style的接口),一组是node管理(C++ Style的接口)。这两组之间是没有深度耦合的,但是组内耦合是比较重。很多其实是为了达到 "不容易被误用" 的目的做的检查和保护。你提的优化方向思路非常好,但是如果要在atbus里执行的话还需要保持命名风格,考虑不易被误用的场景。把配置结构,回调结构分离。把创建流程工厂化确实是个更好的设计。同时has-a关系比is-a关系有更好的可维护性和兼容性。我们是故意禁用掉virtual的,一方面是因为这个在跨平台的时候,符号可见性上会有一些兼容性问题,另一方面是避免多种继承和RTTI。

from libatbus.

github-actions avatar github-actions commented on August 25, 2024

This issue was marked as stale due to lack of activity.

from libatbus.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.