celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { printf("CONSUMING_DRIVER: starting bundle\n"); celix_status_t status = CELIX_SUCCESS; consuming_driver_bundle_instance_pt bi = userData; consuming_driver_pt driver = NULL; status = consumingDriver_create(context, &driver); if (status == CELIX_SUCCESS) { driver_service_pt service = NULL; status = consumingDriver_createService(driver, &service); if (status == CELIX_SUCCESS) { properties_pt props = properties_create(); properties_set(props, "DRIVER_ID", CONSUMING_DRIVER_ID); status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME, service, props, &bi->registration); } } if (status == CELIX_SUCCESS) { printf("CONSUMING_DRIVER: registered driver service.\n"); } else { char error[256]; printf("CONSUMING_DRIVER: Could not register driver service. Get error %s\n", celix_strerror(status, error, 256)); } return status; }
void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...) { char message[256]; celix_strerror(code, message, 256); char msg[512]; va_list listPointer; va_start(listPointer, fmsg); vsprintf(msg, fmsg, listPointer); framework_log(logger, level, func, file, line, "%s [%d]: %s", message, code, msg); }
void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...) { mock_c()->actualCall("framework_logCode")->withIntParameters("code", code); char message[256]; celix_strerror(code, message, 256); char msg[512]; va_list listPointer; va_start(listPointer, fmsg); vsprintf(msg, fmsg, listPointer); test_logger_log(logger, level, func, file, line, "%s [%d]: %s", message, code, msg); }
celix_status_t shell_addCommand(shell_pt shell_ptr, service_reference_pt reference_ptr) { celix_status_t status = CELIX_SUCCESS; command_service_pt command_ptr = NULL; char *name_str = NULL; if (!shell_ptr && !reference_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { status = bundleContext_getService(shell_ptr->bundle_context_ptr, reference_ptr, (void **) &command_ptr); if (!command_ptr) { status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { status = serviceReference_getProperty(reference_ptr, "command.name", &name_str); if (!name_str) { logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Command service must contain a 'command.name' property!"); status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { hashMap_put(shell_ptr->command_name_map_ptr, name_str, command_ptr); hashMap_put(shell_ptr->command_reference_map_ptr, reference_ptr, command_ptr); } if (status != CELIX_SUCCESS) { shell_removeCommand(shell_ptr, reference_ptr); char err[32]; celix_strerror(status, err, 32); logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Could not add command, got error %s\n", err); } return status; }
void logCommand_execute(bundle_context_pt context, char *line, FILE *outStream, FILE *errStream) { service_reference_pt readerService = NULL; bundleContext_getServiceReference(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME, &readerService); if (readerService != NULL) { linked_list_pt list = NULL; linked_list_iterator_pt iter = NULL; log_reader_service_pt reader = NULL; bundleContext_getService(context, readerService, (void **) &reader); reader->getLog(reader->reader, &list); iter = linkedListIterator_create(list, 0); while (linkedListIterator_hasNext(iter)) { log_entry_pt entry = linkedListIterator_next(iter); char time[20]; char *level = NULL; char errorString[256]; strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time)); logCommand_levelAsString(context, entry->level, &level); if (entry->errorCode > 0) { celix_strerror(entry->errorCode, errorString, 256); fprintf(outStream, "%s - Bundle: %s - %s - %d %s\n", time, entry->bundleSymbolicName, entry->message, entry->errorCode, errorString); } else { fprintf(outStream, "%s - Bundle: %s - %s\n", time, entry->bundleSymbolicName, entry->message); } } linkedListIterator_destroy(iter); linkedList_destroy(list); bool result = true; bundleContext_ungetService(context, readerService, &result); bundleContext_ungetServiceReference(context, readerService); } else { fprintf(outStream, "No log reader available\n"); } }