static char *execute(char *command, int wait) /* {{{1 */ { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); si.cb = sizeof(si); if (CreateProcess(0, command, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi)) { if (wait) { WaitForSingleObject(pi.hProcess, INFINITE); /* long exit_code; */ /* TODO: GetExitCodeProcess( pi.hProcess, &exit_code); */ CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } return Success(NULL); } else { return Failure(GetError()); } }
BOOL CGuiRecordSet::GetCollect(int nIndex,CString& strValue) { _variant_t vt; _variant_t vtn; vtn.vt = VT_I2; try { vtn.iVal = nIndex; vt = m_rs->Fields->GetItem(vtn)->Value; if (vt.vt==VT_BSTR) { strValue=vt.bstrVal; return TRUE; }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } }
BOOL CGuiRecordSet::GetCollect(int nIndex,double& dbVal) { _variant_t vt; _variant_t vtn; vtn.vt = VT_I2; try { vtn.iVal = nIndex; vt = m_rs->Fields->GetItem(vtn)->Value; if (vt.vt==VT_R8) { dbVal=vt.dblVal; return TRUE; }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } }
float CCoreAudioUnit::GetLatency() { if (!m_audioUnit) return 0.0f; Float64 latency; UInt32 size = sizeof(latency); OSStatus ret = AudioUnitGetProperty(m_audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global, 0, &latency, &size); if (ret) { CLog::Log(LOGERROR, "CCoreAudioUnit::GetLatency: " "Unable to set AudioUnit latency. Error = %s", GetError(ret).c_str()); return 0.0f; } return latency; }
BOOL CGuiParameter::SetValue(CString szCad) { _variant_t vt; if(!szCad.IsEmpty()) { vt.vt = VT_BSTR; vt.bstrVal = szCad.AllocSysString(); } try { pParam->Value=vt; return TRUE; }catch(_com_error &e) { GetError(e); return FALSE; } }
/** * Updates the status (active/inactive) of an iam user's access key, based on * command line input */ int main(int argc, char** argv) { if(argc != 4) { PrintUsage(); return 1; } Aws::String user_name(argv[1]); Aws::String accessKeyId(argv[2]); auto status = Aws::IAM::Model::StatusTypeMapper::GetStatusTypeForName(argv[3]); if (status == Aws::IAM::Model::StatusType::NOT_SET) { PrintUsage(); return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::IAM::IAMClient iam; Aws::IAM::Model::UpdateAccessKeyRequest request; request.SetUserName(user_name); request.SetAccessKeyId(accessKeyId); request.SetStatus(status); auto outcome = iam.UpdateAccessKey(request); if (outcome.IsSuccess()) { std::cout << "Successfully updated status of access key " << accessKeyId << " for user " << user_name << std::endl; } else { std::cout << "Error updated status of access key " << accessKeyId << " for user " << user_name << ": " << outcome.GetError().GetMessage() << std::endl; } } Aws::ShutdownAPI(options); return 0; }
bool CParseBase::BasicParseLoop(CCodeElementList *pCodeList) { CObjectClass *pOC; while((pOC = GetNextObjectClass(m_iCurLine)) != 0) { if (!pOC->Parse(*this, *pCodeList)) return false; } if (m_iCurPos >= (int) m_msText[m_iCurLine].csText.Len()) { SetError(CPB_EOL); // End of Line return false; } if (GetError() != CPB_NOERROR) return false; return true; }
BOOL CGuiRecordSet::GetCollect(int nIndex,COleDateTime& dtVal) { _variant_t vt; _variant_t vtn; vtn.vt = VT_I2; try { vtn.iVal = nIndex; vt = m_rs->Fields->GetItem(vtn)->Value; if (vt.vt==VT_DATE) { dtVal=vt.date; return TRUE; }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } }
Float64 CCoreAudioDevice::GetNominalSampleRate() { if (!m_DeviceId) return 0.0f; AudioObjectPropertyAddress propertyAddress; propertyAddress.mScope = kAudioDevicePropertyScopeOutput; propertyAddress.mElement = 0; propertyAddress.mSelector = kAudioDevicePropertyNominalSampleRate; Float64 sampleRate = 0.0f; UInt32 propertySize = sizeof(Float64); OSStatus ret = AudioObjectGetPropertyData(m_DeviceId, &propertyAddress, 0, NULL, &propertySize, &sampleRate); if (ret != noErr) { CLog::Log(LOGERROR, "CCoreAudioDevice::GetNominalSampleRate: " "Unable to retrieve current device sample rate. Error = %s", GetError(ret).c_str()); return 0.0f; } return sampleRate; }
BOOL CGuiRecordSet::GetCollect(LPCTSTR lpField,int& nValue) { _variant_t vt; try { vt = m_rs->Fields->GetItem(lpField)->Value; if (vt.vt==VT_I2) { nValue=vt.intVal; return TRUE; }else if (vt.vt==VT_BOOL) { nValue=vt.boolVal; return TRUE; }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } }
bool CAUOutputDevice::SetCurrentDevice(AudioDeviceID deviceId) { if (!m_audioUnit) return false; OSStatus ret = AudioUnitSetProperty(m_audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, kOutputBus, &deviceId, sizeof(AudioDeviceID)); if (ret) { CLog::Log(LOGERROR, "CCoreAudioUnit::SetCurrentDevice: " "Unable to set current device. Error = %s", GetError(ret).c_str()); return false; } m_DeviceId = deviceId; CLog::Log(LOGDEBUG, "CCoreAudioUnit::SetCurrentDevice: " "Current device 0x%08x", (uint)m_DeviceId); return true; }
AudioDeviceID CCoreAudioHardware::GetDefaultOutputDevice() { UInt32 size = sizeof(AudioDeviceID); AudioDeviceID deviceId = 0; AudioObjectPropertyAddress propertyAddress; propertyAddress.mScope = kAudioObjectPropertyScopeGlobal; propertyAddress.mElement = kAudioObjectPropertyElementMaster; propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice; OSStatus ret = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, &deviceId); // outputDevice is set to 0 if there is no audio device available // or if the default device is set to an encoded format if (ret || !deviceId) { CLog::Log(LOGERROR, "CCoreAudioHardware::GetDefaultOutputDevice:" " Unable to identify default output device. Error = %s", GetError(ret).c_str()); return 0; } return deviceId; }
bool CAUOutputDevice::SetChannelMap(CoreAudioChannelList* pChannelMap) { // The number of array elements must match the // number of output channels provided by the device if (!m_audioUnit || !pChannelMap) return false; UInt32 channels = pChannelMap->size(); UInt32 size = sizeof(SInt32) * channels; SInt32* pMap = new SInt32[channels]; for (UInt32 i = 0; i < channels; i++) pMap[i] = (*pChannelMap)[i]; OSStatus ret = AudioUnitSetProperty(m_audioUnit, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Input, 0, pMap, size); if (ret) CLog::Log(LOGERROR, "CCoreAudioUnit::GetBufferFrameSize: " "Unable to get current device's buffer size. Error = %s", GetError(ret).c_str()); delete[] pMap; return (!ret); }
UbuntuUnityHack::UbuntuUnityHack(QObject* parent) : QObject(parent) { // Check if we're on Ubuntu first. QFile lsb_release("/etc/lsb-release"); if (lsb_release.open(QIODevice::ReadOnly)) { QByteArray data = lsb_release.readAll(); if (!data.contains("DISTRIB_ID=Ubuntu")) { // It's not Ubuntu - don't do anything. return; } } // Get the systray whitelist from gsettings. If this fails we're probably // not running on a system with unity QProcess* get = new QProcess(this); connect(get, SIGNAL(finished(int)), SLOT(GetFinished(int))); connect(get, SIGNAL(error(QProcess::ProcessError)), SLOT(GetError())); get->start(kGSettingsFileName, QStringList() << "get" << kUnityPanel << kUnitySystrayWhitelist); }
bool CCoreAudioDevice::AddIOProc() { // Allow only one IOProc at a time if (!m_DeviceId || m_IoProc) return false; OSStatus ret = AudioDeviceCreateIOProcID(m_DeviceId, DirectRenderCallback, this, &m_IoProc); if (ret) { CLog::Log(LOGERROR, "CCoreAudioDevice::AddIOProc: " "Unable to add IOProc. Error = %s", GetError(ret).c_str()); m_IoProc = NULL; return false; } Start(); CLog::Log(LOGDEBUG, "CCoreAudioDevice::AddIOProc: " "IOProc %p set for device 0x%04x", m_IoProc, (uint)m_DeviceId); return true; }
BOOL CGuiRecordSet::GetCollect(int nIndex,COleCurrency& cyVal) { _variant_t vt; _variant_t vtn; vtn.vt = VT_CY; try { vtn.iVal =nIndex; vt = m_rs->Fields->GetItem(vtn)->Value; if (vt.vt==VT_CY) { cyVal.m_cur=vt.cyVal; return TRUE; }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } }
HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow) { PMAIN_WND_INFO Info; HWND hMainWnd = NULL; Info = (MAIN_WND_INFO*) HeapAlloc(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(MAIN_WND_INFO)); if (Info != NULL) { Info->nCmdShow = nCmdShow; hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE, szMainWndClass, lpCaption, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CW_USEDEFAULT, CW_USEDEFAULT, 680, 450, NULL, NULL, hInstance, Info); if (hMainWnd == NULL) { //int ret; //ret = GetLastError(); GetError(); HeapFree(ProcessHeap, 0, Info); } } return hMainWnd; }
HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow) { PMAIN_WND_INFO Info; HWND hMainWnd = NULL; Info = (PMAIN_WND_INFO)HeapAlloc(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(MAIN_WND_INFO)); if (Info != NULL) { Info->nCmdShow = nCmdShow; Info->Display = DevicesByType; Info->bShowHidden = TRUE; hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE, szMainWndClass, lpCaption, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CW_USEDEFAULT, CW_USEDEFAULT, 600, 450, NULL, NULL, hInstance, Info); if (hMainWnd == NULL) { GetError(); HeapFree(ProcessHeap, 0, Info); } } return hMainWnd; }
/** * Creates a cloud watch logs subscription filter, based on command line input */ int main(int argc, char** argv) { if (argc != 5) { std::cout << "Usage: " << std::endl << " put_subscription_filter " << "<filter_name> <filter_pattern> <log_group_name> " << "<lambda_function_arn>" << std::endl; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String filter_name(argv[1]); Aws::String filter_pattern(argv[2]); Aws::String log_group(argv[3]); Aws::String dest_arn(argv[4]); Aws::CloudWatchLogs::CloudWatchLogsClient cwl; Aws::CloudWatchLogs::Model::PutSubscriptionFilterRequest request; request.SetFilterName(filter_name); request.SetFilterPattern(filter_pattern); request.SetLogGroupName(log_group); request.SetDestinationArn(dest_arn); auto outcome = cwl.PutSubscriptionFilter(request); if (!outcome.IsSuccess()) { std::cout << "Failed to create cloudwatch logs subscription filter " << filter_name << ": " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully created cloudwatch logs subscription " << "filter " << filter_name << std::endl; } } Aws::ShutdownAPI(options); return 0; }
void CCoreAudioHardware::ResetStream(AudioStreamID stream) { // Find the streams current physical format AudioStreamBasicDescription currentFormat; UInt32 paramSize = sizeof(currentFormat); AudioStreamGetProperty(stream, 0, kAudioStreamPropertyPhysicalFormat, ¶mSize, ¤tFormat); // If it's currently AC-3/SPDIF then reset it to some mixable format if (currentFormat.mFormatID == 'IAC3' || currentFormat.mFormatID == kAudioFormat60958AC3) { AudioStreamBasicDescription *formats = CCoreAudioHardware::FormatsList(stream); bool streamReset = false; if (!formats) return; for (int i = 0; !streamReset && formats[i].mFormatID != 0; i++) { if (formats[i].mFormatID == kAudioFormatLinearPCM) { OSStatus ret = AudioStreamSetProperty(stream, NULL, 0, kAudioStreamPropertyPhysicalFormat, sizeof(formats[i]), &(formats[i])); if (ret != noErr) { CLog::Log(LOGDEBUG, "CCoreAudioHardware::ResetStream: " "Unable to retrieve the list of available devices. Error = %s", GetError(ret).c_str()); continue; } else { streamReset = true; Sleep(10); } } } free(formats); } }
bool CCoreAudioDevice::RemoveIOProc() { if (!m_DeviceId || !m_IoProc) return false; Stop(); OSStatus ret = AudioDeviceDestroyIOProcID(m_DeviceId, m_IoProc); if (ret) CLog::Log(LOGERROR, "CCoreAudioDevice::RemoveIOProc: " "Unable to remove IOProc. Error = %s", GetError(ret).c_str()); else CLog::Log(LOGDEBUG, "CCoreAudioDevice::RemoveIOProc: " "IOProc %p removed for device 0x%04x", m_IoProc, (uint)m_DeviceId); m_IoProc = NULL; // Clear the reference no matter what m_pSource = NULL; Sleep(100); return true; }
void ConnectThread::ThreadFunc() { m_socket = m_address.m_socketFactory->CreateSocket(); m_socket->Bind(m_address.m_localIP, m_address.m_localPort); if(m_socket->Connect(m_address.m_ip, m_address.m_port)) { Connector* connector = m_address.m_connectorFactory->CreateConnector(m_socket); connector->SetId(m_address.m_id); connector->SetRemoteAddr(m_address.m_ip, m_address.m_port); m_socket = 0; ConnectorMessage msg(connector); onSignal(msg); } else { ConnectErrorMessage errMsg(m_address.m_moduleName, "", GetError()); onSignal(errMsg); delete m_socket; m_socket = 0; } }
BOOL CGuiParameter::GetValue(int& nVal) { _variant_t vt; vt = pParam->Value; try { if (vt.vt==VT_I2) { nVal=vt.intVal; return TRUE; }else if (vt.vt==VT_BOOL) { nVal=vt.boolVal; return TRUE; }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } }
int main() { int n, TC; printf("Input dimension (n): "); scanf("%d", &n); if (n <= 0) return -1; printf("Input number of the threads: "); scanf("%d", &TC); if (n <= 0) return -2; double * a = new double[n*n]; double * b = new double[n]; double * x = new double[n]; int * index = new int[n]; double * ac = new double[n*n]; double * bc = new double[n*n]; FillMatrix(a, b, n); for (int i = 0; i < n*n; i++) ac[i] = a[i]; // copy of A for (int i = 0; i < n; i++) bc[i] = b[i]; // copy of B PrintMatrix(a, b, n); timeval tv1; gettimeofday(&tv1, 0); if (!SolveSystem(n, a, b, x, index, TC)) { printf("Bad matrix!\n"); return -3; } timeval tv2; gettimeofday(&tv2,0); double Time = double(tv2.tv_sec)*1000000.0+double(tv2.tv_usec)-double(tv1.tv_sec)*1000000.0+double(tv1.tv_usec); printf("Result:\n"); PrintSolution(x, n); printf("\n\nThreads: %d,\nError: %1.17lf,\nTime=%1.4lf sec.\n", TC, GetError(ac, bc, x, n), Time/1000000.0); delete a; delete b; delete x; delete index; delete ac; return 0; }
// ======================================================================== // Function: GetIPAddress // Purpose: To get the IP address of the string as an ipaddress // structure. Throws an exception if the address cannot be // converted. // ======================================================================== ipaddress GetIPAddress( const std::string p_address ) { if( IsIPAddress( p_address ) ) { // if the address is just a regular IP address, there's no need // to do a DNS lookup, so just convert the string directly into // its binary format. ipaddress addr = inet_addr( p_address.c_str() ); // if the address is invalid, throw a HOST_NOT_FOUND exception. if( addr == INADDR_NONE ) { throw Exception( EDNSNotFound ); } // by this point, the address is valid, so return it. return addr; } else { // the address isn't an IP address, so we need to look it up using // DNS. struct hostent* host = gethostbyname( p_address.c_str() ); // if there was an error, throw an exception. if( host == 0 ) { // get the error from h_errno. throw Exception( GetError( false ) ); } // now perform some really wierd casting tricks to get the value. // h_addr is a char*, so cast it into an ipaddress*, and // dereference it to get the value. return *((ipaddress*)host->h_addr); } }
/** * Creates a long-polled sqs queue based on command line input */ int main(int argc, char** argv) { if (argc != 3) { std::cout << "Usage: long_polling_on_create_queue <queue_name> " << "<poll_time_in_seconds>" << std::endl; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String queue_name = argv[1]; Aws::String poll_time = argv[2]; Aws::SQS::SQSClient sqs; Aws::SQS::Model::CreateQueueRequest request; request.SetQueueName(queue_name); request.AddAttributes( Aws::SQS::Model::QueueAttributeName::ReceiveMessageWaitTimeSeconds, poll_time); auto outcome = sqs.CreateQueue(request); if (outcome.IsSuccess()) { std::cout << "Successfully created queue " << queue_name << std::endl; } else { std::cout << "Error creating queue " << queue_name << ": " << outcome.GetError().GetMessage() << std::endl; } } Aws::ShutdownAPI(options); return 0; }
/** * Deletes an access key from an IAM user, based on command line input */ int main(int argc, char** argv) { if (argc != 3) { std::cout << "Usage: delete_access_key <user_name> <access_key_id>" << std::endl; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String user_name(argv[1]); Aws::String key_id(argv[2]); Aws::IAM::IAMClient iam; Aws::IAM::Model::DeleteAccessKeyRequest request; request.SetUserName(user_name); request.SetAccessKeyId(key_id); auto outcome = iam.DeleteAccessKey(request); if (!outcome.IsSuccess()) { std::cout << "Error deleting access key " << key_id << " from user " << user_name << ": " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully deleted access key " << key_id << " for IAM user " << user_name << std::endl; } } Aws::ShutdownAPI(options); return 0; }
ModelicaCompiler::ModelicaCompiler(string model,string file_name,string model_path,bool load_file, bool load_package) : _model(model) ,_file_name(file_name) ,_model_path(model_path) ,_load_package(load_package) ,_omcPtr(0) { std::cout << "Modelica compiler file "<< std::endl; char* omhome= getenv ("OPENMODELICAHOME");//should get value for OM home std::cout << "omhome " << omhome << std::endl; if(omhome==NULL) std::cout << "OPENMODELICAHOME variable doesn't set" << std::endl; //string path = getTempPath(); int status =0; std::cout << "Intialize OMC, use gcc" << std::endl; status = InitOMC(&_omcPtr,"gcc",omhome); if(status > 0) { std::cout << "..ok" << std::endl; loadFile(load_file); } else { std::cout << "..failed" << std::endl; char* errorMsg = 0; status = GetError(_omcPtr, &errorMsg); string errorMsgStr(errorMsg); throw std::runtime_error("error to intialize OMC: " + errorMsgStr); } }
BOOL CFlashManager::Flash_Start(IDispatch* pDisp) { CFuncLog log(g_pLog, "CFlashManager::Flash_Start()"); CComQIPtr<ShockwaveFlashObjects::IShockwaveFlash> spSWF(pDisp); if (!spSWF) { log.LogString(LOG_ERROR, " FAILURE: CComQIPtr<ShockwaveFlashObjects::IShockwaveFlash> spSWF == NULL)"); return FALSE; } // If using the wsShell.swf loader then to play the // flash we must actually call Rewind(). This fixes the // problem where flash types with the wsShell loader were // failing to play. For all other flash types we call Play(). HRESULT hr = S_OK; if (IsWsShellUsed(pDisp)) hr = spSWF->Rewind(); else hr = spSWF->Play(); if (FAILED(hr)) { CString szMsg; szMsg.Format("Play/Rewind FAILED(%X)", hr); GetError(szMsg); log.LogString(LOG_ERROR, szMsg.GetBuffer()); return FALSE; } if (g_pLog) { CString szMsg; szMsg.Format("SUCCESS"); log.LogString(LOG_INFO, szMsg.GetBuffer()); } return TRUE; }
void ReloadCustomImage(Bitmap *bitmap, char *basename) { char *filename = getCustomImageFilename(basename); Bitmap *new_bitmap; if (filename == NULL) /* (should never happen) */ { Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename); return; } if (strEqual(filename, bitmap->source_filename)) { /* The old and new image are the same (have the same filename and path). This usually means that this image does not exist in this graphic set and a fallback to the existing image is done. */ return; } if ((new_bitmap = LoadImage(filename)) == NULL) { Error(ERR_WARN, "LoadImage() failed: %s", GetError()); return; } if (bitmap->width != new_bitmap->width || bitmap->height != new_bitmap->height) { Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions", filename); FreeBitmap(new_bitmap); return; } TransferBitmapPointers(new_bitmap, bitmap); free(new_bitmap); }