Changeset 04803bf in mainline for uspace/srv/hid/adb_mouse/adb_dev.c
- Timestamp:
- 2011-03-21T22:00:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 143932e3
- Parents:
- b50b5af2 (diff), 7308e84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
uspace/srv/hid/adb_mouse/adb_dev.c (moved) (moved from uspace/app/tester/ipc/register.c ) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/adb_mouse/adb_dev.c
rb50b5af2 r04803bf 1 1 /* 2 * Copyright (c) 20 06 Ondrej Palkovsky2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #include <stdio.h> 30 #include <unistd.h> 29 /** @addtogroup mouse 30 * @{ 31 */ 32 /** @file 33 * @brief 34 */ 35 36 #include <ipc/adb.h> 31 37 #include <async.h> 38 #include <vfs/vfs.h> 39 #include <fcntl.h> 32 40 #include <errno.h> 33 #include "../tester.h"34 41 35 #define MAX_CONNECTIONS 50 42 #include "adb_mouse.h" 43 #include "adb_dev.h" 36 44 37 static int connections[MAX_CONNECTIONS];45 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall); 38 46 39 static void client_connection(ipc_callid_t iid, ipc_call_t *icall) 47 static int dev_phone; 48 49 int adb_dev_init(void) 40 50 { 41 unsigned int i; 42 43 TPRINTF("Connected phone %#x accepting\n", icall->in_phone_hash); 44 ipc_answer_0(iid, EOK); 45 for (i = 0; i < MAX_CONNECTIONS; i++) { 46 if (!connections[i]) { 47 connections[i] = icall->in_phone_hash; 48 break; 49 } 51 const char *input = "/dev/adb/mouse"; 52 int input_fd; 53 54 printf(NAME ": open %s\n", input); 55 56 input_fd = open(input, O_RDONLY); 57 if (input_fd < 0) { 58 printf(NAME ": Failed opening %s (%d)\n", input, input_fd); 59 return false; 60 } 61 62 dev_phone = fd_phone(input_fd); 63 if (dev_phone < 0) { 64 printf(NAME ": Failed to connect to device\n"); 65 return false; 66 } 67 68 /* NB: The callback connection is slotted for removal */ 69 if (async_connect_to_me(dev_phone, 0, 0, 0, adb_dev_events) != 0) { 70 printf(NAME ": Failed to create callback from device\n"); 71 return false; 50 72 } 51 73 74 return 0; 75 } 76 77 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall) 78 { 79 /* Ignore parameters, the connection is already opened */ 52 80 while (true) { 81 53 82 ipc_call_t call; 54 83 ipc_callid_t callid = async_get_call(&call); 84 55 85 int retval; 56 57 switch (IPC_GET_ METHOD(call)) {86 87 switch (IPC_GET_IMETHOD(call)) { 58 88 case IPC_M_PHONE_HUNGUP: 59 TPRINTF("Phone %#x hung up\n", icall->in_phone_hash); 60 retval = 0; 61 break; 62 case IPC_TEST_METHOD: 63 TPRINTF("Received well known message from %#x: %#x\n", 64 icall->in_phone_hash, callid); 65 ipc_answer_0(callid, EOK); 89 /* TODO: Handle hangup */ 90 return; 91 case IPC_FIRST_USER_METHOD: 92 mouse_handle_data(IPC_GET_ARG1(call)); 66 93 break; 67 94 default: 68 TPRINTF("Received unknown message from %#x: %#x\n", 69 icall->in_phone_hash, callid); 70 ipc_answer_0(callid, ENOENT); 71 break; 95 retval = ENOENT; 72 96 } 97 async_answer_0(callid, retval); 73 98 } 74 99 } 75 100 76 char *test_register(void) 77 { 78 async_set_client_connection(client_connection); 79 80 ipcarg_t phonead; 81 int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead); 82 if (res != 0) 83 return "Failed registering IPC service"; 84 85 TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE); 86 async_manager(); 87 88 return NULL; 89 } 101 /** 102 * @} 103 */
Note:
See TracChangeset
for help on using the changeset viewer.
