Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cmu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李维杰
cmu
Commits
f134760d
Commit
f134760d
authored
Jun 22, 2020
by
李维杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加新请求
parent
ff491e70
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
3 deletions
+61
-3
cmd_processer_client.cc
kcp-client/src/cmd_processer_client.cc
+31
-3
cmd_processer_client.h
kcp-client/src/cmd_processer_client.h
+12
-0
mqtt_request.cc
thirdparty/mqtt/mqtt_request.cc
+17
-0
mqtt_request.h
thirdparty/mqtt/mqtt_request.h
+1
-0
No files found.
kcp-client/src/cmd_processer_client.cc
View file @
f134760d
...
...
@@ -10,6 +10,8 @@ namespace offcn
CmdProcesserClient
::
CmdProcesserClient
()
:
mqtt_wrapper_
(
NULL
)
{
local_id_
=
kLocalID
;
mqtt_wrapper_
=
new
offcn
::
MqttWrapper
(
this
);
}
CmdProcesserClient
::~
CmdProcesserClient
()
...
...
@@ -21,13 +23,22 @@ namespace offcn
}
}
void
CmdProcesserClient
::
SetLocalID
(
std
::
string
id
)
{
local_id_
=
id
;
}
bool
CmdProcesserClient
::
Connect
()
{
return
mqtt_wrapper_
->
ConnectMqttServer
(
kLocalID
);
return
mqtt_wrapper_
->
ConnectMqttServer
(
local_id_
);
}
bool
CmdProcesserClient
::
SubscribeTopic
()
{
return
mqtt_wrapper_
->
SubscribeTopic
(
kLocalID
);
return
mqtt_wrapper_
->
SubscribeTopic
(
local_id_
);
}
bool
CmdProcesserClient
::
SendLocalCandidate
(
std
::
string
tid
,
std
::
string
type
,
std
::
string
candidate
)
{
std
::
string
req
=
MqttRequest
::
Candidate
(
local_id_
,
tid
,
type
,
candidate
);
return
mqtt_wrapper_
->
SendRequest
(
tid
,
req
);
}
/**
...
...
@@ -47,7 +58,7 @@ namespace offcn
printf
(
"subscribe topic success!
\n
"
);
std
::
string
topic
=
kGlobalTopic
;
std
::
string
req
=
MqttRequest
::
JoinRequest
(
kLocalID
);;
std
::
string
req
=
MqttRequest
::
JoinRequest
(
local_id_
);;
mqtt_wrapper_
->
SendRequest
(
topic
,
req
);
}
...
...
@@ -57,6 +68,22 @@ namespace offcn
}
void
CmdProcesserClient
::
OnServerMessageArrived
(
std
::
string
topic
,
std
::
string
message
)
{
std
::
string
path
;
ReqValue
values
;
if
(
!
MqttRequest
::
ParseResponse
(
message
,
path
,
values
))
{
printf
(
"Error : Parse request error
\n
"
);
return
;
}
if
(
path
.
compare
(
"join"
)
==
0
)
{
std
::
string
ids
=
values
[
"ids"
];
std
::
string
result
=
values
[
"result"
];
if
(
ids
.
length
()
>
0
)
{
publisher_list_
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
ids
,
ids
));
}
}
}
}
\ No newline at end of file
kcp-client/src/cmd_processer_client.h
View file @
f134760d
#pragma once
#include "mqtt_wrapper.h"
#include <map>
namespace
offcn
{
...
...
@@ -11,8 +12,13 @@ namespace offcn
~
CmdProcesserClient
();
public
:
void
SetLocalID
(
std
::
string
id
);
bool
Connect
();
bool
SubscribeTopic
();
/**
* @param type offer/answer
*/
bool
SendLocalCandidate
(
std
::
string
tid
,
std
::
string
type
,
std
::
string
candidate
);
public
:
/**
...
...
@@ -26,5 +32,10 @@ namespace offcn
private
:
MqttWrapper
*
mqtt_wrapper_
;
private
:
std
::
map
<
std
::
string
,
std
::
string
>
publisher_list_
;
std
::
map
<
std
::
string
,
std
::
string
>
subscriber_list_
;
private
:
std
::
string
local_id_
;
};
}
\ No newline at end of file
thirdparty/mqtt/mqtt_request.cc
View file @
f134760d
...
...
@@ -115,6 +115,23 @@ namespace offcn
return
true
;
}
bool
MqttRequest
::
ParseResponse
(
std
::
string
&
response
,
std
::
string
&
path
,
ReqValue
&
values
)
{
Json
::
Value
root
;
if
(
!
GetJsonValue
(
response
,
root
))
return
false
;
if
(
!
root
[
"path"
]
||
!
root
[
"fid"
])
return
false
;
path
=
root
[
"path"
].
asString
();
std
::
string
fid
=
root
[
"fid"
].
asString
();
if
(
path
.
compare
(
"join"
)
==
0
)
{
values
[
"ids"
]
=
root
[
"ids"
].
asString
();
values
[
"result"
]
=
root
[
"result"
].
asString
();
}
return
true
;
}
std
::
string
MqttRequest
::
JoinResponse
(
std
::
string
ids
,
std
::
string
result
)
{
...
...
thirdparty/mqtt/mqtt_request.h
View file @
f134760d
...
...
@@ -15,6 +15,7 @@ namespace offcn
static
std
::
string
Candidate
(
std
::
string
local_id
,
std
::
string
remote_id
,
std
::
string
type
,
std
::
string
candidate
);
static
bool
ParseRequest
(
std
::
string
&
req
,
std
::
string
&
path
,
ReqValue
&
values
);
static
bool
ParseResponse
(
std
::
string
&
response
,
std
::
string
&
path
,
ReqValue
&
values
);
static
std
::
string
JoinResponse
(
std
::
string
ids
,
std
::
string
result
);
static
std
::
string
UpdateResponse
(
std
::
string
result
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment