//------------------------------------------------------------------*
HRESULT CControlMgt::DoSimpleCommand(UINT uCmd, UINT uTrials)
{
	HRESULT hr = S_OK;

    if(uTrials == 1)
    {
        UINT uLen = 0;
	    BYTE *pData = NULL;

	    HEAP_ALLOC(pData, uLen);

	    hr = myConnection.TransferData(FALSE, uCmd, &pData, &uLen);

        if (pData)
        {
            HEAP_FREE(pData, uLen);
        }
    }
    else
    {
    	UINT uResult = (UINT)-1;

        for (IEC_UINT uCount = 0; SUCCEEDED(hr) && uResult != 0 && uCount < uTrials; uCount++) 
	    {
		    UINT uLen	= sizeof(IEC_UINT);
		    BYTE *pData = NULL;

		    if (uCount > 0) {
			    SleepEx(100, TRUE);
		    }

		    HEAP_ALLOC(pData, uLen);

		    *(IEC_UINT*)pData = TRANSLATE_SHORT(uCount);

		    hr = myConnection.TransferData(FALSE, uCmd, &pData, &uLen);

		    if (SUCCEEDED(hr) && uLen < sizeof(IEC_UINT)) {
			    hr = E_FAIL;
		    }
		    
		    if (SUCCEEDED(hr)) {
			    uResult = TRANSLATE_SHORT(*(IEC_UINT *)pData);
		    }

		    HEAP_FREE(pData, uLen);
	    }						
	    if (uCount == uTrials) 
        {
		    hr = E_FAIL;
	    }
    }

	return hr;
}
STDMETHODIMP
    CControlMgt::ProjectDownload(/*[in]*/ SAFEARRAY/*(unsigned char)*/ **ppDataDown)
{
    HRESULT hr;
    unsigned char HUGEP *parr;

    // Get a pointer to the elements of the array.
    hr = ::SafeArrayAccessData(*ppDataDown, (void HUGEP**)&parr);
    if(FAILED(hr))
    {
        return hr;
    }

    UINT uLen	= ((*ppDataDown)->rgsabound[0]).cElements;
	BYTE *pData = NULL;

	HEAP_ALLOC(pData, uLen);
    
    memcpy(pData, parr, uLen);

    ::SafeArrayUnaccessData(*ppDataDown);	    

	hr = myConnection.TransferData(FALSE, CMD_SAVE_PROJECT, &pData, &uLen);

    if (pData)
    {
        HEAP_FREE(pData, uLen);
    }

    return hr;
}
Exemple #3
0
BOOL
arrowAdd( SDWORD iBaseX, SDWORD iBaseY, SDWORD iBaseZ,
          SDWORD iHeadX, SDWORD iHeadY, SDWORD iHeadZ, UBYTE iColour )
{
    ARROW	*psArrow;

    if ( !HEAP_ALLOC( g_psArrowHeap, &psArrow) )
    {
        return FALSE;
    }

    /* ivis y,z swapped */
    psArrow->vecBase.x = iBaseX;
    psArrow->vecBase.y = iBaseZ;
    psArrow->vecBase.z = iBaseY;

    psArrow->vecHead.x = iHeadX;
    psArrow->vecHead.y = iHeadZ;
    psArrow->vecHead.z = iHeadY;

    psArrow->iColour   = iColour;

    /* add to list */
    psArrow->psNext = g_psArrowList;
    g_psArrowList   = psArrow;
}
static void GetDNSPrefixes(StringTimeNode **head)
{
	DWORD dwRetVal = 0;

	ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
	ULONG family = AF_UNSPEC;

	PIP_ADAPTER_ADDRESSES pAddresses = NULL;
	ULONG outBufLen = 0;

	PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;

	outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
	pAddresses = (IP_ADAPTER_ADDRESSES *)HEAP_ALLOC(outBufLen);
	if (pAddresses == NULL)
		return;

	// Make an initial call to GetAdaptersAddresses to get the 
	// size needed into the outBufLen variable
	ULONG ret = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
	if (ERROR_BUFFER_OVERFLOW == ret) {
		HEAP_FREE(pAddresses);
		pAddresses = (IP_ADAPTER_ADDRESSES *) HEAP_ALLOC(outBufLen);
	}

	if (pAddresses == NULL)
		return;

	dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);

	if (dwRetVal == NO_ERROR) {
		pCurrAddresses = pAddresses;
		while (pCurrAddresses) {
			WCHAR *dnsSuffix = pCurrAddresses->DnsSuffix;
			if (dnsSuffix && *dnsSuffix) {
				char *dnsSuffix2 = WstrToUtf8(dnsSuffix);
				StringTimeNodeAllocAndInsert(head, dnsSuffix2);
				free(dnsSuffix2);
			}
			pCurrAddresses = pCurrAddresses->Next;
		}
	}
	HEAP_FREE(pAddresses);
	return;
}
STDMETHODIMP
    CControlMgt::ProjectUpload(/*[out]*/ SAFEARRAY/*(unsigned char)*/ **ppDataUp)
{
    HRESULT hr = S_OK;

    UINT uLen	= 0;
	BYTE *pData = NULL;

	HEAP_ALLOC(pData, uLen);

  	hr = myConnection.TransferData(FALSE, CMD_LOAD_PROJECT, &pData, &uLen);

    if (hr!=S_OK)
    {
        if (pData)
        {
            HEAP_FREE(pData, uLen);
        }
        return hr;
    }

    SAFEARRAYBOUND Bound;
    Bound.lLbound = 0;
    Bound.cElements = uLen;

    (*ppDataUp) = ::SafeArrayCreate(VT_UI1, 1, &Bound);
    if (NULL == (*ppDataUp))
    {
        return E_FAIL;    
    }

    long lIndex = 0;
    
    for(lIndex = 0; lIndex<(long)uLen; lIndex++)
    {
        unsigned char ch = pData[lIndex];
        hr = ::SafeArrayPutElement((*ppDataUp), &lIndex, 
                                    (void*)(&ch));
        if (FAILED(hr))
        {
            if (pData)
            {
                HEAP_FREE(pData, uLen);
            }
            return hr;
        }
    }

    if (pData)
    {
        HEAP_FREE(pData, uLen);
    }

    return hr;
}
Exemple #6
0
// create a new group
BOOL grpCreate(DROID_GROUP	**ppsGroup)
{
	if (!HEAP_ALLOC(psGrpHeap, ppsGroup))
	{
		return FALSE;
	}

	(*ppsGroup)->type = GT_NORMAL;
	(*ppsGroup)->refCount = 0;
	(*ppsGroup)->psList = NULL;
	(*ppsGroup)->psCommander = NULL;
	memset(&(*ppsGroup)->sRunData, 0, sizeof(RUN_DATA));

	return TRUE;
}
Exemple #7
0
/*************************************************************************
* 5. Definition of external functions
*************************************************************************/
ADBG_Case_t *ADBG_Case_New(
	const ADBG_Case_SuiteEntry_t *SuiteEntry_p,
	ADBG_SuiteData_t *SuiteData_p
	)
{
	ADBG_Case_t *Case_p;

	Case_p = HEAP_ALLOC(ADBG_Case_t);
	if (Case_p == NULL)
		return NULL;

	memset(Case_p, 0, sizeof(ADBG_Case_t));
	Case_p->SuiteEntry_p = SuiteEntry_p;
	Case_p->SuiteData_p = SuiteData_p;
	return Case_p;
}
STDMETHODIMP
    CControlMgt::SaveFile(/*[in, string]*/ BSTR sName, /*[in]*/ SAFEARRAY/*(unsigned char)*/ **ppData)
{
    HRESULT hr;
    unsigned char HUGEP *parr;
    CString strName = sName;

    // Get a pointer to the elements of the array.
    hr = ::SafeArrayAccessData(*ppData, (void HUGEP**)&parr);
    if(FAILED(hr))
    {
        return hr;
    }

    UINT uLenData	= ((*ppData)->rgsabound[0]).cElements;
    UINT uLenString = strName.GetLength() + 1;
    UINT uLen = uLenData + uLenString;

	BYTE *pData = NULL;

	HEAP_ALLOC(pData, uLen);

    strcpy((char*)pData, strName);
    pData[uLenString-1] = 0;
    
    memcpy(&(pData[uLenString]), parr, uLenData);

    ::SafeArrayUnaccessData(*ppData);	    

	hr = myConnection.TransferData(FALSE, CMD_SAVE_FILE, &pData, &uLen); 

    if (pData)
    {
        HEAP_FREE(pData, uLen);
    }

    return hr;
}
// IpType : 0 : IPV6 and IPV4; 4:IPV4; 6:IPV6
U32 CDeviceMgr_i::GetAdapterInfo(NET_ADAPTER_INFO AdapterList[10],U8& AdapterListCnt, U8 IpType)
{
    U32 ret                             = ERR_OK_I;
    //DWORD dwSize = 0;
    //DWORD dwRetVal = 0;
    int i = 0;

    // Set the flags to pass to GetAdaptersAddresses
    ULONG flags = GAA_FLAG_INCLUDE_PREFIX;

    // default to unspecified address family (both)
    ULONG family = AF_UNSPEC;

    //LPVOID lpMsgBuf = NULL;

    PIP_ADAPTER_ADDRESSES pAddresses = NULL;
    //ULONG outBufLen = 0;

    PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
    PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
    PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL;
    PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL;
    IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
    IP_ADAPTER_PREFIX *pPrefix = NULL;

    if (IpType == 4)
        family = AF_INET;
    else if (IpType == 6)
        family = AF_INET6;
    else
        family = AF_UNSPEC;

    ULONG uListSize                     = sizeof(g_buffer); // max. 10 adpater
    //int nAdapterIndex                   = 0;
    bool bDeleteBuffer                  = FALSE;
    pAddresses = (PIP_ADAPTER_ADDRESSES)g_buffer;

    AdapterListCnt = 0;

    DWORD dwRet = GetAdaptersAddresses(family, flags, NULL, pAddresses, &uListSize);
    if (dwRet == ERROR_NO_DATA) // No adapter information exists for the local computer.
    {
        TRACE_I(_T("** No adapter information exists for the local computer!\n"));
        ret = ERR_NO_ADAPTER_I;
    }
    else if (dwRet == ERROR_BUFFER_OVERFLOW)
    {
        pAddresses = (PIP_ADAPTER_ADDRESSES)HEAP_ALLOC(uListSize);
        bDeleteBuffer      = TRUE;
        dwRet              = GetAdaptersAddresses(family, flags, NULL, pAddresses, &uListSize);
        if(pAddresses == NULL)
            return ERR_NO_MORE_MEMORY_I;
    }
    else if(dwRet == ERROR_INVALID_PARAMETER)
    {
        ret = ERR_INVALID_PARAM_I;
    }
    else
    {
        ret = ERR_WIN32_ERROR_I;
    }

    TCHAR buff[256];
    //DWORD bufflen = 256;

    if (dwRet == ERROR_SUCCESS)
    {
        ret = ERR_OK_I;

        pCurrAddresses = pAddresses;
        U8 ulIdx = 0;
        while (pCurrAddresses)
        {
            if(ulIdx >= 10)
                break;

            NET_ADAPTER_INFO* pAdapterList = (NET_ADAPTER_INFO*)&AdapterList[ulIdx++];
            AdapterListCnt = ulIdx;

            //printf("\tLength of the IP_ADAPTER_ADDRESS struct: %ld\n", pCurrAddresses->Length);
            pAdapterList->IfIndex = pCurrAddresses->IfIndex;
            //printf("\tIfIndex (IPv4 interface): %u\n", pCurrAddresses->IfIndex); // Specifies the index of the interface with which these addresses are associated.

#ifdef HAVE_UNICODE_I
            mbs2wcsz(buff, sizeof(buff),  pCurrAddresses->AdapterName);
            StrCpyN(pAdapterList->szAdapterName,buff, sizeof(pAdapterList->szAdapterName));
#else
            StrCpyN(pAdapterList->szAdapterName, pCurrAddresses->AdapterName, sizeof(pAdapterList->szAdapterName));
#endif
            //printf("\tAdapter name: %s\n", pCurrAddresses->AdapterName);

            pAdapterList->bWirelessCard = IsWirelessCard(pAdapterList->szAdapterName);

#ifdef HAVE_UNICODE_I
            StrCpyN(pAdapterList->szDnsSuffix, pCurrAddresses->DnsSuffix, sizeof(pAdapterList->szDnsSuffix));
#else
            wcs2mbsz(buff, sizeof(buff),  pCurrAddresses->DnsSuffix);
            //printf("\tDNS Suffix: %s\n", buff);
            StrCpyN(pAdapterList->szDnsSuffix, buff, sizeof(pAdapterList->szDnsSuffix));
#endif

#ifdef HAVE_UNICODE_I
            StrCpyN(pAdapterList->szDescription, pCurrAddresses->Description, sizeof(pAdapterList->szDescription));
#else
            wcs2mbsz(buff, sizeof(buff),  pCurrAddresses->Description);
            StrCpyN(pAdapterList->szDescription, buff, sizeof(pAdapterList->szDescription));
#endif
            //_tprintf(_T("\tDescription: %s\n"), pAdapterList->szDescription);

#ifdef HAVE_UNICODE_I
            StrCpyN(pAdapterList->szConnectionName, pCurrAddresses->FriendlyName, sizeof(pAdapterList->szConnectionName));
#else
            wcs2mbsz(buff, sizeof(buff),  pCurrAddresses->FriendlyName);
            StrCpyN(pAdapterList->szConnectionName, buff, sizeof(pAdapterList->szConnectionName));
#endif
            //printf("\tFriendly name: %s\n", buff);

            pUnicast = pCurrAddresses->FirstUnicastAddress;
            if (pUnicast != NULL)
            {
                for (i = 0; pUnicast != NULL; i++)
                {
                    if(i>=0xFF)
                        break;

                    if(FillIpAddr(buff, pUnicast->Address, i, pAdapterList->UnicastAddr) == FALSE)
                        break;
                    //printf("\tIP Address(Unicast Addresses): %s \n", buff);
                    pUnicast = pUnicast->Next;
                }
                pAdapterList->UnicastAddrCnt = (u8)(i&0x0FF);
                //printf("\tNumber of Unicast Addresses: %d\n", i);
            }
            else
            {
                pAdapterList->UnicastAddrCnt = 0;
                //printf("\tNo Unicast Addresses\n");
            }

            pAnycast = pCurrAddresses->FirstAnycastAddress;
            if (pAnycast)
            {
                for (i = 0; pAnycast != NULL; i++)
                {
                    if(i>=0xFF)
                        break;

                    if(FillIpAddr(buff, pAnycast->Address, i, pAdapterList->AnycastAddr) == FALSE)
                        break;
                    //printf("\tIP Address(Anycast Addresses): %s \n", buff);
                    pAnycast = pAnycast->Next;
                }
                //printf("\tNumber of Anycast Addresses: %d\n", i);
                pAdapterList->AnycastAddrCnt = (u8)(i&0x0FF);
            }
            else
            {
                pAdapterList->AnycastAddrCnt  = 0;
                // printf("\tNo Anycast Addresses\n");
            }

            pMulticast = pCurrAddresses->FirstMulticastAddress;
            if (pMulticast)
            {
                for (i = 0; pMulticast != NULL; i++)
                {
                    if(i>=0xFF)
                        break;

                    if(FillIpAddr(buff, pMulticast->Address, i, pAdapterList->MulticastAddr) == FALSE)
                        break;
                    //printf("\tIP Address(Multicast Addresses): %s \n", buff);
                    pMulticast = pMulticast->Next;
                }
                pAdapterList->MulticastAddrCnt = (u8)(i&0x0FF);
                //printf("\tNumber of Multicast Addresses: %d\n", i);
            }
            else
            {
                //printf("\tNo Multicast Addresses\n");
                pAdapterList->MulticastAddrCnt = 0;
            }

            pDnServer = pCurrAddresses->FirstDnsServerAddress;
            if (pDnServer)
            {
                for (i = 0; pDnServer != NULL; i++)
                {
                    if(i>=0xFF)
                        break;

                    if(FillIpAddr(buff, pDnServer->Address, i, pAdapterList->DnsServer) == FALSE)
                        break;
                    //printf("\tIP Address(DNS Server): %s \n", buff);
                    pDnServer = pDnServer->Next;
                }
                pAdapterList->DnsServerCnt = (u8)(i&0x0FF);
                //printf("\tNumber of DNS Server Addresses: %d\n", i);
            }
            else
            {
                //printf("\tNo DNS Server Addresses\n");
                pAdapterList->DnsServerCnt = 0;
            }

            pPrefix = pCurrAddresses->FirstPrefix;
            if (pPrefix)
            {
                for (i = 0; pPrefix != NULL; i++)
                {
                    if(i>=0xFF)
                        break;

                    if(FillIpAddr(buff, pPrefix->Address, i, pAdapterList->PrefixAddr) == FALSE)
                        break;
                    pPrefix = pPrefix->Next;
                }
                pAdapterList->PrefixAddrCnt = (u8)(i&0x0FF);
            }
            else
            {
                pAdapterList->PrefixAddrCnt = 0;
                //printf("\tNo IP Adapter Prefix entries\n");
            }

            pAdapterList->uMacAddressLen = 0;
            pAdapterList->uMacAddress[0] = 0;
            if (pCurrAddresses->PhysicalAddressLength != 0)
            {
                pAdapterList->uMacAddressLen = (u8)(pCurrAddresses->PhysicalAddressLength);
                memcpy(pAdapterList->uMacAddress, pCurrAddresses->PhysicalAddress, pAdapterList->uMacAddressLen);
                FormatMACToStr(pAdapterList->szMacAddr, pCurrAddresses->PhysicalAddress, pCurrAddresses->PhysicalAddressLength);
            }

            /*
            IP_ADAPTER_DDNS_ENABLED(0x01) Dynamic DNS is enabled on this adapter.
            IP_ADAPTER_REGISTER_ADAPTER_SUFFIX (0x02) Register the DNS suffix for this adapter.
            IP_ADAPTER_DHCP_ENABLED (0x04) Dynamic Host Configuration Protocol is enabled on this adapter.
            */
            //printf("\tFlags: %ld\n", pCurrAddresses->Flags);
            pAdapterList->Flags = pCurrAddresses->Flags;
            pAdapterList->bDhcpEnabled = (pCurrAddresses->Flags&IP_ADAPTER_DHCP_ENABLED) ? TRUE:FALSE;
            pAdapterList->bDDNSEnabled = (pCurrAddresses->Flags&IP_ADAPTER_DDNS_ENABLED) ? TRUE:FALSE;
            pAdapterList->Mtu = pCurrAddresses->Mtu;
            //printf("\tMtu: %lu Bytes\n", pCurrAddresses->Mtu); // Specifies the maximum transmission unit (MTU), in bytes.

            /*
            #define MIB_IF_TYPE_OTHER               1
            #define MIB_IF_TYPE_ETHERNET            6
            #define MIB_IF_TYPE_TOKENRING           9
            #define MIB_IF_TYPE_FDDI                15
            #define MIB_IF_TYPE_PPP                 23
            #define MIB_IF_TYPE_LOOPBACK            24
            #define MIB_IF_TYPE_SLIP                28
            */
            pAdapterList->IfType = pCurrAddresses->IfType;
            //printf("\tIfType: %ld\n", pCurrAddresses->IfType);  // Specifies the type of interface using the values defined by the Internet Assigned Numbers Authority (IANA).

            if(pCurrAddresses->IfType == MIB_IF_TYPE_ETHERNET)
            {
                pAdapterList->bEthernetCard  = TRUE;
                pAdapterList->bPhysicalCard = TRUE;
            }
            else
            {
                pAdapterList->bEthernetCard  = FALSE;
                pAdapterList->bPhysicalCard = FALSE;
            }

            /*
            // OperStatus values from RFC 2863
            typedef enum {
            IfOperStatusUp = 1,
            IfOperStatusDown,
            IfOperStatusTesting,
            IfOperStatusUnknown,
            IfOperStatusDormant,
            IfOperStatusNotPresent,
            IfOperStatusLowerLayerDown
            } IF_OPER_STATUS; */

            pAdapterList->OperStatus = pCurrAddresses->OperStatus;
            if(pCurrAddresses->OperStatus==IfOperStatusUp)
            {
                pAdapterList->bConnected = TRUE;
            }
            else if(pCurrAddresses->OperStatus==IfOperStatusDown)
            {
                pAdapterList->bConnected = FALSE;
            }

            //printf("\tOperStatus: %ld\n", pCurrAddresses->OperStatus);
            // Specifies the operational status of the interface

            pAdapterList->Ipv6IfIndex = pCurrAddresses->Ipv6IfIndex;

            //printf("\tIpv6IfIndex (IPv6 interface): %u\n", pCurrAddresses->Ipv6IfIndex);
            //       printf("\tZoneIndices (hex): ");

            //       for (i = 0; i < 16; i++)
            //       {
            //         printf("%lx ", pCurrAddresses->ZoneIndices[i]);
            //       }
            //       printf("\n");

            pCurrAddresses = pCurrAddresses->Next;
        } // while
    }
    else if (dwRet == ERROR_NO_DATA) // No adapter information exists for the local computer.
    {
        TRACE_I(_T("*** No adapter information exists for the local computer!\n"));
        ret = ERR_NO_ADAPTER_I;
    }
    else if (dwRet == ERROR_BUFFER_OVERFLOW)
    {
        ret = ERR_NO_MORE_MEMORY_I;
    }
    else if(dwRet == ERROR_INVALID_PARAMETER)
    {
        ret = ERR_INVALID_PARAM_I;
    }
    else
    {
        ret = ERR_WIN32_ERROR_I;
    }

    if(bDeleteBuffer && pAddresses)
    {
        HEAP_FREE(pAddresses);
    }

    return ret;
}
STDMETHODIMP
    CControlMgt::ProjectInfoUpload(/*[out, string]*/ BSTR* psProjVers,
	                                         /*[out, string]*/ BSTR* psProjName,
	                                         /*[out, string]*/ BSTR* psModified,
	                                         /*[out, string]*/ BSTR* psCreated,
                                             /*[out, string]*/ BSTR* psOwner,
	                                         /*[out, string]*/ BSTR* psComment1,
	                                         /*[out, string]*/ BSTR* psComment2,
	                                         /*[out, string]*/ BSTR* psComment3)
{
    HRESULT hr = S_OK;

    CString strProjVers;
    CString strProjName;
    CString strModified;
    CString strCreated;
    CString strOwner;
    CString strComment1;
    CString strComment2;
    CString strComment3;

    if (psProjVers  == NULL || 
        psProjName  == NULL || 
        psModified  == NULL || 
        psCreated   == NULL || 
        psOwner     == NULL || 
        psComment1  == NULL || 
        psComment2  == NULL || 
        psComment3  == NULL)
    {
        return E_POINTER;
    }

    *psProjVers = NULL;
    *psProjName = NULL; 
    *psModified = NULL; 
    *psCreated  = NULL; 
    *psOwner    = NULL; 
    *psComment1 = NULL; 
    *psComment2 = NULL; 
    *psComment3 = NULL;

    UINT uLen	= 0;
	BYTE *pData = NULL;

	HEAP_ALLOC(pData, uLen);

	hr = myConnection.TransferData(FALSE, CMD_GET_PROJ_INFO, &pData, &uLen);

	if (uLen < sizeof(XProjInfo))
	{
		hr = E_FAIL;
	}

	if (SUCCEEDED(hr))
	{
        try
        {
            XProjInfo* pPI = (XProjInfo*)pData;

            strProjVers = pPI->szProjVers;
            strProjName = pPI->szProjName;
            strModified = pPI->szModified;
            strCreated  = pPI->szCreated;
            strOwner    = pPI->szOwner;
            strComment1 = pPI->szComment1;
            strComment2 = pPI->szComment2;
            strComment3 = pPI->szComment3;

            *psProjVers = strProjVers.AllocSysString();
            *psProjName = strProjName.AllocSysString();
            *psModified = strModified.AllocSysString();
            *psCreated  = strCreated.AllocSysString();
            *psOwner    = strOwner.AllocSysString();
            *psComment1 = strComment1.AllocSysString();
            *psComment2 = strComment2.AllocSysString();
            *psComment3 = strComment3.AllocSysString(); 
        }
        catch (CMemoryException* e)
        {
            e->Delete();
            
            if (*psProjVers)
            {
                SysFreeString(*psProjVers);
            }
            if (*psProjName)
            {
                SysFreeString(*psProjName);
            }
            if (*psModified)
            {
                SysFreeString(*psModified);
            }
            if (*psCreated)
            {
                SysFreeString(*psCreated);
            }
            if (*psOwner)
            {
                SysFreeString(*psOwner);
            }
            if (*psComment1)
            {
                SysFreeString(*psComment1);
            }
            if (*psComment2)
            {
                SysFreeString(*psComment2);
            }
            if (*psComment3)
            {
                SysFreeString(*psComment3);
            }

            hr = E_OUTOFMEMORY;
        }	
    }

	HEAP_FREE(pData, uLen);

    return hr;
}
//=======================================================================
//      interface   ICustOnlCmds
//=======================================================================
//------------------------------------------------------------------*
STDMETHODIMP
    CControlMgt::CustDownUpLoad(/*[in]*/  SAFEARRAY/*(unsigned char)*/ **ppDataDown, 
                                          /*[out]*/ SAFEARRAY/*(unsigned char)*/ **ppDataUp)
{
    HRESULT hr;
    unsigned char HUGEP *parr;

    // Get a pointer to the elements of the array.
    hr = ::SafeArrayAccessData(*ppDataDown, (void HUGEP**)&parr);
    if(FAILED(hr))
    {
        return hr;
    }

    UINT uLen	= ((*ppDataDown)->rgsabound[0]).cElements;
	BYTE *pData = NULL;

	HEAP_ALLOC(pData, uLen);
    
    memcpy(pData, parr, uLen);

    ::SafeArrayUnaccessData(*ppDataDown);	    

	hr = myConnection.TransferData(FALSE, CMD_CUSTOM, &pData, &uLen);

    if (hr!=S_OK)
    {
        if (pData)
        {
            HEAP_FREE(pData, uLen);
        }
        return hr;
    }

    SAFEARRAYBOUND Bound;
    Bound.lLbound = 0;
    Bound.cElements = uLen;

    (*ppDataUp) = ::SafeArrayCreate(VT_UI1, 1, &Bound);
    if (NULL == (*ppDataUp))
    {
        return E_FAIL;    
    }

    long lIndex = 0;
    
    for(lIndex = 0; lIndex<(long)uLen; lIndex++)
    {
        unsigned char ch = pData[lIndex];
        hr = ::SafeArrayPutElement((*ppDataUp), &lIndex, 
                                    (void*)(&ch));
        if (FAILED(hr))
        {
            if (pData)
            {
                HEAP_FREE(pData, uLen);
            }
            return hr;
        }
    }

    if (pData)
    {
        HEAP_FREE(pData, uLen);
    }

    return hr;
}
STDMETHODIMP
    CControlMgt::LoadFile(/*[in, string]*/ BSTR sName, /*[out]*/ SAFEARRAY/*(unsigned char)*/ **ppData)
{
    HRESULT hr;
    
    CString strName = sName;
    
    UINT uLen= strName.GetLength() + 1;

	BYTE *pData = NULL;

	HEAP_ALLOC(pData, uLen);

    strcpy((char*)pData, strName);
    pData[uLen-1] = 0;

	hr = myConnection.TransferData(FALSE, CMD_LOAD_FILE, &pData, &uLen);   

    if (hr!=S_OK)
    {
        if (pData)
        {
            HEAP_FREE(pData, uLen);
        }
        return hr;
    }

    SAFEARRAYBOUND Bound;
    Bound.lLbound = 0;
    Bound.cElements = uLen;

    (*ppData) = ::SafeArrayCreate(VT_UI1, 1, &Bound);
    if (NULL == (*ppData))
    {
        return E_FAIL;    
    }

    long lIndex = 0;
    
    for(lIndex = 0; lIndex<(long)uLen; lIndex++)
    {
        unsigned char ch = pData[lIndex];
        hr = ::SafeArrayPutElement((*ppData), &lIndex, 
                                    (void*)(&ch));
        if (FAILED(hr))
        {
            if (pData)
            {
                HEAP_FREE(pData, uLen);
            }
            return hr;
        }
    }

    if (pData)
    {
        HEAP_FREE(pData, uLen);
    }

    return hr;
}
Exemple #13
0
/* Create a button widget data structure */
BOOL buttonCreate(W_BUTTON **ppsWidget, W_BUTINIT *psInit)
{
	if (psInit->style & ~(WBUT_PLAIN | WIDG_HIDDEN | WFORM_NOCLICKMOVE |
						  WBUT_NOPRIMARY | WBUT_SECONDARY | WBUT_TXTCENTRE ))
	{
		ASSERT((FALSE, "Unknown button style"));
		return FALSE;
	}

//#ifdef DEBUG
//	if (psInit->pText)
//	{
//		ASSERT((PTRVALID(psInit->psFont, sizeof(PROP_FONT)),
//			"buttonCreate: Invalid font pointer"));
//	}
//#endif

	/* Allocate the required memory */
#if W_USE_MALLOC
	*ppsWidget = (W_BUTTON *)MALLOC(sizeof(W_BUTTON));
	if (*ppsWidget == NULL)
#else
	if (!HEAP_ALLOC(psButHeap, ppsWidget))
#endif
	{
		ASSERT((FALSE, "buttonCreate: Out of memory"));
		return FALSE;
	}
	/* Allocate memory for the text and copy it if necessary */
	if (psInit->pText)
	{
#if W_USE_STRHEAP
		if (!widgAllocCopyString(&(*ppsWidget)->pText, psInit->pText))
		{
			ASSERT((FALSE, "buttonCreate: Out of memory"));
#if W_USE_MALLOC
			FREE(*ppsWidget);
#else
			HEAP_FREE(psButHeap, *ppsWidget);
#endif
			return FALSE;
		}
#else
		(*ppsWidget)->pText = psInit->pText;
#endif
	}
	else
	{
		(*ppsWidget)->pText = NULL;
	}
	/* Allocate the memory for the tip and copy it if necessary */
	if (psInit->pTip)
	{
#if W_USE_STRHEAP
		if (!widgAllocCopyString(&(*ppsWidget)->pTip, psInit->pTip))
		{
			/* Out of memory - just carry on without the tip */
			ASSERT((FALSE, "buttonCreate: Out of memory"));
			(*ppsWidget)->pTip = NULL;
		}
#else
		(*ppsWidget)->pTip = psInit->pTip;
#endif
	}
	else
	{
		(*ppsWidget)->pTip = NULL;
	}

	/* Initialise the structure */
	(*ppsWidget)->type = WIDG_BUTTON;
	(*ppsWidget)->id = psInit->id;
	(*ppsWidget)->formID = psInit->formID;
	(*ppsWidget)->style = psInit->style;
	(*ppsWidget)->x = psInit->x;
	(*ppsWidget)->y = psInit->y;
	(*ppsWidget)->width = psInit->width;
	(*ppsWidget)->height = psInit->height;
	(*ppsWidget)->callback = psInit->pCallback;
	(*ppsWidget)->pUserData = psInit->pUserData;
	(*ppsWidget)->UserData = psInit->UserData;
	(*ppsWidget)->AudioCallback = WidgGetAudioCallback();
	(*ppsWidget)->HilightAudioID = WidgGetHilightAudioID();
	(*ppsWidget)->ClickedAudioID = WidgGetClickedAudioID();


	if (psInit->pDisplay)
	{
		(*ppsWidget)->display = psInit->pDisplay;
	}
	else
	{
		(*ppsWidget)->display = buttonDisplay;
	}
//	(*ppsWidget)->psFont = psInit->psFont;
	(*ppsWidget)->FontID = psInit->FontID;

	buttonInitialise(*ppsWidget);

	return TRUE;
}
Exemple #14
0
void* lzowrite_init(const char* filename) {
	//Prepare the buffers
	struct lzowrite_buffer* buffer = malloc(sizeof(struct lzowrite_buffer));
	buffer->output = fopen(filename, "w");
	buffer->length = 0;

	//Allocate workmemory
	HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
	buffer->workmemory = wrkmem;

	//Write LZO fileformat
	unsigned char magic[LZOWRITE_LZO_MAGIC_LEN] = LZOWRITE_LZO_MAGIC;
	fwrite(magic, sizeof(unsigned char), LZOWRITE_LZO_MAGIC_LEN, buffer->output);

	//Init header
	struct lzowrite_file_header* fheader = malloc(sizeof(struct lzowrite_file_header));
	fheader->version = LZOWRITE_LZO_VERSION;
	fheader->library_version = lzo_version();
	fheader->needed_version = LZOWRITE_LZO_VERSION_NEEDED_TO_EXTRACT;
	fheader->compression_method = LZOWRITE_LZO_METHOD;
	fheader->compression_level = LZOWRITE_LZO_COMPRESSION_LEVEL;
	fheader->compression_flags = LZOWRITE_LZO_FLAGS;
	fheader->mode = LZOWRITE_LZO_MODE;
	fheader->file_name_length = 0;
	fheader->file_header_checksum = 1;
	fheader->file_mtime_high = 0;
	fheader->file_mtime_low = 0;

	fwrite(&fheader->version, sizeof(uint16_t), 1, buffer->output);
	fwrite(&fheader->library_version, sizeof(uint16_t), 1, buffer->output);
	fwrite(&fheader->needed_version, sizeof(uint16_t), 1, buffer->output);
	fwrite(&fheader->compression_method, sizeof(uint8_t), 1, buffer->output);
	fwrite(&fheader->compression_level, sizeof(uint8_t), 1, buffer->output);
	fwrite(&fheader->compression_flags, sizeof(uint32_t), 1, buffer->output);
	fwrite(&fheader->mode, sizeof(uint32_t), 1, buffer->output);
	fwrite(&fheader->file_mtime_low, sizeof(uint32_t), 1, buffer->output);
	fwrite(&fheader->file_mtime_high, sizeof(uint32_t), 1, buffer->output);
	fwrite(&fheader->file_name_length, sizeof(uint8_t), 1, buffer->output);

	//Calculate checksum
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->version, 2);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->library_version, 2);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->needed_version, 2);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->compression_method, 1);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->compression_level, 1);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->compression_flags, 4);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->mode, 4);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->file_mtime_low, 4);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->file_mtime_high, 4);
	fheader->file_header_checksum = lzo_adler32(fheader->file_header_checksum, (lzo_bytep)&fheader->file_name_length, 1);


	fwrite(&((uint8_t*)(&fheader->file_header_checksum))[3], sizeof(uint8_t), 1, buffer->output);
	fwrite(&((uint8_t*)(&fheader->file_header_checksum))[2], sizeof(uint8_t), 1, buffer->output);
	fwrite(&((uint8_t*)(&fheader->file_header_checksum))[1], sizeof(uint8_t), 1, buffer->output);
	fwrite(&((uint8_t*)(&fheader->file_header_checksum))[0], sizeof(uint8_t), 1, buffer->output);

	free(fheader);

	return buffer;
}
Exemple #15
0
void Model::loadC3D(XBuffer& buf)
{
	int i,j,size;
	int num_vert_total,version;
	int num,vert_ind,norm_ind,sort_info;
	unsigned color_id,color_shift;
	char skip_char;
	int phi,psi,tetta;
	
	buf > version;
	//std::cout<<"Load C3D. Version:"<<version<<std::endl;
	if(version != C3D_VERSION_1 && version != C3D_VERSION_3)
		ErrH.Abort("Incorrect C3D version", version);

	buf > num_vert > num_norm > num_poly > num_vert_total;

	buf > xmax > ymax > zmax;
	buf > xmin > ymin > zmin;
	buf > x_off > y_off > z_off;
	buf > rmax;
	buf > phi > psi > tetta;
	/*std::cout<<"num_vert:"<<num_vert<<" num_norm:"<<num_norm<<" num_poly:"<<num_poly<<" num_vert_total:"<<num_vert_total<<std::endl;
	std::cout<<"xmax:"<<xmax<<" ymax:"<<ymax<<" zmax:"<<zmax<<std::endl;
	std::cout<<"xmin:"<<xmin<<" ymin:"<<ymin<<" zmin:"<<zmin<<std::endl;
	std::cout<<"x_off:"<<x_off<<" y_off:"<<y_off<<" z_off:"<<z_off<<std::endl;
	std::cout<<"rmax:"<<rmax<<std::endl;
	std::cout<<"phi:"<<phi<<" psi:"<<psi<<" tetta:"<<tetta<<std::endl;*/
	if(version == C3D_VERSION_3)
		buf > volume > rcm > J;
	else
		ErrH.Abort("C3D - old version.You need to update all m3d & a3d");

	size = num_vert*sizeof(Vertex) + num_norm*sizeof(Normal) + num_poly*sizeof(Polygon);


	memory_allocation_method = 1;
	HEAP_BEGIN(size);
	vertices = HEAP_ALLOC(num_vert,Vertex);
	normals = HEAP_ALLOC(num_norm,Normal);
	polygons = HEAP_ALLOC(num_poly,Polygon);

	if(phi == 83 && psi == 83 && tetta == 83){
		float tf;
		for(i = 0;i < num_vert;i++){
			buf > tf > tf > tf;
			buf > vertices[i].x_8 > vertices[i].y_8 > vertices[i].z_8
			    > sort_info;
			}
		}
	else{
		int ti;
		for(i = 0;i < num_vert;i++){
			buf > ti > ti > ti;
			buf > vertices[i].x_8 > vertices[i].y_8 > vertices[i].z_8
			    > sort_info;
			}
		}

	for(i = 0;i < num_norm;i++)
		buf > normals[i].x > normals[i].y > normals[i].z
		    > normals[i].n_power > sort_info;

	for(i = 0;i < num_poly;i++){
		buf > num > sort_info
		    > color_id > color_shift
		    > skip_char > skip_char 
		    > skip_char > skip_char 
		    > polygons[i].middle_x > polygons[i].middle_y > polygons[i].middle_z;
		
		polygons[i].color_id = color_id < COLORS_IDS::MAX_COLORS_IDS ? color_id : COLORS_IDS::BODY;

		if(num != 3)
			ErrH.Abort("Non triangular 3D model");
		for(j = 0;j < 3;j++){
			buf > vert_ind > norm_ind;
			polygons[i].vertices[j] = &vertices[vert_ind];
			polygons[i].normals[j] = &normals[norm_ind];
			}
		}

	//buf.set(3*num_poly*sizeof(VariablePolygon*),XB_CUR);
	buf.set(3*num_poly*4,XB_CUR);

	HEAP_END;
}
Exemple #16
0
/* Create a button widget data structure */
BOOL labelCreate(W_LABEL **ppsWidget, W_LABINIT *psInit)
{
	/* Do some validation on the initialisation struct */
	if (psInit->style & ~(WLAB_PLAIN | WLAB_ALIGNLEFT |
						   WLAB_ALIGNRIGHT | WLAB_ALIGNCENTRE | WIDG_HIDDEN))
	{
		ASSERT((FALSE, "Unknown button style"));
		return FALSE;
	}

//	ASSERT((PTRVALID(psInit->psFont, sizeof(PROP_FONT)),
//		"labelCreate: Invalid font pointer"));

	/* Allocate the required memory */
#if W_USE_MALLOC
	*ppsWidget = (W_LABEL *)MALLOC(sizeof(W_LABEL));
	if (*ppsWidget == NULL)
#else
	if (!HEAP_ALLOC(psLabHeap, ppsWidget))
#endif
	{
		ASSERT((FALSE, "Out of memory"));
		return FALSE;
	}
	/* Allocate the memory for the tip and copy it if necessary */
	if (psInit->pTip)
	{
#if W_USE_STRHEAP
		if (!widgAllocCopyString(&(*ppsWidget)->pTip, psInit->pTip))
		{
			/* Out of memory - just carry on without the tip */
			ASSERT((FALSE, "buttonCreate: Out of memory"));
			(*ppsWidget)->pTip = NULL;
		}
#else
		(*ppsWidget)->pTip = psInit->pTip;
#endif
	}
	else
	{
		(*ppsWidget)->pTip = NULL;
	}

	/* Initialise the structure */
	(*ppsWidget)->type = WIDG_LABEL;
	(*ppsWidget)->id = psInit->id;
	(*ppsWidget)->formID = psInit->formID;
	(*ppsWidget)->style = psInit->style;
	(*ppsWidget)->x = psInit->x;
	(*ppsWidget)->y = psInit->y;
	(*ppsWidget)->width = psInit->width;
	(*ppsWidget)->height = psInit->height;

	if (psInit->pDisplay)
	{
		(*ppsWidget)->display = psInit->pDisplay;
	}
	else
	{
		(*ppsWidget)->display = labelDisplay;
	}
	(*ppsWidget)->callback = psInit->pCallback;
	(*ppsWidget)->pUserData = psInit->pUserData;
	(*ppsWidget)->UserData = psInit->UserData;
//	(*ppsWidget)->psFont = psInit->psFont;
	(*ppsWidget)->FontID = psInit->FontID;

	if (psInit->pText)
	{
		widgCopyString((*ppsWidget)->aText, psInit->pText);
	}
	else
	{
		*(*ppsWidget)->aText = 0;
	}

	return TRUE;
}
Exemple #17
0
void Model::loadC3Dvariable(XBuffer& buf)
{
	int i,j,size;
	int num_vert_total,version;
	int num,vert_ind,norm_ind,sort_info;
	unsigned color_id,color_shift;
	int phi,psi,tetta;

	buf > version;
	if(version != C3D_VERSION_1 && version != C3D_VERSION_3)
		ErrH.Abort("Incorrect C3D version");

	buf > num_vert > num_norm > num_poly > num_vert_total;

	buf > xmax > ymax > zmax;
	buf > xmin > ymin > zmin;
	buf > x_off > y_off > z_off;
	buf > rmax;
	buf > phi > psi > tetta;
	if(version == C3D_VERSION_3)
		buf > volume > rcm > J;
#ifdef _ROAD_
	else
		ErrH.Abort("C3D - old version.You need to update all m3d & a3d");
#endif

#ifdef COMPACT_3D
	size = num_vert*sizeof(Vertex) + num_norm*sizeof(Normal) + num_poly*sizeof(VariablePolygon);
#else
	size = num_vert*sizeof(Vertex) + num_norm*sizeof(Normal) +
		   num_poly*(sizeof(VariablePolygon) + 3*sizeof(VariablePolygon*));
#endif
	size += num_vert_total*(sizeof(Vertex*) + sizeof(Normal*));

	memory_allocation_method = 1;
	HEAP_BEGIN(size);
	vertices = HEAP_ALLOC(num_vert,Vertex);
	normals = HEAP_ALLOC(num_norm,Normal);
	variable_polygons = HEAP_ALLOC(num_poly,VariablePolygon);

	if(phi == 83 && psi == 83 && tetta == 83){
		for(i = 0;i < num_vert;i++){
		#ifdef COMPACT_3D
			float tf;
			buf > tf > tf > tf;
		#else
			buf > vertices[i].x > vertices[i].y > vertices[i].z;
		#endif
			buf > vertices[i].x_8 > vertices[i].y_8 > vertices[i].z_8
			    > sort_info;
			}
		}
	else{
		int ti;
		for(i = 0;i < num_vert;i++){
		#ifdef COMPACT_3D
			buf > ti > ti > ti;
		#else
			buf > ti;
			vertices[i].x = (float)ti;
			buf > ti;
			vertices[i].y = (float)ti;
			buf > ti;
			vertices[i].z = (float)ti;
		#endif
			buf > vertices[i].x_8 > vertices[i].y_8 > vertices[i].z_8
			    > sort_info;
			}
		}

	for(i = 0;i < num_norm;i++)
		buf > normals[i].x > normals[i].y > normals[i].z
		    > normals[i].n_power > sort_info;

	for(i = 0;i < num_poly;i++){
		buf > num > sort_info
		    > color_id > color_shift
		    > variable_polygons[i].flat_normal.x > variable_polygons[i].flat_normal.y
		    > variable_polygons[i].flat_normal.z > variable_polygons[i].flat_normal.n_power
		    > variable_polygons[i].middle_x > variable_polygons[i].middle_y > variable_polygons[i].middle_z;
		    
		variable_polygons[i].color_id = color_id < COLORS_IDS::MAX_COLORS_IDS ? color_id : COLORS_IDS::BODY;

		variable_polygons[i].num_vert = num;
		variable_polygons[i].vertices = HEAP_ALLOC(num,Vertex*);
		variable_polygons[i].normals = HEAP_ALLOC(num,Normal*);
		for(j = 0;j < num;j++){
			buf > vert_ind > norm_ind;
			variable_polygons[i].vertices[j] = &vertices[vert_ind];
			variable_polygons[i].normals[j] = &normals[norm_ind];
			}
		}

#ifndef COMPACT_3D
	int poly_ind;
	for(i = 0;i < 3;i++){
		sorted_variable_polygons[i] = HEAP_ALLOC(num_poly,VariablePolygon*);
		for(j = 0;j < num_poly;j++){
			buf > poly_ind;
			sorted_variable_polygons[i][j] = &variable_polygons[poly_ind];
			}
		}
#else
	//buf.set(3*num_poly*sizeof(VariablePolygon*),XB_CUR);
	buf.set(3*num_poly*4,XB_CUR);
#endif
	HEAP_END;
}
/* Receive
 * ----------------------------------------------------------------------------
 */
