void
CPulseGenerator::RequestStopOfPeriodicUpdates( void* requestor )
{   GUCEF_TRACE;

    LockData();
    if ( NULL != requestor )
    {
        m_periodicUpdateRequestors.erase( requestor );
    }

    // Determine the new common divider interval for all clients
    m_updateDeltaInMilliSecs = DetermineRequiredPulseInterval();

    // Check if we have a driver we can pass the request on to
    if ( NULL != m_driver )
    {
        // Depending on whether we have more clients wanting updates
        // we should either update the frequency or switch to manually requested pulses
        if ( !m_periodicUpdateRequestors.empty() )
        {
            m_driver->RequestPulseInterval( *this, m_updateDeltaInMilliSecs );
        }
        else
        {
            m_driver->RequestStopOfPeriodicUpdates( *this );
        }
    }
    UnlockData();
}
void
CPulseGenerator::RequestPulse( void )
{   GUCEF_TRACE;

    LockData();
    // Are we already doing period updates ?
    if ( m_periodicUpdateRequestors.size() == 0 )
    {
        // We are not so we must trigger an update either by delegation to a
        // driver or by doing so directly
        if ( NULL != m_driver )
        {
            UnlockData();
            m_driver->RequestPulse( *this );
        }
        else
        {
            UInt64 newTickCount = GUCEFGetTickCount();
            UInt64 deltaTicks = newTickCount - m_lastCycleTickCount;
            CPulseData pulseData( newTickCount, deltaTicks, 0);
            m_lastCycleTickCount = newTickCount;
            UnlockData();

            NotifyObservers( PulseEvent, &pulseData );
        }
    }
}
示例#3
0
void CGetScreenInfo::GetDataSource(BYTE** pBuff, DWORD* pdwLen, BYTE** pBuffLzw, DWORD* pdwLenLzw)
{
	LockData();
	DWORD dwRLzwLen = 0;
	if(pBuff)
		*pBuff = m_ScreenData.pScreenData;
	if(pdwLen)
		*pdwLen = m_ScreenData.dwBufLen;
	if(pBuffLzw)
	{
		if(m_ScreenData.dwBufLen > m_ScreenDataLzw.dwBufLen)
		{
			if(m_ScreenDataLzw.pScreenData != NULL)
				delete m_ScreenDataLzw.pScreenData;
			m_ScreenDataLzw.pScreenData = new BYTE[m_ScreenData.dwBufLen];
			if( !m_ScreenDataLzw.pScreenData )
			{
				m_ScreenDataLzw.dwBufLen = 0;
				return ;
			}
		}
		m_ScreenDataLzw.dwBufLen = m_ScreenData.dwBufLen;
		//压缩
		FCLzw lzw;
		memset(m_ScreenDataLzw.pScreenData, 0, m_ScreenData.dwBufLen);
		dwRLzwLen =  lzw.LZW_Encode(m_ScreenData.pScreenData, m_ScreenData.dwBufLen, m_ScreenDataLzw.pScreenData, m_pHash);
		*pBuffLzw = m_ScreenDataLzw.pScreenData;
	}
	if(pdwLenLzw)
			*pdwLenLzw = dwRLzwLen;
}
示例#4
0
void
CObservingNotifier::UnsubscribeAllFromObserver( void )
{GUCEF_TRACE;

    LockData();
    m_observer.UnsubscribeAllFromObserver();
    UnlockData();
}
void
CLogSvcClient::SetApplicationName( const CORE::CString& applicationName )
{GUCEF_TRACE;

    LockData();
    m_appName = applicationName;
    UnlockData();
}
示例#6
0
UInt32
CObservingNotifier::GetObserverNotifierCount( void )
{GUCEF_TRACE;

    LockData();
    UInt32 retval( m_observer.GetNotifierCount() );
    UnlockData();
    return retval;
}
示例#7
0
void
CObservingNotifier::UnsubscribeFrom( CNotifier* notifier )
{GUCEF_TRACE;

    if ( NULL != notifier )
    {
        LockData();
        notifier->Unsubscribe( &m_observer );
        UnlockData();
    }
}
示例#8
0
char * PlotWndPropText::GetText(size_t index)
{
    if (this->seriesInPlotWndProp.size() == 0)
        return false;

    auto seriesText = dynamic_cast<TextSeriesProp *>(this->seriesInPlotWndProp[0]);
    seriesText->LockData();
    size_t size = seriesText->DataSize();
    char * data = seriesText->GetData(size - 1 - index);
    seriesText->UnlockData();
    return data;
}
示例#9
0
int DoCommDlg(int iWhichOper) 
/* returns whether file was retrieved */
/* iWhichOper is the imi* code from the menu */
{
    int iRetval;

    bSave =  iWhichOper == imiSaveAs;

    iRetval = !InitCommDlg(iWhichOper);

    if (!iRetval)
        goto end;

    LockData(0);
    switch(iWhichOper)
    {
        case imiOpen:
            iRetval = GetOpenFileName((LPOPENFILENAME)&OFN);
        break;
        case imiSaveAs:
            iRetval = GetSaveFileName((LPOPENFILENAME)&OFN);
        break;
    }
    UnlockData(0);

    if (CommDlgExtendedError())
    {
        iRetval = FALSE;
        Error(IDPMTNoMemory);
    }

    end:

    if (iRetval)
    {
        lstrcpy(szLastDir,szFileName);
        szLastDir[OFN.nFileOffset] = 0;
        OFN.lpstrInitialDir = szLastDir;
    }

    switch(iWhichOper)
    {
        case imiOpen:
        case imiSaveAs:
            if (lpfnOFNHook)
                FreeProcInstance(lpfnOFNHook);
            lpfnOFNHook = NULL;
        break;
    }

    return iRetval;
}
void
CPulseGenerator::ForceStopOfPeriodicPulses( void )
{   GUCEF_TRACE;

    LockData();
    m_forcedStopOfPeriodPulses = true;
    if ( NULL != m_driver )
    {
        UnlockData();
        m_driver->RequestStopOfPeriodicUpdates( *this );
        return;
    }
    UnlockData();
}
void
CPulseGenerator::RequestPeriodicPulses( void* requestor )
{   GUCEF_TRACE;

    LockData();
    m_periodicUpdateRequestors[ requestor ] = m_updateDeltaInMilliSecs;
    if ( m_driver != NULL && m_periodicUpdateRequestors.size() == 1 )
    {
        UnlockData();
        m_driver->RequestPeriodicPulses( *this, m_updateDeltaInMilliSecs );
        return;
    }
    UnlockData();
}
void
CLogSvcClient::SendAllQueuedItems( void )
{GUCEF_TRACE;

    LockData();
    
    // We will copy the queue because the actual sending of the log
    // messages can cause more items to be queued
    TLogMsgStack logQueueCopy = m_logQueue;

    UnlockData();

    // Go through queue and send all items
    TLogMsgStack::reverse_iterator i = logQueueCopy.rbegin();
    while ( i != logQueueCopy.rend() )
    {
        TLogMessage& logMessage = (*i);

        // Send the logging msg header
        if ( m_tcpClient.Send( logMessage.msgHeader, 15 ) )
        {
            // Now send the logging text
            m_tcpClient.Send( logMessage.logMsg.C_String() ,
                              logMessage.logMsg.Length()   );
        }
        ++i;
    }

    LockData();

    // Clear the queue.
    // Any log messages that where added while sending will be dropped
    m_logQueue.clear();

    UnlockData();
}
void
CPulseGenerator::OnDriverPulse( void )
{   GUCEF_TRACE;

    LockData();
    UInt64 tickCount = MT::PrecisionTickCount();
    UInt64 deltaTicks = tickCount - m_lastCycleTickCount;
    Float64 deltaMilliSecs = deltaTicks / m_timerFreq;
    m_lastCycleTickCount = tickCount;
    UnlockData();

    CPulseData pulseData( tickCount, deltaTicks, deltaMilliSecs );
    NotifyObservers( PulseEvent, &pulseData );

}
示例#14
0
void
CObservingNotifier::SubscribeToImp( CNotifier* notifier                 ,
                                    const CEvent& eventid               ,
                                    CIEventHandlerFunctorBase* callback )
{GUCEF_TRACE;

    if ( NULL != notifier )
    {
        LockData();
        notifier->Subscribe( &m_observer ,
                             eventid     ,
                             callback    );
        UnlockData();
    }
}
void
CPulseGenerator::RequestPeriodicPulses( void )
{   GUCEF_TRACE;

    LockData();
    if ( !m_forcedStopOfPeriodPulses )
    {
        if ( NULL != m_driver )
        {
            UnlockData();
            m_driver->RequestPeriodicPulses( *this, m_updateDeltaInMilliSecs );
            return;
        }
    }
    UnlockData();
}
void
CPulseGenerator::RequestPulseInterval( const UInt32 minimalPulseDeltaInMilliSecs )
{   GUCEF_TRACE;

    LockData();
    if ( minimalPulseDeltaInMilliSecs < m_updateDeltaInMilliSecs )
    {
        if ( NULL != m_driver )
        {
            m_updateDeltaInMilliSecs = minimalPulseDeltaInMilliSecs;
            UnlockData();
            m_driver->RequestPulseInterval( *this, m_updateDeltaInMilliSecs );
            return;
        }
    }
    UnlockData();
}
void
CPulseGenerator::SetPulseGeneratorDriver( CIPulseGeneratorDriver* driver )
{   GUCEF_TRACE;

    LockData();
    m_driver = driver;
    if ( IsPulsingPeriodicly() )
    {
        UnlockData();
        m_driver->RequestPulseInterval( *this, m_updateDeltaInMilliSecs );
    }
    else
    {
        UnlockData();
        m_driver->RequestPulse( *this );
    }
}
void
CPulseGenerator::AllowPeriodicPulses( void )
{   GUCEF_TRACE;

    LockData();
    if ( m_forcedStopOfPeriodPulses )
    {
        m_forcedStopOfPeriodPulses = false;
        if ( NULL != m_driver && m_periodicUpdateRequestors.size() > 0 )
        {
            UnlockData();
            m_driver->RequestPeriodicPulses( *this, m_updateDeltaInMilliSecs );
            return;
        }
    }
    UnlockData();
}
示例#19
0
COLORREF CGetColor::GetPixel(int nXPos, int nYPos)
{
	COLORREF cr = {0};
	RECT rcScreen;
	rcScreen.left = nXPos;
	rcScreen.top = nYPos;
	rcScreen.right = nXPos + 1;
	rcScreen.bottom = nYPos + 1;
	if(CopyScreenToData(&rcScreen))
	{
		BYTE* pData;
		DWORD dwLen;
		GetDataSource(&pData, &dwLen);
		DWORD dwBitCount = GetBitCount();
		DWORD dwPaletteSize = 0;
		if (dwBitCount <= 8) 
			dwPaletteSize = (1 <<  dwBitCount) *  sizeof(RGBQUAD);
		BITMAPFILEHEADER bmpFileHred;
		BITMAPINFOHEADER bi;
		memcpy(&bmpFileHred, pData, sizeof(BITMAPFILEHEADER));
		memcpy(&bi, pData + sizeof(BITMAPFILEHEADER), sizeof(BITMAPINFOHEADER));
		
		if(dwBitCount == 8)
		{
			DWORD DataSizePerLine = ((bi.biWidth * dwBitCount + 31) / 32) * 4;
			BYTE* pColor = pData +  sizeof(BITMAPFILEHEADER) +  sizeof(BITMAPINFOHEADER) + dwPaletteSize + DataSizePerLine * ( bi.biHeight - 1) + 0;
			BYTE bColor; memcpy(&bColor, pColor, sizeof(BYTE));
			int nColor = (int)bColor;
			RGBQUAD rgb;
			memcpy(&rgb, pData +  sizeof(BITMAPFILEHEADER) +  sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD)*nColor) , sizeof(RGBQUAD));
			cr = RGB(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue);
		}
		if(dwBitCount == 24)
		{
			DWORD DataSizePerLine = ((bi.biWidth * dwBitCount + 31) / 32) * 4;
			BYTE* pColor = pData +  sizeof(BITMAPFILEHEADER) +  sizeof(BITMAPINFOHEADER) + 0 + DataSizePerLine * ( bi.biHeight - 1) + 0;
		//	BYTE bColor; memcpy(&bColor, pColor, sizeof(BYTE));
		//	int nColor = (int)bColor;
			RGBQUAD rgb;
			memcpy(&rgb, pColor , sizeof(RGBQUAD));
			cr = RGB(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue);
		}
		LockData(false);
	}
	return cr;
}
void
CPulseGenerator::RequestPeriodicPulses( void* requestor                    ,
                                        const UInt32 pulseDeltaInMilliSecs )
{   GUCEF_TRACE;

    LockData();
    if ( NULL != requestor )
    {
        m_periodicUpdateRequestors[ requestor ] = pulseDeltaInMilliSecs;
    }

    m_updateDeltaInMilliSecs = DetermineRequiredPulseInterval();

    if ( NULL != m_driver )
    {
        UnlockData();
        m_driver->RequestPeriodicPulses( *this, m_updateDeltaInMilliSecs );
        return;
    }
    UnlockData();
}
示例#21
0
/* NOTES:
 *   For Win16, programmers generally use WINAPI WinMain(...) but WINAPI is defined in such a way
 *   that it always makes the function prolog return FAR. Unfortunately, when Watcom C's runtime
 *   calls this function in a memory model that's compact or small, the call is made as if NEAR,
 *   not FAR. To avoid a GPF or crash on return, we must simply declare it PASCAL instead. */
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
	WNDCLASS wnd;
	MSG msg;

	myInstance = hInstance;

