[Spice-devel] [vdagent-linux v2 3/5] udscs: use GObject macro
Jakub Janků
jjanku at redhat.com
Tue Apr 30 09:33:37 UTC 2019
Use G_DECLARE_FINAL_TYPE().
Rename
struct udscs_connection --> UdscsConnection
Signed-off-by: Jakub Janků <jjanku at redhat.com>
---
src/udscs.c | 15 ++++++---------
src/udscs.h | 28 +++++++---------------------
src/vdagent/clipboard.c | 8 ++++----
src/vdagent/clipboard.h | 4 ++--
src/vdagent/file-xfers.c | 6 +++---
src/vdagent/file-xfers.h | 4 ++--
src/vdagent/vdagent.c | 4 ++--
src/vdagent/x11-priv.h | 2 +-
src/vdagent/x11.c | 2 +-
src/vdagent/x11.h | 2 +-
src/vdagentd/vdagentd.c | 20 ++++++++++----------
11 files changed, 39 insertions(+), 56 deletions(-)
diff --git a/src/udscs.c b/src/udscs.c
index 7ae1ebe..5f769ca 100644
--- a/src/udscs.c
+++ b/src/udscs.c
@@ -30,18 +30,15 @@
#include "vdagentd-proto-strings.h"
#include "vdagent-connection.h"
-struct udscs_connection {
+struct _UdscsConnection {
VDAgentConnection parent_instance;
-
int debug;
-
- /* Callbacks */
udscs_read_callback read_callback;
};
G_DEFINE_TYPE(UdscsConnection, udscs_connection, VDAGENT_TYPE_CONNECTION);
-static void debug_print_message_header(struct udscs_connection *conn,
+static void debug_print_message_header(UdscsConnection *conn,
struct udscs_message_header *header,
const gchar *direction)
{
@@ -100,13 +97,13 @@ static void udscs_connection_class_init(UdscsConnectionClass *klass)
conn_class->handle_message = conn_handle_message;
}
-struct udscs_connection *udscs_connect(const char *socketname,
+UdscsConnection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
VDAgentConnErrorCb error_cb,
int debug)
{
GIOStream *io_stream;
- struct udscs_connection *conn;
+ UdscsConnection *conn;
GError *err = NULL;
io_stream = vdagent_socket_connect(socketname, &err);
@@ -131,7 +128,7 @@ struct udscs_connection *udscs_connect(const char *socketname,
return conn;
}
-void udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
+void udscs_write(UdscsConnection *conn, uint32_t type, uint32_t arg1,
uint32_t arg2, const uint8_t *data, uint32_t size)
{
gpointer buf;
@@ -277,7 +274,7 @@ static gboolean udscs_server_accept_cb(GSocketService *service,
gpointer user_data)
{
struct udscs_server *server = user_data;
- struct udscs_connection *new_conn;
+ UdscsConnection *new_conn;
new_conn = g_object_new(UDSCS_TYPE_CONNECTION, NULL);
new_conn->debug = server->debug;
diff --git a/src/udscs.h b/src/udscs.h
index 382da06..b2d71b6 100644
--- a/src/udscs.h
+++ b/src/udscs.h
@@ -29,25 +29,11 @@
G_BEGIN_DECLS
-#define UDSCS_TYPE_CONNECTION (udscs_connection_get_type())
-#define UDSCS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UDSCS_TYPE_CONNECTION, UdscsConnection))
-#define UDSCS_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UDSCS_TYPE_CONNECTION))
-#define UDSCS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UDSCS_TYPE_CONNECTION, UdscsConnectionClass))
-#define UDSCS_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UDSCS_TYPE_CONNECTION))
-#define UDSCS_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), UDSCS_TYPE_CONNECTION, UdscsConnectionClass))
-
-typedef struct udscs_connection UdscsConnection;
-typedef struct UdscsConnectionClass UdscsConnectionClass;
-
-struct UdscsConnectionClass {
- VDAgentConnectionClass parent_class;
-};
-
-GType udscs_connection_get_type(void);
+#define UDSCS_TYPE_CONNECTION udscs_connection_get_type()
+G_DECLARE_FINAL_TYPE(UdscsConnection, udscs_connection, UDSCS, CONNECTION, VDAgentConnection);
/* ---------- Generic bits and client-side API ---------- */
-struct udscs_connection;
struct udscs_message_header {
uint32_t type;
uint32_t arg1;
@@ -59,7 +45,7 @@ struct udscs_message_header {
* received. The callback does not own the data buffer and should not free it.
* The data buffer will be freed shortly after the read callback returns.
*/
-typedef void (*udscs_read_callback)(struct udscs_connection *connp,
+typedef void (*udscs_read_callback)(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data);
/* Connect to the unix domain socket specified by socketname.
@@ -68,14 +54,14 @@ typedef void (*udscs_read_callback)(struct udscs_connection *connp,
* If debug is true then the events on this connection will be traced.
* This includes the incoming and outgoing message names.
*/
-struct udscs_connection *udscs_connect(const char *socketname,
+UdscsConnection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
VDAgentConnErrorCb error_cb,
int debug);
/* Queue a message for delivery to the client connected through conn.
*/
-void udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
+void udscs_write(UdscsConnection *conn, uint32_t type, uint32_t arg1,
uint32_t arg2, const uint8_t *data, uint32_t size);
#ifndef UDSCS_NO_SERVER
@@ -87,7 +73,7 @@ struct udscs_server;
/* Callbacks with this type will be called when a new connection to a
* server is accepted.
*/
-typedef void (*udscs_connect_callback)(struct udscs_connection *conn);
+typedef void (*udscs_connect_callback)(UdscsConnection *conn);
/* Create a server for the given file descriptor. This allows us to use
* pre-configured sockets for use with systemd socket activation, etc.
@@ -133,7 +119,7 @@ void udscs_server_write_all(struct udscs_server *server,
/* Callback type for udscs_server_for_all_clients. Clients can be disconnected
* from this callback just like with a read callback.
*/
-typedef int (*udscs_for_all_clients_callback)(struct udscs_connection *conn,
+typedef int (*udscs_for_all_clients_callback)(UdscsConnection *conn,
void *priv);
/* Call func for all clients connected to the server, passing through
diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c
index a8d2e91..e423f84 100644
--- a/src/vdagent/clipboard.c
+++ b/src/vdagent/clipboard.c
@@ -60,8 +60,8 @@ typedef struct {
struct VDAgentClipboards {
#ifdef WITH_GTK
- struct udscs_connection *conn;
- Selection selections[SELECTION_COUNT];
+ UdscsConnection *conn;
+ Selection selections[SELECTION_COUNT];
#else
struct vdagent_x11 *x11;
#endif
@@ -435,8 +435,8 @@ err:
#endif
}
-VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11,
- struct udscs_connection *conn)
+VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11,
+ UdscsConnection *conn)
{
#ifdef WITH_GTK
guint sel_id;
diff --git a/src/vdagent/clipboard.h b/src/vdagent/clipboard.h
index f819b49..6a79f9f 100644
--- a/src/vdagent/clipboard.h
+++ b/src/vdagent/clipboard.h
@@ -26,8 +26,8 @@
typedef struct VDAgentClipboards VDAgentClipboards;
-VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11,
- struct udscs_connection *conn);
+VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11,
+ UdscsConnection *conn);
void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive);
void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type);
diff --git a/src/vdagent/file-xfers.c b/src/vdagent/file-xfers.c
index 3b431ee..4898fc0 100644
--- a/src/vdagent/file-xfers.c
+++ b/src/vdagent/file-xfers.c
@@ -39,7 +39,7 @@
struct vdagent_file_xfers {
GHashTable *xfers;
- struct udscs_connection *vdagentd;
+ UdscsConnection *vdagentd;
char *save_dir;
int open_save_dir;
int debug;
@@ -76,7 +76,7 @@ static void vdagent_file_xfer_task_free(gpointer data)
}
struct vdagent_file_xfers *vdagent_file_xfers_create(
- struct udscs_connection *vdagentd, const char *save_dir,
+ UdscsConnection *vdagentd, const char *save_dir,
int open_save_dir, int debug)
{
struct vdagent_file_xfers *xfers;
@@ -373,7 +373,7 @@ void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
}
}
-void vdagent_file_xfers_error_disabled(struct udscs_connection *vdagentd, uint32_t msg_id)
+void vdagent_file_xfers_error_disabled(UdscsConnection *vdagentd, uint32_t msg_id)
{
g_return_if_fail(vdagentd != NULL);
diff --git a/src/vdagent/file-xfers.h b/src/vdagent/file-xfers.h
index 29a7717..3cfbe53 100644
--- a/src/vdagent/file-xfers.h
+++ b/src/vdagent/file-xfers.h
@@ -27,7 +27,7 @@
struct vdagent_file_xfers;
struct vdagent_file_xfers *vdagent_file_xfers_create(
- struct udscs_connection *vdagentd, const char *save_dir,
+ UdscsConnection *vdagentd, const char *save_dir,
int open_save_dir, int debug);
void vdagent_file_xfers_destroy(struct vdagent_file_xfers *xfer);
@@ -37,7 +37,7 @@ void vdagent_file_xfers_status(struct vdagent_file_xfers *xfers,
VDAgentFileXferStatusMessage *msg);
void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
VDAgentFileXferDataMessage *msg);
-void vdagent_file_xfers_error_disabled(struct udscs_connection *vdagentd,
+void vdagent_file_xfers_error_disabled(UdscsConnection *vdagentd,
uint32_t msg_id);
int vdagent_file_xfers_create_file(const char *save_dir, char **file_name_p);
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 181c51a..9516f8b 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -46,7 +46,7 @@ typedef struct VDAgent {
VDAgentClipboards *clipboards;
struct vdagent_x11 *x11;
struct vdagent_file_xfers *xfers;
- struct udscs_connection *conn;
+ UdscsConnection *conn;
GIOChannel *x11_channel;
GMainLoop *loop;
@@ -165,7 +165,7 @@ static void vdagent_quit_loop(VDAgent *agent)
g_main_loop_quit(agent->loop);
}
-static void daemon_read_complete(struct udscs_connection *conn,
+static void daemon_read_complete(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data)
{
VDAgent *agent = g_object_get_data(G_OBJECT(conn), "agent");
diff --git a/src/vdagent/x11-priv.h b/src/vdagent/x11-priv.h
index 99676d2..70adcc5 100644
--- a/src/vdagent/x11-priv.h
+++ b/src/vdagent/x11-priv.h
@@ -111,7 +111,7 @@ struct vdagent_x11 {
Atom selection_req_atom;
#endif
Window root_window[MAX_SCREENS];
- struct udscs_connection *vdagentd;
+ UdscsConnection *vdagentd;
int debug;
int fd;
int screen_count;
diff --git a/src/vdagent/x11.c b/src/vdagent/x11.c
index c2515a8..2d246ca 100644
--- a/src/vdagent/x11.c
+++ b/src/vdagent/x11.c
@@ -196,7 +196,7 @@ static gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
#endif
}
-struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
+struct vdagent_x11 *vdagent_x11_create(UdscsConnection *vdagentd,
int debug, int sync)
{
struct vdagent_x11 *x11;
diff --git a/src/vdagent/x11.h b/src/vdagent/x11.h
index bb2ac80..c49a397 100644
--- a/src/vdagent/x11.h
+++ b/src/vdagent/x11.h
@@ -28,7 +28,7 @@
struct vdagent_x11;
-struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
+struct vdagent_x11 *vdagent_x11_create(UdscsConnection *vdagentd,
int debug, int sync);
void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected);
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index 689a83a..0565881 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -76,7 +76,7 @@ static uint32_t *capabilities = NULL;
static int capabilities_size = 0;
static const char *active_session = NULL;
static unsigned int session_count = 0;
-static struct udscs_connection *active_session_conn = NULL;
+static UdscsConnection *active_session_conn = NULL;
static int agent_owns_clipboard[256] = { 0, };
static int retval = 0;
static int client_connected = 0;
@@ -332,7 +332,7 @@ static void do_client_file_xfer(struct vdagent_virtio_port *vport,
uint8_t *data)
{
uint32_t msg_type, id;
- struct udscs_connection *conn;
+ UdscsConnection *conn;
switch (message_header->type) {
case VD_AGENT_FILE_XFER_START: {
@@ -646,7 +646,7 @@ static void virtio_write_clipboard(uint8_t selection, uint32_t msg_type,
}
/* vdagentd <-> vdagent communication handling */
-static void do_agent_clipboard(struct udscs_connection *conn,
+static void do_agent_clipboard(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data)
{
uint8_t selection = header->arg1;
@@ -787,10 +787,10 @@ static void check_xorg_resolution(void)
}
}
-static int connection_matches_active_session(struct udscs_connection *conn,
+static int connection_matches_active_session(UdscsConnection *conn,
void *priv)
{
- struct udscs_connection **conn_ret = (struct udscs_connection **)priv;
+ UdscsConnection **conn_ret = (UdscsConnection **)priv;
struct agent_data *agent_data = g_object_get_data(G_OBJECT(conn), "agent_data");
/* Check if this connection matches the currently active session */
@@ -816,7 +816,7 @@ static void release_clipboards(void)
}
}
-static void update_active_session_connection(struct udscs_connection *new_conn)
+static void update_active_session_connection(UdscsConnection *new_conn)
{
if (session_info) {
new_conn = NULL;
@@ -877,7 +877,7 @@ static gboolean remove_active_xfers(gpointer key, gpointer value, gpointer conn)
return 0;
}
-static void agent_connect(struct udscs_connection *conn)
+static void agent_connect(UdscsConnection *conn)
{
struct agent_data *agent_data;
agent_data = g_new0(struct agent_data, 1);
@@ -927,7 +927,7 @@ static void agent_disconnect(VDAgentConnection *conn, GError *err)
update_active_session_connection(NULL);
}
-static void do_agent_xorg_resolution(struct udscs_connection *conn,
+static void do_agent_xorg_resolution(UdscsConnection *conn,
struct udscs_message_header *header,
guint8 *data)
{
@@ -960,7 +960,7 @@ static void do_agent_xorg_resolution(struct udscs_connection *conn,
check_xorg_resolution();
}
-static void do_agent_file_xfer_status(struct udscs_connection *conn,
+static void do_agent_file_xfer_status(UdscsConnection *conn,
struct udscs_message_header *header,
guint8 *data)
{
@@ -988,7 +988,7 @@ static void do_agent_file_xfer_status(struct udscs_connection *conn,
g_hash_table_remove(active_xfers, task_id);
}
-static void agent_read_complete(struct udscs_connection *conn,
+static void agent_read_complete(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data)
{
switch (header->type) {
--
2.20.1
More information about the Spice-devel
mailing list