void wxMFrame::CreateToolAndStatusBars() { bool tb, sb; wxConfigBase * const pConf = GetFrameOptionsConfig(); if ( pConf != NULL ) { tb = GetOptionValue(pConf, MP_SHOW_TOOLBAR).GetBoolValue(); sb = GetOptionValue(pConf, MP_SHOW_STATUSBAR).GetBoolValue(); } else { tb = GetNumericDefault(MP_SHOW_TOOLBAR) != 0; sb = GetNumericDefault(MP_SHOW_STATUSBAR) != 0; } wxMenuBar * const mb = GetMenuBar(); mb->Check(WXMENU_VIEW_TOOLBAR, tb); mb->Check(WXMENU_VIEW_STATUSBAR, sb); if ( tb ) DoCreateToolBar(); if ( sb ) DoCreateStatusBar(); }
// helper function which either writes the given boolean value option to the // config or deletes it from it if the new value is the same as default one // // notice that this only works for the frame values as there is no inheritance // with the frames profiles, otherwise deleting the value wouldn't have been // enough static void UpdateBoolConfigValue(wxConfigBase *pConf, const MOption opt, bool value) { // to compare boolean value with option value we need to cast it to long to // avoid ambiguities const long lValue = value; if ( GetOptionValue(pConf, opt) != lValue ) { // current value must be changed but how? if ( lValue == GetNumericDefault(opt) ) { // it's enough to just delete the existing value pConf->DeleteEntry(GetOptionName(opt)); } else // we must really write the new value to the config { pConf->Write(GetOptionName(opt), value); } } //else: we already have the right value in the config, nothing to do ASSERT_MSG( GetOptionValue(pConf, opt) == lValue, "didn't update a boolean option correctly" ); }
bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) return false; CFX_WideString opt_value = GetOptionValue(index); if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) return false; if (bSelected) { if (GetType() == ListBox) { SelectOption(index, true); if (!(m_Flags & kFormListMultiSelect)) { m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false); } else { CPDF_Array* pArray = m_pDict->SetNewFor<CPDF_Array>("V"); for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false); } } } } else { m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false); CPDF_Array* pI = m_pDict->SetNewFor<CPDF_Array>("I"); pI->AddNew<CPDF_Number>(index); } } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (GetType() == ListBox) { SelectOption(index, false); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveFor("V"); } else if (pValue->IsArray()) { std::unique_ptr<CPDF_Array> pArray(new CPDF_Array); for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false); } } if (pArray->GetCount() > 0) m_pDict->SetFor("V", std::move(pArray)); } } else { m_pDict->RemoveFor("V"); m_pDict->RemoveFor("I"); } } } if (bNotify) NotifyListOrComboBoxAfterChange(); return true; }
void Game::CalculateScores() { // // Work out the score weightings int scoreMode = GetOptionValue( "ScoreMode" ); switch( scoreMode ) { case 0: // Standard m_pointsPerSurvivor = 0; m_pointsPerDeath = -1; m_pointsPerKill = 2; m_pointsPerNuke = 0; m_pointsPerCollatoral = -2; break; case 1: // Survivor m_pointsPerSurvivor = 1; m_pointsPerDeath = 0; m_pointsPerKill = 0; m_pointsPerNuke = 0; m_pointsPerCollatoral = -1; break; case 2: // Genocide m_pointsPerSurvivor = 0; m_pointsPerDeath = 0; m_pointsPerKill = 1; m_pointsPerNuke = 0; m_pointsPerCollatoral = -1; break; } // // Work out the scores based on the weightings int startingPopulation = GetOptionValue( "PopulationPerTerritory" ) * 1000000.0f; startingPopulation *= GetOptionValue( "TerritoriesPerTeam" ); for( int t = 0; t < g_app->GetWorld()->m_teams.Size(); ++t ) { Team *team = g_app->GetWorld()->m_teams[t]; m_score[team->m_teamId] = (startingPopulation - team->m_friendlyDeaths) * m_pointsPerSurvivor + team->m_friendlyDeaths * m_pointsPerDeath + team->m_enemyKills * m_pointsPerKill + m_nukeCount[team->m_teamId] * m_pointsPerNuke * 1000000.0f + team->m_collatoralDamage * m_pointsPerCollatoral; m_score[team->m_teamId] /= 1000000.0f; } }
LERC_Band::LERC_Band(GDALMRFDataset *pDS, const ILImage &image, int b, int level): GDALMRFRasterBand(pDS, image, b, level) { // Pick 1/1000 for floats and 0.5 losless for integers if (eDataType == GDT_Float32 || eDataType == GDT_Float64 ) precision = strtod(GetOptionValue( "LERC_PREC" , ".001" ),NULL); else precision = std::max(0.5, strtod(GetOptionValue("LERC_PREC", ".5"), NULL)); // Encode in V2 by default version = GetOptlist().FetchBoolean("V1", FALSE) ? 1:2; // Enlarge the page buffer in this case, LERC may expand data pDS->SetPBufferSize( 2 * image.pageSizeBytes); }
void CConfigFile::GetOptionValue(const string& sSection, const string& sParam, int& nValue, int nDefValue) { if (!GetOptionValue(sSection, sParam, nValue)) { nValue = nDefValue; } }
int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue) const { for (int i = 0; i < CountOptions(); i++) { if (GetOptionValue(i) == csOptValue) return i; } return -1; }
int CProfileOptions::GetOptionValueAsInt(const char* command, bool getDefault/*=false*/) { if (!command) return -1; return atoi(GetOptionValue(command, getDefault)); }
float CProfileOptions::GetOptionValueAsFloat(const char* command, bool getDefault/*=false*/) { if (!command) return -1.0f; return (float) atof(GetOptionValue(command, getDefault)); }
CEVENT(Channel, SubscribeChannels) { World* world = World::GetPtr(); std::list <std::string> *names=new std::list<std::string>(); std::list <std::string>::iterator it, itEnd; Channel* chan=NULL; Player* mobile=(Player*)caller; mobile->events.AddCallback("OptionChanged", std::bind(&Channel::OptionChanged, std::placeholders::_1, std::placeholders::_2)); world->GetChannelNames(names); itEnd = names->end(); for (it = names->begin(); it != itEnd; ++it) { if (GetOptionValue((*it), mobile).GetInt() == 1) { chan=world->FindChannel((*it)); if (chan) { chan->AddListener(mobile,true); } } } delete names; }
void CConfigFile::GetOptionValue(const string& sSection, const string& sParam, ushort& nValue, ushort usDefValue) { if (!GetOptionValue(sSection, sParam, nValue)) { nValue = usDefValue; } }
int CPDF_FormField::GetSelectedIndex(int index) { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue == NULL) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (pValue == NULL) { return -1; } } if (pValue->GetType() == PDFOBJ_NUMBER) { return pValue->GetInteger(); } CFX_WideString sel_value; if (pValue->GetType() == PDFOBJ_STRING) { if (index != 0) { return -1; } sel_value = pValue->GetUnicodeText(); } else { if (pValue->GetType() != PDFOBJ_ARRAY) { return -1; } if (index < 0) { return -1; } CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index); sel_value = elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); } if (index < CountSelectedOptions()) { int iOptIndex = GetSelectedOptionIndex(index); CFX_WideString csOpt = GetOptionValue(iOptIndex); if (csOpt == sel_value) { return iOptIndex; } } int nOpts = CountOptions(); for (int i = 0; i < nOpts; i++) { if (sel_value == GetOptionValue(i)) { return i; } } return -1; }
int CPDF_FormField::FindOption(CFX_WideString csOptLabel) { int iCount = CountOptions(); for (int i = 0; i < iCount; i++) { CFX_WideString csValue = GetOptionValue(i); if (csValue == csOptLabel) { return i; } } return -1; }
void CProfileOptions::AddOrReplacePendingOption(const char* command, const char* param) { std::vector<SPendingOption>::iterator it = m_pendingOptions.begin(); std::vector<SPendingOption>::const_iterator end = m_pendingOptions.end(); for(; it!=end; ++it) { SPendingOption& option = (*it); if(option.command.compare(command)) continue; if(option.preview) { SetOptionValue(command, param); } if(option.original.compare(param)) { option.param = param; } else { m_pendingOptions.erase(it); } return; } COption* pOption = GetOption(command); if(pOption != NULL) { if(pOption->IsPreview()) { m_pendingOptions.push_back(SPendingOption(command, param, GetOptionValue(command), true, pOption->IsConfirmation(), pOption->IsRequiresRestart(), pOption->IsWriteToConfig())); SetOptionValue(command, param); } else { m_pendingOptions.push_back(SPendingOption(command, param, GetOptionValue(command), false, pOption->IsConfirmation(), pOption->IsRequiresRestart(), pOption->IsWriteToConfig())); } } }
bool CConfigFile::GetOptionValue(const string& sSection, const string& sParam, ushort& nValue) { bool bResult = false; string sValue; if (true == (bResult = GetOptionValue(sSection, sParam, sValue))) { nValue = atoi( sValue.c_str() ); } return bResult; }
int CPDF_FormField::GetSelectedIndex(int index) { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (!pValue) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (!pValue) return -1; } if (pValue->IsNumber()) return pValue->GetInteger(); CFX_WideString sel_value; if (pValue->IsString()) { if (index != 0) return -1; sel_value = pValue->GetUnicodeText(); } else { CPDF_Array* pArray = pValue->AsArray(); if (!pArray || index < 0) return -1; CPDF_Object* elementValue = pArray->GetElementValue(index); sel_value = elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); } if (index < CountSelectedOptions()) { int iOptIndex = GetSelectedOptionIndex(index); CFX_WideString csOpt = GetOptionValue(iOptIndex); if (csOpt == sel_value) { return iOptIndex; } } int nOpts = CountOptions(); for (int i = 0; i < nOpts; i++) { if (sel_value == GetOptionValue(i)) { return i; } } return -1; }
string CProfileOptions::GetOptionValueOrCreate(const char* command, bool getDefault/*=false*/) { CRY_ASSERT(command != NULL); if(!command || !command[0]) return ""; if(!IsOption(command)) { AddOption(command, ""); } return GetOptionValue(command, getDefault); }
int CPDF_FormField::GetDefaultSelectedItem() const { ASSERT(GetType() == ComboBox || GetType() == ListBox); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); if (!pValue) return -1; CFX_WideString csDV = pValue->GetUnicodeText(); if (csDV.IsEmpty()) return -1; for (int i = 0; i < CountOptions(); i++) { if (csDV == GetOptionValue(i)) return i; } return -1; }
void wxMFrame::ShowInInitialState() { bool showFullScreen; wxConfigBase * const pConf = GetFrameOptionsConfig(); if ( pConf ) showFullScreen = GetOptionValue(pConf, MP_SHOW_FULLSCREEN).GetBoolValue(); else showFullScreen = GetNumericDefault(MP_SHOW_FULLSCREEN) != 0; Show(true); if ( showFullScreen ) ShowFullScreen(true); }
int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue, int iStartIndex) { if (iStartIndex < 0) { iStartIndex = 0; } int iCount = CountOptions(); for (; iStartIndex < iCount; iStartIndex++) { CFX_WideString csValue = GetOptionValue(iStartIndex); if (csValue == csOptValue) { return iStartIndex; } } return -1; }
FX_BOOL CPDF_FormField::IsItemSelected(int index) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) { return FALSE; } if (IsOptionSelected(index)) { return TRUE; } CFX_WideString opt_value = GetOptionValue(index); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue == NULL) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (pValue == NULL) { return FALSE; } } if (pValue->GetType() == PDFOBJ_STRING) { if (pValue->GetUnicodeText() == opt_value) { return TRUE; } return FALSE; } if (pValue->GetType() == PDFOBJ_NUMBER) { if (pValue->GetString().IsEmpty()) { return FALSE; } if (pValue->GetInteger() == index) { return TRUE; } return FALSE; } if (pValue->GetType() != PDFOBJ_ARRAY) { return FALSE; } CPDF_Array* pArray = (CPDF_Array*)pValue; int iPos = -1; for (int j = 0; j < CountSelectedOptions(); j ++) { if (GetSelectedOptionIndex(j) == index) { iPos = j; break; } } for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i == iPos) { return TRUE; } return FALSE; }
FX_BOOL CPDF_FormField::IsItemSelected(int index) const { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) { return FALSE; } if (IsOptionSelected(index)) { return TRUE; } CFX_WideString opt_value = GetOptionValue(index); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (!pValue) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (!pValue) { return FALSE; } } if (pValue->IsString()) return pValue->GetUnicodeText() == opt_value; if (pValue->IsNumber()) { if (pValue->GetString().IsEmpty()) return FALSE; return (pValue->GetInteger() == index); } CPDF_Array* pArray = pValue->AsArray(); if (!pArray) return FALSE; int iPos = -1; for (int j = 0; j < CountSelectedOptions(); j++) { if (GetSelectedOptionIndex(j) == index) { iPos = j; break; } } for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++) if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && i == iPos) { return TRUE; } return FALSE; }
bool wxMFrame::RestorePosition(const char *name, int *x, int *y, int *w, int *h, bool *i, bool *m) { // only i and m might be NULL CHECK( x && y && w && h, FALSE, _T("NULL pointer in wxMFrame::RestorePosition") ); wxConfigBase * const pConf = GetFrameOptionsConfig(name); if ( pConf != NULL ) { *x = GetOptionValue(pConf, MP_XPOS); *y = GetOptionValue(pConf, MP_YPOS); *w = GetOptionValue(pConf, MP_WIDTH); *h = GetOptionValue(pConf, MP_HEIGHT); if ( i ) *i = GetOptionValue(pConf, MP_ICONISED).GetBoolValue(); if ( m ) *m = GetOptionValue(pConf, MP_MAXIMISED).GetBoolValue(); // assume that if one entry existed, then the other existed too return pConf->HasEntry(GetOptionName(MP_XPOS)); } else { // it's ok if it's done the first time *x = GetNumericDefault(MP_XPOS); *y = GetNumericDefault(MP_YPOS); *w = GetNumericDefault(MP_WIDTH); *h = GetNumericDefault(MP_HEIGHT); if ( i ) *i = GetNumericDefault(MP_ICONISED) != 0; if ( m ) *m = GetNumericDefault(MP_MAXIMISED) != 0; return FALSE; } }
FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) return FALSE; CFX_WideString opt_value = GetOptionValue(index); if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) return FALSE; if (bSelected) { if (GetType() == ListBox) { SelectOption(index, TRUE); if (!(m_Flags & kFormListMultiSelect)) { m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); } else { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } m_pDict->SetFor("V", pArray); } } else { m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); CPDF_Array* pI = new CPDF_Array; pI->AddInteger(index); m_pDict->SetFor("I", pI); } } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (GetType() == ListBox) { SelectOption(index, FALSE); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveFor("V"); } else if (pValue->IsArray()) { std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( new CPDF_Array); for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } if (pArray->GetCount() > 0) m_pDict->SetFor("V", pArray.release()); // std::move someday } } else { m_pDict->RemoveFor("V"); m_pDict->RemoveFor("I"); } } } if (bNotify) NotifyListOrComboBoxAfterChange(); return TRUE; }
/** * @fn HRESULT receive_execute(struct CONN_BCAP_SERVER *bcap_param) * @brief Receives the b-CAP packet and executes callback functions. * @param[in,out] bcap_param b-CAP communication object. */ static HRESULT receive_execute(struct CONN_BCAP_SERVER *bcap_param) { int index; int32_t relation_id; uint16_t i, clear_flag = 1; uint32_t cur, start, diff; HRESULT hr; struct CONN_BCAP_SERVER *tmp_param = bcap_param; struct CONN_PARAM_COMMON *device = &bcap_param->device; struct BCAP_PACKET tmp_send_packet, tmp_recv_packet, *send_packet = &bcap_param->last_send, *recv_packet = &bcap_param->last_recv; struct VEC_OBJECT *pObj = NULL; BSTR bstrOpt = NULL; VARIANT vntTmp, vntOpt; VariantInit(&vntTmp); VariantInit(&vntOpt); /* Initializes temporary packet */ tmp_recv_packet.argc = (uint16_t) -1; tmp_recv_packet.args = NULL; /* Receives b-CAP packet */ hr = bcap_recv(device, &tmp_recv_packet, 0); if(SUCCEEDED(hr)) { /* Sets S_EXECUTING packet */ memset(&tmp_send_packet, 0, sizeof(struct BCAP_PACKET)); tmp_send_packet.serial = tmp_recv_packet.serial; tmp_send_packet.id = S_EXECUTING; /* Checks retry packet */ switch(device->type) { case CONN_UDP: tmp_param = search_node(bcap_param, device->arg, sizeof(struct sockaddr_in)); if(tmp_param == NULL) { /* Checks life limit */ if((bcap_param->num_child >= BCAP_CLIENT_MAX) && (check_lifelimit(bcap_param) >= BCAP_CLIENT_MAX)) { tmp_send_packet.id = E_MAX_CONNECT; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } /* Adds child */ change_relation(bcap_param, ADD_CHILD, &device->sock); tmp_param = bcap_param->node1; } send_packet = &tmp_param->last_send; //break; case CONN_COM: /* Sets retry count */ tmp_recv_packet.reserv = (tmp_recv_packet.reserv == 0) ? tmp_recv_packet.serial : tmp_recv_packet.reserv; /* If already responded, then does not execute */ if(send_packet->serial == tmp_recv_packet.reserv) { /* Copies last send packet */ tmp_send_packet = *send_packet; /* Sets new serial number */ tmp_send_packet.serial = tmp_recv_packet.serial; /* Sends temporary send packet */ bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } break; default: break; } /* Checks execute thread */ hr = wait_event(&bcap_param->comp_evt, 0); if(hr == E_TIMEOUT) { /* Sends result busy process */ tmp_send_packet.id = E_BUSY_PROC; bcap_send(device, &tmp_send_packet); goto exit_proc; } switch(tmp_recv_packet.id) { case ID_SERVICE_START: case ID_CONTROLLER_CONNECT: case ID_CONTROLLER_GETEXTENSION: case ID_CONTROLLER_GETFILE: case ID_FILE_GETFILE: case ID_CONTROLLER_GETROBOT: case ID_CONTROLLER_GETTASK: case ID_CONTROLLER_GETVARIABLE: case ID_EXTENSION_GETVARIABLE: case ID_FILE_GETVARIABLE: case ID_ROBOT_GETVARIABLE: case ID_TASK_GETVARIABLE: case ID_CONTROLLER_GETCOMMAND: case ID_CONTROLLER_GETMESSAGE: if(bcap_param->num_object >= BCAP_OBJECT_MAX) { tmp_send_packet.id = E_MAX_OBJECT; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } if(tmp_recv_packet.id == ID_SERVICE_START) { if((tmp_recv_packet.argc >= 1) && (tmp_recv_packet.args != NULL)) { VariantCopy(&vntTmp, &tmp_recv_packet.args[0]); hr = VariantChangeType(&vntTmp, &vntTmp, 0, VT_BSTR); if(FAILED(hr)) { tmp_send_packet.id = hr; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } } else { vntTmp.vt = VT_BSTR; vntTmp.bstrVal = SysAllocString(L""); } bstrOpt = SysAllocString(L"WDT"); hr = GetOptionValue(vntTmp.bstrVal, bstrOpt, VT_UI4, &vntOpt); vntOpt.ulVal = (vntOpt.vt == VT_UI4) ? vntOpt.ulVal : INIT_WDT_INTERVAL; if(vntOpt.ulVal < MIN_WDT_INTERVAL) { tmp_send_packet.id = E_INVALIDARG; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } else { tmp_param->wdt_interval = vntOpt.ulVal; } SysFreeString(bstrOpt); VariantClear(&vntOpt); bstrOpt = SysAllocString(L"InvokeTimeout"); hr = GetOptionValue(vntTmp.bstrVal, bstrOpt, VT_UI4, &vntOpt); vntOpt.ulVal = (vntOpt.vt == VT_UI4) ? vntOpt.ulVal : INIT_EXEC_TIMEOUT; if(vntOpt.ulVal < MIN_WDT_INTERVAL) { tmp_send_packet.id = E_INVALIDARG; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } else { tmp_param->exec_timeout = vntOpt.ulVal; } SysFreeString(bstrOpt); VariantClear(&vntOpt); VariantClear(&vntTmp); bstrOpt = NULL; } break; default: break; } /* Resets last received packet */ if(recv_packet->args != NULL) { for(i = 0; i < recv_packet->argc; i++) { VariantClear(&recv_packet->args[i]); } free(recv_packet->args); } /* Copies to last receive packet */ clear_flag = 0; *recv_packet = tmp_recv_packet; /* Runs execute thread */ reset_event(&bcap_param->comp_evt); set_event(&bcap_param->exec_evt); if(SUCCEEDED(hr)) { start = gettimeofday_msec(); while(1) { hr = wait_event(&bcap_param->comp_evt, tmp_param->wdt_interval); if(SUCCEEDED(hr)) { break; } else { /* Sends S_EXECUTING packet */ hr = bcap_send(device, &tmp_send_packet); if(FAILED(hr)) { break; } } /* Checks executing timeout */ cur = gettimeofday_msec(); diff = calc_time_diff(start, cur); if(diff > tmp_param->exec_timeout) { hr = E_TIMEOUT; break; } } } } exit_proc: if(hr == S_OK) { if(bcap_param->last_send.id == S_OK) { /* Changes the vector of created objects */ relation_id = m_map_id[recv_packet->id].relation_id; if(relation_id > 0) { // Push pObj = (struct VEC_OBJECT *) malloc(sizeof(struct VEC_OBJECT)); if(pObj != NULL) { memset(pObj, 0, sizeof(struct VEC_OBJECT)); pObj->id = relation_id; pObj->hObj = (recv_packet->id == ID_SERVICE_START) ? 0 : bcap_param->last_send.args[0].lVal; push_vector(bcap_param, pObj); } } else if(relation_id < 0) { // Pop index = search_vector(bcap_param, recv_packet->id, (recv_packet->id == ID_SERVICE_STOP) ? 0 : recv_packet->args[0].lVal); if(index >= 0) { pop_vector(bcap_param, &pObj, index); free(pObj); } if((device->type == CONN_UDP) && (recv_packet->id == ID_SERVICE_STOP)) { change_relation(tmp_param, DESTROY_SELF, NULL); change_relation(bcap_param, DELETE_CHILD, NULL); tmp_param = NULL; } } } /* Responds the result message */ hr = bcap_send(device, &bcap_param->last_send); if(SUCCEEDED(hr) && (tmp_param != NULL)) { tmp_param->last_send.serial = bcap_param->last_send.serial; tmp_param->last_send.reserv = bcap_param->last_send.reserv; tmp_param->last_send.id = bcap_param->last_send.id; tmp_param->last_send.argc = bcap_param->last_send.argc; VariantCopy(tmp_param->last_send.args, bcap_param->last_send.args); tmp_param->last_modified = gettimeofday_msec(); } } /* Clears temporary packet */ if(clear_flag) { if(tmp_recv_packet.args != NULL) { for(i = 0; i < tmp_recv_packet.argc; i++) { VariantClear(&tmp_recv_packet.args[i]); } free(tmp_recv_packet.args); } } VariantClear(&vntTmp); VariantClear(&vntOpt); if(bstrOpt) { SysFreeString(bstrOpt); } return hr; }
static DWORD ParseLeaveArgs( IN int argc, IN const char *argv[], OUT PLEAVE_ARGS pArgs ) { DWORD dwError = 0; PCSTR programName = NULL; PCSTR option = NULL; LW_ARGV_CURSOR cursor; SHOW_USAGE_CALLBACK ShowUsageHelp = ShowLeaveUsageHelp; SHOW_USAGE_CALLBACK ShowUsageError = ShowLeaveUsageError; memset(pArgs, 0, sizeof(*pArgs)); LwArgvCursorInit(&cursor, argc, argv); programName = LwArgvCursorPop(&cursor); // Process options: for (;;) { option = PopNextOption(&cursor); if (!option) { break; } else if (IsHelpOption(option)) { ShowUsageHelp(programName); } else if (!strcmp("--multiple", option)) { SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_MULTIPLE); dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszDomain); GOTO_CLEANUP_ON_WINERROR(dwError); LwStrToUpper(pArgs->pszDomain); } else { fprintf(stderr, "Unrecognized option: %s\n", option); ShowUsageError(programName); } } // Optional arguments dwError = GetArgumentValue(programName, ShowUsageError, &cursor, NULL, &pArgs->pszUsername); assert(!dwError); dwError = GetArgumentValue(programName, ShowUsageError, &cursor, NULL, &pArgs->pszPassword); assert(!dwError); if (LwArgvCursorRemaining(&cursor)) { fprintf(stderr, "Too many arguments.\n"); ShowUsageError(programName); } // Initialize implicit domain argument. if (!pArgs->pszDomain) { dwError = GetCurrentDomain(&pArgs->pszDomain); if (NERR_SetupNotJoined == dwError) { fprintf(stderr, "The computer is not joined to a domain.\n"); exit(1); } GOTO_CLEANUP_ON_WINERROR(dwError); } // If USERNAME was specified, clean it up and get password // as needed. if (pArgs->pszUsername) { dwError = CleanupUsername(pArgs->pszDomain, &pArgs->pszUsername); GOTO_CLEANUP_ON_WINERROR(dwError); if (!pArgs->pszPassword) { dwError = PromptPassword(pArgs->pszUsername, &pArgs->pszPassword); GOTO_CLEANUP_ON_WINERROR(dwError); } } cleanup: if (dwError) { FreeLeaveArgsContents(pArgs); } return dwError; }
static DWORD ParseJoinArgs( IN int argc, IN const char *argv[], OUT PJOIN_ARGS pArgs ) { DWORD dwError = 0; PCSTR programName = NULL; PCSTR option = NULL; LW_ARGV_CURSOR cursor; SHOW_USAGE_CALLBACK ShowUsageHelp = ShowJoinUsageHelp; SHOW_USAGE_CALLBACK ShowUsageError = ShowJoinUsageError; memset(pArgs, 0, sizeof(*pArgs)); LwArgvCursorInit(&cursor, argc, argv); programName = LwArgvCursorPop(&cursor); // Process options: for (;;) { option = PopNextOption(&cursor); if (!option) { break; } else if (IsHelpOption(option)) { ShowUsageHelp(programName); } else if (!strcmp("--name", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszMachineName); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--dnssuffix", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszDnsSuffix); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--ou", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOu); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--osname", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOsName); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--osversion", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOsVersion); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--osservicepack", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOsServicePack); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--notimesync", option)) { SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_NOTIMESYNC); } else if (!strcmp("--multiple", option)) { SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_NOTIMESYNC); SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_MULTIPLE); } else { fprintf(stderr, "Unrecognized option: %s\n", option); ShowUsageError(programName); } } // Process arguments: dwError = GetArgumentValue(programName, ShowUsageError, &cursor, "DOMAIN", &pArgs->pszDomain); GOTO_CLEANUP_ON_WINERROR(dwError); LwStrToUpper(pArgs->pszDomain); dwError = GetArgumentValue(programName, ShowUsageError, &cursor, "USERNAME", &pArgs->pszUsername); GOTO_CLEANUP_ON_WINERROR(dwError); // Optional argument dwError = GetArgumentValue(programName, ShowUsageError, &cursor, NULL, &pArgs->pszPassword); assert(!dwError); if (LwArgvCursorRemaining(&cursor)) { fprintf(stderr, "Too many arguments.\n"); ShowUsageError(programName); } // Initialize missing options as needed if (!pArgs->pszDnsSuffix) { dwError = LwAllocateString(pArgs->pszDomain, &pArgs->pszDnsSuffix); GOTO_CLEANUP_ON_WINERROR(dwError); } LwStrToLower(pArgs->pszDnsSuffix); if (!pArgs->pszMachineName) { dwError = GetHostname(&pArgs->pszMachineName); GOTO_CLEANUP_ON_WINERROR(dwError); } if (!pArgs->pszOsName || !pArgs->pszOsVersion || !pArgs->pszOsServicePack) { dwError = GetOsInfo( pArgs->pszOsName ? NULL : &pArgs->pszOsName, pArgs->pszOsVersion ? NULL : &pArgs->pszOsVersion, pArgs->pszOsServicePack ? NULL : &pArgs->pszOsServicePack); GOTO_CLEANUP_ON_WINERROR(dwError); } dwError = CleanupUsername(pArgs->pszDomain, &pArgs->pszUsername); GOTO_CLEANUP_ON_WINERROR(dwError); if (!pArgs->pszPassword) { dwError = PromptPassword(pArgs->pszUsername, &pArgs->pszPassword); GOTO_CLEANUP_ON_WINERROR(dwError); } cleanup: if (dwError) { FreeJoinArgsContents(pArgs); } return dwError; }
/** Set the socket options @param [in] Argc The number of arguments @param [in] Argv The argument value array @retval 0 The application exited normally. @retval Other An error occurred. **/ int main ( IN int Argc, IN char **Argv ) { socklen_t BytesToWrite; socklen_t LengthInBytes; CONST OPTIONS * pEnd; CONST OPTIONS * pOption; int s; int Status; DEBUG (( DEBUG_INFO, "%a starting\r\n", Argv[0])); // // Parse the socket option // pOption = &mOptions[0]; pEnd = &pOption[sizeof ( mOptions ) / sizeof ( mOptions[0])]; if ( 2 <= Argc ) { while ( pEnd > pOption ) { if ( 0 == strcmp ( Argv[1], pOption->pOptionName )) { break; } pOption += 1; } if ( pEnd <= pOption ) { Print ( L"ERROR: Invalid option: %a\r\n", Argv[1]); Argc = 1; } } // // Display the help if necessary // if (( 2 > Argc ) || ( 3 < Argc )) { Print ( L"%a <option>\r\n", Argv[0]); Print ( L"\r\n" ); Print ( L"Option one of:\r\n" ); pOption = &mOptions[0]; while ( pEnd > pOption ) { Print ( L" %a: %a\r\n", pOption->pOptionName, pOption->bSetAllowed ? "get/set" : "get" ); pOption += 1; } errno = EINVAL; } else { // // Determine if the value is to be set // BytesToWrite = 0; if (( 3 > Argc ) || ( 0 < ( BytesToWrite = GetOptionValue ( pOption, Argv[2])))) { // // Get the socket // s = socket ( AF_INET, 0, 0 ); if ( -1 == s ) { Print ( L"ERROR - Unable to open the socket, errno: %d\r\n", errno ); } else { // // Display the option value // LengthInBytes = sizeof ( mBuffer ); Status = getsockopt ( s, pOption->OptionLevel, pOption->OptionValue, &mBuffer, &LengthInBytes ); if ( -1 == Status ) { Print ( L"ERROR - getsockopt failed, errno: %d\r\n", errno ); } else { DisplayOption ( pOption, LengthInBytes, FALSE, (BOOLEAN)( 0 == BytesToWrite )); // // Determine if the value is to be set // if (( 0 < BytesToWrite ) && ( BytesToWrite == LengthInBytes )) { // // Set the option value // Status = setsockopt ( s, pOption->OptionLevel, pOption->OptionValue, &mValue, BytesToWrite ); if ( -1 == Status ) { Print ( L"ERROR - setsockopt failed, errno: %d\r\n", errno ); } else { // // Display the updated option value // Status = getsockopt ( s, pOption->OptionLevel, pOption->OptionValue, &mBuffer, &LengthInBytes ); if ( -1 == Status ) { Print ( L"ERROR - getsockopt failed, errno: %d\r\n", errno ); } else { DisplayOption ( pOption, LengthInBytes, TRUE, TRUE ); } } } } // // Done with the socket // close ( s ); } } } // // All done // DEBUG (( DEBUG_INFO, "%a exiting, errno: %d\r\n", Argv[0], errno )); return errno; }
CKernelOptions::CKernelOptions (void) : m_nWidth (0), m_nHeight (0), m_nLogLevel (LogDebug), m_nUSBPowerDelay (0), m_CPUSpeed (CPUSpeedLow), m_nSoCMaxTemp (60) { strcpy (m_LogDevice, "tty1"); strcpy (m_KeyMap, DEFAULT_KEYMAP); s_pThis = this; CBcmPropertyTags Tags; if (!Tags.GetTag (PROPTAG_GET_COMMAND_LINE, &m_TagCommandLine, sizeof m_TagCommandLine)) { return; } if (m_TagCommandLine.Tag.nValueLength >= sizeof m_TagCommandLine.String) { return; } m_TagCommandLine.String[m_TagCommandLine.Tag.nValueLength] = '\0'; m_pOptions = (char *) m_TagCommandLine.String; char *pOption; while ((pOption = GetToken ()) != 0) { char *pValue = GetOptionValue (pOption); if (strcmp (pOption, "width") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 640 <= nValue && nValue <= 1980) { m_nWidth = nValue; } } else if (strcmp (pOption, "height") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 480 <= nValue && nValue <= 1080) { m_nHeight = nValue; } } else if (strcmp (pOption, "logdev") == 0) { strncpy (m_LogDevice, pValue, sizeof m_LogDevice-1); m_LogDevice[sizeof m_LogDevice-1] = '\0'; } else if (strcmp (pOption, "loglevel") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && nValue <= LogDebug) { m_nLogLevel = nValue; } } else if (strcmp (pOption, "keymap") == 0) { strncpy (m_KeyMap, pValue, sizeof m_KeyMap-1); m_KeyMap[sizeof m_KeyMap-1] = '\0'; } else if (strcmp (pOption, "usbpowerdelay") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 200 <= nValue && nValue <= 8000) { m_nUSBPowerDelay = nValue; } } else if (strcmp (pOption, "fast") == 0) { if (strcmp (pValue, "true") == 0) { m_CPUSpeed = CPUSpeedMaximum; } } else if (strcmp (pOption, "socmaxtemp") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 40 <= nValue && nValue <= 78) { m_nSoCMaxTemp = nValue; } } } }
FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) return FALSE; CFX_WideString opt_value = GetOptionValue(index); if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) return FALSE; if (bSelected) { if (GetType() == ListBox) { SelectOption(index, TRUE); if (!(m_Flags & FORMLIST_MULTISELECT)) { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); } else { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } m_pDict->SetAt("V", pArray); } } else { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); CPDF_Array* pI = new CPDF_Array; pI->AddInteger(index); m_pDict->SetAt("I", pI); } } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (GetType() == ListBox) { SelectOption(index, FALSE); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveAt("V"); } else if (pValue->IsArray()) { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } if (pArray->GetCount() < 1) pArray->Release(); else m_pDict->SetAt("V", pArray); } } else { m_pDict->RemoveAt("V"); m_pDict->RemoveAt("I"); } } } if (bNotify) NotifyListOrComboBoxAfterChange(); return TRUE; }