コード例 #1
0
//---------------------------------------------------------------------------
void __fastcall DB_Loading::Execute()
{
	NameThreadForDebugging("TH_DB_Loading");

	DBManager->ALDB_Connect();
	DBManager->CADB_Connect();
	//---- Place thread code here ----
	while(stkc_frm->run == true)
	{
		try
		{
	               	stkc_frm->STK_SRVinfo.SRV_NOWDATE = FormatDateTime("MM/DD/YY", Now());;
			stkc_frm->STK_SRVinfo.SRV_NOWTIME = Time().TimeString();

			DBManager->Alarm_List_Load();
			DBManager->GetAllCarrierinfo();
			Sleep(300);
		}
		catch(Exception *e)
		{


		}

    }


}
コード例 #2
0
ファイル: CleanupThread.cpp プロジェクト: kilitary/form
// ---------------------------------------------------------------------------
void __fastcall CleanupThread::Execute()
{
    NameThreadForDebugging("CleanupThread");

    DWORD freed = 0;
    while (1)
    {
        freed = 0;

        if (delete_wnd_buttons_job)
        {
            
            delete_wnd_buttons_job = false;
        }

        Sleep(1);
    }
}
コード例 #3
0
ファイル: FtpThread.cpp プロジェクト: kilitary/fatftpapp
void __fastcall FtpThread::Do(void)
{
    NameThreadForDebugging("FtpThread");
    // ---- Place thread code here ----

    if (!mounted)
    {
        Form1->dwnimg->Visible = false;
        Form1->rlimg->Visible = false;
        Form1->pasvconnecting->Visible = false;
        ff_SocketBuffers(13111072);
        ff_SocketNoDelay(Form1->tcpnodelay->Checked);
        // ff_ReadAheadMinCache(384000);
        ff_SocketOOBInline(Form1->oobinline->Checked);

        mounted = true;

        char ffhost[255];
        deunicode(Form1->host->Text.c_str(), ffhost, sizeof(ffhost));
        Form1->filelist->Clear();
        Form1->filelist->AddItem("ff_ConnectFTP", 0);

        // deb("execing ff_connectftp");

        if (!ff_ConnectFTP(ffhost, 21))
        {
            mounted = false;
            return;
        }

        if (stopftpthread)
            return;

        char user[111], pass[111];
        deunicode(Form1->user->Text.c_str(), user, sizeof(user));
        deunicode(Form1->pass->Text.c_str(), pass, sizeof(pass));

        deb("user %s pass %s",user,pass);
        // deb("seting butns, add log");
        Form1->filelist->AddItem("ff_AuthFTP", 0);

        Form1->Button1->Caption = "отключить";

        // deb("execing ff_authftp()");
        if (!ff_AuthFTP(user, pass))
        {
            mounted = false;
            Form1->Button1->Caption = "подключить";
            return;
        }

        if (stopftpthread)
            return;

        // deb("add log ff_ScanFTP");
        Form1->filelist->AddItem("ff_ScanFTP", 0);
        // deb("execing ff_ScanFTP()");
        ff_ScanFTP(0, 50000, 50000);

        if (stopftpthread)
            return;
        // deb("add log ff_MountDisk");
        Form1->filelist->AddItem("ff_MountDisk", 0);
        // deb("execing ff_MountDisk()");
        ff_MountDisk('y');

        if (stopftpthread)
            return;

        // deb("add log scan");
        Form1->filelist->AddItem("scan", 0);

        if (stopftpthread)
            return;
        Form1->filelist->Clear();
        WIN32_FIND_DATA wfd;
        HANDLE hf;
        hf = FindFirstFile("y:\\*", &wfd);
        Form1->filelist->AddItem(wfd.cFileName, 0);
        while (FindNextFile(hf, &wfd))
        {

            Form1->filelist->AddItem(wfd.cFileName, 0);
        }
        char s[111];
        sprintf(s, "ftp://%s:%s@%s:%d [connected]", user, pass, ffhost, 21);
        Form1->Caption = s;
        // Application->ProcessMessages();
        // Form1->filelist->Clear();

        deb("ready");
    }
    else
    {
        mounted = false;
        Form1->Button1->Caption = "подключить";
        ff_Clear();

        Form1->timeout->Text = "0";
        Form1->netspd->Text = "0";
    }
}
コード例 #4
0
ファイル: FtpControl.cpp プロジェクト: kilitary/fatftp
// ---------------------------------------------------------------------------
void __fastcall FtpControl::Execute()
{
	DWORD nopwait = 0;
	DWORD nopcmdtm = GetTickCount();
	DWORD secondtm = GetTickCount();
	NameThreadForDebugging("FtpControl");

	fdeb("FtpControl thread %x", GetCurrentThreadId());

	// Priority = tpIdle;

	fce = new TEvent(false);

	while (true)
	{
		Sleep(50);

		if (GetTickCount() - secondtm >= 1000)
		{
			secondtm = GetTickCount();
			call_events(E_SECOND, (LPVOID)rand());
		}
//
//		if (GetTickCount() - nopcmdtm >= nopwait)
//		{
//			nopwait = 23400 + (rand() % 13400);
//
//			if (!FtpSocket || processing_disk_event)
//				continue;
//
//			char *cmds[] =
//			{
//				"NOp", "fEAT", "NooP", "STAT", "HELP", "TYPE", "SYST", "PWD"
//			};
//
//			int num = rand() % 8;
//
//			ftplock();
//
//			ftpcmd(cmds[num], 0, 0);
//
//			char b[11111];
//			ftprl(b, timeoutst, 0);
//
//			while (ftphasdata())
//				ftprl(b, timeoutst, 0);
//
//			ftpunlock();
//
//			// ftpunlock();
//
//			nopcmdtm = GetTickCount();
//		 }

		if (!ccs)
			continue;

		ccs->Enter();

		for (vector<CACHE>::iterator it = cache.begin(); it != cache.end(); it++)
		{

			if (GetTickCount() - (*it).lastaccessed >= 10000)
			{
				try
				{
					if ((SIZE_T)HeapSize(GetProcessHeap(), 0, (*it).buf) != (SIZE_T) - 1)
					{
						// fdeb(E_CACHEMSG, "cache: freeing %7lu bytes (%7lu in records) of '%s' @ %08X",
						// HeapSize(GetProcessHeap(), 0, (*it).buf), (*it).size, (*it).fn, (*it).buf);

						int numcaches = ((int)cache.size()) - 1;
						unsigned long heapsiz;
						heapsiz = (unsigned long)HeapSize(GetProcessHeap(), 0, (*it).buf);

						HeapFree(GetProcessHeap(), 0, (*it).buf);
						it = cache.erase(it);

						call_events(E_CACHEFREED, (LPVOID)(*it).buf, (LPVOID)(*it).fn, (LPVOID)heapsiz,
							(LPVOID)(*it).offset, (LPVOID)numcaches);

						if (it == cache.end())
							break;
					}
					else
					{
						deb(E_FTPCONTROL, "cache block @ %p for '%s' size: %lu is not heap allocated!",
							(*it).buf, (*it).fn, (*it).size);
					}
				}
				catch(...)
				{
					exp;
				}
			}
			//
			// // decrease blocks
			// unsigned long maxcachebufsize = precacheminbytes; // 8 * 1024 * 1024;
			// if ((*it).bufsize > maxcachebufsize)
			// {
			// unsigned long newsiz = maxcachebufsize - 512000;
			// memcpy((*it).buf, (void*)((unsigned long)(*it).buf + (unsigned long)(*it).size -
			// (unsigned long)maxcachebufsize), newsiz);
			//
			// (*it).buf = HeapReAlloc(GetProcessHeap(), 0, (*it).buf, newsiz);
			// cache_list();
			// deb(E_CACHEMSG, "cache block %p truncated from %lu to %lu", (*it).buf, (*it).bufsize,
			// newsiz);
			//
			//
			// (*it).offset += ((*it).bufsize - newsiz);
			// if (!(*it).buf)
			// ds;
			// (*it).size = newsiz;
			// (*it).bufsize = newsiz;
			// }

		}
		ccs->Leave();

		// fdeb(E_CACHEMSG,"check for cache");

		files_sort_diskevent();

		int seqreads;
		seqreads = cache_seq_reads();

		for (vector<FATFILE>::iterator it = files.begin(); it != files.end(); it++)
		{

			if (GetTickCount() - (*it).lastaccessed >= 2000)
			{
				(*it).sequential_reads = 0;

			}

			if ((*it).lastlen && GetTickCount() - (*it).lastdisktime <= 1500)
			{
				// fdeb("checking %s", (*it).fn);
				unsigned long precachesize = 0;
				unsigned long readoffset = 0;
				unsigned long flen = 0;

				unsigned long stofs = 0; // (*it).lastoffset + (*it).lastlen;

				if (!(*it).sequential_reads)
				{
					// fdeb(E_CACHEMSG, "have another %lu bytes @ %lu", (*it).lastlen * 10,
					// stofs - (*it).lastoffset + (*it).lastlen);
					// fdeb( "skip sequential_read");
					continue;

				}
				else
				{
					// fdeb(E_CACHEMSG, "sequential_reads %lu, cache %lu @ %lu", (*it).sequential_reads,
					// (*it).nextcachelen, (*it).nextcacheoffset);

					if (in_cache((*it).dosfn, (*it).lastoffset, (*it).nextcachelen))
					{
						// fdeb("skip precache");
						continue;
					}
				}

				// stofs = highcacheoffset((*it).dosfn);
				// stofs = seqcacheoffset((*it).dosfn);
				stofs = (*it).nextcacheoffset;
				if (stofs <= 65535)
					stofs = 0;
				deb("nextcachelen=%lu", (*it).nextcachelen);
				flen = (*it).nextcachelen;
				if (!flen)
					flen = (*it).nextcachelen ;
				if (!flen)
					flen = 512000;
				(*it).nowcaching = true;
				(*it).nowcachingoffset = stofs;
				(*it).nowcachinglen = flen;
				strcpy(nowcachingdosfn, (*it).dosfn);
				// fdeb(E_CACHEMSG, "seqcacheoffset %lu", stofs);

				if (!ftptrylock())
					continue;

				char curdir[255];
				int code = 250;
				strncpy(curdir, ftpcurdir, sizeof(curdir));
				fdeb("allocating %lu bytes", flen);
				char *buf = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, flen);
				fdeb("flen %lu, buf @ %p %lu", flen, buf, HeapSize(GetProcessHeap(), 0, buf));
				// ftpcs->Enter();
				// fdeb("

				if (strcmpi((*it).ftppath, ftpcurdir) != 0)
				{

					ftpcd("/");
					code = 250;

					if (strlen((*it).ftppath))
						code = ftpcd((*it).ftppath);

					if (code != 250)
					{
						ftpcd("/");
						// ecs->Leave();
						// processing_disk_event = false;
						// ftpcs->Leave();
						ftpunlock();
						continue;
					}

					strcpy(ftpcurdir, (*it).ftppath);
				}

				fdeb("caching %lu '%s' @ %lu  ", flen, (*it).fn, stofs);

				call_events(E_STARTPRECACHE, (LPVOID)(*it).fn, (LPVOID)flen, (LPVOID)stofs);

				fdeb("ftpgetfile(%-15s, %8lu, %8p, %8lu)", (*it).fn, (unsigned long)stofs, buf,
					(unsigned long)flen);

				call_events(E_FTPPREGETFILE, (LPVOID)(*it).ftppath, (LPVOID)(*it).fn, (LPVOID)stofs,
					(LPVOID)buf, (LPVOID)flen);

				DWORD ftpgettm = GetTickCount();

				unsigned long nrd = ftpgetfile((*it).fn, (unsigned long)stofs, (char*)buf, flen,
					(*it).dosfn, 65535, stofs);

				ftpunlock(); // ftpcs->Leave();

				HeapFree(GetProcessHeap(), 0, buf);

				(*it).nowcaching = false;

				ftpgettm = GetTickCount() - ftpgettm;

				// fdeb(E_CACHEMSG, "precacheclstrs [%lu]", (*it).precacheclstrs);
				fdeb("ftpgetfile(%-15s, %8lu, %8p, %8lu) = %lu", (*it).fn, (unsigned long)stofs, buf,
					(unsigned long)flen, nrd);

				call_events(E_FTPGETFILE, (LPVOID)(*it).ftppath, (LPVOID)(*it).fn, (LPVOID)stofs,
					(LPVOID)buf, (LPVOID)flen, (LPVOID)ftpcontroltime, (LPVOID)ftpdatatime,
					(LPVOID)nrd);

				if (nrd > 0)
				{
					// cache_save((*it).ftppath, (*it).dosfn, ((unsigned long)stofs), nrd, buf);

					(*it).nextcacheoffset = stofs + flen;
					// (*it).lastoffset = stofs;

				}
				else
				{
					(*it).lastlen = 0;
					fdeb("zero download %lu @ %lu fsize %lu!", flen, stofs, (*it).size);
					// ds;
				}

				nopcmdtm = GetTickCount();

			}
		}

	}
}
コード例 #5
0
ファイル: ShmThread.cpp プロジェクト: kilitary/form
// ---------------------------------------------------------------------------
void __fastcall ShmThread::Execute()
{
    NameThreadForDebugging("ShmThread");

    status = shmbuf;
    cmd = shmbuf +sizeof(char);
    data = shmbuf +sizeof(char)+sizeof(char);
    shmbuf[0] = SHM_READY;
    shme->ResetEvent();

    while (1)
    {
        shme->WaitFor(INFINITE);

        if (status[0] != SHM_RREADY)
        {
            deb("shm signaled");
            shme->ResetEvent();
            continue;
        }

        // deb("shm cmd %d", cmd[0]);

        shme->ResetEvent();
        // Synchronize(Do);
        // shme->SetEvent();
        // }
        // }
        //
        // void __fastcall ShmThread::Do(void)
        // {

        if (!shmbuf)
        {
            MessageBox(Application->MainFormHandle, "error no shmbuf", "err", MB_OK);
            ExitProcess(0);
        }

        switch(cmd[0])
        {
            case LO_UPDWNDPIC:
            // deb("L:O_UPDWNDPIC");
            // ReadFile(hPipe, &hid, sizeof(hid), &dwRead, false);
            HANDLE hid;
            LPVOID p;
            HDC hdc;
            BITMAPINFO *pbmi;
            LPVOID dbuf;
            Graphics::TBitmap *ub;

            memcpy(&hid, data, sizeof(hid));
            // data += sizeof(HANDLE);

            bool fail;
            fail = false;
            wcs->Acquire();
            bool found;
            found = false;
            WNDBUTTONS *pwnd;
            pwnd = NULL;

            try
            {
                pwnd = (WNDBUTTONS*)hid;
                for (wnd_buttons_v::iterator it = wnd_buttons.begin();it!=wnd_buttons.end();it++)
                {
                    // deb("%x > %x",(*it)->id,hid);

                    if ((*it)->id == hid)
                    {
                        // deb("found %x",hid);
                        found = true;
                        break;
                    }
                }

                if (!found || IsBadReadPtr(pwnd, sizeof(WNDBUTTONS)))
                {
                    fail = true;
                }
                else
                {

                    // deb(" LO_UPDWNDPIC => %x ", pwnd);
                    // deb("%d:%d", pwnd->rect.left, pwnd->rect.top);

                    if (pwnd->pic)
                    {
                        // deb(" SHM:LO_UPDWNDPIC @ %p deleting %p", pwnd, pwnd->pic);
                        delete pwnd->pic;

                    }

                    ub = new Graphics::TBitmap();

                    pbmi = (BITMAPINFO*)(data +sizeof(HANDLE));
                    dbuf = data +sizeof(BITMAPINFO)+sizeof(HANDLE);

                    hdc = CreateCompatibleDC(0);

                    ub->SetSize(pwnd->rect.right - pwnd->rect.left, pwnd->rect.bottom - pwnd->rect.top);

                    if (!SetDIBits(hdc, ub->Handle, 0, pbmi->bmiHeader.biHeight, dbuf, pbmi, DIB_PAL_COLORS))
                    {
                        deb("bmi->h: %d bits %d", pbmi->bmiHeader.biHeight, pbmi->bmiHeader.biBitCount);
                        deb("bmihdr sz %d", pbmi->bmiHeader.biSize);
                        deb("updwndpic setdibits: %s", fmterr());
                    }
                    DeleteDC(hdc);

                    pwnd->pic = ub;

                }
            }
            catch(...)
            {
                char sz1[1024];
                // deb("exception in shmthread: %s", deunicode(e.Message.c_str(), sz1, sizeof(sz1)));
                deb("shmthread exception");
                fail = true;
                data[0] = SHM_FAIL;
            }

            if (!fail && found)
            {
                if (pwnd->visible)
                {
                    extern TEvent *bgraphics_event;

                    bgraphics_event->SetEvent();
                    graphics_event->SetEvent();
                }

                // deb("success update %x %d:%d v:%d", hid, pwnd->rect.left, pwnd->rect.top, pwnd->visible);
                data[0] = SHM_READY;
            }
            else
            {
                // deb("unsuccessfull update of %x", hid);
                data[0] = SHM_FAIL;
            }
            wcs->Release();
            break;

            /////////////////            /////////////////            /////////////////            /////////////////            /////////////////

            case LO_UPDATEBGBITMAP:
            //shmb->Acquire();
            // deb("case LO_UPDATEBGBITMAP:");
            extern Graphics::TBitmap *BackgroundBitmap;
            BackgroundBitmap = (Graphics::TBitmap*)1;
            procId = (DWORD*)data;

            BackgroundProcessId = (DWORD)*procId;

            bgupd->Enter();

            memcpy(&bgbmi, data+sizeof(DWORD) , sizeof(bgbmi));

            if (!bgbmi.bmiHeader.biSizeImage ||!bgbmi.bmiHeader.biHeight)
                deb("bmi bg height %d", bgbmi.bmiHeader.biHeight);
         //   deb("size %d", bgbmi.bmiHeader.biSizeImage);

            try
            {
                memcpy(bgbuf, data +sizeof(bgbmi)+sizeof(DWORD), bgbmi.bmiHeader.biSizeImage);
            }
            catch(...)
            {
                deb("exception while shmcopy bg");
            }
            //

            bgupd->Leave();

            bg_change->SetEvent();
         //   shmb->Release();

            graphics_event->SetEvent();

      //      deb("done bg upd");
            data[0] = SHM_READY;
            break;

            default:
            deb("unknwon shm cmd %d", *cmd);
            break;
        }

        *status = SHM_READY;

        // shmb->Release();

    }
}