Commit 5db1f541 authored by Vincent Wei's avatar Vincent Wei
Browse files

tune

parent f495a59e
......@@ -206,6 +206,24 @@ int us_ping_client (const USClient* us_client)
return 0;
}
/* return zero on success; none-zero on error */
int us_send_event (const USClient* us_client, const struct _remote_event* event)
{
ssize_t n = 0;
struct _frame_header header;
header.type = FT_EVENT;
header.payload_len = sizeof (struct _remote_event);
n = write (us_client->fd, &header, sizeof (struct _frame_header));
n += write (us_client->fd, event, sizeof (struct _remote_event));
if (n != (sizeof (struct _frame_header) + sizeof (struct _remote_event))) {
LOG (("us_send_event: error when wirtting socket: %ld\n", n));
return 1;
}
return 0;
}
/* return zero on success; <0 on closed; >0 on error */
int us_on_client_data (USClient* us_client)
{
......
......@@ -56,6 +56,7 @@ int us_accept (int listenfd, pid_t *pidptr, uid_t *uidptr);
int us_on_connected (USClient* us_client);
int us_ping_client (const USClient* us_client);
int us_send_event (const USClient* us_client, const struct _remote_event* event);
int us_on_client_data (USClient* us_client);
/* microsecond */
......
......@@ -229,16 +229,40 @@ onopen (WSClient * client)
static int
onclose (WSClient * client)
{
return 0;
return 0;
}
static int
onmessage (WSClient * client)
{
WSMessage **msg = &client->message;
WSMessage **msg = &client->message;
char* message = (*msg)->payload;
struct _remote_event event = { EVENT_NULL };
printf ("INFO: got a message from client (%d): %s\n", client->listener, (*msg)->payload);
return 0;
if (strncasecmp (message, "MOUSEDOWN ", 10) == 0) {
if (sscanf (message + 10, "%d %d", &event.value1, &event.value2) == 2) {
event.type = EVENT_LBUTTONDOWN;
}
}
else if (strncasecmp (message, "MOUSEMOVE ", 10) == 0) {
if (sscanf (message + 10, "%d %d", &event.value1, &event.value2) == 2) {
event.type = EVENT_MOUSEMOVE;
}
}
else if (strncasecmp (message, "MOUSEUP ", 8) == 0) {
if (sscanf (message + 8, "%d %d", &event.value1, &event.value2) == 2) {
event.type = EVENT_LBUTTONUP;
}
}
if (event.type != EVENT_NULL) {
us_send_event (client->us_buddy, &event);
}
else {
LOG (("WARNING: got a unknown or bad message from client (%d): %s\n", client->listener, (*msg)->payload));
}
return 0;
}
static void
......
......@@ -66,4 +66,18 @@ struct _frame_header {
unsigned char payload[0];
};
#define EVENT_NULL 0
#define EVENT_MOUSEMOVE 1
#define EVENT_LBUTTONDOWN 2
#define EVENT_LBUTTONUP 3
#define EVENT_KEYDOWN 11
#define EVENT_KEYUP 12
struct _remote_event {
int type;
int value1;
int value2;
};
#endif // for #ifndef WD_SERVER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment