Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
293288a5
Commit
293288a5
authored
Nov 19, 2020
by
Hauke Goldhammer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update qt example to new remote group api
parent
d3480579
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
38 deletions
+45
-38
examples/qtsupport/chatwidget.cpp
examples/qtsupport/chatwidget.cpp
+25
-16
examples/qtsupport/qt_group_chat.cpp
examples/qtsupport/qt_group_chat.cpp
+20
-22
No files found.
examples/qtsupport/chatwidget.cpp
View file @
293288a5
...
...
@@ -27,15 +27,17 @@ ChatWidget::~ChatWidget() {
void
ChatWidget
::
init
(
actor_system
&
system
)
{
super
::
init
(
system
);
set_message_handler
([
=
](
actor_companion
*
self
)
->
message_handler
{
set_message_handler
([
=
](
actor_companion
*
self
)
->
message_handler
{
return
{
[
=
](
join_atom
,
const
group
&
what
)
{
if
(
chatroom_
)
{
self
->
send
(
chatroom_
,
name_
+
" has left the chatroom"
);
self
->
leave
(
chatroom_
);
auto
groups
=
self
->
joined_groups
();
for
(
auto
&&
grp
:
groups
)
{
print
((
"*** leave "
+
to_string
(
grp
)).
c_str
());
self
->
send
(
grp
,
name_
+
" has left the chatroom"
);
self
->
leave
(
grp
);
}
print
((
"*** join "
+
to_string
(
what
)).
c_str
());
self
->
join
(
what
);
print
((
"*** joined "
+
to_string
(
what
)).
c_str
());
chatroom_
=
what
;
self
->
send
(
what
,
name_
+
" has entered the chatroom"
);
},
...
...
@@ -44,9 +46,7 @@ void ChatWidget::init(actor_system& system) {
name_
=
std
::
move
(
name
);
print
(
"*** changed name to "
+
QString
::
fromUtf8
(
name_
.
c_str
()));
},
[
=
](
quit_atom
)
{
quit_and_close
();
},
[
=
](
quit_atom
)
{
quit_and_close
();
},
[
=
](
const
string
&
txt
)
{
// don't print own messages
if
(
self
!=
self
->
current_sender
())
...
...
@@ -55,7 +55,15 @@ void ChatWidget::init(actor_system& system) {
[
=
](
const
group_down_msg
&
gdm
)
{
print
(
"*** chatroom offline: "
+
QString
::
fromUtf8
(
to_string
(
gdm
.
source
).
c_str
()));
},
[
=
](
leave_atom
)
{
auto
groups
=
self
->
joined_groups
();
for
(
auto
&&
grp
:
groups
)
{
std
::
cout
<<
"*** leave "
<<
to_string
(
grp
)
<<
std
::
endl
;
self
->
send
(
grp
,
name_
+
" has left the chatroom"
);
self
->
leave
(
grp
);
}
},
};
});
}
...
...
@@ -68,7 +76,7 @@ void ChatWidget::sendChatMessage() {
if
(
line
.
startsWith
(
'/'
))
{
vector
<
string
>
words
;
split
(
words
,
line
.
midRef
(
1
).
toUtf8
().
constData
(),
is_any_of
(
" "
));
if
(
words
.
size
()
>
1
)
if
(
words
.
size
()
>
1
)
{
if
(
words
.
front
()
==
"join"
&&
words
.
size
()
==
3
)
{
auto
x
=
system
().
groups
().
get
(
words
[
1
],
words
[
2
]);
if
(
!
x
)
...
...
@@ -84,6 +92,7 @@ void ChatWidget::sendChatMessage() {
"/setName <new name>
\n
"
);
return
;
}
}
if
(
name_
.
empty
())
{
print
(
"*** please set a name before sending messages"
);
return
;
...
...
examples/qtsupport/qt_group_chat.cpp
View file @
293288a5
...
...
@@ -33,13 +33,10 @@ using namespace caf;
class
config
:
public
actor_system_config
{
public:
std
::
string
name
;
std
::
string
group_id
;
config
()
{
opt_group
{
custom_options_
,
"global"
}
.
add
(
name
,
"name,n"
,
"set name"
)
.
add
(
group_id
,
"group,g"
,
"join group (format: <module>:<id>)
"
);
.
add
<
std
::
string
>
(
"name,n"
,
"set name"
)
.
add
<
std
::
string
>
(
"group,g"
,
"join group
"
);
}
};
...
...
@@ -52,25 +49,26 @@ int main(int argc, char** argv) {
if
(
cfg
.
cli_helptext_printed
)
return
0
;
cfg
.
load
<
io
::
middleman
>
();
actor_system
system
{
cfg
};
auto
name
=
cfg
.
name
;
actor_system
sys
{
cfg
};
std
::
string
name
;
if
(
auto
config_name
=
get_if
<
std
::
string
>
(
&
cfg
,
"name"
))
name
=
*
config_name
;
while
(
name
.
empty
())
{
std
::
cout
<<
"please enter your name: "
<<
std
::
flush
;
if
(
!
std
::
getline
(
std
::
cin
,
name
))
{
std
::
cerr
<<
"*** no name given... terminating"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
}
group
grp
;
// evaluate group parameters
if
(
!
cfg
.
group_id
.
empty
())
{
auto
p
=
cfg
.
group_id
.
find
(
':'
);
if
(
p
==
std
::
string
::
npos
)
{
cerr
<<
"*** error parsing argument "
<<
cfg
.
group_id
<<
", expected format: <module_name>:<group_id>"
;
if
(
auto
locator
=
get_if
<
std
::
string
>
(
&
cfg
,
"group"
))
{
if
(
auto
grp_p
=
sys
.
groups
().
get
(
*
locator
))
{
grp
=
std
::
move
(
*
grp_p
);
}
else
{
auto
module
=
cfg
.
group_id
.
substr
(
0
,
p
);
auto
group_uri
=
cfg
.
group_id
.
substr
(
p
+
1
);
auto
g
=
system
.
groups
().
get
(
module
,
group_uri
);
if
(
!
g
)
{
cerr
<<
"*** unable to get group "
<<
group_uri
<<
" from module "
<<
module
<<
": "
<<
to_string
(
g
.
error
())
<<
endl
;
return
-
1
;
}
grp
=
std
::
move
(
*
g
);
std
::
cerr
<<
R"(*** failed to parse ")"
<<
*
locator
<<
R"(" as group locator: )"
<<
to_string
(
grp_p
.
error
())
<<
std
::
endl
;
}
}
QApplication
app
{
argc
,
argv
};
...
...
@@ -78,7 +76,7 @@ int main(int argc, char** argv) {
QMainWindow
mw
;
Ui
::
ChatWindow
helper
;
helper
.
setupUi
(
&
mw
);
helper
.
chatwidget
->
init
(
sys
tem
);
helper
.
chatwidget
->
init
(
sys
);
auto
client
=
helper
.
chatwidget
->
as_actor
();
if
(
!
name
.
empty
())
send_as
(
client
,
client
,
set_name_atom_v
,
move
(
name
));
...
...
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