Permalink
Browse files

working on the changes in the psuedo client with some minor cleanup i…

…n the psuedo compositor
  • Loading branch information...
1 parent eb7e8c5 commit f8d8327b65a7218df4f6a91adf6071e317b6ccc4 @kempj committed Aug 10, 2011
Showing with 129 additions and 77 deletions.
  1. +99 −32 rwl_client.c
  2. +30 −45 rwl_compositor.c
View
@@ -246,7 +246,7 @@ struct wl_server_display {
struct wl_list client_list;
};
-/*struct wl_display {
+struct wl_display {
struct wl_proxy proxy;
struct wl_connection *connection;
int fd;
@@ -264,8 +264,7 @@ struct wl_server_display {
struct wl_list sync_list, frame_list;
uint32_t key;
-};*/
-
+};
/*struct wl_event_loop {
int epoll_fd;
@@ -288,17 +287,16 @@ static int
rwl_forward(int fd, uint32_t mask, void *data)
{
struct rwl_connection *connection = data;
-
- //read in from fd_from
- //write to fd_to
+ //demarshal
+ //send closure
return 1;
}
int
-rwl_create_forward(int remote_fd, struct wl_server_display *main_display)
+rwl_create_forward(struct wl_server client_display,
+ int remote_fd,
+ struct wl_server_display *main_display)
{
- struct wl_display *client_display = wl_display_connect(NULL);
- int local_fd = wl_display_get_fd(client_display,NULL,NULL);
struct rwl_connection *connection_in, *connection_out;
connection_in = malloc(sizeof connection_in);
@@ -325,61 +323,130 @@ rwl_create_forward(int remote_fd, struct wl_server_display *main_display)
return 1;
}
+
+struct wl_display *
+rwl_local_display_connect(const char *name)
+{
+ struct wl_display *display;
+ const char *debug;
+ char *connection, *end;
+ int flags;
+
+ debug = getenv("WAYLAND_DEBUG");
+ if (debug)
+ wl_debug = 1;
+
+ display = malloc(sizeof *display);
+ if (display == NULL)
+ return NULL;
+
+ memset(display, 0, sizeof *display);
+ connection = getenv("WAYLAND_SOCKET");
+ if (connection) {
+ display->fd = strtol(connection, &end, 0);
+ if (*end != '\0') {
+ free(display);
+ return NULL;
+ }
+ flags = fcntl(display->fd, F_GETFD);
+ if (flags != -1)
+ fcntl(display->fd, F_SETFD, flags | FD_CLOEXEC);
+ } else if (connect_to_socket(display, name) < 0) {
+ free(display);
+ return NULL;
+ }
+
+ display->objects = wl_hash_table_create();
+ if (display->objects == NULL) {
+ close(display->fd);
+ free(display);
+ return NULL;
+ }
+ wl_list_init(&display->global_listener_list);
+ wl_list_init(&display->global_list);
+
+ display->proxy.object.interface = &wl_display_interface;
+ display->proxy.object.id = 1;
+ display->proxy.display = display;
+
+ wl_list_init(&display->sync_list);
+ wl_list_init(&display->frame_list);
+
+ display->proxy.object.implementation =
+ (void(**)(void)) &display_listener;
+ display->proxy.user_data = display;
+
+ display->connection = wl_connection_create(display->fd,
+ connection_update,
+ display);
+ if (display->connection == NULL) {
+ wl_hash_table_destroy(display->objects);
+ close(display->fd);
+ free(display);
+ return NULL;
+ }
+
+// wl_display_bind(display, 1, "wl_display", 1);
+
+ return display;
+}
+
static int
rwl_remote_connection(int fd, uint32_t mask, void *data)
{
- struct rwl_remote_display *display = data;
+ struct wl_server_display *display = data;
+ struct wl_display *client_display = rwl_local_display_connect(NULL);
struct sockaddr_storage incoming_addr;
socklen_t size;
- int remote_fd = accept(display->fd,(struct sockaddr *) &incoming_addr, size);
- rwl_create_forward(remote_fd, display->display);
+ int remote_fd = accept(fd,(struct sockaddr *) &incoming_addr, size);
+ //user client tools to get a fd to the local compositor
+ rwl_create_forward(client_display, remote_fd, display);
//call rwl_forward
return 1;
}
int
-main(int argc, char **argv)
+get_listening_fd(char *port)
{
- struct wl_server_display *display;
- struct rwl_remote_display *remote_display;
- struct window *window;
int fd, err;
struct addrinfo *local_address_info;
- printf("0\n");
-// return 0;
-
- display = rwl_display_create();
- if((err = getaddrinfo(NULL, "35000", NULL, &local_address_info)) != 0) {
+ if(port == NULL)
+ port = (char *)&"35000\0";
+
+ if((err = getaddrinfo(NULL, port , NULL, &local_address_info)) != 0) {
fprintf(stderr, "pclient:getaddrinfo error: %s\n", gai_strerror(err));
return EXIT_FAILURE;
}
- printf("1\n");
fd = socket(local_address_info->ai_family,
local_address_info->ai_socktype,
local_address_info->ai_protocol);
bind(fd,local_address_info->ai_addr,local_address_info->ai_addrlen);
- printf("2\n");
listen(fd,8);
- printf("3\n");
- remote_display = malloc(sizeof remote_display);
- remote_display->display = display;
- remote_display->fd = fd;
+}
+int
+main(int argc, char **argv)
+{
+ struct wl_server_display *display;
+ struct window *window;
+ int fd;
+
+ display = rwl_display_create();
+
+ fd = get_listening_fd(NULL);
wl_event_loop_add_fd(display->loop,
fd, WL_EVENT_READABLE,
rwl_remote_connection,
- remote_display);
+ display);
- while (true){
- printf("mainloop");
+ while (true)
rwl_display_run(display);
-
- }
+
return 0;
}
View
@@ -11,7 +11,7 @@
#include <sys/file.h>
#include <netdb.h>
-static char* remote_address;
+char* remote_address;
struct wl_socket {
int fd;
@@ -138,7 +138,7 @@ rwl_client_connection_data(int fd, uint32_t mask, void *data)
if (len < size)
break;
- object = wl_hash_table_lookup(client_in->display->objects, p[0]);
+ /*object = wl_hash_table_lookup(client_in->display->objects, p[0]);
if (object == NULL) {
wl_client_post_error(client_in, &client_in->display->object,
WL_DISPLAY_ERROR_INVALID_OBJECT,
@@ -157,9 +157,10 @@ rwl_client_connection_data(int fd, uint32_t mask, void *data)
wl_connection_consume(connection_in, size);
len -= size;
continue;
- }
+ }*/
- message = &object->interface->methods[opcode];
+ message = &wl_display_interface.methods[opcode];
+ //&object->interface->methods[opcode];
closure = wl_connection_demarshal(client_in->connection, size,
client_in->display->objects,
message);
@@ -177,7 +178,6 @@ rwl_client_connection_data(int fd, uint32_t mask, void *data)
continue;
}
- //do I need to vmarshal?
wl_closure_send(closure, client_out->connection);
wl_closure_print(closure, object, 1);
@@ -199,55 +199,57 @@ rwl_client_pair_create(struct wl_display *display, int fd_local, int fd_remote)
incoming_fwd = malloc(sizeof *incoming_fwd);
if (incoming_fwd == NULL)
- return NULL;
-
+ return -1;
outgoing_fwd = malloc(sizeof *outgoing_fwd);
if (outgoing_fwd == NULL)
- return NULL;
+ return -1;
+
outgoing_fwd->client_in = local_client;
outgoing_fwd->client_out = remote_client;
-
+
incoming_fwd->client_in = remote_client;
incoming_fwd->client_out = local_client;
local_client = malloc(sizeof *local_client);
if (local_client == NULL)
- return NULL;
-
+ return -1;
memset(local_client, 0, sizeof *local_client);
local_client->display = display;
+
+ remote_client = malloc(sizeof *remote_client);
+ if (remote_client == NULL)
+ return -1;
+ memset(remote_client, 0, sizeof *remote_client);
+ remote_client->display = display;
+
local_client->source = wl_event_loop_add_fd(display->loop, fd_local,
WL_EVENT_READABLE,
rwl_client_connection_data, outgoing_fwd);
+
+ remote_client->source = wl_event_loop_add_fd(display->loop, fd_remote,
+ WL_EVENT_READABLE,
+ rwl_client_connection_data, incoming_fwd);
+
+ if(remote_client->source == NULL)
+ printf("This shoudln't be null\n");
+
local_client->connection =
wl_connection_create(fd_local, wl_client_connection_update, local_client);
if (local_client->connection == NULL) {
free(local_client);
- return NULL;
+ return -1;
}
//wl_list_insert(display->client_list.prev, &local_client->link);
//wl_list_init(&local_client->resource_list);
-
- remote_client = malloc(sizeof *remote_client);
- if (remote_client == NULL)
- return NULL;
-
- memset(remote_client, 0, sizeof *remote_client);
- remote_client->display = display;
-
- remote_client->display = display;
- remote_client->source = wl_event_loop_add_fd(display->loop, fd_remote,
- WL_EVENT_READABLE,
- rwl_client_connection_data, incoming_fwd);
remote_client->connection =
wl_connection_create(fd_remote, wl_client_connection_update, remote_client);
if (remote_client->connection == NULL) {
free(remote_client);
- return NULL;
+ return -1;
}
//wl_list_insert(display->client_list.prev, &remote_client->link);
@@ -264,8 +266,6 @@ rwl_socket_data(int fd, uint32_t mask, void *data)
socklen_t length;
int client_fd, remote_fd;
- remote_fd = rwl_get_remote_connection(remote_address);
-
length = sizeof name;
client_fd =
accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC);
@@ -278,6 +278,8 @@ rwl_socket_data(int fd, uint32_t mask, void *data)
if (client_fd < 0)
fprintf(stderr, "failed to accept, errno: %d\n", errno);
+ remote_fd = rwl_get_remote_connection(remote_address);
+
rwl_client_pair_create(display, client_fd, remote_fd);
//wl_closure_print();
return 1;
@@ -394,7 +396,6 @@ rwl_display_add_socket(struct wl_display *display, const char *name)
return 0;
}
-
int
main(int argc, char *argv[])
{
@@ -404,30 +405,14 @@ main(int argc, char *argv[])
if(argc > 1){
remote_address = argv[2];
} else{
- remote_address = (char *) malloc(13 * sizeof (char));
- remote_address = &"127.0.0.1\0";
- //printf("assigned %s\n", remote_address);
+ remote_address = (char *)&"127.0.0.1\0";
}
if (rwl_display_add_socket(display, NULL)) {
fprintf(stderr, "failed to add socket: %m\n");
exit(EXIT_FAILURE);
}
- int fd = rwl_get_remote_connection(NULL);
-
- int length = 13;
-
- while(length > 0){
- printf("num left = %d\n", length = send(fd, "Hello World\n", 13, 0));
- }
-
- /*wl_event_loop_add_fd(display->loop,
- fd, WL_EVENT_READABLE,
- ,
- connection_out);
- */
- printf("Entering the main loop\n");
wl_display_run(display);
}

0 comments on commit f8d8327

Please sign in to comment.