Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
5d779b79
提交
5d779b79
authored
12月 19, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
worker: Remove ugly "static" Channel singleton.
上级
0febb7e8
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
21 行增加
和
19 行删除
+21
-19
Request.h
worker/include/Channel/Request.h
+6
-2
UnixStreamSocket.h
worker/include/Channel/UnixStreamSocket.h
+0
-3
Request.cpp
worker/src/Channel/Request.cpp
+13
-5
UnixStreamSocket.cpp
worker/src/Channel/UnixStreamSocket.cpp
+2
-9
没有找到文件。
worker/include/Channel/Request.h
浏览文件 @
5d779b79
#ifndef MS_CHANNEL_REQUEST_H
#ifndef MS_CHANNEL_REQUEST_H
#define MS_CHANNEL_REQUEST_H
#define MS_CHANNEL_REQUEST_H
#include "Channel/UnixStreamSocket.h"
#include <string>
#include <string>
#include <json/json.h>
#include <json/json.h>
...
@@ -9,19 +10,22 @@ namespace Channel
...
@@ -9,19 +10,22 @@ namespace Channel
class
Request
class
Request
{
{
public
:
public
:
static
Channel
::
Request
*
Factory
(
Json
::
Value
&
msg
);
static
Channel
::
Request
*
Factory
(
Channel
::
UnixStreamSocket
*
channel
,
Json
::
Value
&
msg
);
public
:
public
:
Request
(
std
::
string
&
id
,
std
::
string
&
method
,
Json
::
Value
&
data
);
Request
(
Channel
::
UnixStreamSocket
*
channel
,
std
::
string
&
id
,
std
::
string
&
method
,
Json
::
Value
&
data
);
virtual
~
Request
();
virtual
~
Request
();
void
Reply
(
int
status
);
void
Reply
(
int
status
);
public
:
public
:
// Passed by argument:
// Passed by argument:
Channel
::
UnixStreamSocket
*
channel
=
nullptr
;
std
::
string
id
;
std
::
string
id
;
std
::
string
method
;
std
::
string
method
;
Json
::
Value
data
;
Json
::
Value
data
;
// Others:
bool
replied
=
false
;
};
};
}
}
...
...
worker/include/Channel/UnixStreamSocket.h
浏览文件 @
5d779b79
...
@@ -37,9 +37,6 @@ namespace Channel
...
@@ -37,9 +37,6 @@ namespace Channel
// Others:
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
size_t
msgStart
=
0
;
// Where the latest message starts.
};
};
// Channel singleton.
extern
UnixStreamSocket
*
channel
;
}
}
#endif
#endif
worker/src/Channel/Request.cpp
浏览文件 @
5d779b79
#define MS_CLASS "Channel::Request"
#define MS_CLASS "Channel::Request"
#include "Channel/Request.h"
#include "Channel/Request.h"
#include "Channel/UnixStreamSocket.h"
#include "Logger.h"
#include "Logger.h"
namespace
Channel
namespace
Channel
{
{
/* Static methods. */
/* Static methods. */
Channel
::
Request
*
Request
::
Factory
(
Json
::
Value
&
msg
)
Channel
::
Request
*
Request
::
Factory
(
Channel
::
UnixStreamSocket
*
channel
,
Json
::
Value
&
msg
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -23,12 +22,13 @@ namespace Channel
...
@@ -23,12 +22,13 @@ namespace Channel
std
::
string
id
=
msg
[
"id"
].
asString
();
std
::
string
id
=
msg
[
"id"
].
asString
();
std
::
string
method
=
msg
[
"method"
].
asString
();
std
::
string
method
=
msg
[
"method"
].
asString
();
return
new
Request
(
id
,
method
,
msg
[
"data"
]);
return
new
Request
(
channel
,
id
,
method
,
msg
[
"data"
]);
}
}
/* Instance methods. */
/* Instance methods. */
Request
::
Request
(
std
::
string
&
id
,
std
::
string
&
method
,
Json
::
Value
&
data
)
:
Request
::
Request
(
Channel
::
UnixStreamSocket
*
channel
,
std
::
string
&
id
,
std
::
string
&
method
,
Json
::
Value
&
data
)
:
channel
(
channel
),
id
(
id
),
id
(
id
),
method
(
method
),
method
(
method
),
data
(
data
)
data
(
data
)
...
@@ -45,11 +45,19 @@ namespace Channel
...
@@ -45,11 +45,19 @@ namespace Channel
{
{
MS_TRACE
();
MS_TRACE
();
if
(
this
->
replied
)
{
MS_ERROR
(
"already replied"
);
return
;
}
this
->
replied
=
true
;
Json
::
Value
json
;
Json
::
Value
json
;
json
[
"id"
]
=
this
->
id
;
json
[
"id"
]
=
this
->
id
;
json
[
"status"
]
=
status
;
json
[
"status"
]
=
status
;
Channel
::
channel
->
Send
(
json
);
this
->
channel
->
Send
(
json
);
}
}
}
}
worker/src/Channel/UnixStreamSocket.cpp
浏览文件 @
5d779b79
...
@@ -13,10 +13,6 @@
...
@@ -13,10 +13,6 @@
namespace
Channel
namespace
Channel
{
{
/* Singletons. */
UnixStreamSocket
*
channel
=
nullptr
;
/* Static variables. */
/* Static variables. */
MS_BYTE
UnixStreamSocket
::
writeBuffer
[
MESSAGE_MAX_SIZE
];
MS_BYTE
UnixStreamSocket
::
writeBuffer
[
MESSAGE_MAX_SIZE
];
...
@@ -28,10 +24,6 @@ namespace Channel
...
@@ -28,10 +24,6 @@ namespace Channel
listener
(
listener
)
listener
(
listener
)
{
{
MS_TRACE
();
MS_TRACE
();
// Store a singleton.
MS_ASSERT
(
Channel
::
channel
==
nullptr
,
"Channel singleton already set"
);
Channel
::
channel
=
this
;
}
}
UnixStreamSocket
::~
UnixStreamSocket
()
UnixStreamSocket
::~
UnixStreamSocket
()
...
@@ -163,7 +155,7 @@ namespace Channel
...
@@ -163,7 +155,7 @@ namespace Channel
MS_THROW_ERROR
(
"invalid JSON"
);
MS_THROW_ERROR
(
"invalid JSON"
);
}
}
Channel
::
Request
*
request
=
Request
::
Factory
(
json
);
Channel
::
Request
*
request
=
Request
::
Factory
(
this
,
json
);
if
(
request
)
if
(
request
)
{
{
...
@@ -181,6 +173,7 @@ namespace Channel
...
@@ -181,6 +173,7 @@ namespace Channel
request
->
Reply
(
500
);
request
->
Reply
(
500
);
}
}
// Delete the Request.
delete
request
;
delete
request
;
}
}
else
else
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论