void MakeDirectory(char *OutputFileName) { #ifdef PLATFORM_WINDOWS if (!CreateDirectory(OutputFileName, 0)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { ErrorPrint("Create directory %s failed\n", OutputFileName); } } #else if (mkdir(OutputFileName, 0755) < 0) { if (errno != EEXIST) { ErrorPrint("mkdir %s failed, errno = %d\n", OutputFileName, errno); } else { struct stat FileStatus; if (stat(OutputFileName, &FileStatus) < 0) { ErrorPrint("stat %s failed, errno = %d\n", OutputFileName, errno); } // TODO(wheatdog): Support symbolic link? if (!S_ISDIR(FileStatus.st_mode)) { ErrorPrint("%s existed and it is not a folder.\n", OutputFileName); } } } #endif }
bool NetReceiveOutputPin::addTransSocket(SOCKET sock) { int tryCount = 20 * 100; //尝试20秒 while (--tryCount > 0) { if (m_mt.majortype == GUID_NULL) { Sleep(10); } else break; } if (tryCount == 0) { return false; } if (!sendData(sock, (char*)&m_mt, sizeof(m_mt))) { ErrorPrint("Send media type error"); return false; } if (!sendData(sock, (char*)m_mt.pbFormat, m_mt.cbFormat)) { ErrorPrint("Send media format type error"); return false; } CAutoLock lock(&m_TransSocketListCrit); m_TransSocketList.push_back(sock); return true; }
bool Connection::acceptConnection(int connfd) { if (mFd >= 0) { ErrorPrint("[acceptConnection] accept connetion error! the conn is in use!"); return false; } mFd = connfd; // set nonblocking if (!core::setNonblocking(mFd)) { ErrorPrint("[acceptConnection] set nonblocking error! %s", coreStrError()); goto err_1; } tryRegReadEvent(); mConnStatus = ConnStatus_Connected; return true; err_1: close(mFd); mFd = -1; return false; }
static int CalibrationDataWriteAndVerify(int address, unsigned char *buffer, int many) { int it; unsigned char check; switch(ar9300_calibration_data_get(AH)) { case calibration_data_flash: #ifdef MDK_AP { int fd; // UserPrint("Do block write \n"); // for(it=0;it<many;it++) // printf("a = %x, data = %x \n",(address-it), buffer[it]); if((fd = open("/dev/caldata", O_RDWR)) < 0) { perror("Could not open flash\n"); return 1 ; } for(it=0; it<many; it++) { lseek(fd, address-it, SEEK_SET); if (write(fd, &buffer[it], 1) < 1) { perror("\nwrite\n"); return -1; } } close(fd); } return 0; #endif case calibration_data_eeprom: for(it=0; it<many; it++) { Ar9300EepromWrite(address-it,&buffer[it],1); Ar9300EepromRead(address-it,&check,1); if(check!=buffer[it]) { ErrorPrint(EepromVerify,address-it,buffer[it],check); return -1; } } break; case calibration_data_otp: for(it=0; it<many; it++) { Ar9300OtpWrite(address-it,&buffer[it],1,1); Ar9300OtpRead(address-it,&check,1,1); if(check!=buffer[it]) { ErrorPrint(EepromVerify,address-it,buffer[it],check); return -1; } } break; return -1; } return 0; }
void Connection::send(const void *data, size_t datalen) { if (mFd < 0) { ErrorPrint("[send] send error! socket uninited or shuted!"); return; } if (mConnStatus != ConnStatus_Connected) { ErrorPrint("[send] can't send data in such status(%d)", mConnStatus); return; } const char *ptr = (const char *)data; if (tryFlushRemainPacket()) { int sentlen = ::send(mFd, data, datalen, 0); // int sentlen = -1; errno = EAGAIN; if ((size_t)sentlen == datalen) return; if (sentlen > 0) { ptr += sentlen; datalen -= sentlen; } } if (checkSocketErrors()) return; cachePacket(ptr, datalen); tryRegWriteEvent(); // 注册发送缓冲区可写事件 }
bool NetReceiveOutputPin::setSocket(SOCKET sock) { // CAutoLock lock(&m_SocketCrit); closesocket(m_Socket); m_Socket = sock; if (!receiveData(m_Socket, (char*)&m_mt, sizeof(m_mt))) { ErrorPrint("Receive media type error"); return false; } m_mt.pbFormat = (PBYTE)CoTaskMemAlloc(m_mt.cbFormat); if (!receiveData(m_Socket, (char*)m_mt.pbFormat, m_mt.cbFormat)) { ErrorPrint("Receive media format type error"); return false; } if(m_mt.majortype == MEDIATYPE_Video && m_mt.formattype == FORMAT_VideoInfo) { VIDEOINFOHEADER* videoHeader = (VIDEOINFOHEADER*)m_mt.pbFormat; videoHeader->bmiHeader.biSizeImage = videoHeader->bmiHeader.biWidth * videoHeader->bmiHeader.biHeight * videoHeader->bmiHeader.biBitCount / 8; m_mt.SetSampleSize(videoHeader->bmiHeader.biSizeImage); // tmp.pbFormat = (PBYTE)CoTaskMemAlloc(sizeof(VIDEOINFOHEADER)); // boost::scoped_array<char> formatBufferContainer((char*)tmp.pbFormat); } ReleaseSemaphore(m_SocketSema, 1, NULL); // 通知设置了新的socket return true; }
int Help(char *name, void (*print)(char *buffer)) { char buffer[MBUFFER]; char start[MBUFFER]; int count; int found; if(print!=0) { count=0; found=0; if(HelpFile==0) { HelpOpen("nart.help"); } if(HelpFile!=0) { SformatOutput(start,MBUFFER-1,"<tag=%s>",name); buffer[MBUFFER-1]=0; HelpRewind(); // // look for start of documentation section, <tag=name> // while(HelpRead(buffer,MBUFFER-1)>=0) { if(Smatch(buffer,start)) { found=1; break; } } // // print all lines up to the next <tag=anything> // if(found) { ErrorPrint(ParseHelpDescriptionStart); while(HelpRead(buffer,MBUFFER-1)>=0) { if(strncmp(buffer,"<tag=",5)==0) { break; } ErrorPrint(ParseHelp,buffer); count++; } ErrorPrint(ParseHelpDescriptionEnd); return count; } } } return -1; }
bool Connection::connect(const SA *sa, socklen_t salen) { if (mFd >= 0) shutdown(); if (mFd >= 0) { ErrorPrint("[connect] accept connetion error! the conn is in use!"); return false; } mFd = socket(AF_INET, SOCK_STREAM, 0); if (mFd < 0) { ErrorPrint("[connect] create socket error! %s", coreStrError()); return false; } // set nonblocking if (!core::setNonblocking(mFd)) { ErrorPrint("[connect] set nonblocking error! %s", coreStrError()); goto err_1; } if (::connect(mFd, sa, salen) == 0) // 连接成功 { tryRegReadEvent(); mConnStatus = ConnStatus_Connected; if (mHandler) mHandler->onConnected(this); } else { if (errno == EINPROGRESS) { mConnStatus = ConnStatus_Connecting; tryRegWriteEvent(); } else { goto err_1; } } return true; err_1: close(mFd); mFd = -1; return false; }
int main( int argc, char **argv ) { LOG_FUNCTION_START(); LogPrint( "S2Sim Started" ); GetConnectionManager(); GetMatlabManager(); GetControlManager(); GetSystemManager(); auto iterationNumber = 0; GetControlManager().WaitUntilReady(); while ( 1 ) { try { GetSystemManager().AdvanceTimeStep(); } catch ( ... ) { ErrorPrint( "System Error, Exiting" ); break; } ++iterationNumber; LogPrint( "Time: ", iterationNumber ); } LOG_FUNCTION_END(); return ( EXIT_SUCCESS ); }
int cnpkFlushSendData( CnpkCtx* pCnpk ) { int result = 0; char size_str[32]; if( pCnpk->flgProc ){ if( pCnpk->nBufSize > 0 ){ snprintf(size_str, 31, "%d", pCnpk->nBufSize); if( cnprocWriteCommand(pCnpk->pipe_fds, CNPK_ID_SEND_DATA, size_str, strlen(size_str)+1) == 0 ){ cnprocWriteData(pCnpk->pipe_fds, pCnpk->bufPDLData, pCnpk->nBufSize ); } if( (result = cnprocCheckResponse(pCnpk->pipe_fds, CNPK_ID_SEND_DATA, NULL, NULL)) == 0 ) pCnpk->nBufSize = 0; } if( cnprocWriteCommand(pCnpk->pipe_fds, CNPK_ID_FLUSH_SEND_DATA, NULL, 0) < 0 ){ ErrorPrint( "cnpklib -->cnpkFlushSendData\n"); goto write_error; } result = cnprocCheckResponse(pCnpk->pipe_fds, CNPK_ID_FLUSH_SEND_DATA, NULL, NULL); } return result; write_error: return CNPK_ERROR; }
ULONG ExceptionFilter ( _In_ PEXCEPTION_POINTERS ExceptionPointers ) /*++ Routine Description: ExceptionFilter breaks into the debugger if an exception happens inside the callback. Arguments: ExceptionPointers - unused Return Value: Always returns EXCEPTION_CONTINUE_SEARCH --*/ { ErrorPrint("Exception %lx, ExceptionPointers = %p", ExceptionPointers->ExceptionRecord->ExceptionCode, ExceptionPointers); DbgBreakPoint(); return EXCEPTION_EXECUTE_HANDLER; }
// // Returns a pointer to the specified function. // static void *CalibrationFunctionFind(char *prefix, char *function) { void *f; char buffer[MBUFFER]; if(osCheckLibraryHandle(CalibrationLibrary)!=0) { // // try adding the prefix in front of the name // SformatOutput(buffer,MBUFFER-1,"%s%s",prefix,function); buffer[MBUFFER-1]=0; f=osGetFunctionAddress(buffer,CalibrationLibrary); if(f==0) { // // try without the prefix in front of the name // f=osGetFunctionAddress(function,CalibrationLibrary); } return f; } ErrorPrint(CalibrationLoadBad,prefix,function); CalibrationUnload(); return 0; }
bool CaptureAndSend::start() { if (m_CurrentState == Running) { return true; } if (!m_NetSenderFilter->start()) { return false; } HRESULT hr = S_OK; IGraphBuilder* graphBuilder; hr = m_FilterGraph->QueryInterface(IID_IGraphBuilder, (void**)&graphBuilder); if (FAILED(hr)) { ErrorPrint("Get graph builder interface error",hr); return false; } ComReleaser graphBuilderReleaser(graphBuilder); IMediaControl* mediaControl; hr = m_FilterGraph->QueryInterface(IID_IMediaControl, (void**)&mediaControl); if(FAILED(hr)) { ErrorPrint("Get media control error", hr); return false; } ComReleaser mediaControlReleaser(mediaControl); hr = mediaControl->Run(); if(FAILED(hr)) { ErrorPrint("Run error",hr); return false; } if (m_CurrentState == Stopped) { g_StartCount++; } m_CurrentState = Running; return true; }
VOID DetectOSVersion() /*++ Routine Description: This routine determines the OS version and initializes some globals used in the sample. Arguments: None Return value: None. On failure, global variables stay at default value --*/ { RTL_OSVERSIONINFOEXW VersionInfo = {0}; NTSTATUS Status; ULONGLONG ConditionMask = 0; // // Set VersionInfo to Win7's version number and then use // RtlVerifVersionInfo to see if this is win8 or greater. // VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo); VersionInfo.dwMajorVersion = 6; VersionInfo.dwMinorVersion = 1; VER_SET_CONDITION(ConditionMask, VER_MAJORVERSION, VER_LESS_EQUAL); VER_SET_CONDITION(ConditionMask, VER_MINORVERSION, VER_LESS_EQUAL); Status = RtlVerifyVersionInfo(&VersionInfo, VER_MAJORVERSION | VER_MINORVERSION, ConditionMask); if (NT_SUCCESS(Status)) { g_IsWin8OrGreater = FALSE; InfoPrint("DetectOSVersion: This machine is running Windows 7 or an older OS."); } else if (Status == STATUS_REVISION_MISMATCH) { g_IsWin8OrGreater = TRUE; InfoPrint("DetectOSVersion: This machine is running Windows 8 or a newer OS."); } else { ErrorPrint("RtlVerifyVersionInfo returned unexpected error status 0x%x.", Status); // // default action is to assume this is not win8 // g_IsWin8OrGreater = FALSE; } }
CaptureAndSend::CaptureAndSend(IFilterGraph* filterGraph, IPin* capturePin): m_FilterGraph(filterGraph), m_CapturePin(capturePin), m_CurrentState(Stopped) { if (!initialCaptureAndSend()) { ErrorPrint("Initial Capture and send error"); throw std::runtime_error("Initial capture and send error"); } }
int CalibrationGetCommand(int client) { if(osCheckLibraryHandle(CalibrationLibrary)==0) { ErrorPrint(CalibrationMissing); return -1; } if(_CalGetCommand!=0) { _CalGetCommand(client); } else { ErrorPrint(CalibrationNoFunction,"Calibration_GetCommand"); return -1; } return 0; }
void print9300_Header_newItems(int client, const ar9300_eeprom_t *ahp_Eeprom, int iBand) { char eepItemName[100], eepItemValue[100]; int itemNum; int emptyRight = 1; // print for ar9300Eeprom_switchcomspdt lc=0; itemNum = get_num_switchcomspdt(); if (itemNum>0) { get_switchcomspdt(eepItemName, eepItemValue, itemNum-1, ahp_Eeprom, iBand); print9300_half_Line(eepItemName, eepItemValue, 1); // print9300_lineEnd(emptyRight); // for second item // print9300_half_Line(eepItemName, eepItemValue, 0); // print9300_lineEnd(0); } itemNum = get_num_xLNABiasStrength(); if (itemNum>0) { get_xLNABiasStrength(eepItemName, eepItemValue, itemNum-1, ahp_Eeprom, iBand); print9300_half_Line(eepItemName, eepItemValue, 0); print9300_lineEnd(0); } itemNum = get_num_rfGainCap(); if (itemNum>0) { get_rfGainCap(eepItemName, eepItemValue, itemNum-1, ahp_Eeprom, iBand); print9300_half_Line(eepItemName, eepItemValue, 1); } itemNum = get_num_txGainCap(); if (itemNum>0) { get_txGainCap(eepItemName, eepItemValue, itemNum-1, ahp_Eeprom, iBand); print9300_half_Line(eepItemName, eepItemValue, 0); print9300_lineEnd(0); } if(iBand == band_A){ // print for ar9300Eeprom_tempslopextension lc=0; itemNum = get_num_tempslopextension(); if (itemNum>0) { get_tempslopextension(eepItemName, eepItemValue, itemNum-1, ahp_Eeprom); print9300_whole_Line(eepItemName, eepItemValue); } } // print a space line at the end of header print SformatOutput(buffer, MBUFFER-1," | | |"); ErrorPrint(NartOther,buffer); }
void HCWarning( int err_num, ... ) { ErrString string = err_strings[err_num]; va_list values; fputc( '\n', stderr ); va_start( values, err_num ); ErrorPrint( stderr, string, values ); va_end( values ); return; }
BOOL UtilOpenDevice( _In_ LPTSTR szWin32DeviceName, _Out_ HANDLE *phDevice ) /*++ Routine Description: Opens a device Arguments: szWin32DeviceName - name of the device phDevice - pointer to a variable that receives the handle to the device Return Value: TRUE if the device is successfully opened, FALSE otherwise. --*/ { BOOL ReturnValue = FALSE; HANDLE hDevice; // // Open the device // hDevice = CreateFile ( szWin32DeviceName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hDevice == INVALID_HANDLE_VALUE) { ErrorPrint("CreateFile(%ls) failed, last error 0x%x", szWin32DeviceName, GetLastError() ); goto Exit; } ReturnValue = TRUE; Exit: *phDevice = hDevice; return ReturnValue; }
void SleepModeCommand(int client) { int error; char *name; int np, ip, ngot; int value, selection; // // prepare beginning of error message in case we need to use it // error=0; // //parse arguments and do it // np=CommandParameterMany(); for(ip=0; ip<np; ip++) { name=CommandParameterName(ip); if (strlen(name)==0) continue; // sometime there are tab or space at the end count as np with name as "", skip it selection=ParameterSelect(name,SleepModeParameter,sizeof(SleepModeParameter)/sizeof(SleepModeParameter[0])); switch(selection) { case SleepMode: ngot=SformatInput(CommandParameterValue(ip,0)," %d ",&value); if(ngot != 1 || (value < SleepModeMin || value > SleepModeMax)) { ErrorPrint(ParseBadValue, CommandParameterValue(value, 0),"mode"); error++; } break; default: break; } } if (error == 0) { if (CurrentSleepMode == value) { UserPrint("The device is currently in %s mode.\n", (value == SLEEP_MODE_SLEEP ? "sleep" : (value == SLEEP_MODE_WAKEUP ? "wakeup" : "deep sleep"))); } else { SendOn(client); DeviceSleepMode(value); SendOff(client); CurrentSleepMode = value; } } SendDone(client); }
int CalibrationSetCommand(int client) { char *name, *calDllName; int np, index; // Check if the command is dll load first. np=CommandParameterMany(); name=CommandParameterName(0); index=ParameterSelectIndex(name,&calDllLoadParameter,1); if(index == 0) { calDllName=CommandParameterValue(0,0); if(CalibrationLoad(calDllName)!=0) { return -1; } return 1; } // Following part will handle different cal parameter set commands // First check if calibration dll was loaded before. if(osCheckLibraryHandle(CalibrationLibrary)==0) { ErrorPrint(CalibrationMissing); return -1; } if(_CalSetCommand!=0) { _CalSetCommand(client); } else { ErrorPrint(CalibrationNoFunction,"Calibration_SetCommand"); return -1; } return 0; }
bool Connection::connect(const char *ip, int port) { struct sockaddr_in remoteAddr; remoteAddr.sin_family = AF_INET; remoteAddr.sin_port = htons(port); if (inet_pton(AF_INET, ip, &remoteAddr.sin_addr) < 0) { ErrorPrint("[connect] illegal ip(%s)", ip); return false; } return connect((const SA *)&remoteAddr, sizeof(remoteAddr)); }
void HCError( int err_num, ... ) { ErrString string = err_strings[err_num]; va_list values; fputc( '\n', stderr ); va_start( values, err_num ); ErrorPrint( stderr, string, values ); va_end( values ); // Throw an exception to jump back to main(). throw HCException(); }
PCALLBACK_CONTEXT FindAndRemoveCallbackContext( _In_ LARGE_INTEGER Cookie ) /*++ Routine Description: Utility method to find a callback context using the cookie value and then remove it. Arguments: Cookie - the cookie value associated with the callback context. The cookie is returned when CmRegisterCallbackEx is called. Return Value: Pointer to the found callback context --*/ { PCALLBACK_CONTEXT CallbackCtx = NULL; PLIST_ENTRY Entry; ExAcquireFastMutex(&g_CallbackCtxListLock); Entry = g_CallbackCtxListHead.Flink; while (Entry != &g_CallbackCtxListHead) { CallbackCtx = CONTAINING_RECORD(Entry, CALLBACK_CONTEXT, CallbackCtxList); if (CallbackCtx->Cookie.QuadPart == Cookie.QuadPart) { RemoveEntryList(&CallbackCtx->CallbackCtxList); g_NumCallbackCtxListEntries--; break; } } ExReleaseFastMutex(&g_CallbackCtxListLock); if (CallbackCtx == NULL) { ErrorPrint("FindAndRemoveCallbackContext failed: No context with specified cookied was found."); } return CallbackCtx; }
bool CaptureAndSend::stop() { if (m_CurrentState == Stopped) { return true; } if(!m_NetSenderFilter->stop()) { return false; } g_StartCount--; if ( g_StartCount == 0) { HRESULT hr; IMediaControl* mediaControl; hr = m_FilterGraph->QueryInterface(IID_IMediaControl, (void**)&mediaControl); if(FAILED(hr)) { ErrorPrint("Get media control error", hr); return false; } ComReleaser mediaControlReleaser(mediaControl); hr = mediaControl->Stop(); if(FAILED(hr)) { ErrorPrint("Stop error",hr); return false; } } m_CurrentState = Stopped; return true; }
void print9300_lineEnd(int emptyRight) { int i=0; // fill the space for right side of the line if (emptyRight==1) { nc = SformatOutput(&buffer[lc],MBUFFER-lc-1,"|"); lc+=nc; for (i=0; i<TOTAL_SPACE; i++) { nc = SformatOutput(&buffer[lc],MBUFFER-lc-1," "); lc+=nc; } } nc = SformatOutput(&buffer[lc],MBUFFER-lc-1,"|\n"); ErrorPrint(NartOther, buffer); lc=0; }
int cnpkNextPage( CnpkCtx* pCnpk ) { int result = 0; #ifdef DEBUG_MESSAGE fputs("DEBUG: cnpkNextPage\n", stderr); #endif if( pCnpk->flgProc ){ if( pCnpk->nBufSize > 0 ){ char size_str[32]; snprintf(size_str, 31, "%d", pCnpk->nBufSize); if( cnprocWriteCommand(pCnpk->pipe_fds, CNPK_ID_SEND_DATA, size_str, strlen(size_str)+1) == 0 ){ cnprocWriteData(pCnpk->pipe_fds, pCnpk->bufPDLData, pCnpk->nBufSize); if( (result=cnprocCheckResponse(pCnpk->pipe_fds, CNPK_ID_SEND_DATA, NULL, NULL)) == 0 ) pCnpk->nBufSize = 0; else goto flush_error; } } if( cnprocWriteCommand(pCnpk->pipe_fds, CNPK_ID_NEXT_PAGE, NULL, 0) < 0 ){ ErrorPrint( "cnpklib -->cnpkNextPage\n"); goto write_error; } result = cnprocCheckResponse(pCnpk->pipe_fds, CNPK_ID_NEXT_PAGE, NULL, NULL); }else{ pCnpk->numPage++; } return result; flush_error: write_error: return CNPK_ERROR; }
void ThreadedTCPServer::SetNotificationCallback( TNotification notification ) { LOG_FUNCTION_START(); if ( this->m_notification != nullptr && this->m_started ) { ErrorPrint( "Multiple notification callbacks not allowed" ); } this->m_notification = notification; if ( this->m_notification != nullptr ) { this->m_started = true; this->Listen(); this->m_thread = std::thread( &ThreadedTCPServer::ExecutionBody, this ); this->m_thread.detach(); } LOG_FUNCTION_END(); }
BOOL UtilGetServiceState ( _In_ SC_HANDLE hService, _Out_ DWORD* State ) /*++ Routine Description: Gets the state of the service using QueryServiceStatusEx Arguments: hService - handle to the service to query State - pointer to a variable that receives the state Return Value: TRUE if service is queried successfully. --*/ { SERVICE_STATUS_PROCESS ServiceStatus; DWORD BytesNeeded; BOOL Result; *State = 0; Result = QueryServiceStatusEx ( hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ServiceStatus, sizeof(ServiceStatus), &BytesNeeded); if (Result == FALSE) { ErrorPrint("QueryServiceStatusEx failed, last error 0x%x", GetLastError()); return FALSE; } *State = ServiceStatus.dwCurrentState; return TRUE; }
bool SCA_PythonController::Compile() { m_bModified= false; // if a script already exists, decref it before replace the pointer to a new script if (m_bytecode) { Py_DECREF(m_bytecode); m_bytecode=NULL; } // recompile the scripttext into bytecode m_bytecode = Py_CompileString(m_scriptText.c_str(), m_scriptName.c_str(), Py_file_input); if (m_bytecode) { return true; } else { ErrorPrint("Python error compiling script"); return false; } }