fi
declare -gxr __ipc_root="/var/lib/toolbox/ipc"
- declare -gxr __ipc_pubsub_root="$__ipc_root/pubsub"
-
declare -gxir __ipc_version=1
- interface "encode" \
- "decode"
+ interface "get_root" \
+ "msg_new" \
+ "msg_get" \
+ "msg_dump" \
+ "msg_get_version" \
+ "msg_get_source" \
+ "msg_get_destination" \
+ "msg_get_user" \
+ "msg_get_timestamp" \
+ "msg_get_data" \
+ "msg_get_topic" \
+ "encode" \
+ "decode" \
+ "endpoint_open" \
+ "endpoint_close" \
+ "endpoint_send" \
+ "endpoint_recv" \
+ "endpoint_subscribe" \
+ "endpoint_publish" \
+ "endpoint_foreach_message" \
+
return 0
}
+ipc_get_root() {
+ echo "$__ipc_root"
+}
+
ipc_encode() {
local decoded="$1"
return 0
}
-_ipc_msg_get() {
+ipc_msg_get() {
local envelope="$1"
local field="$2"
local signature_ok
msg=$(_ipc_get "$envelope" "message")
- version=$(_ipc_msg_get "$envelope" "version")
+ version=$(ipc_msg_get "$envelope" "version")
signer_name=$(ipc_msg_get_signer_name "$envelope")
signer_email=$(ipc_msg_get_signer_email "$envelope")
signer_key=$(ipc_msg_get_signer_key "$envelope")
return 0
}
-_ipc_msg_new() {
+ipc_msg_new() {
local source="$1"
local destination="$2"
local data="$3"
local version
- if ! version=$(_ipc_msg_get "$msg" "version"); then
+ if ! version=$(ipc_msg_get "$msg" "version"); then
return 1
fi
local src
- if ! src=$(_ipc_msg_get "$msg" "source"); then
+ if ! src=$(ipc_msg_get "$msg" "source"); then
return 1
fi
local dst
- if ! dst=$(_ipc_msg_get "$msg" "destination"); then
+ if ! dst=$(ipc_msg_get "$msg" "destination"); then
return 1
fi
local user
- if ! user=$(_ipc_msg_get "$msg" "user"); then
+ if ! user=$(ipc_msg_get "$msg" "user"); then
return 1
fi
local timestamp
- if ! timestamp=$(_ipc_msg_get "$msg" "timestamp"); then
+ if ! timestamp=$(ipc_msg_get "$msg" "timestamp"); then
return 1
fi
local data
local data_raw
- if ! data=$(_ipc_msg_get "$msg" "data"); then
+ if ! data=$(ipc_msg_get "$msg" "data"); then
return 1
fi
local topic
- if ! topic=$(_ipc_msg_get "$msg" "topic"); then
+ if ! topic=$(ipc_msg_get "$msg" "topic"); then
return 1
fi
name="priv/$USER.$self.$$.$(date +"%s").$RANDOM"
fi
- endpoint="$__ipc_root/$name"
+ endpoint="$(ipc_get_root)/$name"
if ! [ -d "$endpoint" ]; then
if ! mkdir -p "$endpoint/subscriptions"; then
local endpoint
local subscription
- endpoint="$__ipc_root/$name"
+ endpoint="$(ipc_get_root)/$name"
if ! queue_destroy "$endpoint/queue"; then
return 1
local queue
- queue="$__ipc_root/$endpoint/queue"
+ queue="$(ipc_get_root)/$endpoint/queue"
if ! queue_put "$queue" "$msg"; then
return 1
local msg
- if ! msg=$(_ipc_msg_new "$source" "$destination" "$data" "$topic"); then
+ if ! msg=$(ipc_msg_new "$source" "$destination" "$data" "$topic"); then
return 1
fi
local queue
local msg
- queue="$__ipc_root/$endpoint/queue"
+ queue="$(ipc_get_root)/$endpoint/queue"
if ! msg=$(queue_get "$queue" "$timeout"); then
return 1
_ipc_endpoint_topic_create() {
local topic="$1"
- if ! mkdir -p "$__ipc_pubsub_root/$topic"; then
+ if ! mkdir -p "$(ipc_get_root)/pubsub/$topic"; then
return 1
fi
local topicdir
local subscription
- topicdir="$__ipc_pubsub_root/$topic"
+ topicdir="$(ipc_get_root)/pubsub/$topic"
subscription="$topicdir/${endpoint//\//_}"
if ! ln -sf "$endpoint" "$subscription"; then
return 1
fi
- if ! ln -sfn "$topicdir" "$__ipc_root/$endpoint/subscriptions/$topic"; then
+ if ! ln -sfn "$topicdir" "$(ipc_get_root)/$endpoint/subscriptions/$topic"; then
rm -f "$subscription"
return 1
fi
fi
echo "$subscriber"
- done < <(find "$__ipc_pubsub_root/$topic" -mindepth 1 -maxdepth 1 -type l)
+ done < <(find "$(ipc_get_root)/pubsub/$topic" -mindepth 1 -maxdepth 1 -type l)
return 0
}
local queue
- queue="$__ipc_root/$endpoint/queue"
+ queue="$(ipc_get_root)/$endpoint/queue"
if ! queue_foreach "$queue" _ipc_endpoint_foreach_message_helper \
"$endpoint" "$func" "${args[@]}"; then
rm -rf "/tmp/test.$$"
}
+Describe "ipc_get_root()"
+ It "returns /var/lib/toolbox/ipc"
+ When call ipc_get_root
+ The stdout should equal "/var/lib/toolbox/ipc"
+ End
+End
+
Describe "Encoding"
It "ipc_encode() outputs base64"
_test_encoding() {
BeforeAll 'setup'
AfterAll 'cleanup'
- It "_ipc_msg_new() outputs base64 encoded data"
+ It "ipc_msg_new() outputs base64 encoded data"
_test_ipc_msg_new_is_base64() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The status should equal 0
End
- It "_ipc_msg_new() outputs an encoded JSON object"
+ It "ipc_msg_new() outputs an encoded JSON object"
_test_ipc_msg_new_is_json() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The stderr should not start with "parse error"
End
- It "_ipc_msg_new() generates valid toolbox.ipc.envelope objects"
+ It "ipc_msg_new() generates valid toolbox.ipc.envelope objects"
_test_ipc_msg_new_json_schema_envelope() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The status should equal 0
End
- It "_ipc_msg_new() messages contain valid toolbox.ipc.message objects"
+ It "ipc_msg_new() messages contain valid toolbox.ipc.message objects"
_test_ipc_msg_new_json_schema_message() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The status should equal 0
End
- It "_ipc_msg_new()/ipc_msg_get_version() sets/gets the correct version"
+ It "ipc_msg_new()/ipc_msg_get_version() sets/gets the correct version"
_test_ipc_msg_new_version() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The stdout should equal "$__ipc_version"
End
- It "_ipc_msg_new()/ipc_msg_get_user() sets/gets the correct user"
+ It "ipc_msg_new()/ipc_msg_get_user() sets/gets the correct user"
_test_ipc_msg_new_user() {
local msg
- msg=$(_ipc_msg_new "from" "to" "data")
+ msg=$(ipc_msg_new "from" "to" "data")
ipc_msg_get_user "$msg"
}
The stdout should equal "$USER"
End
- It "_ipc_msg_new()/ipc_msg_get_timestamp() sets/gets the correct timestamp"
+ It "ipc_msg_new()/ipc_msg_get_timestamp() sets/gets the correct timestamp"
_test_ipc_msg_new_timestamp() {
local before
local after
local timestamp
before=$(date +"%s")
- msg=$(_ipc_msg_new "from" "to" "data")
+ msg=$(ipc_msg_new "from" "to" "data")
after=$(date +"%s")
timestamp=$(ipc_msg_get_timestamp "$msg")
The status should equal 0
End
- It "_ipc_msg_new()/ipc_msg_get_source() sets/gets the correct source"
+ It "ipc_msg_new()/ipc_msg_get_source() sets/gets the correct source"
_test_ipc_msg_new_source() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The stdout should equal "from"
End
- It "_ipc_msg_new()/ipc_msg_get_destination() sets/gets the correct destination"
+ It "ipc_msg_new()/ipc_msg_get_destination() sets/gets the correct destination"
_test_ipc_msg_new_destination() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
The stdout should equal "to"
End
- It "_ipc_msg_new()/ipc_msg_get_data() sets/gets the correct data"
+ It "ipc_msg_new()/ipc_msg_get_data() sets/gets the correct data"
_test_ipc_msg_new_data() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
_test_ipc_msg_get_signer_name() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
_test_ipc_msg_get_signer_email() {
local msg
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi
local msg
local key
- if ! msg=$(_ipc_msg_new "from" "to" "data"); then
+ if ! msg=$(ipc_msg_new "from" "to" "data"); then
return 1
fi