Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
b24eb4d7
提交
b24eb4d7
authored
2月 09, 2017
作者:
colm
提交者:
Mike Jerris
3月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9952: Initial rpc application implementation
上级
a9945a68
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
74 行增加
和
65 行删除
+74
-65
blade_rpcproto.c
libs/libblade/src/blade_rpcproto.c
+72
-63
blade_rpcproto.h
libs/libblade/src/include/blade_rpcproto.h
+2
-2
没有找到文件。
libs/libblade/src/blade_rpcproto.c
浏览文件 @
b24eb4d7
...
...
@@ -124,7 +124,7 @@ static void blade_rpc_parse_fqcommand(const char* fscommand, char *namespace, ch
if
(
fscommand
[
i
]
==
'.'
&&
dotfound
==
KS_FALSE
)
{
dotfound
=
KS_TRUE
;
x
=
0
;
x
=
-
1
;
}
else
if
(
dotfound
==
KS_FALSE
)
{
namespace
[
x
]
=
fscommand
[
i
];
...
...
@@ -142,7 +142,6 @@ static void blade_rpc_parse_fqcommand(const char* fscommand, char *namespace, ch
KS_DECLARE
(
ks_status_t
)
blade_rpc_init
(
ks_pool_t
*
pool
)
{
if
(
g_handle
==
NULL
)
{
g_handle
=
ks_pool_alloc
(
pool
,
sizeof
(
blade_rpc_handle_ex_t
));
ks_hash_create
(
&
g_handle
->
namespace_hash
,
...
...
@@ -196,15 +195,16 @@ static blade_rpc_callbackpair_t *blade_rpc_find_callbacks_locked(char *namespace
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
namespace_hash
,
namespace
,
KS_UNLOCKED
);
if
(
n
)
{
char
fqcommand
[
KS_RPCMESSAGE_FQCOMMAND_LENGTH
+
1
];
blade_rpc_make_fqcommand
(
namespace
,
command
,
fqcommand
);
ks_hash_read_lock
(
n
->
method_hash
);
callbacks
=
ks_hash_search
(
n
->
method_hash
,
fqcommand
,
KS_UNLOCKED
);
ks_mutex_lock
(
callbacks
->
lock
);
callbacks
=
ks_hash_search
(
n
->
method_hash
,
command
,
KS_UNLOCKED
);
ks_hash_read_lock
(
n
->
method_hash
);
if
(
callbacks
)
{
ks_mutex_lock
(
callbacks
->
lock
);
}
ks_hash_read_unlock
(
n
->
method_hash
);
}
return
callbacks
;
...
...
@@ -219,9 +219,12 @@ static blade_rpc_callbackpair_t *blade_rpc_find_template_locked(char *name, char
ks_hash_read_lock
(
n
->
method_hash
);
callbacks
=
ks_hash_search
(
n
->
method_hash
,
command
,
KS_UNLOCKED
);
ks_mutex_lock
(
callbacks
->
lock
);
ks_hash_read_lock
(
n
->
method_hash
);
if
(
callbacks
)
{
ks_mutex_lock
(
callbacks
->
lock
);
}
ks_hash_read_unlock
(
n
->
method_hash
);
}
return
callbacks
;
...
...
@@ -245,7 +248,10 @@ static blade_rpc_callbackpair_t *blade_rpc_find_callbacks_locked_fq(char *fqcomm
ks_hash_read_lock
(
n
->
method_hash
);
callbacks
=
ks_hash_search
(
n
->
method_hash
,
fqcommand
,
KS_UNLOCKED
);
ks_mutex_lock
(
callbacks
->
lock
);
if
(
callbacks
)
{
ks_mutex_lock
(
callbacks
->
lock
);
}
ks_hash_read_unlock
(
n
->
method_hash
);
}
...
...
@@ -329,17 +335,21 @@ KS_DECLARE(ks_status_t) blade_rpc_declare_namespace(char* namespace, const char*
n
=
ks_pool_alloc
(
g_handle
->
pool
,
sizeof
(
blade_rpc_namespace_t
)
+
strlen
(
namespace
)
+
1
);
strncpy
(
n
->
name
,
namespace
,
KS_RPCMESSAGE_NAMESPACE_LENGTH
);
strncpy
(
n
->
version
,
version
,
KS_RPCMESSAGE_VERSION_LENGTH
);
ks_hash_create
(
&
n
->
method_hash
,
KS_HASH_MODE_CASE_SENSITIVE
,
KS_HASH_FLAG_RWLOCK
+
KS_HASH_FLAG_DUP_CHECK
+
KS_HASH_FLAG_FREE_VALUE
,
g_handle
->
pool
);
ks_hash_insert
(
g_handle
->
namespace_hash
,
n
->
name
,
n
);
}
ks_hash_write_unlock
(
g_handle
->
namespace_hash
);
ks_log
(
KS_LOG_DEBUG
,
"Setting message namespace value %s, version %s"
,
namespace
,
version
);
ks_log
(
KS_LOG_DEBUG
,
"Setting message namespace value %s, version %s
\n
"
,
namespace
,
version
);
return
KS_STATUS_SUCCESS
;
}
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
namespace_
function
(
char
*
namespace
,
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_function
(
char
*
namespace
,
char
*
command
,
jrpc_func_t
func
,
jrpc_func_t
respfunc
)
...
...
@@ -355,11 +365,11 @@ KS_DECLARE(ks_status_t)blade_rpc_register_namespace_function(char *namespace,
char
fqcommand
[
KS_RPCMESSAGE_FQCOMMAND_LENGTH
];
memset
(
fqcommand
,
0
,
sizeof
(
fqcommand
));
strcpy
(
fqcommand
,
namespace
);
strcpy
(
fqcommand
,
"."
);
//
strcpy(fqcommand, namespace);
//
strcpy(fqcommand, ".");
strcat
(
fqcommand
,
command
);
int
lkey
=
strlen
(
fq
command
)
+
1
;
int
lkey
=
strlen
(
command
)
+
1
;
if
(
lkey
<
16
)
{
lkey
=
16
;
...
...
@@ -409,15 +419,19 @@ KS_DECLARE(ks_status_t)blade_rpc_register_namespace_function(char *namespace,
}
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
prefix
_request_function
(
char
*
namespace
,
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
custom
_request_function
(
char
*
namespace
,
char
*
command
,
jrpc_func_t
prefix_func
,
jrpc_func_t
postfix_func
)
{
ks_status_t
s
=
KS_STATUS_FAIL
;
char
fqcommand
[
KS_RPCMESSAGE_FQCOMMAND_LENGTH
];
memset
(
fqcommand
,
0
,
sizeof
(
fqcommand
));
strcat
(
fqcommand
,
command
);
ks_hash_write_lock
(
g_handle
->
namespace_hash
);
blade_rpc_callbackpair_t
*
callbacks
=
blade_rpc_find_callbacks_locked
(
namespace
,
command
);
blade_rpc_callbackpair_t
*
callbacks
=
blade_rpc_find_callbacks_locked
(
namespace
,
fq
command
);
if
(
callbacks
)
{
...
...
@@ -436,15 +450,19 @@ KS_DECLARE(ks_status_t)blade_rpc_register_prefix_request_function(char *namespac
return
s
;
}
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
prefix
_response_function
(
char
*
namespace
,
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
custom
_response_function
(
char
*
namespace
,
char
*
command
,
jrpc_func_t
prefix_func
,
jrpc_func_t
postfix_func
)
{
ks_status_t
s
=
KS_STATUS_FAIL
;
char
fqcommand
[
KS_RPCMESSAGE_FQCOMMAND_LENGTH
];
memset
(
fqcommand
,
0
,
sizeof
(
fqcommand
));
strcat
(
fqcommand
,
command
);
ks_hash_write_lock
(
g_handle
->
namespace_hash
);
blade_rpc_callbackpair_t
*
callbacks
=
blade_rpc_find_callbacks_locked
(
namespace
,
command
);
blade_rpc_callbackpair_t
*
callbacks
=
blade_rpc_find_callbacks_locked
(
namespace
,
fq
command
);
if
(
callbacks
)
{
...
...
@@ -465,10 +483,13 @@ KS_DECLARE(ks_status_t)blade_rpc_register_prefix_response_function(char* namespa
KS_DECLARE
(
void
)
blade_rpc_remove_namespace
(
char
*
namespace
)
{
char
nskey
[
KS_RPCMESSAGE_NAMESPACE_LENGTH
];
memset
(
nskey
,
0
,
sizeof
(
nskey
));
strcat
(
nskey
,
namespace
);
ks_hash_write_lock
(
g_handle
->
namespace_hash
);
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
namespace_hash
,
n
amespace
,
KS_UNLOCKED
);
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
namespace_hash
,
n
skey
,
KS_UNLOCKED
);
ks_hash_iterator_t
*
it
=
ks_hash_first
(
n
->
method_hash
,
KS_HASH_FLAG_RWLOCK
);
...
...
@@ -504,19 +525,28 @@ KS_DECLARE(void) blade_rpc_remove_namespace(char* namespace)
KS_DECLARE
(
ks_status_t
)
blade_rpc_declare_template
(
char
*
templatename
,
const
char
*
version
)
{
char
nskey
[
KS_RPCMESSAGE_NAMESPACE_LENGTH
];
memset
(
nskey
,
0
,
sizeof
(
nskey
));
strcat
(
nskey
,
templatename
);
/* find/insert to namespace hash as needed */
ks_hash_write_lock
(
g_handle
->
template_hash
);
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
template_hash
,
templatename
,
KS_UNLOCKED
);
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
template_hash
,
nskey
,
KS_UNLOCKED
);
if
(
n
==
NULL
)
{
n
=
ks_pool_alloc
(
g_handle
->
pool
,
sizeof
(
blade_rpc_namespace_t
)
+
strlen
(
templatename
)
+
1
);
strncpy
(
n
->
name
,
templatename
,
KS_RPCMESSAGE_NAMESPACE_LENGTH
);
strncpy
(
n
->
version
,
version
,
KS_RPCMESSAGE_VERSION_LENGTH
);
ks_hash_create
(
&
n
->
method_hash
,
KS_HASH_MODE_CASE_SENSITIVE
,
KS_HASH_FLAG_RWLOCK
+
KS_HASH_FLAG_DUP_CHECK
+
KS_HASH_FLAG_FREE_VALUE
,
g_handle
->
pool
);
ks_hash_insert
(
g_handle
->
template_hash
,
n
->
name
,
n
);
}
ks_hash_write_unlock
(
g_handle
->
template_hash
);
ks_log
(
KS_LOG_DEBUG
,
"Declaring application template namespace %s, version %s"
,
templatename
,
version
);
ks_log
(
KS_LOG_DEBUG
,
"Declaring application template namespace %s, version %s
\n
"
,
templatename
,
version
);
return
KS_STATUS_SUCCESS
;
}
...
...
@@ -526,11 +556,21 @@ KS_DECLARE(ks_status_t)blade_rpc_register_template_function(char *name,
jrpc_func_t
func
,
jrpc_func_t
respfunc
)
{
(
void
)
blade_rpc_find_template_locked
;
//remove
if
(
!
func
&&
!
respfunc
)
{
return
KS_STATUS_FAIL
;
}
int
lkey
=
strlen
(
command
)
+
1
;
char
nskey
[
KS_RPCMESSAGE_NAMESPACE_LENGTH
];
memset
(
nskey
,
0
,
sizeof
(
nskey
));
strcat
(
nskey
,
name
);
char
fqcommand
[
KS_RPCMESSAGE_FQCOMMAND_LENGTH
];
memset
(
fqcommand
,
0
,
sizeof
(
fqcommand
));
strcat
(
fqcommand
,
command
);
int
lkey
=
strlen
(
fqcommand
)
+
1
;
if
(
lkey
<
16
)
{
lkey
=
16
;
...
...
@@ -538,7 +578,7 @@ KS_DECLARE(ks_status_t)blade_rpc_register_template_function(char *name,
ks_hash_read_lock
(
g_handle
->
template_hash
);
/* lock template hash */
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
template_hash
,
n
ame
,
KS_UNLOCKED
);
blade_rpc_namespace_t
*
n
=
ks_hash_search
(
g_handle
->
template_hash
,
n
skey
,
KS_UNLOCKED
);
if
(
n
==
NULL
)
{
ks_hash_read_unlock
(
g_handle
->
template_hash
);
...
...
@@ -546,7 +586,9 @@ KS_DECLARE(ks_status_t)blade_rpc_register_template_function(char *name,
return
KS_STATUS_FAIL
;
}
blade_rpc_callbackpair_t
*
callbacks
=
blade_rpc_find_template_locked
(
name
,
command
);
ks_hash_read_lock
(
n
->
method_hash
);
blade_rpc_callbackpair_t
*
callbacks
=
ks_hash_search
(
n
->
method_hash
,
fqcommand
,
KS_UNLOCKED
);
ks_hash_read_unlock
(
n
->
method_hash
);
/* just ignore attempt to re register callbacks */
/* as the template may already be in use leading to confusion */
...
...
@@ -616,43 +658,6 @@ KS_DECLARE(ks_status_t)blade_rpc_inherit_template(char *namespace, char* templat
ks_hash_iterator_t
*
it
=
ks_hash_first
(
n
->
method_hash
,
KS_HASH_FLAG_RWLOCK
);
ks_hash_iterator_t
*
itfirst
=
it
;
/* first check that there are no name conflicts */
while
(
it
)
{
const
void
*
key
;
void
*
value
;
ks_ssize_t
len
=
strlen
(
key
);
ks_hash_this
(
it
,
&
key
,
&
len
,
&
value
);
blade_rpc_callbackpair_t
*
t_callback
=
(
blade_rpc_callbackpair_t
*
)
value
;
ks_mutex_lock
(
t_callback
->
lock
);
char
fqcommand
[
KS_RPCMESSAGE_FQCOMMAND_LENGTH
+
1
];
blade_rpc_make_fqcommand
(
namespace
,
t_callback
->
command
,
fqcommand
);
blade_rpc_callbackpair_t
*
ns_callbacks
=
ks_hash_search
(
ns
->
method_hash
,
fqcommand
,
KS_UNLOCKED
);
if
(
ns_callbacks
)
{
/* if something already registered for this function kick the entire inherit */
ks_hash_read_unlock
(
g_handle
->
template_hash
);
ks_hash_read_unlock
(
g_handle
->
namespace_hash
);
ks_hash_read_unlock
(
ns
->
method_hash
);
ks_mutex_unlock
(
t_callback
->
lock
);
ks_log
(
KS_LOG_ERROR
,
"Implementing template %s in namespace %s rejected. Command %s is ambiguous
\n
"
,
template
,
namespace
,
t_callback
->
command
);
return
KS_STATUS_FAIL
;
}
ks_mutex_unlock
(
t_callback
->
lock
);
it
=
ks_hash_next
(
&
it
);
}
/* ok - if we have got this far then the inherit is problem free */
it
=
itfirst
;
while
(
it
)
{
const
void
*
key
;
...
...
@@ -669,7 +674,10 @@ KS_DECLARE(ks_status_t)blade_rpc_inherit_template(char *namespace, char* templat
blade_rpc_callbackpair_t
*
callbacks
=
(
blade_rpc_callbackpair_t
*
)
ks_pool_alloc
(
g_handle
->
pool
,
lkey
+
sizeof
(
blade_rpc_callbackpair_t
));
strcpy
(
callbacks
->
command
,
t_callback
->
command
);
strcat
(
callbacks
->
command
,
template
);
strcat
(
callbacks
->
command
,
"."
);
strcat
(
callbacks
->
command
,
t_callback
->
command
);
callbacks
->
command_length
=
lkey
;
callbacks
->
request_func
=
t_callback
->
request_func
;
callbacks
->
response_func
=
t_callback
->
response_func
;
...
...
@@ -731,6 +739,7 @@ KS_DECLARE(ks_status_t) blade_rpc_write_json(cJSON* json)
if
(
data
)
{
ks_log
(
KS_LOG_DEBUG
,
"%s
\n
"
,
data
);
//return blade_rpc_write_data(sessionid, data, strlen(data));
return
KS_STATUS_SUCCESS
;
}
ks_log
(
KS_LOG_ERROR
,
"Unable to parse json
\n
"
);
return
KS_STATUS_FAIL
;
...
...
libs/libblade/src/include/blade_rpcproto.h
浏览文件 @
b24eb4d7
...
...
@@ -76,11 +76,11 @@ KS_DECLARE(ks_status_t) blade_rpc_register_function(char* namespace,
char
*
command
,
jrpc_func_t
func
,
jrpc_func_t
respfunc
);
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
prefix
_request_function
(
char
*
namespace
,
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
custom
_request_function
(
char
*
namespace
,
char
*
command
,
jrpc_func_t
prefix_func
,
jrpc_func_t
postfix_func
);
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
prefix
_response_function
(
char
*
namespace
,
KS_DECLARE
(
ks_status_t
)
blade_rpc_register_
custom
_response_function
(
char
*
namespace
,
char
*
command
,
jrpc_func_t
prefix_func
,
jrpc_func_t
postfix_func
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论