int
attachUiImpl_create(SockAddress* console_socket)
{
    char* handshake = NULL;

    _attachUiImpl.console_socket = *console_socket;

    
    _attachUiImpl.core_connection =
        core_connection_create_and_switch(console_socket, "attach-UI",
                                          &handshake);
    if (_attachUiImpl.core_connection == NULL) {
        derror("Unable to connect to the attach-UI service: %s\n",
               errno_str);
        return -1;
    }

    fprintf(stdout, "UI is now attached to the core at %s.",
            sock_address_to_string(console_socket));
    if (handshake != NULL) {
        if (handshake[0] != '\0') {
            fprintf(stdout, " Handshake: %s", handshake);
        }
        free(handshake);
    }
    fprintf(stdout, "\n");

    return 0;
}
int
coreCmdProxy_create(SockAddress* console_socket)
{
    char* handshake = NULL;

    // Connect to the ui-core-control service.
    _coreCmdProxy.core_connection =
        core_connection_create_and_switch(console_socket, "ui-core-control",
                                          &handshake);
    if (_coreCmdProxy.core_connection == NULL) {
        derror("Unable to connect to the ui-core-control service: %s\n",
               errno_str);
        return -1;
    }

    // Initialze command writer and response reader.
    _coreCmdProxy.sock = core_connection_get_socket(_coreCmdProxy.core_connection);
    _coreCmdProxy.sync_writer = syncsocket_init(_coreCmdProxy.sock);
    if (_coreCmdProxy.sync_writer == NULL) {
        derror("Unable to initialize CoreCmdProxy writer: %s\n", errno_str);
        coreCmdProxy_destroy();
        return -1;
    }
    _coreCmdProxy.sync_reader = syncsocket_init(_coreCmdProxy.sock);
    if (_coreCmdProxy.sync_reader == NULL) {
        derror("Unable to initialize CoreCmdProxy reader: %s\n", errno_str);
        coreCmdProxy_destroy();
        return -1;
    }


    fprintf(stdout, "ui-core-control is now connected to the core at %s.",
            sock_address_to_string(console_socket));
    if (handshake != NULL) {
        if (handshake[0] != '\0') {
            fprintf(stdout, " Handshake: %s", handshake);
        }
        free(handshake);
    }
    fprintf(stdout, "\n");

    return 0;
}
int
userEventsProxy_create(SockAddress* console_socket)
{
    char* handshake = NULL;

    
    _userEventsProxy.core_connection =
        core_connection_create_and_switch(console_socket, "user-events",
                                          &handshake);
    if (_userEventsProxy.core_connection == NULL) {
        derror("Unable to connect to the user-events service: %s\n",
               errno_str);
        return -1;
    }

    
    _userEventsProxy.sock =
        core_connection_get_socket(_userEventsProxy.core_connection);
    _userEventsProxy.sync_writer = syncsocket_init(_userEventsProxy.sock);
    if (_userEventsProxy.sync_writer == NULL) {
        derror("Unable to initialize UserEventsProxy writer: %s\n", errno_str);
        userEventsProxy_destroy();
        return -1;
    }

    fprintf(stdout, "user-events is now connected to the core at %s.",
            sock_address_to_string(console_socket));
    if (handshake != NULL) {
        if (handshake[0] != '\0') {
            fprintf(stdout, " Handshake: %s", handshake);
        }
        free(handshake);
    }
    fprintf(stdout, "\n");

    return 0;
}