static int CreateTargets(const AwaClientSession * session, AwaClientSetOperation * operation, char ** targets, unsigned int numCreates) { int count = 0; int i = 0; // Handle all object instance creates first Debug("Filtering for Object Instance creates\n"); for (i = 0; i < numCreates; ++i) { Target * target = CreateTarget(targets[i]); if (Client_IsObjectTarget(session, target) || Client_IsObjectInstanceTarget(session, target)) { if (AwaClientSetOperation_CreateObjectInstance(operation, target->Path) == AwaError_Success) { Verbose("Create %s\n", target->Path); ++count; } } else { // Skip it Debug("Skipping %s (%d)\n", targets[i], i); } FreeTarget(&target); } // Then handle all optional resource creates Debug("Filtering for Resource creates\n"); for (i = 0; i < numCreates; ++i) { Target * target = CreateTarget(targets[i]); if (Client_IsResourceTarget(session, target)) { if (AwaClientSetOperation_CreateOptionalResource(operation, target->Path) == AwaError_Success) { Verbose("Create %s\n", target->Path); ++count; } } else { // Skip it Debug("Skipping %s (%d)\n", targets[i], i); } FreeTarget(&target); } return count; }
static int CreateTargets(const AwaServerSession * session, AwaServerWriteOperation * operation, const char * clientID, char ** targets, unsigned int numCreates) { int count = 0; int i = 0; // Handle object instance creates Debug("Filtering for Object Instance creates\n"); for (i = 0; i < numCreates; ++i) { Target * target = CreateTarget(targets[i]); if (Server_IsObjectTarget(session, target) || Server_IsObjectInstanceTarget(session, target)) { if (AwaServerWriteOperation_CreateObjectInstance(operation, target->Path) == AwaError_Success) { Verbose("Create %s\n", target->Path); ++count; } } else { // Skip it Debug("Skipping %s (%d)\n", targets[i], i); } FreeTarget(&target); } return count; }
void BPMiniGame_Sharpshooter::Tick() { if (SuccessTime != -1 && SuccessTime + 500 < TheGame->TickCount) { Success(); } if (LastCreatedTime + CreateDelay + PauseTime < TheGame->TickCount) { switch (TheGame->RandomRange(0, 5)) { case 0: case 1: case 2: case 3: CreateTarget(-1); break; case 4: case 5: CreateTarget(1); break; case 6: // take a breather break; } } for (int i = Targets.Count - 1; i >= 0; --i) { BPMiniGame_Sharpshooter_Target* target = Targets[i]; if (target->HitTime != -1 && target->HitTime + 150 < TheGame->TickCount) { Targets.RemoveAt(i); continue; } if (target->CreatedTime != -1 && target->CreatedTime + TargetLife < TheGame->TickCount) { if (target->HitTime == -1) { target->HitTime = TheGame->TickCount; } } } }
void CmdCreateBuffer::EndExecute(CommandContext* pContext, const ASTCommand* command) const { RenderScriptContext* c = static_cast<RenderScriptContext*>(pContext); if (c->_bufferName == StringUtils::Null) { Warn("Unnamed buffer!"); c->_bufferName = "buffer-"; c->_bufferName += Convert::ToString(c->_rsys.GetRenderTargetCount()); } StringID bufferNameId = NamedObject::AsyncStringID(c->_bufferName); if (c->_numTargets == 1) { RenderTargetPtr r = CreateTarget(c, c->_targets[0], 0); c->_rsys.RegisterTarget(bufferNameId, r); } else { MultiRenderTarget::CreateParams params; params.dimensions = c->_bufferDim; params.numColorTargets = 0; params.useDepth = false; for(uint32 i = 0; i < c->_numTargets; ++i) { auto& t = c->_targets[i]; if(t.isDepthTarget) { params.useDepth = true; params.depth.format = t.format; params.depth.useAsTexture = t.asTexture; params.depth.useTarget = CreateTarget(c, t, 0); } else { auto& t2 = params.targets[params.numColorTargets++]; t2.format = t.format; t2.useAsTexture = t.asTexture; t2.useTarget = CreateTarget(c, t, params.numColorTargets-1); } } c->_rsys.CreateMultiRenderTarget(bufferNameId, params, c->_bufferDimFactor.x, c->_bufferDimFactor.y); } }
int main(int argc, char ** argv) { int result = 0; AwaServerSession * session = NULL; AwaServerExecuteOperation * operation = NULL; struct gengetopt_args_info ai; 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) { Error("Specify one or more resource paths.\n"); result = 1; goto cleanup; } // Create Session session = Server_EstablishSession(ai.ipcAddress_arg, ai.ipcPort_arg); if (session == NULL) { Error("EstablishSession failed\n"); result = 1; goto cleanup; } operation = AwaServerExecuteOperation_New(session); if (operation == NULL) { Error("AwaServerExecuteOperation_New failed\n"); result = 1; goto cleanup; } AwaExecuteArguments arguments = { .Data = NULL, .Size = 0 }; if (ai.stdin_given) { char buf[BUFSIZ]; int numBytes = 0; while (fread(buf+numBytes, 1, 1, stdin) == 1) { numBytes++; } arguments.Data = buf; arguments.Size = numBytes; Verbose("Read payload from stdin: %s [%zu bytes]\n", buf, arguments.Size); } else { Verbose("No payload specified.\n"); } int i = 0; for (i = 0; i < ai.inputs_num; ++i) { Target * target = CreateTarget(ai.inputs[i]); if (target != NULL) { AddTarget(operation, ai.clientID_arg, target, &arguments); FreeTarget(&target); } } result = ProcessExecuteOperation(session, operation, ai.clientID_arg); cleanup: if (session) { Server_ReleaseSession(&session); } if (operation) { AwaServerExecuteOperation_Free(&operation); } cmdline_parser_free(&ai); return result; }
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; AwaClientDeleteOperation * 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) { printf("Specify one or more resource paths.\n"); result = 1; goto cleanup; } session = Client_EstablishSession(ai.ipcAddress_arg, ai.ipcPort_arg); if (session != NULL) { // Create delete operation operation = AwaClientDeleteOperation_New(session); if (operation == NULL) { Error("AwaClientDeleteOperation_New failed\n"); result = 1; goto cleanup; } int i = 0; for (i = 0; i < ai.inputs_num; ++i) { Target * target = CreateTarget(ai.inputs[i]); if (target != NULL) { AddTarget(operation, target); FreeTarget(&target); } } } else { Error("Failed to establish Awa Session\n"); result = 1; goto cleanup; } result = ProcessDeleteOperation(operation); cleanup: if (session != NULL) { Client_ReleaseSession(&session); } cmdline_parser_free(&ai); return result; }
/* Handle the left button mouse click, when a tool is active */ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) { BOARD_ITEM* DrawStruct = GetCurItem(); bool exit = false; bool no_tool = GetToolId() == ID_NO_TOOL_SELECTED; if( no_tool || ( DrawStruct && DrawStruct->GetFlags() ) ) { m_canvas->SetAutoPanRequest( false ); if( DrawStruct && DrawStruct->GetFlags() ) // Command in progress { m_canvas->SetIgnoreMouseEvents( true ); m_canvas->CrossHairOff( aDC ); switch( DrawStruct->Type() ) { case PCB_ZONE_AREA_T: if( DrawStruct->IsNew() ) { m_canvas->SetAutoPanRequest( true ); Begin_Zone( aDC ); } else { End_Move_Zone_Corner_Or_Outlines( aDC, (ZONE_CONTAINER*) DrawStruct ); } exit = true; break; case PCB_TRACE_T: case PCB_VIA_T: if( DrawStruct->IsDragging() ) { PlaceDraggedOrMovedTrackSegment( (TRACK*) DrawStruct, aDC ); exit = true; } break; case PCB_TEXT_T: Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, aDC ); exit = true; break; case PCB_MODULE_TEXT_T: PlaceTexteModule( (TEXTE_MODULE*) DrawStruct, aDC ); exit = true; break; case PCB_PAD_T: PlacePad( (D_PAD*) DrawStruct, aDC ); exit = true; break; case PCB_MODULE_T: PlaceModule( (MODULE*) DrawStruct, aDC ); exit = true; break; case PCB_TARGET_T: PlaceTarget( (PCB_TARGET*) DrawStruct, aDC ); exit = true; break; case PCB_LINE_T: if( no_tool ) // when no tools: existing item moving. { Place_DrawItem( (DRAWSEGMENT*) DrawStruct, aDC ); exit = true; } break; case PCB_DIMENSION_T: if( ! DrawStruct->IsNew() ) { // We are moving the text of an existing dimension. Place it PlaceDimensionText( (DIMENSION*) DrawStruct, aDC ); exit = true; } break; default: DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() err: DrawType %d m_Flags != 0" ), DrawStruct->Type() ); exit = true; break; } m_canvas->SetIgnoreMouseEvents( false ); m_canvas->CrossHairOn( aDC ); if( exit ) return; } else if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT ) && !wxGetKeyState( WXK_CONTROL ) ) { DrawStruct = PcbGeneralLocateAndDisplay(); if( DrawStruct ) SendMessageToEESCHEMA( DrawStruct ); } } if( DrawStruct ) // display netclass info for zones, tracks and pads { switch( DrawStruct->Type() ) { case PCB_ZONE_AREA_T: case PCB_TRACE_T: case PCB_VIA_T: case PCB_PAD_T: GetDesignSettings().SetCurrentNetClass( ((BOARD_CONNECTED_ITEM*)DrawStruct)->GetNetClassName() ); updateTraceWidthSelectBox(); updateViaSizeSelectBox(); break; default: break; } } switch( GetToolId() ) { case ID_MAIN_MENUBAR: case ID_NO_TOOL_SELECTED: break; case ID_PCB_MUWAVE_TOOL_SELF_CMD: case ID_PCB_MUWAVE_TOOL_GAP_CMD: case ID_PCB_MUWAVE_TOOL_STUB_CMD: case ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD: case ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD: MuWaveCommand( aDC, aPosition ); break; case ID_PCB_HIGHLIGHT_BUTT: { int netcode = SelectHighLight( aDC ); if( netcode < 0 ) SetMsgPanel( GetBoard() ); else { NETINFO_ITEM* net = GetBoard()->FindNet( netcode ); if( net ) { MSG_PANEL_ITEMS items; net->GetMsgPanelInfo( items ); SetMsgPanel( items ); } } } break; case ID_PCB_SHOW_1_RATSNEST_BUTT: DrawStruct = PcbGeneralLocateAndDisplay(); Show_1_Ratsnest( DrawStruct, aDC ); if( DrawStruct ) SendMessageToEESCHEMA( DrawStruct ); break; case ID_PCB_MIRE_BUTT: if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { SetCurItem( (BOARD_ITEM*) CreateTarget( aDC ) ); m_canvas->MoveCursorToCrossHair(); } else if( DrawStruct->Type() == PCB_TARGET_T ) { PlaceTarget( (PCB_TARGET*) DrawStruct, aDC ); } else { DisplayError( this, wxT( "OnLeftClick err: not a PCB_TARGET_T" ) ); } break; case ID_PCB_CIRCLE_BUTT: case ID_PCB_ARC_BUTT: case ID_PCB_ADD_LINE_BUTT: { STROKE_T shape = S_SEGMENT; if( GetToolId() == ID_PCB_CIRCLE_BUTT ) shape = S_CIRCLE; if( GetToolId() == ID_PCB_ARC_BUTT ) shape = S_ARC; if( IsCopperLayer( GetActiveLayer() ) ) { DisplayError( this, _( "Graphic not allowed on Copper layers" ) ); break; } if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( NULL, shape, aDC ); SetCurItem( DrawStruct ); m_canvas->SetAutoPanRequest( true ); } else if( DrawStruct && (DrawStruct->Type() == PCB_LINE_T) && DrawStruct->IsNew() ) { DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( (DRAWSEGMENT*) DrawStruct, shape, aDC ); SetCurItem( DrawStruct ); m_canvas->SetAutoPanRequest( true ); } } break; case ID_TRACK_BUTT: if( !IsCopperLayer( GetActiveLayer() ) ) { DisplayError( this, _( "Tracks on Copper layers only " ) ); break; } if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { DrawStruct = (BOARD_ITEM*) Begin_Route( NULL, aDC ); SetCurItem( DrawStruct ); if( DrawStruct ) m_canvas->SetAutoPanRequest( true ); } else if( DrawStruct && DrawStruct->IsNew() ) { TRACK* track = Begin_Route( (TRACK*) DrawStruct, aDC ); // SetCurItem() must not write to the msg panel // because a track info is displayed while moving the mouse cursor if( track ) // A new segment was created SetCurItem( DrawStruct = (BOARD_ITEM*) track, false ); m_canvas->SetAutoPanRequest( true ); } break; case ID_PCB_ZONES_BUTT: case ID_PCB_KEEPOUT_AREA_BUTT: /* ZONE or KEEPOUT Tool is selected. Determine action for a left click: * this can be start a new zone or select and move an existing zone outline corner * if found near the mouse cursor */ if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { if( Begin_Zone( aDC ) ) { m_canvas->SetAutoPanRequest( true ); DrawStruct = GetBoard()->m_CurrentZoneContour; GetScreen()->SetCurItem( DrawStruct ); } } else if( DrawStruct && (DrawStruct->Type() == PCB_ZONE_AREA_T) && DrawStruct->IsNew() ) { // Add a new corner to the current outline being created: m_canvas->SetAutoPanRequest( true ); Begin_Zone( aDC ); DrawStruct = GetBoard()->m_CurrentZoneContour; GetScreen()->SetCurItem( DrawStruct ); } else { DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() zone internal error" ) ); } break; case ID_PCB_ADD_TEXT_BUTT: if( IsLayerInList( EDGE_LAYER, GetActiveLayer() ) ) { DisplayError( this, _( "Texts not allowed on Edge Cut layer" ) ); break; } if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { SetCurItem( CreateTextePcb( aDC ) ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetAutoPanRequest( true ); } else if( DrawStruct->Type() == PCB_TEXT_T ) { Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, aDC ); m_canvas->SetAutoPanRequest( false ); } else { DisplayError( this, wxT( "OnLeftClick err: not a PCB_TEXT_T" ) ); } break; case ID_PCB_MODULE_BUTT: if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { m_canvas->MoveCursorToCrossHair(); DrawStruct = (BOARD_ITEM*) LoadModuleFromLibrary( wxEmptyString, Prj().PcbFootprintLibs(), true, aDC ); SetCurItem( DrawStruct ); if( DrawStruct ) StartMoveModule( (MODULE*) DrawStruct, aDC, false ); } else if( DrawStruct->Type() == PCB_MODULE_T ) { PlaceModule( (MODULE*) DrawStruct, aDC ); m_canvas->SetAutoPanRequest( false ); } else { DisplayError( this, wxT( "Internal err: Struct not PCB_MODULE_T" ) ); } break; case ID_PCB_DIMENSION_BUTT: if( IsLayerInList( EDGE_LAYER|ALL_CU_LAYERS, GetActiveLayer() ) ) { DisplayError( this, _( "Dimension not allowed on Copper or Edge Cut layers" ) ); break; } if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { DrawStruct = (BOARD_ITEM*) EditDimension( NULL, aDC ); SetCurItem( DrawStruct ); m_canvas->SetAutoPanRequest( true ); } else if( DrawStruct && (DrawStruct->Type() == PCB_DIMENSION_T) && DrawStruct->IsNew() ) { DrawStruct = (BOARD_ITEM*) EditDimension( (DIMENSION*) DrawStruct, aDC ); SetCurItem( DrawStruct ); m_canvas->SetAutoPanRequest( true ); } else { DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() error item is not a DIMENSION" ) ); } break; case ID_PCB_DELETE_ITEM_BUTT: if( !DrawStruct || !DrawStruct->GetFlags() ) { DrawStruct = PcbGeneralLocateAndDisplay(); if( DrawStruct && (DrawStruct->GetFlags() == 0) ) { RemoveStruct( DrawStruct, aDC ); SetCurItem( DrawStruct = NULL ); } } break; case ID_PCB_PLACE_OFFSET_COORD_BUTT: m_canvas->DrawAuxiliaryAxis( aDC, GR_XOR ); SetAuxOrigin( GetCrossHairPosition() ); m_canvas->DrawAuxiliaryAxis( aDC, GR_COPY ); OnModify(); break; case ID_PCB_PLACE_GRID_COORD_BUTT: m_canvas->DrawGridAxis( aDC, GR_XOR, GetBoard()->GetGridOrigin() ); SetGridOrigin( GetCrossHairPosition() ); m_canvas->DrawGridAxis( aDC, GR_COPY, GetBoard()->GetGridOrigin() ); break; default: DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() id error" ) ); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); break; } }
int main(int argc, char ** argv) { int result = 0; AwaServerObserveOperation * operation; struct gengetopt_args_info ai; AwaServerSession * session = NULL; Target ** targets = NULL; // Catch CTRL-C to ensure clean-up signal(SIGINT, INThandler); 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) { Error("Specify one or more resource paths.\n"); result = 1; goto cleanup; } session = Server_EstablishSession(ai.ipcAddress_arg, ai.ipcPort_arg); if (session != NULL) { operation = AwaServerObserveOperation_New(session); if (operation == NULL) { Error("Failed to create observe operation\n"); exit(1); } targets = malloc(ai.inputs_num * sizeof(Target *)); ObserveContext observeContext; observeContext.targets = targets; observeContext.numTargets = ai.inputs_num; observeContext.quiet = ai.quiet_given; // pass the quiet parameter as our context int count = 0; int i = 0; for (i = 0; i < ai.inputs_num; ++i) { targets[i] = CreateTarget(ai.inputs[i]); if (targets[i] != NULL) { count = ObserveTarget(operation, ai.clientID_arg, targets[i], &observeContext) ? count + 1 : count; } } if (AwaServerObserveOperation_Perform(operation, OPERATION_PERFORM_TIMEOUT) != AwaError_Success) { Error("Failed to perform observe operation\n"); goto cleanup; } int validCount = count; const AwaServerObserveResponse * response = AwaServerObserveOperation_GetResponse(operation, ai.clientID_arg); ObservationNode * currentObservation = g_observationListHead; ObservationNode * nextObservation; while (currentObservation != NULL) { nextObservation = currentObservation->next; const AwaPathResult * pathResult = NULL; AwaServerObservation * observation = (AwaServerObservation *)(currentObservation->observation); const char * path = AwaServerObservation_GetPath(observation); pathResult = AwaServerObserveResponse_GetPathResult(response, path); if (AwaPathResult_GetError(pathResult) != AwaError_Success) { Error("Failed to observe to %s: %s\n", path, AwaError_ToString(AwaPathResult_GetError(pathResult))); validCount--; } currentObservation = nextObservation; } AwaServerObserveOperation_Free(&operation); // Wait if there's something to wait for Debug("count %d\n", count); if (count > 0) { if (validCount > 0) { Wait(session, ai.waitTime_arg, ai.waitCount_arg); } CancelObservationFromTargets(session, ai.clientID_arg); } } else { Error("Failed to establish Awa Session\n"); result = 1; } cleanup: if (session) { FreeObservationList(); Server_ReleaseSession(&session); } if (targets) { int i; for (i = 0; i < ai.inputs_num; ++i) { if (targets[i] != NULL) { FreeTarget(&targets[i]); } } free(targets); } cmdline_parser_free(&ai); return result; }
int main(int argc, char ** argv) { int result = 0; AwaClientSubscribeOperation * operation; struct gengetopt_args_info ai; AwaClientSession * session = NULL; // Catch CTRL-C to ensure clean-up signal(SIGINT, INThandler); 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) { Error("Specify one or more resource paths.\n"); result = 1; goto cleanup; } session = Client_EstablishSession(ai.ipcAddress_arg, ai.ipcPort_arg); if (session != NULL) { operation = AwaClientSubscribeOperation_New(session); if (operation == NULL) { Error("Failed to create subscribe operation\n"); exit(1); } void * context = &ai.quiet_given; // pass the quiet parameter as our context int count = 0; int i = 0; for (i = 0; i < ai.inputs_num; ++i) { Target * target = CreateTarget(ai.inputs[i]); if (target != NULL) { count = SubscribeToTarget(session, operation, target, context) ? count + 1 : count; FreeTarget(&target); } } if (AwaClientSubscribeOperation_Perform(operation, OPERATION_PERFORM_TIMEOUT) != AwaError_Success) { Error("Failed to perform subscribe operation\n"); goto cleanup; } int validCount = count; const AwaClientSubscribeResponse * response = AwaClientSubscribeOperation_GetResponse(operation); SubscriptionNode * currentSubscription = g_subscriptionListHead; SubscriptionNode * nextSubscription; while (currentSubscription != NULL) { nextSubscription = currentSubscription->next; const AwaPathResult * pathResult = NULL; const char * path = NULL; switch (currentSubscription->type) { case AwaSubscribeType_Change: { AwaClientChangeSubscription * subscription = (AwaClientChangeSubscription *)(currentSubscription->subscription); path = AwaClientChangeSubscription_GetPath(subscription); break; } case AwaSubscribeType_Execute: { AwaClientExecuteSubscription * subscription = (AwaClientExecuteSubscription *)(currentSubscription->subscription); path = AwaClientExecuteSubscription_GetPath(subscription); break; } default: Error("Unsupported subscribe type: %d for path %s\n", currentSubscription->type, path); break; } pathResult = AwaClientSubscribeResponse_GetPathResult(response, path); if (AwaPathResult_GetError(pathResult) != AwaError_Success) { Error("Failed to subscribe to %s: %s\n", path, AwaError_ToString(AwaPathResult_GetError(pathResult))); validCount--; } currentSubscription = nextSubscription; } AwaClientSubscribeOperation_Free(&operation); Debug("count %d\n", count); // Wait if there's something to wait for if (count > 0) { if (validCount > 0) { Wait(session, ai.waitTime_arg, ai.waitCount_arg); } UnsubscribeFromTargets(session); } } else { Error("Failed to establish Awa Session\n"); result = 1; } cleanup: if (session) { FreeSubscriptionList(); Client_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; }