したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

1627 ◆adhRKFl5jU:2009/03/12(木) 12:50:42
#include "DownloadManager.hpp"

#include <string>
#include <map>

#include <windows.h>

/*----------*/
unsigned int
DownloadManager::WaitThread(void *){
return 0;
}

/*==========*/
DownloadManager::DownloadManager(const char *hash)
: m_hash(hash), m_hRunning(NULL), m_hPipe(NULL), m_hFlag(NULL)
{}

/*==========*/
bool
DownloadManager::AddPID(DWORD pid){
std::map<DWORD, HANDLE>::const_iterator it = m_pis.find(pid);
if(it == m_pis.end()){
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid);
if(hProcess != NULL){
m_pis.insert(std::make_pair(pid, hProcess));
return true;
}
return false;
}

return true;
}

/*==========*/
bool
DownloadManager::Initialize(){
m_hRunning = CreateMutexA(NULL, FALSE, ("DLRunning:" + m_hash).c_str());
if(m_hRunning == NULL){
return false;
}
WaitForSingleObject(m_hRunning, INFINITE);

m_hPipe = CreateNamedPipeA(("\\\\.\\pipe\\" + m_hash).c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 0, 0, 1000, NULL);
if(m_hPipe == INVALID_HANDLE_VALUE){
ReleaseMutex(m_hRunning);
CloseHandle(m_hRunning);

return false;
}

m_hFlag = CreateEventA(NULL, TRUE, FALSE, ("DLFlag:" + m_hash).c_str());
if(m_hFlag == NULL){
CloseHandle(m_hPipe);
ReleaseMutex(m_hRunning);
CloseHandle(m_hRunning);

return false;
}

HANDLE hCreated = OpenEventA(EVENT_MODIFY_STATE, FALSE, ("DLCreated:" + m_hash).c_str());
if(hCreated == NULL){
CloseHandle(m_hFlag);
CloseHandle(m_hPipe);
ReleaseMutex(m_hRunning);
CloseHandle(m_hRunning);

return false;
}
if(SetEvent(hCreated) == FALSE){
CloseHandle(hCreated);
CloseHandle(m_hFlag);
CloseHandle(m_hPipe);
ReleaseMutex(m_hRunning);
CloseHandle(m_hRunning);

return false;
}
CloseHandle(hCreated);

return true;
}

/*==========*/
int
DownloadManager::Loop(){
return 0;
}

/*==========*/
bool
DownloadManager::Finalize(){
CloseHandle(m_hPipe);
ReleaseMutex(m_hRunning);
CloseHandle(m_hRunning);
return true;
}


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板