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

upgrade to Zenoh V0.6.0-dev.0 #2

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
388baa8
upgrade to Zenoh V0.6.0-dev.0
sanri Sep 17, 2022
1a73c81
create example ZInfo
sanri Sep 20, 2022
2957684
change KeyExpr Dispose()
sanri Sep 20, 2022
c057bac
publish nuget
sanri Sep 20, 2022
2638e09
修复发送中文字符串出现乱码的问题
sanri Nov 4, 2022
c7c69e0
update version number
sanri Nov 7, 2022
8d1fd1c
delete function z_init_logger()
sanri Nov 10, 2022
9cd602c
update example ZInfo
sanri Nov 11, 2022
897d052
20221111
sanri Nov 11, 2022
8f9a249
20221113
sanri Nov 13, 2022
6b3ab72
20221113
sanri Nov 13, 2022
d678ef4
update to zenohc v0.6
sanri Nov 14, 2022
82e12ea
repair "A callback was made on a garbage collected delegate"
sanri Nov 15, 2022
38a5232
update to zenohc v0.7
sanri Dec 19, 2022
01917af
change project directory
sanri Aug 13, 2023
7b3164f
reconstruction
sanri Aug 17, 2023
2bb0b60
ZInfo
sanri Aug 18, 2023
5df2b1e
ZPub
sanri Aug 18, 2023
fc114fa
v0.1.0
sanri Aug 18, 2023
4796709
Optimize memory usage and reduce one copy.
sanri Aug 21, 2023
4ce2b27
ZGet
sanri Aug 22, 2023
e224e4c
update readme.md
sanri Aug 22, 2023
e16ea65
Add command line args parse
sanri Aug 23, 2023
db59fc2
Add queryable
sanri Aug 24, 2023
7465357
update readme
sanri Aug 24, 2023
d4f0acf
update nuget package badges
sanri Aug 24, 2023
eb917d4
change nuget badge color
sanri Aug 24, 2023
9d857f0
add function PutData
sanri Aug 24, 2023
5b39152
fixed an issue where callback functions were recycled early
sanri Nov 21, 2023
0a08c68
20250113
sanri Jan 13, 2025
2657885
20250115
sanri Jan 15, 2025
66361db
20250118
sanri Jan 18, 2025
f5114fb
20250123
sanri Jan 23, 2025
1d9525b
20250124
sanri Jan 24, 2025
97dd260
20250207
sanri Feb 7, 2025
cb52e60
20250208
sanri Feb 8, 2025
08802e7
20250209
sanri Feb 9, 2025
f5438ce
20250210
sanri Feb 10, 2025
222010f
20250211
sanri Feb 11, 2025
aa5ca33
20250211
sanri Feb 11, 2025
065d075
20250212
sanri Feb 12, 2025
700c291
20250222
sanri Feb 22, 2025
9d5311f
20250223
sanri Feb 23, 2025
c26166a
20250224
sanri Feb 24, 2025
9dc9c45
20250225
sanri Feb 25, 2025
ef6eea5
20250226
sanri Feb 26, 2025
2f67dc4
20250227
sanri Feb 27, 2025
79b2e64
20250228
sanri Feb 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

.idea
obj
bin

*.user
package/
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
![zenoh banner](./zenoh-dragon.png)

