diff options
author | Simon Busch <morphis@gravedo.de> | 2012-01-29 14:40:58 +0100 |
---|---|---|
committer | Simon Busch <morphis@gravedo.de> | 2012-02-03 17:39:56 +0100 |
commit | 3f3690d87ab76ff51f6197f1c4af4a30745ddcb2 (patch) | |
tree | f3fcb5b4e7d2a0937fabd51b8da30e6a01f820e5 /samsung-ipc/ipc.c | |
parent | 151efe36ffa69b841f7e9a6c4245015e2ab15657 (diff) | |
download | external_libsamsung-ipc-3f3690d87ab76ff51f6197f1c4af4a30745ddcb2.zip external_libsamsung-ipc-3f3690d87ab76ff51f6197f1c4af4a30745ddcb2.tar.gz external_libsamsung-ipc-3f3690d87ab76ff51f6197f1c4af4a30745ddcb2.tar.bz2 |
Rework device specific code so we can build one library for all devices now
Signed-off-by: Simon Busch <morphis@gravedo.de>
Diffstat (limited to 'samsung-ipc/ipc.c')
-rw-r--r-- | samsung-ipc/ipc.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c index f7fbb6d..c4384ff 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -29,15 +29,21 @@ #include "ipc_private.h" -extern struct ipc_ops ipc_fmt_ops; -extern struct ipc_ops ipc_rfs_ops; -extern struct ipc_handlers ipc_default_handlers; +struct ipc_device_desc devices[IPC_DEVICE_MAX+1]; void log_handler_default(const char *message, void *user_data) { printf("%s\n", message); } +void ipc_register_device_client_handlers(int device, struct ipc_ops *fmt_ops, + struct ipc_ops *rfs_ops, struct ipc_handlers *handlers) +{ + devices[device].fmt_ops = fmt_ops; + devices[device].rfs_ops = rfs_ops; + devices[device].handlers = handlers; +} + void ipc_client_log(struct ipc_client *client, const char *message, ...) { assert(client->log_handler != NULL); @@ -51,30 +57,31 @@ void ipc_client_log(struct ipc_client *client, const char *message, ...) va_end(args); } -struct ipc_client* ipc_client_new(int client_type) +struct ipc_client* ipc_client_new(int device_type, int client_type) { struct ipc_client *client; - struct ipc_ops *ops = NULL; + + if (device_type < 0 || device_type > IPC_DEVICE_MAX) + return 0; + if (client_type < 0 || client_type > IPC_CLIENT_TYPE_RFS) + return 0; + + client = (struct ipc_client*) malloc(sizeof(struct ipc_client)); + client->type = client_type; switch (client_type) { - case IPC_CLIENT_TYPE_FMT: - ops = &ipc_fmt_ops; - break; case IPC_CLIENT_TYPE_RFS: - ops = &ipc_rfs_ops; + client->ops = devices[device_type].rfs_ops; + break; + case IPC_CLIENT_TYPE_FMT: + client->ops = devices[device_type].fmt_ops; break; - default: - return NULL; } - client = (struct ipc_client*) malloc(sizeof(struct ipc_client)); - client->type = client_type; - client->ops = ops; client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers)); client->log_handler = log_handler_default; - - memcpy(client->handlers, &ipc_default_handlers, sizeof(struct ipc_handlers)); + memcpy(client->handlers, devices[device_type].handlers , sizeof(struct ipc_handlers)); return client; } |