void DriveTransfer::Execute() { OC_LOG_INFO("Copying started"); // TODO: Add handling of multiple destinations std::string destination = _destinationPaths[0]; int index = 0; for (FileTransferInfo& info : *_fileList) { QString relativeFilePath = QString::fromStdString(info.RelativeFolderPath + info.FileName); int64_t checksum = 0; TransferFile(_sourcePath.c_str(), relativeFilePath, QString::fromStdString(destination), checksum); emit FileTransfered(index, checksum); info.FullTargetPath = destination + "/" + relativeFilePath.toStdString(); index++; } // NOTE: Workaround, as QThread::finished() wasn't emitted emit TransferFinished(); OC_LOG_INFO("Copying finished"); }
TestT() { if ((ourWay.DoIt().DidIt())) { OC_LOG_INFO("...DidIt ourWay"); } else { OC_LOG_ERROR("...Failed to DoIt ourWay"); } if ((theirWay.CanDoIt())) { OC_LOG_INFO("...CanDoIt theirWay"); } else { OC_LOG_ERROR("...failed CanDoIt theirWay"); } OC_LOG_INFO("...Having fun"); OC_LOG_WARNING("...Be careful"); OC_LOG_ERROR("...Ooops something went wrong"); OC_LOG_FATAL("...We're done"); }
int oc_main_init(oc_handler_t *handler) { int ret; extern int oc_stack_errno; if (initialized == true) { return 0; } oc_ri_init(); #ifdef OC_SECURITY handler->get_credentials(); oc_sec_load_pstat(); oc_sec_load_doxm(); oc_sec_load_cred(); oc_sec_dtls_init_context(); #endif ret = oc_connectivity_init(); if (ret < 0) { goto err; } handler->init(); #ifdef OC_SERVER if (handler->register_resources) { handler->register_resources(); } #endif #ifdef OC_SECURITY oc_sec_create_svr(); oc_sec_load_acl(); #endif if (oc_stack_errno != 0) { ret = -oc_stack_errno; goto err; } OC_LOG_INFO("oci: Initialized\n"); #ifdef OC_CLIENT handler->requests_entry(); #endif initialized = true; return 0; err: oc_abort("oc_main: Error in stack initialization\n"); return ret; }
void DriveTransfer::TransferFile(QString sourcePath, QString relativeFilePath, QString targetPath, int64_t& checksum) { QFile source(sourcePath + "/" + relativeFilePath); _subTaskDescription = "Copying " + relativeFilePath.toStdString(); // TODO: Ensure trailing slash to remove need of appending it in multiple places if (QFile::exists(targetPath + relativeFilePath)) { QFile::remove(targetPath + "/" + relativeFilePath); } QFile target(targetPath + "/" + relativeFilePath); OC_LOG_INFO("From: " + source.fileName().toStdString() + " To: " + target.fileName().toStdString()); source.open(QIODevice::ReadOnly); target.open(QIODevice::WriteOnly); if (source.error() || target.error()) { OC_LOG_ERROR("DriveTransfer failed."); return; } int TRANSFER_BLOCK_SIZE = 1024 * 1024; // 1MB float progressBlock = source.size() / 100.0f; int totalRead = 0; int progress = 0; const std::unique_ptr<IHashGenerator> hashGenerator(new xxHashAdapter()); hashGenerator->Initialize(); // TODO: Error handling char* buffer = new char[TRANSFER_BLOCK_SIZE]; while (!source.atEnd()) { qint64 readSize = source.read(buffer, TRANSFER_BLOCK_SIZE); target.write(buffer, readSize); hashGenerator->Update(buffer, readSize); totalRead += readSize; //progress = totalRead / progressBlock; if (totalRead > progressBlock * progress) { progress += totalRead / progressBlock; ProgressChanged(progress); } } checksum = hashGenerator->Retrieve(); }
bool Graphic::Initialize(HWND hwnd, const GraphicConfig& config) { OC_LOG_INFO("GraphicSystem initializing"); m_hwnd = hwnd; m_config = config; m_backBufferWidth = m_config.m_windowWitdh; m_backBufferHeigth = m_config.m_windowHeight; OC_ASSERT_MSG(m_config.m_MSAASample > 0, "Invalid MSAA samples!"); // Minimum is 1 // Create the device and device context. UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED; #if defined(OC_DEBUG) createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL featureLevel; HRESULT hr = D3D11CreateDevice( 0, // default adapter D3D_DRIVER_TYPE_HARDWARE, 0, // no software device createDeviceFlags, 0, // default feature level array (select greatest supported -> DX11) 0, // number of feature level in the array above D3D11_SDK_VERSION, //SDK version m_dxDevice.GetAddressOf(), //Created device &featureLevel, //Selected feature level m_dxImmediateContext.GetAddressOf()); //Device context if (FAILED(hr)) { OC_LOG_ERROR("D3D11CreateDevice failed"); return false; } if (featureLevel != D3D_FEATURE_LEVEL_11_0) { OC_LOG_ERROR("Direct3D Feature Level 11 unsupported"); return false; } #if defined(OC_DEBUG) ComPtr<ID3D11InfoQueue> infoQueue; DXCall(m_dxDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void**)infoQueue.GetAddressOf())); infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, TRUE); infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, TRUE); #endif // Check 4X MSAA quality support for our back buffer format. // All Direct3D 11 capable devices support 4X MSAA for all render // target formats, so we only need to check quality support. UINT MSAAQuality; DXCall(m_dxDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, m_config.m_MSAASample, &MSAAQuality)); // Validate quality OC_ASSERT(MSAAQuality > 0); OC_ASSERT_MSG(m_config.m_selectBestMSAAQuality || m_config.m_MSAAQuality <= MSAAQuality -1, "Invalid MSAA quality"); if (m_config.m_selectBestMSAAQuality) { m_config.m_MSAAQuality = MSAAQuality - 1; } DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC)); // Describe the back buffer sd.BufferDesc.Width = m_backBufferWidth; sd.BufferDesc.Height = m_backBufferHeigth; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //Texture format of the back buffer ( 8 bits rgb + alpha) sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // Multisampling (anti-aliasing), all DX11 device support at least 4X multisampling for all render target format sd.SampleDesc.Count = m_config.m_MSAASample; sd.SampleDesc.Quality = m_config.m_MSAAQuality - 1; // Describes the surface usage and CPU access options for the back buffer. // The back buffer can be used for shader input or render-target output. sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = m_hwnd; sd.Windowed = !m_config.m_fullScreen; // Options for handling pixels in a display surface after calling IDXGISwapChain1::Present1. sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // Options for swap-chain behavior. sd.Flags = 0; // NOTE : This flag can change the resolution... //sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // To correctly create the swap chain, we must use the IDXGIFactory that was // used to create the device. If we tried to use a different IDXGIFactory instance // (by calling CreateDXGIFactory), we get an error: "IDXGIFactory::CreateSwapChain: // This function is being called with a device from a different IDXGIFactory." ComPtr<IDXGIDevice> dxgiDevice = nullptr; DXCall(m_dxDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)dxgiDevice.GetAddressOf())); ComPtr<IDXGIAdapter> dxgiAdapter = nullptr; DXCall(dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)dxgiAdapter.GetAddressOf())); ComPtr<IDXGIFactory> dxgiFactory = nullptr; DXCall(dxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)dxgiFactory.GetAddressOf())); DXCall(dxgiFactory->CreateSwapChain(m_dxDevice.Get(), &sd, m_swapChain.GetAddressOf())); // The remaining steps that need to be carried out for d3d creation // also need to be executed every time the window is resized. BindDefaultBuffers(); OC_LOG_INFO("GraphicSystem initialize completed"); return true; }