[![NuGet](https://img.shields.io/nuget/v/Zenoh.svg)](https://www.nuget.org/packages/Zenoh)
[![Gitter](https://badges.gitter.im/atolab/zenoh.svg)](https://gitter.im/atolab/zenoh?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![NuGet](https://img.shields.io/nuget/v/Zenoh-CS?color=blue)](https://www.nuget.org/packages/Zenoh-CS/)
[![License](https://img.shields.io/badge/License-EPL%202.0-blue)](https://choosealicense.com/licenses/epl-2.0/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# Eclipse zenoh C# API
# Zenoh C# API

[Eclipse zenoh](http://zenoh.io) is an extremely efficient and fault-tolerant [Named Data Networking](http://named-data.net) (NDN) protocol
that is able to scale down to extremely constrainded devices and networks.
[中文/chinese readme](https://github.com/sanri/zenoh-csharp/blob/master/README.zh.md)

[Zenoh](http://zenoh.io) is an extremely efficient and fault-tolerant [Named Data Networking](http://named-data.net) (NDN) protocol that is able to scale down to extremely constrainded devices and networks.

The C# API is for pure clients, in other terms does not support peer-to-peer communication,
can be easily tested against a zenoh router running in a Docker container (see https://zenoh.io/docs/getting-started/quick-test/).

The C# API is for pure clients, in other terms does not support peer-to-peer communication, can be easily tested against a zenoh router running in a Docker container (see https://github.com/eclipse-zenoh/zenoh#how-to-test-it).

-------------------------------
## How to install it

Requirements:
- The [zenoh-c](https://github.com/eclipse-zenoh/zenoh-c) library must be installed on your host

The Eclipse zenoh C# library is available on NuGet:
- The [zenoh-c](https://github.com/eclipse-zenoh/zenoh-c) library must be installed on your host
- The zenoh C# library [Zenoh-CS](https://www.nuget.org/packages/Zenoh-CS/) is available on NuGet(Only x64).

### Supported .NET Standards
- .NET 6.0
- .NET 7.0

### Supported CPU arch
- x64
- arm64 (untested)

The library is configured to target the **.NET Standard 2.0** at minimum.
### Mapping between Zenoh-CS and Zenoh-C versions
| Zenoh-C | Zenoh-CS |
|:---------:|:--------:|
| v0.7.2-rc | v0.1.* |


-------------------------------
## How to build it

Requirements:
Requirements:
* The [zenoh-c](https://github.com/eclipse-zenoh/zenoh-c) library must be installed on your host
* A .NET environment

Simply run `dotnet build Zenoh/`.
* A .NET environment. .NET6 or .NET7 [SDK](https://dotnet.microsoft.com/zh-cn/download/dotnet)

Build:
Because some of Zenoh-C data structures are not the same length in `x64` and `arm64`, you need to add the option `-p:Platform=x64` or `-p:Platform=ARM64` when building.
```shell
# x64 CPU
dotnet build Zenoh.csproj -c Release -p:Platform=x64
# arm64 CPU
dotnet build Zenoh.csproj -c Release -p:Platform=ARM64
```

-------------------------------
## Running the Examples

The examples are configured to target **net5.0**.

The simplest way to run some of the examples is to get a Docker image of the **zenoh** network router (see https://github.com/eclipse-zenoh/zenoh#how-to-test-it) and then to run the examples on your machine.

Then, run the zenoh-csharp examples following the instructions in [examples/Zenoh.Net/README.md](https://github.com/eclipse-zenoh/zenoh-csharp/blob/master/examples/Zenoh.Net/README.md)
Build and run the zenoh-csharp examples following the instructions in [examples/README.md](https://github.com/sanri/zenoh-csharp/blob/master/examples/README.md)
55 changes: 55 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
![zenoh banner](./zenoh-dragon.png)

[![NuGet](https://img.shields.io/nuget/v/Zenoh-CS?color=blue)](https://www.nuget.org/packages/Zenoh-CS/)
[![License](https://img.shields.io/badge/License-EPL%202.0-blue)](https://choosealicense.com/licenses/epl-2.0/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# Zenoh C# API

[Zenoh](http://zenoh.io)是一种非常高效和容错的命名数据网络([NDN](http://named-data.net))协议, 能够在非常受限制的设备和网络中运行.

C# API是用于纯客户端的, 可以很容易地针对运行在Docker容器中的zenoh路由器进行测试 (参考[快速测试](https://zenoh.io/docs/getting-started/quick-test/)).

-------------------------------
## 如何安装

需求:
- 库 [zenoh-c](https://github.com/eclipse-zenoh/zenoh-c) 必需被安装在你的主机上.
- Zenoh C# 库 [Zenoh-CS](https://www.nuget.org/packages/Zenoh-CS/) 库在NuGet上可用(只支持x64)

### 支持的 .NET 标准
- .NET 6.0
- .NET 7.0

### 支持的CPU架构
- x64
- arm64 (未测试)

### Zenoh-CS 版本与 Zenoh-C 版本对应关系
| Zenoh-C | Zenoh-CS |
|:---------:|:--------:|
| v0.7.2-rc | v0.1.* |


-------------------------------
## 如何构建

需求:
- 库 [zenoh-c](https://github.com/eclipse-zenoh/zenoh-c) 必需被安装在你的主机上.
- 主机安装有 .NET6 或 .NET7 的 [SDK](https://dotnet.microsoft.com/zh-cn/download/dotnet)

构建命令:
由于Zenoh-C的部分数据结构在 `x64` 与 `arm64` 下长度不一样, 所以构建时需要增加选项 `-p:Platform=x64` 或 `-p:Platform=ARM64`
```shell
# x64 CPU
dotnet build Zenoh.csproj -c Release -p:Platform=x64
# arm64 CPU
dotnet build Zenoh.csproj -c Release -p:Platform=ARM64
```


-------------------------------
## 运行示例

构建和运行示程序, 参考 [examples/README.zh.md](https://github.com/sanri/zenoh-csharp/blob/master/examples/README.zh.md)

191 changes: 191 additions & 0 deletions Zenoh/Channel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using System;
using System.Runtime.InteropServices;

namespace Zenoh;

public enum ChannelType
{
Ring,
Fifo
}

public abstract class Channel : IDisposable
{
internal nint Handle{get; private protected set;}
public ChannelType ChannelType { get; private protected set; }

public abstract void Dispose();

internal void CheckDisposed()
{
if (Handle == nint.Zero)
{
throw new InvalidOperationException("Channel is disposed");
}
}
}

public abstract class ChannelSample: Channel
{
/// <summary>
/// <para>
/// Returns sample from the buffer channel.
/// </para>
/// <para>
/// If there are no more pending replies will block until next sample is received,
/// or until the channel is dropped (normally when there are no more samples to receive).
/// </para>
/// </summary>
/// <param name="sample"></param>
/// <returns>
/// <para>"ZResult.Ok" in case of success.</para>
/// <para>"ZResult.ChannelDisconnected" if channel was dropped (the sample will be set to "null").</para>
/// </returns>
public abstract Result Recv(out Sample? sample);

/// <summary>
/// <para>
/// Returns sample from the buffer channel.
/// </para>
/// <para>
/// If there are no more pending replies will return immediately (with sample set to null).
/// </para>
/// </summary>
/// <param name="sample"></param>
/// <returns>
/// <para>"ZResult.Ok" in case of success.</para>
/// <para>"ZResult.ChannelDisconnected" if channel was dropped (the sample will be set to "null").</para>
/// <para>"ZResult.ChannelNodata" if the channel is still alive, but its buffer is empty (the sample will be set to "null").</para>
/// </returns>
public abstract Result TryRecv(out Sample? sample);

}

public sealed class ChannelSampleRing : ChannelSample
{
// z_owned_ring_handler_sample_t

internal ChannelSampleRing()
{
ChannelType = ChannelType.Ring;
var pChannel = Marshal.AllocHGlobal(Marshal.SizeOf<ZOwnedRingHandlerSample>());
ZenohC.z_internal_ring_handler_sample_null(pChannel);
Handle = pChannel;
}

public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~ChannelSampleRing()=>Dispose(false);

private void Dispose(bool disposing)
{
if (Handle == nint.Zero) return;

ZenohC.z_ring_handler_sample_drop(Handle);
Marshal.FreeHGlobal(Handle);
Handle = nint.Zero;
}

public override Result Recv(out Sample? sample)
{
CheckDisposed();

sample = Sample.CreateOwnedSample();
var pLoanedRingHandlerSample = ZenohC.z_ring_handler_sample_loan(Handle);

var r = ZenohC.z_ring_handler_sample_recv(pLoanedRingHandlerSample, sample.Handle);

if (r == Result.Ok) return Result.Ok;

sample.Dispose();
sample = null;
return r;
}

public override Result TryRecv(out Sample? sample)
{
CheckDisposed();

sample = Sample.CreateOwnedSample();
var pLoanedRingHandlerSample = ZenohC.z_ring_handler_sample_loan(Handle);

var r = ZenohC.z_ring_handler_sample_try_recv(pLoanedRingHandlerSample, sample.Handle);

if (r == Result.Ok) return Result.Ok;

sample.Dispose();
sample = null;
return r;
}
}

public sealed class ChannelSampleFifo : ChannelSample
{
// z_owned_fifo_handler_sample_t

private ChannelSampleFifo()
{
ChannelType = ChannelType.Fifo;
var pChannel = Marshal.AllocHGlobal(Marshal.SizeOf<ZOwnedFifoHandlerSample>());
ZenohC.z_internal_fifo_handler_sample_null(pChannel);
Handle = pChannel;
}

public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~ChannelSampleFifo()=>Dispose(false);

private void Dispose(bool disposing)
{
if (Handle == nint.Zero) return;

ZenohC.z_fifo_handler_sample_drop(Handle);
Marshal.FreeHGlobal(Handle);
Handle = nint.Zero;
}

public override Result Recv(out Sample? sample)
{
CheckDisposed();

sample = Sample.CreateOwnedSample();
var pLoanedFifoHandlerSample = ZenohC.z_fifo_handler_sample_loan(Handle);

var r = ZenohC.z_fifo_handler_sample_recv(pLoanedFifoHandlerSample, sample.Handle);

if (r == Result.Ok) return Result.Ok;

sample.Dispose();
sample = null;
return r;
}

public override Result TryRecv(out Sample? sample)
{
CheckDisposed();

sample = Sample.CreateOwnedSample();
var pLoanedFifoHandlerSample = ZenohC.z_fifo_handler_sample_loan(Handle);

var r = ZenohC.z_fifo_handler_sample_try_recv(pLoanedFifoHandlerSample, sample.Handle);

if (r == Result.Ok) return Result.Ok;

sample.Dispose();
sample = null;
return r;
}
}

public abstract class ChannelReply : Channel
{
}

Loading