-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
294 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
defmodule Zenohex do | ||
@moduledoc """ | ||
Documentation for `Zenohex`. | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
@doc """ | ||
alias Zenohex.Nif | ||
alias Zenohex.Session | ||
|
||
@doc ~S""" | ||
Open a zenoh Session. | ||
## Examples | ||
iex> Zenohex.open!() | ||
""" | ||
@spec open :: NifZenoh.session() | ||
def open do | ||
NifZenoh.zenoh_open() | ||
@spec open! :: Session.t() | ||
def open!() do | ||
Nif.zenoh_open() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,40 @@ | ||
defmodule Zenohex.PullSubscriber do | ||
@moduledoc """ | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
alias Zenohex.Nif | ||
|
||
@type t :: reference() | ||
|
||
@doc """ | ||
Pull data. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> subscriber = Zenohex.Session.declare_pull_subscriber!(session, "key/expression") | ||
iex> Zenohex.PullSubscriber.pull!(subscriber) | ||
:ok | ||
""" | ||
@spec pull!(t()) :: :ok | ||
def pull!(pull_subscriber) do | ||
def pull!(pull_subscriber) when is_reference(pull_subscriber) do | ||
Nif.pull_subscriber_pull(pull_subscriber) | ||
end | ||
|
||
@spec recv_timeout!(t(), non_neg_integer()) :: integer() | float() | binary() | :timeout | ||
def recv_timeout!(pull_subscriber, timeout_us) do | ||
@doc """ | ||
Receive data. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> subscriber = Zenohex.Session.declare_pull_subscriber!(session, "key/expression") | ||
iex> Zenohex.PullSubscriber.recv_timeout!(subscriber, 1000) | ||
:timeout | ||
""" | ||
@spec recv_timeout!(t(), pos_integer()) :: integer() | float() | binary() | :timeout | ||
def recv_timeout!(pull_subscriber, timeout_us) | ||
when is_reference(pull_subscriber) and is_integer(timeout_us) and timeout_us > 0 do | ||
Nif.pull_subscriber_recv_timeout(pull_subscriber, timeout_us) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
defmodule Zenohex.Queryable do | ||
@moduledoc """ | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
@type t :: reference() | ||
@type complete :: boolean() | ||
|
||
defmodule Options do | ||
@moduledoc """ | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
@type t :: %__MODULE__{complete: complete()} | ||
@type complete :: boolean() | ||
defstruct complete: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
defmodule Zenohex.Session do | ||
@moduledoc """ | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
alias Zenohex.Nif | ||
alias Zenohex.Publisher | ||
alias Zenohex.Subscriber | ||
alias Zenohex.Queryable | ||
|
||
@type t :: reference() | ||
|
||
@doc ~S""" | ||
Create a Publisher for the given key expression. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> Zenohex.Session.declare_publisher!(session, "key/expression") | ||
""" | ||
@spec declare_publisher!(t(), String.t(), Publisher.Options.t()) :: Publisher.t() | ||
def declare_publisher!(session, key_expr, opts \\ %Publisher.Options{}) | ||
when is_reference(session) and is_binary(key_expr) and is_struct(opts, Publisher.Options) do | ||
Nif.declare_publisher(session, key_expr, opts) | ||
end | ||
|
||
@doc ~S""" | ||
Create a Subscriber for the given key expression. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> Zenohex.Session.declare_subscriber!(session, "key/expression") | ||
""" | ||
@spec declare_subscriber!(t(), String.t(), Subscriber.Options.t()) :: Subscriber.t() | ||
def declare_subscriber!(session, key_expr, opts \\ %Subscriber.Options{}) | ||
when is_reference(session) and is_binary(key_expr) and is_struct(opts, Subscriber.Options) do | ||
Nif.declare_subscriber(session, key_expr, opts) | ||
end | ||
|
||
@doc ~S""" | ||
Create a PullSubscriber for the given key expression. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> Zenohex.Session.declare_pull_subscriber!(session, "key/expression") | ||
""" | ||
@spec declare_pull_subscriber!(t(), String.t(), Subscriber.Options.t()) :: Subscriber.t() | ||
def declare_pull_subscriber!(session, key_expr, opts \\ %Subscriber.Options{}) | ||
when is_reference(session) and is_binary(key_expr) and is_struct(opts, Subscriber.Options) do | ||
Nif.declare_pull_subscriber(session, key_expr, opts) | ||
end | ||
|
||
@doc ~S""" | ||
Create a Quaryable for the given key expression. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> Zenohex.Session.declare_queryable!(session, "key/expression") | ||
""" | ||
@spec declare_queryable!(t(), String.t(), Queryable.Options.t()) :: Queryable.t() | ||
def declare_queryable!(session, key_expr, opts \\ %Queryable.Options{}) | ||
when is_reference(session) and is_binary(key_expr) and is_struct(opts, Queryable.Options) do | ||
Nif.declare_queryable(session, key_expr, opts) | ||
end | ||
|
||
@doc ~S""" | ||
Put data. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> :ok = Zenohex.Session.put!(session, "key/expression", "value") | ||
iex> :ok = Zenohex.Session.put!(session, "key/expression", 0) | ||
iex> :ok = Zenohex.Session.put!(session, "key/expression", 0.0) | ||
""" | ||
@spec put!(t(), String.t(), binary()) :: :ok | ||
def put!(session, key_expr, value) | ||
when is_reference(session) and is_binary(key_expr) and is_binary(value) do | ||
Nif.session_put_binary(session, key_expr, value) | ||
end | ||
|
||
@spec put!(t(), String.t(), integer()) :: :ok | ||
def put!(session, key_expr, value) | ||
when is_reference(session) and is_binary(key_expr) and is_integer(value) do | ||
Nif.session_put_integer(session, key_expr, value) | ||
end | ||
|
||
@spec put!(t(), String.t(), float()) :: :ok | ||
def put!(session, key_expr, value) | ||
when is_reference(session) and is_binary(key_expr) and is_float(value) do | ||
Nif.session_put_float(session, key_expr, value) | ||
end | ||
|
||
@doc ~S""" | ||
Query data from the matching queryables in the system. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> Zenohex.Session.get_timeout!(session, "key/**", 1000) | ||
:timeout | ||
""" | ||
@spec get_timeout!(t(), String.t(), pos_integer()) :: | ||
binary() | integer() | float() | :timeout | ||
# FIXME 返り値がリストになるケースがあるはずなので、 Nif を含めて見直し修正すること | ||
def get_timeout!(session, selector, timeout_us) | ||
when is_reference(session) and is_binary(selector) and is_integer(timeout_us) and | ||
timeout_us > 0 do | ||
Nif.session_get_timeout(session, selector, timeout_us) | ||
end | ||
|
||
@doc ~S""" | ||
Delete data. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> Zenohex.Session.delete!(session, "key/expression") | ||
:ok | ||
""" | ||
@spec delete!(t(), String.t()) :: :ok | ||
def delete!(session, key_expr) when is_reference(session) and is_binary(key_expr) do | ||
Nif.session_delete(session, key_expr) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
defmodule Zenohex.Subscriber do | ||
@moduledoc """ | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
alias Zenohex.Nif | ||
|
||
@type t :: reference() | ||
@type reliability :: :best_effort | :reliable | ||
@opaque t :: reference() | ||
|
||
defmodule Options do | ||
@moduledoc """ | ||
Documentation for `#{__MODULE__}`. | ||
""" | ||
|
||
@type t :: %__MODULE__{reliability: reliability()} | ||
@type reliability :: :best_effort | :reliable | ||
defstruct reliability: :best_effort | ||
end | ||
|
||
@spec recv_timeout!(t(), non_neg_integer()) :: integer() | float() | binary() | :timeout | ||
def recv_timeout!(subscriber, timeout_us) do | ||
@doc """ | ||
Receive data. | ||
## Examples | ||
iex> session = Zenohex.open!() | ||
iex> subscriber = Zenohex.Session.declare_subscriber!(session, "key/expression") | ||
iex> Zenohex.Subscriber.recv_timeout!(subscriber, 1000) | ||
:timeout | ||
""" | ||
@spec recv_timeout!(t(), pos_integer()) :: integer() | float() | binary() | :timeout | ||
def recv_timeout!(subscriber, timeout_us) | ||
when is_reference(subscriber) and is_integer(timeout_us) and timeout_us > 0 do | ||
Nif.subscriber_recv_timeout(subscriber, timeout_us) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
defmodule Zenohex.NifTest do | ||
use ExUnit.Case | ||
use ExUnit.Case, async: true | ||
|
||
alias Zenohex.Nif | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Zenohex.PublisherTest do | ||
use ExUnit.Case, async: true | ||
doctest Zenohex.Publisher | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Zenohex.PullSubscriberTest do | ||
use ExUnit.Case, async: true | ||
doctest Zenohex.PullSubscriber | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Zenohex.SessionTest do | ||
use ExUnit.Case, async: true | ||
doctest Zenohex.Session | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Zenohex.SubscriberTest do | ||
use ExUnit.Case, async: true | ||
doctest Zenohex.Subscriber | ||
end |
Oops, something went wrong.