Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
5155b0f6
Commit
5155b0f6
authored
Jan 03, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ClientMessage: turn into a class
parent
d919f8d5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
110 deletions
+35
-110
ClientMessage.cxx
src/ClientMessage.cxx
+0
-54
ClientMessage.hxx
src/ClientMessage.hxx
+17
-38
ClientSubscribe.cxx
src/ClientSubscribe.cxx
+4
-5
ClientSubscribe.hxx
src/ClientSubscribe.hxx
+2
-2
MessageCommands.cxx
src/MessageCommands.cxx
+12
-11
No files found.
src/ClientMessage.cxx
View file @
5155b0f6
...
...
@@ -40,57 +40,3 @@ client_message_valid_channel_name(const char *name)
return
true
;
}
void
client_message_init_null
(
struct
client_message
*
msg
)
{
assert
(
msg
!=
NULL
);
msg
->
channel
=
NULL
;
msg
->
message
=
NULL
;
}
void
client_message_init
(
struct
client_message
*
msg
,
const
char
*
channel
,
const
char
*
message
)
{
assert
(
msg
!=
NULL
);
msg
->
channel
=
g_strdup
(
channel
);
msg
->
message
=
g_strdup
(
message
);
}
void
client_message_copy
(
struct
client_message
*
dest
,
const
struct
client_message
*
src
)
{
assert
(
dest
!=
NULL
);
assert
(
src
!=
NULL
);
assert
(
client_message_defined
(
src
));
client_message_init
(
dest
,
src
->
channel
,
src
->
message
);
}
struct
client_message
*
client_message_dup
(
const
struct
client_message
*
src
)
{
struct
client_message
*
dest
=
g_slice_new
(
struct
client_message
);
client_message_copy
(
dest
,
src
);
return
dest
;
}
void
client_message_deinit
(
struct
client_message
*
msg
)
{
assert
(
msg
!=
NULL
);
g_free
(
msg
->
channel
);
g_free
(
msg
->
message
);
}
void
client_message_free
(
struct
client_message
*
msg
)
{
client_message_deinit
(
msg
);
g_slice_free
(
struct
client_message
,
msg
);
}
src/ClientMessage.hxx
View file @
5155b0f6
...
...
@@ -22,52 +22,31 @@
#include "gcc.h"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <string>
/**
* A client-to-client message.
*/
struct
client_message
{
char
*
channel
;
char
*
message
;
class
ClientMessage
{
std
::
string
channel
,
message
;
public
:
template
<
typename
T
,
typename
U
>
ClientMessage
(
T
&&
_channel
,
U
&&
_message
)
:
channel
(
std
::
forward
<
T
>
(
_channel
)),
message
(
std
::
forward
<
U
>
(
_message
))
{}
const
char
*
GetChannel
()
const
{
return
channel
.
c_str
();
}
const
char
*
GetMessage
()
const
{
return
message
.
c_str
();
}
};
gcc_pure
bool
client_message_valid_channel_name
(
const
char
*
name
);
gcc_pure
static
inline
bool
client_message_defined
(
const
struct
client_message
*
msg
)
{
assert
(
msg
!=
NULL
);
assert
((
msg
->
channel
==
NULL
)
==
(
msg
->
message
==
NULL
));
return
msg
->
channel
!=
NULL
;
}
void
client_message_init_null
(
struct
client_message
*
msg
);
void
client_message_init
(
struct
client_message
*
msg
,
const
char
*
channel
,
const
char
*
message
);
void
client_message_copy
(
struct
client_message
*
dest
,
const
struct
client_message
*
src
);
gcc_malloc
struct
client_message
*
client_message_dup
(
const
struct
client_message
*
src
);
void
client_message_deinit
(
struct
client_message
*
msg
);
void
client_message_free
(
struct
client_message
*
msg
);
#endif
src/ClientSubscribe.cxx
View file @
5155b0f6
...
...
@@ -25,6 +25,7 @@ extern "C" {
#include "idle.h"
}
#include <assert.h>
#include <string.h>
enum
client_subscribe_result
...
...
@@ -78,21 +79,19 @@ client_unsubscribe_all(Client *client)
}
bool
client_push_message
(
Client
*
client
,
const
struct
client_message
*
msg
)
client_push_message
(
Client
*
client
,
const
ClientMessage
&
msg
)
{
assert
(
client
!=
NULL
);
assert
(
msg
!=
NULL
);
assert
(
client_message_defined
(
msg
));
if
(
client
->
num_messages
>=
CLIENT_MAX_MESSAGES
||
!
client
->
IsSubscribed
(
msg
->
channel
))
!
client
->
IsSubscribed
(
msg
.
GetChannel
()
))
return
false
;
if
(
client
->
messages
==
NULL
)
client_idle_add
(
client
,
IDLE_MESSAGE
);
client
->
messages
=
g_slist_prepend
(
client
->
messages
,
client_message_dup
(
msg
));
new
ClientMessage
(
msg
));
++
client
->
num_messages
;
return
true
;
...
...
src/ClientSubscribe.hxx
View file @
5155b0f6
...
...
@@ -24,7 +24,7 @@
typedef
struct
_GSList
GSList
;
class
Client
;
struct
client_m
essage
;
class
ClientM
essage
;
enum
client_subscribe_result
{
/** success */
...
...
@@ -50,7 +50,7 @@ void
client_unsubscribe_all
(
Client
*
client
);
bool
client_push_message
(
Client
*
client
,
const
struct
client_message
*
msg
);
client_push_message
(
Client
*
client
,
const
ClientMessage
&
msg
);
gcc_malloc
GSList
*
...
...
src/MessageCommands.cxx
View file @
5155b0f6
...
...
@@ -112,11 +112,12 @@ handle_read_messages(Client *client,
GSList
*
messages
=
client_read_messages
(
client
);
for
(
GSList
*
i
=
messages
;
i
!=
NULL
;
i
=
g_slist_next
(
i
))
{
struct
client_message
*
msg
=
(
struct
client_m
essage
*
)
i
->
data
;
ClientMessage
*
msg
=
(
ClientM
essage
*
)
i
->
data
;
client_printf
(
client
,
"channel: %s
\n
message: %s
\n
"
,
msg
->
channel
,
msg
->
message
);
client_message_free
(
msg
);
msg
->
GetChannel
(),
msg
->
GetMessage
());
delete
msg
;
}
g_slist_free
(
messages
);
...
...
@@ -125,9 +126,14 @@ handle_read_messages(Client *client,
}
struct
send_message_context
{
struct
client_m
essage
msg
;
ClientM
essage
msg
;
bool
sent
;
template
<
typename
T
,
typename
U
>
send_message_context
(
T
&&
_channel
,
U
&&
_message
)
:
msg
(
std
::
forward
<
T
>
(
_channel
),
std
::
forward
<
U
>
(
_message
)),
sent
(
false
)
{}
};
static
void
...
...
@@ -137,7 +143,7 @@ send_message(gpointer data, gpointer user_data)
(
struct
send_message_context
*
)
user_data
;
Client
*
client
=
(
Client
*
)
data
;
if
(
client_push_message
(
client
,
&
context
->
msg
))
if
(
client_push_message
(
client
,
context
->
msg
))
context
->
sent
=
true
;
}
...
...
@@ -153,15 +159,10 @@ handle_send_message(Client *client,
return
COMMAND_RETURN_ERROR
;
}
struct
send_message_context
context
;
context
.
sent
=
false
;
client_message_init
(
&
context
.
msg
,
argv
[
1
],
argv
[
2
]);
struct
send_message_context
context
(
argv
[
1
],
argv
[
2
]);
client_list_foreach
(
send_message
,
&
context
);
client_message_deinit
(
&
context
.
msg
);
if
(
context
.
sent
)
return
COMMAND_RETURN_OK
;
else
{
...
...
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