void XBeeResponse::getZBTxStatusResponse(XBeeResponse &zbXBeeResponse) { // way off? ZBTxStatusResponse* zb = static_cast<ZBTxStatusResponse*>(&zbXBeeResponse); // pass pointer array to subclass zb->setFrameData(getFrameData()); setCommon(zbXBeeResponse); }
void XBeeResponse::getZBRxResponse(XBeeResponse &rxResponse) { ZBRxResponse* zb = static_cast<ZBRxResponse*>(&rxResponse); //TODO verify response api id matches this api for this response // pass pointer array to subclass zb->setFrameData(getFrameData()); setCommon(rxResponse); zb->getRemoteAddress64().setMsb((uint32_t(getFrameData()[0]) << 24) + (uint32_t(getFrameData()[1]) << 16) + (uint16_t(getFrameData()[2]) << 8) + getFrameData()[3]); zb->getRemoteAddress64().setLsb((uint32_t(getFrameData()[4]) << 24) + (uint32_t(getFrameData()[5]) << 16) + (uint16_t(getFrameData()[6]) << 8) + (getFrameData()[7])); }
VOID CALLBACK ChDirCompletionRoutine(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) { //VPL_REPORT_INFO("ChDirCompletionRoutine"); int rc; DWORD dwOffset = 0; FILE_NOTIFY_INFORMATION* pInfo; VPLFS_MonitorHandle_t* monHandle = (VPLFS_MonitorHandle_t*)(lpOverlapped->hEvent); if(dwErrorCode==ERROR_OPERATION_ABORTED || g_isInitCount==0 || monHandle->stop) { // Will be handled below. }else if(dwErrorCode != ERROR_SUCCESS) { VPL_REPORT_WARN("Unexpected error:"FMT_DWORD, dwErrorCode); }else { // (dwErrorCode == ERROR_SUCCESS), btw, ERROR_SUCCESS == 0. DWORD nextEntryOffset = 1; VPLFS_MonitorEvent* cbBuffer = (VPLFS_MonitorEvent*) (monHandle->pBuffer+monHandle->nBufferLength); u32 previousEntry = 0; void* eventBuffer = cbBuffer; int eventBufferSize = 0; if(dwNumberOfBytesTransfered == 0) { // This means the buffer overflowed monHandle->cb(monHandle, eventBuffer, eventBufferSize, VPLFS_MonitorCB_OVERFLOW); }else { do { // Get a pointer to the first change record... pInfo = (FILE_NOTIFY_INFORMATION*) &(monHandle->pBuffer[dwOffset]); nextEntryOffset = pInfo->NextEntryOffset; char filename[4 * MAX_PATH]; // a UTF16 char may require at most 4 bytes when encoded in UTF8 // NOTE: pInfo->FileName is not null-terminated! // NOTE: pInfo->FileNameLength is in bytes! int temp_rc = _VPL__wstring_to_utf8(pInfo->FileName, pInfo->FileNameLength / sizeof(WCHAR), filename, ARRAY_SIZE_IN_BYTES(filename)); if(temp_rc != 0) { VPL_REPORT_WARN("%s failed: %d", "_VPL__wstring_to_utf8", temp_rc); // TODO: skip the rest of this loop? } if(!isBeginWithPeriod(filename)) { // If the file is not considered hidden (begins with a period. //VPL_REPORT_INFO("Filename:%s, FilenameLength:"FMT_DWORD", action:"FMT_DWORD", nextEntry:"FMT_DWORD, // filename, pInfo->FileNameLength, pInfo->Action, pInfo->NextEntryOffset); switch(pInfo->Action) { case FILE_ACTION_ADDED: { //VPL_REPORT_INFO("FILE_ACTION_ADDED: %s", filename); cbBuffer->action = VPLFS_MonitorEvent_FILE_ADDED; monHandle->has_rename_old_name = false; setCommon(cbBuffer, filename); previousEntry = cbBuffer->nextEntryOffsetBytes; eventBufferSize += cbBuffer->nextEntryOffsetBytes; cbBuffer = (VPLFS_MonitorEvent*)(((char*)(cbBuffer))+cbBuffer->nextEntryOffsetBytes); }break; case FILE_ACTION_REMOVED: { //VPL_REPORT_INFO("FILE_ACTION_REMOVED: %s", filename); cbBuffer->action = VPLFS_MonitorEvent_FILE_REMOVED; monHandle->has_rename_old_name = false; setCommon(cbBuffer, filename); previousEntry = cbBuffer->nextEntryOffsetBytes; eventBufferSize += cbBuffer->nextEntryOffsetBytes; cbBuffer = (VPLFS_MonitorEvent*)(((char*)(cbBuffer))+cbBuffer->nextEntryOffsetBytes); }break; case FILE_ACTION_MODIFIED: { //VPL_REPORT_INFO("FILE_ACTION_MODIFIED: %s", filename); cbBuffer->action = VPLFS_MonitorEvent_FILE_MODIFIED; monHandle->has_rename_old_name = false; setCommon(cbBuffer, filename); previousEntry = cbBuffer->nextEntryOffsetBytes; eventBufferSize += cbBuffer->nextEntryOffsetBytes; cbBuffer = (VPLFS_MonitorEvent*)(((char*)(cbBuffer))+cbBuffer->nextEntryOffsetBytes); }break; case FILE_ACTION_RENAMED_OLD_NAME: { //VPL_REPORT_INFO("FILE_ACTION_RENAMED_OLD_NAME: %s", filename); monHandle->has_rename_old_name = true; strncpy(monHandle->rename_old_name, filename, MAX_PATH); }break; case FILE_ACTION_RENAMED_NEW_NAME: { //VPL_REPORT_INFO("FILE_ACTION_RENAMED_NEW_NAME: %s", filename); if(monHandle->has_rename_old_name) { cbBuffer->action = VPLFS_MonitorEvent_FILE_RENAMED; setCommon(cbBuffer, monHandle->rename_old_name); cbBuffer->moveTo = ((char*)cbBuffer) + cbBuffer->nextEntryOffsetBytes; std::string moveToName(filename); replaceBackslashWithForwardSlash(moveToName); strncpy((char*)cbBuffer->moveTo, moveToName.c_str(), MAX_PATH); int nameLen = moveToName.size()+1; // +1 for '\0' cbBuffer->filename = (char*)(cbBuffer+1); cbBuffer->nextEntryOffsetBytes += ALIGN(nameLen); previousEntry = cbBuffer->nextEntryOffsetBytes; eventBufferSize += cbBuffer->nextEntryOffsetBytes; cbBuffer = (VPLFS_MonitorEvent*)(((char*)(cbBuffer))+cbBuffer->nextEntryOffsetBytes); monHandle->has_rename_old_name = false; }else{ VPL_REPORT_WARN("RENAMED_NEW_NAME without RENAME_OLD_NAME:%s", filename); } }break; default: VPL_REPORT_WARN("Unhandled action:"FMT_DWORD", %s", pInfo->Action, filename); break; } } // More than one change may happen at the same time. Load the next change and continue... dwOffset += pInfo->NextEntryOffset; }while((pInfo->NextEntryOffset != 0) && (dwOffset<dwNumberOfBytesTransfered) && (monHandle->stop != true)); cbBuffer = (VPLFS_MonitorEvent*)(((char*)cbBuffer)- previousEntry); cbBuffer->nextEntryOffsetBytes = 0; if(eventBufferSize>0) { monHandle->cb(monHandle, eventBuffer, eventBufferSize, VPLFS_MonitorCB_OK); } } } if(g_isInitCount==0 || monHandle->stop) { VPL_REPORT_INFO("Cleaned up file monitor"); CloseHandle(monHandle->hDir); free(monHandle); } else { rc = beginMonitor(monHandle); if(rc != 0) { VPL_REPORT_WARN("beginMonitor failed:%d", rc); } } }