Changeset e005f92 in mainline
- Timestamp:
- 2012-08-16T17:49:13Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cba45af
- Parents:
- d6ddeb7
- Location:
- uspace/srv/logger
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/logger/Makefile
rd6ddeb7 re005f92 32 32 33 33 SOURCES = \ 34 ctl.c \ 34 35 level.c \ 35 36 main.c \ 36 namespace.c 37 namespace.c \ 38 writer.c 37 39 38 40 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/logger/logger.h
rd6ddeb7 re005f92 39 39 #include <adt/prodcons.h> 40 40 #include <io/log.h> 41 #include <async.h> 41 42 #include <bool.h> 42 43 #include <fibril_synch.h> … … 65 66 int set_default_logging_level(log_level_t); 66 67 68 69 void logger_connection_handler_control(ipc_callid_t); 70 void logger_connection_handler_writer(ipc_callid_t); 71 67 72 #endif 68 73 -
uspace/srv/logger/main.c
rd6ddeb7 re005f92 48 48 #include "logger.h" 49 49 50 static int handle_namespace_level_change(sysarg_t new_level)51 {52 void *namespace_name;53 int rc = async_data_write_accept(&namespace_name, true, 0, 0, 0, NULL);54 if (rc != EOK) {55 return rc;56 }57 58 logging_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);59 free(namespace_name);60 if (namespace == NULL)61 return ENOENT;62 63 rc = namespace_change_level(namespace, (log_level_t) new_level);64 namespace_writer_detach(namespace);65 66 return rc;67 }68 69 static int handle_context_level_change(sysarg_t new_level)70 {71 void *namespace_name;72 int rc = async_data_write_accept(&namespace_name, true, 0, 0, 0, NULL);73 if (rc != EOK) {74 return rc;75 }76 77 logging_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);78 free(namespace_name);79 if (namespace == NULL)80 return ENOENT;81 82 void *context_name;83 rc = async_data_write_accept(&context_name, true, 0, 0, 0, NULL);84 if (rc != EOK) {85 namespace_writer_detach(namespace);86 return rc;87 }88 89 rc = namespace_change_context_level(namespace, context_name, new_level);90 free(context_name);91 namespace_writer_detach(namespace);92 93 return rc;94 }95 96 static void connection_handler_control(void)97 {98 printf(NAME "/control: new client.\n");99 100 while (true) {101 ipc_call_t call;102 ipc_callid_t callid = async_get_call(&call);103 104 if (!IPC_GET_IMETHOD(call))105 break;106 107 int rc;108 109 switch (IPC_GET_IMETHOD(call)) {110 case LOGGER_CTL_GET_DEFAULT_LEVEL:111 async_answer_1(callid, EOK, get_default_logging_level());112 break;113 case LOGGER_CTL_SET_DEFAULT_LEVEL:114 rc = set_default_logging_level(IPC_GET_ARG1(call));115 async_answer_0(callid, rc);116 break;117 case LOGGER_CTL_SET_NAMESPACE_LEVEL:118 rc = handle_namespace_level_change(IPC_GET_ARG1(call));119 async_answer_0(callid, rc);120 break;121 case LOGGER_CTL_SET_CONTEXT_LEVEL:122 rc = handle_context_level_change(IPC_GET_ARG1(call));123 async_answer_0(callid, rc);124 break;125 default:126 async_answer_0(callid, EINVAL);127 break;128 }129 }130 131 printf(NAME "/control: client terminated.\n");132 }133 134 static logging_namespace_t *find_namespace_and_attach_writer(void)135 {136 ipc_call_t call;137 ipc_callid_t callid = async_get_call(&call);138 139 if (IPC_GET_IMETHOD(call) != LOGGER_REGISTER) {140 async_answer_0(callid, EINVAL);141 return NULL;142 }143 144 void *name;145 int rc = async_data_write_accept(&name, true, 1, MAX_NAMESPACE_LENGTH, 0, NULL);146 async_answer_0(callid, rc);147 148 if (rc != EOK) {149 return NULL;150 }151 152 logging_namespace_t *result = namespace_writer_attach((const char *) name);153 154 free(name);155 156 return result;157 }158 159 static int handle_receive_message(logging_namespace_t *namespace, sysarg_t context, int level)160 {161 bool skip_message = !namespace_has_reader(namespace, context, level);162 if (skip_message) {163 /* Abort the actual message buffer transfer. */164 ipc_callid_t callid;165 size_t size;166 int rc = ENAK;167 if (!async_data_write_receive(&callid, &size))168 rc = EINVAL;169 170 async_answer_0(callid, rc);171 return rc;172 }173 174 void *message;175 int rc = async_data_write_accept(&message, true, 0, 0, 0, NULL);176 if (rc != EOK) {177 return rc;178 }179 180 namespace_add_message(namespace, message, context, level);181 182 free(message);183 184 return EOK;185 }186 187 static int handle_create_context(logging_namespace_t *namespace, sysarg_t *idx)188 {189 void *name;190 int rc = async_data_write_accept(&name, true, 0, 0, 0, NULL);191 if (rc != EOK) {192 return rc;193 }194 195 rc = namespace_create_context(namespace, name);196 197 free(name);198 199 if (rc < 0)200 return rc;201 202 *idx = (sysarg_t) rc;203 return EOK;204 }205 206 static void connection_handler_sink(logging_namespace_t *namespace)207 {208 printf(NAME "/sink: new client %s.\n", namespace_get_name(namespace));209 210 while (true) {211 ipc_call_t call;212 ipc_callid_t callid = async_get_call(&call);213 214 if (!IPC_GET_IMETHOD(call))215 break;216 217 int rc;218 sysarg_t arg = 0;219 220 switch (IPC_GET_IMETHOD(call)) {221 case LOGGER_CREATE_CONTEXT:222 rc = handle_create_context(namespace, &arg);223 async_answer_1(callid, rc, arg);224 break;225 case LOGGER_MESSAGE:226 rc = handle_receive_message(namespace, IPC_GET_ARG1(call), IPC_GET_ARG2(call));227 async_answer_0(callid, rc);228 break;229 default:230 async_answer_0(callid, EINVAL);231 break;232 }233 }234 235 printf(NAME "/sink: client %s terminated.\n", namespace_get_name(namespace));236 namespace_writer_detach(namespace);237 }238 239 50 static void connection_handler(ipc_callid_t iid, ipc_call_t *icall, void *arg) 240 51 { 241 52 logger_interface_t iface = IPC_GET_ARG1(*icall); 242 53 243 logging_namespace_t *namespace = NULL;244 245 54 switch (iface) { 246 55 case LOGGER_INTERFACE_CONTROL: 247 async_answer_0(iid, EOK); 248 connection_handler_control(); 56 logger_connection_handler_control(iid); 249 57 break; 250 58 case LOGGER_INTERFACE_SINK: 251 /* First call has to be the registration. */ 252 async_answer_0(iid, EOK); 253 namespace = find_namespace_and_attach_writer(); 254 if (namespace == NULL) { 255 fprintf(stderr, NAME ": failed to register namespace.\n"); 256 break; 257 } 258 connection_handler_sink(namespace); 59 logger_connection_handler_writer(iid); 259 60 break; 260 61 default:
Note:
See TracChangeset
for help on using the changeset viewer.