static void la_handler_service_handle_register_finish (GObject *object, GAsyncResult *res, gpointer user_data) { GDBusMethodInvocation *invocation = G_DBUS_METHOD_INVOCATION (user_data); LAHandlerService *service; NSMConsumer *nsm_consumer = NSM_CONSUMER (object); GError *error = NULL; gint error_code; g_return_if_fail (IS_NSM_CONSUMER (nsm_consumer)); g_return_if_fail (G_IS_ASYNC_RESULT (res)); g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation)); /* finish registering the shutdown client */ nsm_consumer_call_register_shutdown_client_finish (nsm_consumer, &error_code, res, &error); if (error != NULL) { DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING ("Failed to register a shutdown consumer:"), DLT_STRING (error->message)); g_error_free (error); } /* retrieve the LAHandlerService from the invocation object */ service = g_object_get_data (G_OBJECT (invocation), "la-handler-service"); /* notify the caller that we have handled the registration request */ la_handler_complete_register (service->interface, invocation); }
void logfile_thread(void *v_conf) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, in thread.")); DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf; register_contexts(conf->LogFile); int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX]; int i; for(i = 0;i < conf->LogFile.Count;i++) logfile_delays[i] = conf->LogFile.TimeDelay[i]; while(!threads.shutdown) { sleep(1); for(i = 0;i < conf->LogFile.Count;i++) { if(conf->LogFile.Mode[i] == SEND_MODE_OFF) continue; if(logfile_delays[i] <= 0) { send_file(conf->LogFile, i); logfile_delays[i] = conf->LogFile.TimeDelay[i]; if(conf->LogFile.Mode[i] == SEND_MODE_ONCE) conf->LogFile.Mode[i] = SEND_MODE_OFF; } else { logfile_delays[i]--; } } } }
bool_t Test_import_all_app(sint_t type, void* pv) { bool_t bEverythingOK = true ; long impBytes =-1; str_t pchBackupFilePath [PATH_ABS_MAX_SIZE]; bEverythingOK = ResetImportData(PersASSelectionType_Application); if(true == bEverythingOK) { (void)snprintf(pchBackupFilePath, sizeof(pchBackupFilePath), "%s%s", "all", BACKUP_FORMAT); /* Restore content */ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Import from:"), DLT_STRING(pchBackupFilePath), DLT_STRING("...")); impBytes = persAdminDataFolderImport(PersASSelectionType_Application, pchBackupFilePath); bEverythingOK = (impBytes >= 0)?true:false; } printf("\nTest_import_all - %s \n", bEverythingOK ? "OK" : "FAILED") ; return bEverythingOK ; }
void init_shell() { DLT_LOG(dltsystem,DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, register callback")); DLT_REGISTER_CONTEXT(shellContext,"CMD","Execute Shell commands"); DLT_REGISTER_INJECTION_CALLBACK(shellContext, 0x1001, dlt_shell_injection_callback); }
int wait_for_files(FiletransferOptions const *opts) { #ifdef linux DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, waiting for files.")); static char buf[INOTIFY_LEN]; ssize_t len = read(ino.handle, buf, INOTIFY_LEN); if(len < 0) { DLT_LOG(filetransferContext, DLT_LOG_ERROR, DLT_STRING("Error while waiting for files in dlt-system file transfer.")); return -1; } unsigned int i = 0; while(i < (len-INOTIFY_SZ)) { struct inotify_event *ie = (struct inotify_event *)&buf[i]; if(ie->len > 0) { if((ie->mask & IN_CLOSE_WRITE) || (ie->mask & IN_MOVED_TO)) { int j; for(j = 0;j < opts->Count;j++) { if(ie->wd == ino.fd[j]) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, found new file.")); int length = strlen(opts->Directory[j])+ie->len+1; if (length > PATH_MAX) { DLT_LOG(filetransferContext, DLT_LOG_ERROR, DLT_STRING("dlt-system-filetransfer: Very long path for file transfer. Cancelling transfer! Length is: "),DLT_INT(length)); return -1; } char *tosend = malloc(length); snprintf(tosend,length, "%s/%s", opts->Directory[j], ie->name); send_one(tosend, opts, j); free(tosend); } } } } i += INOTIFY_SZ + ie->len; } #endif return 0; }
/** * la_handler_service_deregister_consumers: * @service: A #LAHandlerService. * * Unregisters every #ShutdownClient from the Node State Manager. * This method is typically used when the #LAHandlerService is about to shut down. */ void la_handler_service_deregister_consumers (LAHandlerService *service) { GHashTableIter iter; ShutdownClient *client; const gchar *bus_name; const gchar *object_path; const gchar *unit; GError *error = NULL; gint error_code; gint shutdown_mode; g_return_if_fail (LA_HANDLER_IS_SERVICE (service)); g_hash_table_iter_init (&iter, service->clients_to_units); while (g_hash_table_iter_next (&iter, (gpointer *)&client, (gpointer *)&unit)) { /* extract data from the current client */ bus_name = shutdown_client_get_bus_name (client); object_path = shutdown_client_get_object_path (client); shutdown_mode = shutdown_client_get_shutdown_mode (client); /* unregister the shutdown client */ nsm_consumer_call_un_register_shutdown_client_sync (service->nsm_consumer, bus_name, object_path, shutdown_mode, &error_code, NULL, &error); if (error != NULL) { DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING ("Failed to unregister shutdown client:"), DLT_STRING ("object path"), DLT_STRING (object_path), DLT_STRING ("unit"), DLT_STRING (unit), DLT_STRING ("error message"), DLT_STRING (error->message)); g_error_free (error); } else if (error_code != NSM_ERROR_STATUS_OK) { DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING ("Failed to unregister shutdown client:"), DLT_STRING ("object path"), DLT_STRING (object_path), DLT_STRING ("unit"), DLT_STRING (unit), DLT_STRING ("error code"), DLT_INT (error_code)); } } }
static void doInitAppcheck(const char* appName) { char rctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; snprintf(rctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), appName, plugin_gResTableCfg); if(access(rctFilename, F_OK) == 0) { gAppCheckFlag = 1; // "trusted" application DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("trusted app")); } else { gAppCheckFlag = 0; // currently not a "trusted" application DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("NOT trusted app")); } }
void start_filetransfer(DltSystemConfiguration *conf) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, start.")); static pthread_attr_t t_attr; static pthread_t pt; pthread_create(&pt, &t_attr, (void *)filetransfer_thread, conf); threads.threads[threads.count++] = pt; }
void gptpLog(GPTP_LOG_LEVEL level, const char *tag, const char *path, int line, const char *fmt, ...) { char msg[1024]; va_list args; va_start(args, fmt); vsprintf(msg, fmt, args); #ifndef GENIVI_DLT std::chrono::system_clock::time_point cNow = std::chrono::system_clock::now(); time_t tNow = std::chrono::system_clock::to_time_t(cNow); struct tm tmNow; PLAT_localtime(&tNow, &tmNow); std::chrono::system_clock::duration roundNow = cNow - std::chrono::system_clock::from_time_t(tNow); long int millis = (long int) std::chrono::duration_cast<std::chrono::milliseconds>(roundNow).count(); if (path) { fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] [%s:%u] %s\n", tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, path, line, msg); } else { fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] %s\n", tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, msg); } #else DltLogLevelType dlt_level; switch (level) { case GPTP_LOG_LVL_CRITICAL: dlt_level = DLT_LOG_FATAL; break; case GPTP_LOG_LVL_ERROR: dlt_level = DLT_LOG_ERROR; break; case GPTP_LOG_LVL_EXCEPTION: case GPTP_LOG_LVL_WARNING: dlt_level = DLT_LOG_WARN; break; case GPTP_LOG_LVL_INFO: case GPTP_LOG_LVL_STATUS: dlt_level = DLT_LOG_INFO; break; case GPTP_LOG_LVL_DEBUG: dlt_level = DLT_LOG_DEBUG; break; case GPTP_LOG_LVL_VERBOSE: dlt_level = DLT_LOG_VERBOSE; break; default: dlt_level = DLT_LOG_INFO; break; } DLT_LOG(dlt_con_gptp, dlt_level, DLT_STRING(msg)); #endif }
static int private_pclDeinitLibrary(void) { int rval = 1; int* retval; MainLoopData_u data; data.message.cmd = (uint32_t)CMD_QUIT; data.message.string[0] = '\0'; // no string parameter, set to 0 if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) // unregister for lifecycle dbus messages { rval = unregister_lifecycle(gShutdownMode); } #if USE_PASINTERFACE == 1 rval = unregister_pers_admin_service(); if(0 != rval) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclDeinitLibrary - Err to de-initialize IPC protocol for PCL.")); } else { DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclDeinitLibrary - Succ de-initialized IPC protocol for PCL.")); } #endif process_prepare_shutdown(Shutdown_Full); // close all db's and fd's and block access deliverToMainloop_NM(&data); // send quit command to dbus mainloop deleteHandleTrees(); // delete allocated trees deleteBackupTree(); deleteNotifyTree(); pthread_join(gMainLoopThread, (void**)&retval); // wait until the dbus mainloop has ended pthread_mutex_unlock(&gDbusPendingRegMtx); #if USE_FILECACHE pfcDeinitCache(); #endif return rval; }
char *origin_name(char *src){ if (strlen( (char*) basename(src)) > 10 ){ return (char*)(basename(src)+10); } else{ DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-filetransfer, error in recreating origin name!")); return NULL; } }
static void watchToggled(DBusWatch *watch, void *data) { (void)data; DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT64( (long)watch) ); if(dbus_watch_get_enabled(watch)) addWatch(watch, data); else removeWatch(watch, data); }
void register_contexts(LogFileOptions fileopts) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, registering file contexts.")); int i; for(i = 0;i < fileopts.Count;i++) { DLT_REGISTER_CONTEXT(logfileContext[i], fileopts.ContextId[i], fileopts.Filename[i]); } }
void filetransfer_thread(void *v_conf) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, in thread.")); DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf; DLT_REGISTER_CONTEXT(filetransferContext, conf->Filetransfer.ContextId, "File transfer manager."); sleep(conf->Filetransfer.TimeStartup); if(init_filetransfer_dirs(&(conf->Filetransfer)) < 0) return; while(!threads.shutdown) { if(wait_for_files(&(conf->Filetransfer)) < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while waiting files. File transfer shutdown.")); return; } sleep(conf->Filetransfer.TimeDelay); } }
int pclRecoverFromBackup(int backupFd, const char* original) { int handle = open(original, O_TRUNC | O_RDWR); if(handle != -1) { if(pclBackupDoFileCopy(backupFd, handle) == -1) // copy data from one file to another { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("rBackup - couldn't write whole buffer")); } } return handle; }
static void removeWatch(DBusWatch *watch, void *data) { void* w_data = dbus_watch_get_data(watch); (void)data; DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT64( (long)watch) ); if(w_data) free(w_data); dbus_watch_set_data(watch, NULL, NULL); }
int flush_dir_original(FiletransferOptions const *opts, int which){ struct dirent *dp; DIR *dir; const char *sdir = opts->Directory[which]; dir = opendir(sdir); if(dir != NULL) { while((dp = readdir(dir)) != NULL) { if(dp->d_type != DT_REG){ //we don't send directories continue; } DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, old file found in directory.")); int len = strlen(sdir)+strlen(dp->d_name)+2; char *fn = malloc(len); MALLOC_ASSERT(fn); snprintf(fn,len, "%s/%s", sdir, dp->d_name); if(send_one(fn, opts, which) < 0) { closedir(dir); free(fn); return -1; } free(fn); } } else { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not open directory"), DLT_STRING(sdir)); return -1; } closedir(dir); return 0; }
void send_file(LogFileOptions fileopt, int n) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, sending file.")); FILE * pFile; DltContext context = logfileContext[n]; char buffer[1024]; int bytes; int seq = 1; pFile = fopen(fileopt.Filename[n],"r"); if(pFile != NULL) { while (!feof(pFile)) { bytes = fread(buffer,1,sizeof(buffer)-1,pFile); if(bytes>=0) buffer[bytes] = 0; else buffer[0] = 0; if(feof(pFile)) { DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq*-1), DLT_STRING(buffer)); break; } else { DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer)); } } fclose(pFile); } else { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-logfile, failed to open file."), DLT_STRING(fileopt.Filename[n])); } }
bool_t Test_Recover_All(sint_t type, void* pv) { bool_t bEverythingOK = true ; long lTemp ; str_t pchBackupFilePath [PATH_ABS_MAX_SIZE]; /* Reset the backup data for every test */ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Reset backup content...")); lTemp = ResetBackupContent(PersASSelectionType_All, NULL); bEverythingOK = (lTemp >= 0) ? true : false ; DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Test_Recover_All: ResetBackupContent() - "), DLT_STRING(bEverythingOK ? "OK" : "FAILED")); if(true == bEverythingOK) { (void)snprintf(pchBackupFilePath, sizeof(pchBackupFilePath), "%s%s", "all", BACKUP_FORMAT); /* Restore content */ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Restore backup from : "), DLT_STRING(pchBackupFilePath), DLT_STRING("...")); lTemp = persAdminDataBackupRecovery( PersASSelectionType_All, pchBackupFilePath, "", PERSIST_SELECT_ALL_USERS, PERSIST_SELECT_ALL_SEATS); bEverythingOK = (lTemp >= 0) ? true : false ; DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Test_Recover_All: data_backup_recovery() - "), DLT_STRING(bEverythingOK ? "OK" : "FAILED")); } return bEverythingOK ; } /* Test_Recover_All */
void send_dumped_file(FiletransferOptions const *opts,char *dst_tosend) { char *fn = origin_name(dst_tosend); DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sending dumped file:"),DLT_STRING(fn)); if(dlt_user_log_file_header_alias(&filetransferContext, dst_tosend, fn) == 0) { int pkgcount = dlt_user_log_file_packagesCount(&filetransferContext, dst_tosend); int lastpkg = 0; int success = 1; while(lastpkg < pkgcount) { int total = 2; int used = 2; dlt_user_check_buffer(&total, &used); while((total-used) < (total/2)) { struct timespec t; t.tv_sec = 0; t.tv_nsec = 1000000ul*opts->TimeoutBetweenLogs; nanosleep(&t, NULL); dlt_user_check_buffer(&total, &used); } lastpkg++; if(dlt_user_log_file_data(&filetransferContext, dst_tosend, lastpkg, opts->TimeoutBetweenLogs) < 0) { success = 0; break; } } if (success) dlt_user_log_file_end(&filetransferContext, dst_tosend, 1); } DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sent dumped file")); }
int pclInitLibrary(const char* appName, int shutdownMode) { int rval = 1; pthread_mutex_lock(&gInitMutex); if(gPclInitCounter == 0) { DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging"); DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclInitLibrary => INIT PCL - "), DLT_STRING(appName), DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter) ); rval = private_pclInitLibrary(appName, shutdownMode); } else { DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclInitLibrary - INIT PCL - "), DLT_STRING(gAppId), DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitCounter) ); } gPclInitCounter++; // increment after private init, otherwise atomic access is too early pthread_mutex_unlock(&gInitMutex); return rval; }
int pclLifecycleSet(int shutdown) { int rval = 0; if(gShutdownMode == PCL_SHUTDOWN_TYPE_NONE) { if(shutdown == PCL_SHUTDOWN) { DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("lifecycleSet - PCL_SHUTDOWN -"), DLT_STRING(gAppId)); process_prepare_shutdown(Shutdown_Partial); gCancelCounter++; } else if(shutdown == PCL_SHUTDOWN_CANCEL) { DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("lifecycleSet - PCL_SHUTDOWN_CANCEL -"), DLT_STRING(gAppId), DLT_STRING(" Cancel Counter - "), DLT_INT(gCancelCounter)); if(gCancelCounter < Shutdown_MaxCount) { pers_unlock_access(); } else { rval = EPERS_SHUTDOWN_MAX_CANCEL; } } else { rval = EPERS_COMMON; } } else { rval = EPERS_SHUTDOWN_NO_PERMIT; } return rval; }
int dlt_shell_injection_callback(uint32_t service_id, void *data, uint32_t length) { DLT_LOG(dltsystem,DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, injection callback")); char text[1024]; int syserr = 0; strncpy(text,data,length); DLT_LOG(dltsystem,DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, injection injection id:"), DLT_UINT32(service_id)); DLT_LOG(dltsystem,DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, injection data:"), DLT_STRING(text)); switch(service_id) { case 0x1001: if((syserr = system(text)) != 0) { DLT_LOG(dltsystem,DLT_LOG_ERROR, DLT_STRING("dlt-system-shell, abnormal exit status."), DLT_STRING(text), DLT_INT(syserr)); } break; default: DLT_LOG(dltsystem,DLT_LOG_ERROR, DLT_STRING("dlt-system-shell, unknown command received."), DLT_UINT32(service_id), DLT_STRING(text)); break; } return 0; }
bool_t Test_Restore_Configurable_Default_User1(sint_t type, void* pv) { bool_t bEverythingOK = true ; long lRetVal; DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Restore configurable default for User1...")); lRetVal = persAdminDataRestore( PersASSelectionType_User, PersASDefaultSource_Configurable, "", 0x01, PERSIST_SELECT_ALL_SEATS); if(lRetVal < PAS_SUCCESS) { bEverythingOK = false; } DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Test_Restore_Configurable_Default_User1: persAdminDataRestore() - "), DLT_STRING(bEverythingOK ? "OK" : "FAILED")); return bEverythingOK ; } /* Test_Restore_Configurable_Default_User1 */
/** * @param opts FiletransferOptions * @param which which directory is affected -> position in list of opts->Directory * @return Returns 0 if everything was okay. If there was a failure a value < 0 will be returned. */ int flush_dir(FiletransferOptions const *opts, int which) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, flush directory of old files.")); char *compress_dir; char *send_dir; int len = strlen(opts->Directory[which])+strlen(SUBDIR_COMPRESS)+2; compress_dir = malloc (len); MALLOC_ASSERT(compress_dir); snprintf(compress_dir,len,"%s/%s",opts->Directory[which],SUBDIR_COMPRESS); len = strlen(opts->Directory[which])+strlen(SUBDIR_TOSEND)+2; send_dir = malloc (len); MALLOC_ASSERT(send_dir); snprintf(send_dir,len,"%s/%s",opts->Directory[which],SUBDIR_TOSEND); //1st: scan the tosend directory. if ( 0 != flush_dir_send(opts, compress_dir, send_dir) ){ free(send_dir); free(compress_dir); return -1; } //1nd: scan the tocompress directory. if (0 != flush_dir_compress(opts, which, compress_dir, send_dir)){ free(send_dir); free(compress_dir); return -1; } free(send_dir);//no more used free(compress_dir); //last step: scan the original directory - we can reuse the send_one function if ( 0 != flush_dir_original(opts,which)){ return -1; } return 0; }
static void la_handler_service_constructed (GObject *object) { LAHandlerService *service = LA_HANDLER_SERVICE (object); GError *error = NULL; /* connect to the node state manager */ service->nsm_consumer = nsm_consumer_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, "org.genivi.NodeStateManager", "/org/genivi/NodeStateManager/Consumer", NULL, &error); if (error != NULL) { DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING ("Failed to connect to the NSM consumer:"), DLT_STRING (error->message)); g_error_free (error); } }
void Logger_dlt::log(joynr_logging::LogLevel logLevel, const char* message) { DLT_LOG(dltContext, joynrLogLevelToDltLogLevel(logLevel), DLT_STRING(prefix.toAscii()), DLT_STRING(message)); }
int main(int argc, char* argv[]) { int sock; int bytes_read; socklen_t addr_len; int opt, port; char recv_data[MAXSTRLEN]; struct sockaddr_in client_addr, server_addr; char apid[DLT_ID_SIZE]; char ctid[DLT_ID_SIZE]; char version[255]; dlt_set_id(apid, PU_DLT_APP); dlt_set_id(ctid, PU_DLT_CONTEXT); port = RCVPORT; while ((opt = getopt(argc, argv, "a:c:hp:")) != -1) { switch (opt) { case 'a': { dlt_set_id(apid,optarg); break; } case 'c': { dlt_set_id(ctid,optarg); break; } case 'h': { dlt_get_version(version); printf("Usage: dlt-adaptor-udp [options]\n"); printf("Adaptor for forwarding received UDP messages to DLT daemon.\n"); printf("%s \n", version); printf("Options:\n"); printf("-a apid - Set application id to apid (default: UDPA)\n"); printf("-c ctid - Set context id to ctid (default: UDPC)\n"); printf("-p - Set receive port number for UDP messages (default: %d) \n", port); printf("-h - This help\n"); return 0; break; } case 'p': { port = atoi(optarg); break; } default: /* '?' */ { fprintf(stderr, "Unknown option '%c'\n", optopt); exit(3); } } } if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { perror("Socket"); exit(1); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr.s_addr = INADDR_ANY; bzero(&(server_addr.sin_zero), 8); if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { perror("Bind"); return -1; } addr_len = sizeof(struct sockaddr); DLT_REGISTER_APP(apid,PU_DLT_APP_DESC); DLT_REGISTER_CONTEXT(mycontext,ctid,PU_DLT_CONTEXT_DESC); while (1) { bytes_read = 0; bytes_read = recvfrom(sock, recv_data, MAXSTRLEN, 0, (struct sockaddr *)&client_addr, &addr_len); if (bytes_read == -1) { if (errno == EINTR) { continue; } else { DLT_UNREGISTER_CONTEXT(mycontext); DLT_UNREGISTER_APP(); exit(1); } } recv_data[bytes_read] = '\0'; if (bytes_read != 0) { DLT_LOG(mycontext, DLT_LOG_INFO, DLT_STRING(recv_data)); } } DLT_UNREGISTER_CONTEXT(mycontext); DLT_UNREGISTER_APP(); return 0; }
/* function to unregister ojbect path message handler */ static void unregisterMessageHandler(DBusConnection *connection, void *user_data) { (void)connection; (void)user_data; DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPath\n")); }
int main() { unsigned char buffer[256]; int num; DLT_REGISTER_APP("EXA4","Fourth Example"); DLT_REGISTER_CONTEXT(con_exa1,"CON","First context"); for(num=0;num<256;num++) { buffer[num] = num; } DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_RAW")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_RAW(buffer,256)); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX8")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX8(buffer,256)); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX16")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX16(buffer,256)); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX32")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX32(buffer,256)); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX64")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX64(buffer,256)); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_BIN8")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN8(buffer,256)); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_BIN16")); DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN16(buffer,256)); usleep(1000); DLT_UNREGISTER_CONTEXT(con_exa1); DLT_UNREGISTER_APP(); }