ECommError CLogBlock::Receive (BYTE *bypCommand, BYTE **ppData, UINT *upLen)
{
	HEAP_FREE(*ppData, *upLen);

	// Build block frame
	if (m_pDataFrame == NULL)
	{
		m_pDataFrame = (XFrame *)new char [HD_FRAME + m_Para.uBlockLen];
	}

	memset (m_pDataFrame, 0x00, HD_FRAME);

	*upLen	= 0;

	USHORT	uBlock		= 0;
	UINT	uBlockLen	= 0;
	UINT	uDataLen	= 0;
	BOOL	bLast		= FALSE;

	ECommError eError;

	UINT	uProgMax	= m_uMaxRecvProg;
	UINT	uProgCur	= 0;

	while (! bLast)
	{
		PROGRESS(uProgCur,uProgMax);
		
		// Block count starts with 1!
		uBlock++;

		eError = ceError;

		for (UINT i = 0; (i < m_uRepeatOnError && eError != ceOK) || i == 0; i++)
		{
			bLast = FALSE;

			// Send request for response block
			eError = SendInfoBlock (uBlock, BT_REQ);

			if (eError != ceOK)
			{
				// Communication error sending block
				SleepEx (m_uWaitResend, FALSE);
				m_pPhys->Flush();
	
				continue;			
			}

			uBlockLen = m_Para.uBlockLen + HD_FRAME;

			// Receive block
			eError = m_pPhys->Receive((BYTE *)m_pDataFrame, &uBlockLen);

			if (eError != ceOK)
			{
				// Communication error or time out; try again
				SleepEx (m_uWaitResend, FALSE);
				m_pPhys->Flush();

				continue;
			}

			// Check block size
			if (uBlockLen < HD_FRAME)
			{
				// Received block could not be a valid block; try again
				SleepEx (m_uWaitResend, FALSE);
				m_pPhys->Flush();

				TrcPrint(TRC_ERROR, _T("[CLogBlock][Receive] Invalid block length.\n"));

				eError = ceError;
				continue;
			}

			// Convert Big -> Little Endian
			TtoH(m_pDataFrame);

            if (HD_FRAME + m_pDataFrame->BLK.uLen != uBlockLen)
            {
		        TrcPrint(TRC_ERROR, _T("[CLogBlock][Receive] CRC frame data length check failed.\n"));
				PROGRESS_LAST(uProgMax);
		        return ceCRC;
            }

			// Check CRC
			if (CheckCRC (m_pDataFrame) != ceOK)
			{
				TRACE (_T("CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_CRC_\n"));
				TrcPrint(TRC_ERROR, _T("[CLogBlock][Receive] CRC check failed.\n"));

				// Wrong checksum; send NACK and try again
				SleepEx (m_uWaitResend, FALSE);
				m_pPhys->Flush();

				eError = ceCRC;
				continue;
			}

			// Check block type
			if (m_pDataFrame->byType != BT_DATA)
			{
				// Received block could not be a valid block; try again
				SleepEx (m_uWaitResend, FALSE);
				m_pPhys->Flush();

				TrcPrint(TRC_ERROR, _T("[CLogBlock][Receive] Invalid block type (data expected).\n"));

				eError = ceError;
				continue;
			}

			bLast = m_pDataFrame->BLK.byLast;

			// Check block number
			if (m_pDataFrame->BLK.uBlock != uBlock)
			{
				// Received block number does not match
				SleepEx (m_uWaitResend, FALSE);
				m_pPhys->Flush();

				TrcPrint(TRC_ERROR, _T("[CLogBlock][Receive] Invalid block number.\n"));

				eError = ceError;
				continue;
			}

			*bypCommand = m_pDataFrame->BLK.CMD.byCommand;
			uDataLen	= m_pDataFrame->BLK.uLen;

			// Create Command Buffer
			if (uBlock == 1)
			{
				HEAP_ALLOC(*ppData, uDataLen);
			}
			else
			{
				HEAP_RE_ALLOC(*ppData, *upLen + uDataLen);
			}

			if (*ppData == NULL)
			{
				TrcPrint(TRC_ERROR, _T("[CLogBlock][Receive] Alloc Memory.\n"));

				eError = ceError;
				continue;
			}

			// Copy data
			memcpy(*ppData + *upLen, m_pDataFrame->BLK.CMD.pData, uDataLen);
			*upLen += uDataLen;

			if (m_pDataFrame->BLK.CMD.byCommand > 0x80u)
			{
				// Error Message from VMM
				TRACE(_T("<<<  %-8s %3d %4d  \n"), _T("FAILED"), uBlock, m_pDataFrame->BLK.uLen);
				TrcPrint(TRC_INTERFACE, _T("<<<  %-8s %3d %4d  \n"), _T("FAILED"), uBlock, m_pDataFrame->BLK.uLen);

				PROGRESS_LAST(uProgMax);

				return ceOK;
			}
			else
			{
				TRACE(_T("<<<  %-8s %3d %3d  \n"), m_pDataFrame->BLK.CMD.byCommand <= LAST_CMD_VALUE ? szCommandText[m_pDataFrame->BLK.CMD.byCommand] : _T("Invalid"), uBlock, m_pDataFrame->BLK.uLen);
				TrcPrint(TRC_INTERFACE, _T("<<<  %-8s %3d %4d  \n"), m_pDataFrame->BLK.CMD.byCommand <= LAST_CMD_VALUE ? szCommandText[m_pDataFrame->BLK.CMD.byCommand] : _T("Invalid"), uBlock, m_pDataFrame->BLK.uLen);
			}

		} // end for 

		if (eError != ceOK)
		{
			HEAP_FREE(*ppData, *upLen);

			PROGRESS_LAST(uProgMax);
			return eError;
		}

		if (++uProgCur == uProgMax)
		{
			uProgMax += uProgMax;
		}
		
	} // end while

	PROGRESS_LAST(uProgMax);
	
	return ceOK;
}
Exemple #19
0
/* Create a barGraph widget data structure */
BOOL barGraphCreate(W_BARGRAPH **ppsWidget, W_BARINIT *psInit)
{
	if (psInit->style & ~(WBAR_PLAIN | WBAR_TROUGH | WBAR_DOUBLE | WIDG_HIDDEN))
	{
		ASSERT((FALSE, "Unknown bar graph style"));
		return FALSE;
	}

	if (psInit->orientation < WBAR_LEFT || psInit->orientation > WBAR_BOTTOM)
	{
		ASSERT((FALSE, "barGraphCreate: Unknown orientation"));
		return FALSE;
	}

	if (psInit->size > WBAR_SCALE)
	{
		ASSERT((FALSE, "barGraphCreate: Bar size out of range"));
		return FALSE;
	}
	if ((psInit->style & WBAR_DOUBLE) && (psInit->minorSize > WBAR_SCALE))
	{
		ASSERT((FALSE, "barGraphCreate: Minor bar size out of range"));
		return FALSE;
	}

	/* Allocate the required memory */
#if W_USE_MALLOC
	*ppsWidget = (W_BARGRAPH *)MALLOC(sizeof(W_BARGRAPH));
	if (*ppsWidget == NULL)
#else
	if (!HEAP_ALLOC(psBarHeap, ppsWidget))
#endif
	{
		ASSERT((FALSE, "barGraphCreate: Out of memory"));
		return FALSE;
	}
	/* Allocate the memory for the tip and copy it if necessary */
	if (psInit->pTip)
	{
#if W_USE_STRHEAP
		if (!widgAllocCopyString(&(*ppsWidget)->pTip, psInit->pTip))
		{
			/* Out of memory - just carry on without the tip */
			ASSERT((FALSE, "barGraphCreate: Out of memory"));
			(*ppsWidget)->pTip = NULL;
		}
#else
		(*ppsWidget)->pTip = psInit->pTip;
#endif
	}
	else
	{
		(*ppsWidget)->pTip = NULL;
	}

	/* Initialise the structure */
	(*ppsWidget)->type = WIDG_BARGRAPH;
	(*ppsWidget)->id = psInit->id;
	(*ppsWidget)->formID = psInit->formID;
	(*ppsWidget)->style = psInit->style;
	(*ppsWidget)->x = psInit->x;
	(*ppsWidget)->y = psInit->y;
	(*ppsWidget)->width = psInit->width;
	(*ppsWidget)->height = psInit->height;
	(*ppsWidget)->callback = psInit->pCallback;
	(*ppsWidget)->pUserData = psInit->pUserData;
	(*ppsWidget)->UserData = psInit->UserData;
	(*ppsWidget)->barPos = psInit->orientation;
	(*ppsWidget)->majorSize = psInit->size;
	(*ppsWidget)->minorSize = psInit->minorSize;
	(*ppsWidget)->iRange = psInit->iRange;

	/* Set the display function */
	if (psInit->pDisplay)
	{
		(*ppsWidget)->display = psInit->pDisplay;
	}
	else if (psInit->style & WBAR_TROUGH)
	{
		(*ppsWidget)->display = barGraphDisplayTrough;
	}
	else if (psInit->style & WBAR_DOUBLE)
	{
		(*ppsWidget)->display = barGraphDisplayDouble;
	}
	else
	{
		(*ppsWidget)->display = barGraphDisplay;
	}
	/* Set the major colour */
//	(*ppsWidget)->majorCol = screenGetCacheColour(psInit->sCol.red,
//											psInit->sCol.green, psInit->sCol.blue);
	(*ppsWidget)->majorCol = (UBYTE)pal_GetNearestColour(psInit->sCol.red,
															psInit->sCol.green, psInit->sCol.blue);

	/* Set the minor colour if necessary */
	if (psInit->style & WBAR_DOUBLE)
	{
//		(*ppsWidget)->minorCol = screenGetCacheColour(psInit->sMinorCol.red,
//												psInit->sMinorCol.green, psInit->sMinorCol.blue);
		(*ppsWidget)->majorCol = (UBYTE)pal_GetNearestColour(psInit->sMinorCol.red,
												psInit->sMinorCol.green, psInit->sMinorCol.blue);
	}

	barGraphInitialise(*ppsWidget);

	return TRUE;
}