int main(int argc, char ** argv) { int result = 1; struct gengetopt_args_info ai; AwaServerSession * session = NULL; AwaServerWriteOperation * operation = NULL; char address[128]; unsigned int port; if (cmdline_parser(argc, argv, &ai) != 0) { result = 1; goto cleanup; } g_logLevel = ai.debug_given ? 2 : (ai.verbose_given ? 1 : 0); AwaLog_SetLevel(ai.debug_given ? AwaLogLevel_Debug : (ai.verbose_given ? AwaLogLevel_Verbose : AwaLogLevel_Warning)); if (ai.inputs_num == 0 && ai.create_given == 0) { Error("Specify one or more resource paths.\n"); result = 1; goto cleanup; } port = ai.ipcPort_arg; strncpy(address, ai.ipcAddress_arg, strlen(ai.ipcAddress_arg)+1); // Establish Awa Session with the daemon session = Server_EstablishSession(address, port); if (session == NULL) { Error("Failed to establish Awa Session\n"); result = 1; goto cleanup; } AwaWriteMode mode = AwaWriteMode_Update; if (ai.replace_given) mode = AwaWriteMode_Replace; operation = AwaServerWriteOperation_New(session, mode); if (operation == NULL) { Error("AwaServerWriteOperation_New failed\n"); Server_ReleaseSession(&session); result = 1; goto cleanup; } // Add create directives first int count = 0; count = CreateTargets(session, operation, ai.clientID_arg, ai.create_arg, ai.create_given); // Add target paths and values from the command line int i = 0; for (i = 0; i < ai.inputs_num; ++i) { Target * target = CreateTarget(ai.inputs[i]); if (target != NULL) { char * value = Server_GetValue(session, target, ai.inputs[i]); if (value != NULL) { if (AddTargetWithValue(session, operation, target, value) == 0) { ++count; } free(value); value = NULL; } FreeTarget(&target); } } if (count > 0) { result = ProcessWriteOperation(operation, ai.clientID_arg); } cleanup: if (operation) { AwaServerWriteOperation_Free(&operation); } if (session) { Server_ReleaseSession(&session); } cmdline_parser_free(&ai); return result; }
int main(int argc, char ** argv) { int result = 0; struct gengetopt_args_info ai; AwaClientSession * session = NULL; AwaClientSetOperation * operation = NULL; if (cmdline_parser(argc, argv, &ai) != 0) { exit(1); } g_logLevel = ai.debug_given ? 2 : (ai.verbose_given ? 1 : 0); AwaLog_SetLevel(ai.debug_given ? AwaLogLevel_Debug : (ai.verbose_given ? AwaLogLevel_Verbose : AwaLogLevel_Warning)); if ((ai.inputs_num == 0) && (ai.create_given == 0)) { Error("Specify one or more resource paths.\n"); result = 1; goto cleanup; } session = Client_EstablishSession(ai.ipcAddress_arg, ai.ipcPort_arg); if (session != NULL) { // Create Set operation operation = AwaClientSetOperation_New(session); if (operation != NULL) { // Add create directives first int count = 0; count = CreateTargets(session, operation, ai.create_arg, ai.create_given); // Add target paths and values from the command line int i = 0; for (i = 0; i < ai.inputs_num; ++i) { Target * target = CreateTarget(ai.inputs[i]); if (target != NULL) { char * value = Client_GetValue(session, target, ai.inputs[i]); if (value != NULL) { if (AddTargetWithValue(session, operation, target, value) == 0) { ++count; } free(value); value = NULL; } FreeTarget(&target); } } if (count > 0) { // Process Set operation result = ProcessSetOperation(operation); } } else { Error("Failed to create Set operation\n"); result = 1; } } else { Error("Failed to establish Awa Session\n"); result = 1; } cleanup: if (operation) { AwaClientSetOperation_Free(&operation); } if (session) { Client_ReleaseSession(&session); } cmdline_parser_free(&ai); return result; }