#if TARGET_MSDOS == 16 && TARGET_WINDOWS < 31 /* Windows 3.0 or older (any version capable of real-mode) */
    /* our data segment is discardable.
     * in Windows 3.0 real mode that means our data segment can disappear out from under us.
     * unfortunately I don't know how to call the data segment back in.
     * so we have to compensate by locking our data segment in place. */
    LockData();
#endif

	/* FIXME: Windows 3.0 Real Mode: Why are we unable to load our own Application Icon? */
	AppIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPICON));
	if (!AppIcon) MessageBox(NULL,"Unable to load app icon","Oops!",MB_OK);

#ifdef WIN16_NEEDS_MAKEPROCINSTANCE
	WndProc_MPI = MakeProcInstance((FARPROC)WndProc,hInstance);
#endif

	/* NTS: In the Windows 3.1 environment all handles are global. Registering a class window twice won't work.
	 *      It's only under 95 and later (win32 environment) where Windows always sets hPrevInstance to 0
	 *      and window classes are per-application.
	 *
	 *      Windows 3.1 allows you to directly specify the FAR pointer. Windows 3.0 however demands you
	 *      MakeProcInstance it to create a 'thunk' so that Windows can call you (ick). */
	if (!hPrevInstance) {
		wnd.style = CS_HREDRAW|CS_VREDRAW;
#ifdef WIN16_NEEDS_MAKEPROCINSTANCE
		wnd.lpfnWndProc = (WNDPROC)WndProc_MPI;
#else
		wnd.lpfnWndProc = WndProc;
#endif
		wnd.cbClsExtra = 0;
		wnd.cbWndExtra = 0;
		wnd.hInstance = hInstance;
		wnd.hIcon = AppIcon;
		wnd.hCursor = NULL;
		wnd.hbrBackground = NULL;
		wnd.lpszMenuName = NULL;
		wnd.lpszClassName = WndProcClass;

		if (!RegisterClass(&wnd)) {
			MessageBox(NULL,"Unable to register Window class","Oops!",MB_OK);
			return 1;
		}
	}

	HelloMsg();

	hwndMain = CreateWindow(WndProcClass,"Hello!",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,CW_USEDEFAULT,
		300,200,
		NULL,NULL,
		hInstance,NULL);
	if (!hwndMain) {
		MessageBox(NULL,"Unable to create window","Oops!",MB_OK);
		return 1;
	}

	ShowWindow(hwndMain,nCmdShow);
	UpdateWindow(hwndMain); /* FIXME: For some reason this only causes WM_PAINT to print gibberish and cause a GPF. Why? And apparently, Windows 3.0 repaints our window anyway! */

	while (GetMessage(&msg,NULL,0,0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

#if TARGET_MSDOS == 16
    /* Win16 only:
     * If we are the owner (the first instance that registered the window class),
     * then we must reside in memory until we are the last instance resident.
     * If we do not do this, then if multiple instances are open and the user closes US
     * before closing the others, the others will crash (having pulled the code segment
     * behind the window class out from the other processes). */
	if (!hPrevInstance) {
        while (GetModuleUsage(hInstance) > 1) {
            PeekMessage(&msg,NULL,0,0,PM_REMOVE);
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
#endif

	return msg.wParam;
}
示例#22
0
void
CTSGObserver::DoLockData( void ) const
{GUCEF_TRACE;

    LockData();
}
示例#23
0
void * CDECL malloc(size_t size)
{
    SEGHEADER *Seg;         /* segment header pointer */
    WORD    wSeg;           /* segment's selector, must be a stack variable */
    BOOL    NewSeg = FALSE; /* TRUE: a new segment has been allocated */
    void    *Block;         /* obtained block's address */

#if MEMTRACE
    mtr[mtrx].m_func = MTR_MALLOC;
    mtr[mtrx].m_ptr.m_block = NULL;
    mtr[mtrx].m_size = size;
    mtr[mtrx++].m_optimseg = OptimumSeg;
#endif

    if (size == 0) return NULL;

    if (FarStorage == FALSE) {  /* use the local heap */
	HANDLE hMem;

	if ((hMem = LocalAlloc (LMEM_FIXED, size)) != NULL) {
	    return (LPSTR)LocalLock (hMem);
	}
	else return NULL;
    }

    /*-Attempt to suballocate from last used segment */
    if (OptimumSeg) {
	wSeg = HIWORD(OptimumSeg);
#if MEMTRACE
        mtr[mtrx].m_cnt = OptimumSeg->alloc_count;
#endif
	Block = SubAlloc (wSeg, size);
	if (Block != NULL) {
            ++(OptimumSeg->alloc_count);
	    return (char*)Block;     /* quick success ! */
	}
    }

    /*-Scan segment list, attempting to find one where suballocation is
       possible */
    Seg = &SegList;
    for (;;) {
	if (Seg->next == NULL) {
	    /*-initialize a new Segment and chain it on tail */
	    HANDLE      hSeg;
	    DWORD       SegSize;

	    SegSize = max (MINSEGSIZE, HEAPOVH + SEGHEADOFFSET +
				       sizeof(SEGHEADER) + (DWORD)size);
	    hSeg = GlobalAlloc (GMEM_MOVEABLE, SegSize);
	    if (hSeg == NULL) return (char*)NULL;  /* segment allocation
						      failure */
	    SegSize = GlobalSize (hSeg);
	    wSeg = HIWORD(GlobalLock (hSeg));
	    LocalInit (wSeg, 0, SegSize - HEAPOFFSET);
	    GlobalUnlock (hSeg);
	    /* the segment remains locked once, due to LocalInit */

	    SWITCH_DS(wSeg)
	    LockData (0);   /* this ensures the segment's selector will
			       never change */
	    /* note that allocating a GMEM_FIXED segment would have been
	       cleaner but, in Windows 3.0, such segments also end up
	       being page-locked */
	    RESTORE_DS

	    Seg->next = (SEGHEADER*)MAKELONG(SEGHEADOFFSET,wSeg);
	    Seg = Seg->next;
	    Seg->next = NULL;
	    Seg->alloc_count = 0;
	    NewSeg = TRUE;
#if MEMTRACE
    mtr[mtrx].m_func = MTR_MALLOCSEG;
    mtr[mtrx].m_ptr.m_segh = Seg;
    mtr[mtrx].m_cnt = Seg->alloc_count;
    mtr[mtrx].m_size = SegSize;
    mtr[mtrx++].m_optimseg = OptimumSeg;
#endif
	}
	else {
	    Seg = Seg->next;
	    wSeg = HIWORD(Seg);
	}
        
	if (Seg == OptimumSeg) continue;    /* skip this already tried
					       one */
	/*-try to allocate space in that segment */
#if MEMTRACE
        mtr[mtrx].m_cnt = Seg->alloc_count;
#endif
	Block = SubAlloc (wSeg, size);
	if (Block != NULL) ++(Seg->alloc_count);
	if ((Block != NULL) || NewSeg) {
	    OptimumSeg = Seg;   /* next malloc will try this segment
				   first */
	    return (char*)Block;
	}
    }
} /* malloc */