Exemple #1
0
TApiStatus AddIPv4ToFilter(TFilterData* filter,
    TIPAddressType addr_type, char* ip_addr, int mask)
{
    // Convert IPv4 string address to struct
    if(strlen(ip_addr) >= INET_ADDRSTRLEN)
    {
       PrintErrorMessage("AddIPv4ToFilter", "IP address is too long");
       return API_ERROR;
    }

    // Check mask
    if(mask < 0 || mask > 32)
    {
       PrintErrorMessage("AddIPv4ToFilter", "Mask is out of {0,1,...,32}");
       return API_ERROR;
    }

    // Save to data structure
    switch(addr_type)
    {
        case SRC:
            filter->src_ip = ip_addr;
            filter->src_mask = mask;
           break;
        case DST:
            filter->dst_ip = ip_addr;
            filter->dst_mask = mask;
            break;
        default:
            PrintErrorMessage("AddIPv4ToFilter", "Wrong address type");
            return API_ERROR;
    }

    return API_OK;
}
bool LuaManager::ProtectedCall(int narg, int nresults)
{
	try
	{
		Call(narg, nresults);
	}
	catch (luabind::error e)
	{
		m_bSuccess = false;
		if (lua->IsString())
		{
			PrintErrorMessage(lua->GetString(), true, true);
			lua->Pop();
		}
		else
			PrintErrorMessage("LuaManager::ProtectedCall failed - luabind::error thrown, but not error message in stack!", true, false);
	}
	catch (...)
	{
		PrintErrorMessage("LuaManager::ProtectedCall failed - Unhandled Exception", true, true);
		m_bSuccess = false;
	}

	return m_bSuccess;
}
Exemple #3
0
TApiStatus AddPortToFilter(TFilterData* filter,
    TIPAddressType addr_type, int port)
{
    // Check port
    if(port < 0 || port > 65535)
    {
       PrintErrorMessage("AddPortToFilter", "Port is out of {0,1,...,65535}");
       return API_ERROR;
    }

    // Save to data structure
    switch(addr_type)
    {
        case SRC:
           filter->src_port = port;
           break;
        case DST:
           filter->dst_port = port;
           break;
        default:
            PrintErrorMessage("AddPortToFilter", "Wrong port type");
            return API_ERROR;
    }

    return API_OK;
}
Exemple #4
0
TApiStatus SetInterfaceOnNetworkElement(TNetworkElement* element,
    char* interface)
{
    onep_status_t rc;

    // Discover active interfaces if needed
    if(element->interfaces == NULL)
    {
        TApiStatus s = GetInterfacesOnNetworkElement(element);
        if(s != API_OK)
        {
            PrintErrorMessage("SetInterfaceOnNetworkElement", "get interfaces");
            return API_ERROR;
        }
    }

    // Set interface
    TInterfaceItem* intf_item = (TInterfaceItem*)(malloc(sizeof(TInterfaceItem)));
    rc = onep_element_get_interface_by_name(element->ne, interface, &(intf_item->interface));
    if (rc != ONEP_OK) {
        PrintErrorMessage("SetInterfaceOnNetworkElement", onep_strerror(rc));
        return API_ERROR;
    }

    // Add it to list
    intf_item->next = element->interface_list;
    element->interface_list = intf_item;

    return API_OK;
}
Exemple #5
0
/* ===================================================================*/
LDD_TError ADCSendCommand(byte* cmd, uint8 len)
{
    LDD_TError err;
    
    /* Check the command. */
    err = CheckCommand(*cmd, len);
    if(err != ERR_OK)
    {
        PrintErrorMessage(err);
        return err;
    }
    
    /* Prepare the buffer of command transmitted to ADC. */
    err = SPI1Send(cmd, len);
    if(err != ERR_OK)
    {
        PrintErrorMessage(err);         /* If error occurred, print the error message, */
        return err;                     /* then return error type. */
    }
    
    /* Enable the SPI transmission interrupt to transmit. */
    SPI1EnableTxInterrupt();
    
    return err;
}
void Preprocessor::ParsePragma( LexemList& args )
{
    args.pop_front();
    if( args.empty() )
    {
        PrintErrorMessage( "Pragmas need arguments." );
        return;
    }
    std::string p_name = args.begin()->Value;
    args.pop_front();
    std::string p_args;
    if( !args.empty() )
    {
        if( args.begin()->Type != Lexem::STRING )
            PrintErrorMessage( "Pragma parameter should be a string literal." );
        p_args = RemoveQuotes( args.begin()->Value );
        args.pop_front();
    }
    if( !args.empty() )
        PrintErrorMessage( "Too many parameters to pragma." );

    Pragmas.push_back( p_name );
    Pragmas.push_back( p_args );

    Pragma::Instance pi;
    pi.Text = p_args;
    pi.CurrentFile = CurrentFile;
    pi.CurrentFileLine = LinesThisFile;
    pi.RootFile = RootFile;
    pi.GlobalLine = CurrentLine;
    if( CurPragmaCallback )
        CurPragmaCallback->CallPragma( p_name, pi );
}
Exemple #7
0
Fichier : ts.c Projet : rolk/ug
INT NPTSolverExecute (NP_BASE *theNP, INT argc , char **argv)
{
  NP_T_SOLVER *np;
  INT result,level;

  np = (NP_T_SOLVER *) theNP;
  level = CURRENTLEVEL(theNP->mg);

  if (np->y == NULL) {
    PrintErrorMessage('E',"NPTSolverExecute","no vector y");
    return (1);
  }
  if (np->tass == NULL) {
    PrintErrorMessage('E',"NPTSolverExecute","no assemble num proc");
    return (1);
  }
  if (np->nlsolve == NULL) {
    PrintErrorMessage('E',"NPTSolverExecute","no solver num proc");
    return (1);
  }

  if (ReadArgvOption("i",argc,argv)) {
    if (*np->TimePreProcess != NULL)
      if ((*np->TimePreProcess)(np,level,&result)) {
        UserWriteF("NPTSolverExecute: TimePreProcess failed, error code %d\n",
                   result);
        return (1);
      }
  }

  if (ReadArgvOption("0",argc,argv)) {
    if (*np->TimeInit != NULL)
      if ((*np->TimeInit)(np,level,&result)) {
        UserWriteF("NPTSolverExecute: TimeInit failed, error code %d\n",
                   result);
        return (1);
      }
  }

  if (ReadArgvOption("s",argc,argv)) {
    if (*np->TimeStep != NULL)
      if ((*np->TimeStep)(np,level,&result)) {
        UserWriteF("NPTSolverExecute: TimeStep failed, error code %d\n",
                   result);
        return (1);
      }
  }

  if (ReadArgvOption("p",argc,argv)) {
    if (*np->TimePostProcess != NULL)
      if ((*np->TimePostProcess)(np,level,&result)) {
        UserWriteF("NPTSolverExecute: TimePostProcess failed, error code %d\n",
                   result);
        return (1);
      }
  }

  return(0);
}
Exemple #8
0
BOOL OpenAndMergeVHD(PCWSTR pszVhdPath)
{
    BOOL bRet = FALSE;
    DWORD ret;
    HANDLE hVhd;
    MERGE_VIRTUAL_DISK_PARAMETERS mparms;
    OPEN_VIRTUAL_DISK_PARAMETERS oparms;
    MERGE_VIRTUAL_DISK_FLAG flags = MERGE_VIRTUAL_DISK_FLAG_NONE;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"OpenAndMergeVHD %s\n", pszVhdPath);

    oparms.Version = OPEN_VIRTUAL_DISK_VERSION_1;
    oparms.Version1.RWDepth = 2;

    ret = OpenVirtualDisk(&vst, pszVhdPath,
        VIRTUAL_DISK_ACCESS_METAOPS | VIRTUAL_DISK_ACCESS_GET_INFO,
        OPEN_VIRTUAL_DISK_FLAG_NONE, &oparms, &hVhd);

    if (ERROR_SUCCESS == ret) 
    {
        printf("success opening vdisk...\n");

        mparms.Version = MERGE_VIRTUAL_DISK_VERSION_1;
        mparms.Version1.MergeDepth = oparms.Version1.RWDepth - 1; //MERGE_VIRTUAL_DISK_DEFAULT_MERGE_DEPTH;

        ret = MergeVirtualDisk(hVhd, flags, &mparms, NULL);

        if (ERROR_SUCCESS == ret) 
        {
            printf("success merging vdisk...\n");
            bRet = TRUE;
        }
        else 
        {
            printf("failed to expand vdisk... %d\n", ret);
            PrintErrorMessage(GetLastError());
            bRet = FALSE;
        }
    } 
    else
    {
        printf("failed to open vdisk...err %d\n", ret);
        PrintErrorMessage(GetLastError());
        bRet = FALSE;
    }

    if (INVALID_HANDLE_VALUE != hVhd)
    {
        CloseHandle(hVhd);
    }

    return bRet;
}
Exemple #9
0
GLboolean FWindow::Linux_Initialize()
{
	Attributes = new GLint[12]{GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, DepthBits, GLX_STENCIL_SIZE, StencilBits,
	   GLX_RED_SIZE, ColourBits, GLX_GREEN_SIZE, ColourBits, GLX_BLUE_SIZE, ColourBits, None};

	Decorators = 1;
	CurrentWindowStyle |= LINUX_DECORATOR_CLOSE | LINUX_DECORATOR_MAXIMIZE | LINUX_DECORATOR_MINIMIZE | LINUX_DECORATOR_MOVE;

	if (!WindowManager::GetDisplay())
	{
		PrintErrorMessage(ERROR_LINUX_CANNOTCONNECTXSERVER);
		exit(0);
	}

	VisualInfo = glXGetVisualFromFBConfig(WindowManager::GetDisplay(), GetBestFrameBufferConfig()); 

	//VisualInfo = glXChooseVisual(WindowManager::GetDisplay(), 0, Attributes);

	if (!VisualInfo)
	{
		PrintErrorMessage(ERROR_LINUX_INVALIDVISUALINFO);
		exit(0);
	}

	SetAttributes.colormap = XCreateColormap(WindowManager::GetDisplay(),
		DefaultRootWindow(WindowManager::GetDisplay()),
		VisualInfo->visual, AllocNone);

	SetAttributes.event_mask = ExposureMask | KeyPressMask 
	   	| KeyReleaseMask | MotionNotify | ButtonPressMask | ButtonReleaseMask
	   	| FocusIn | FocusOut | Button1MotionMask | Button2MotionMask | Button3MotionMask | 
		Button4MotionMask | Button5MotionMask | PointerMotionMask | FocusChangeMask
		| VisibilityChangeMask | PropertyChangeMask | SubstructureNotifyMask;

	WindowHandle = XCreateWindow(WindowManager::GetInstance()->m_Display,
		XDefaultRootWindow(WindowManager::GetInstance()->m_Display), 0, 0,
		Resolution[0], Resolution[1],
		0, VisualInfo->depth, InputOutput,
		VisualInfo->visual, CWColormap | CWEventMask,
		&SetAttributes);

	if(!WindowHandle)
	{
		PrintErrorMessage(ERROR_LINUX_CANNOTCREATEWINDOW);
		exit(0);
	}

	XMapWindow(WindowManager::GetDisplay(), WindowHandle);
	XStoreName(WindowManager::GetDisplay(), WindowHandle,
		Name);

	InitializeAtomics();

	XSetWMProtocols(WindowManager::GetDisplay(), WindowHandle, &AtomClose, GL_TRUE);	

	return Linux_InitializeGL();
}
Exemple #10
0
BOOL OpenAndGetPhysVHD(PCWSTR pszVhdPath, PWSTR pszPhysicalDiskPath)
{    
    BOOL bRet = FALSE;
    HANDLE hVhd = INVALID_HANDLE_VALUE;
    DWORD ret;
    OPEN_VIRTUAL_DISK_PARAMETERS oparams;
    ATTACH_VIRTUAL_DISK_PARAMETERS iparams;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"OpenAndGetPhysVHD %s\n", pszVhdPath);

    oparams.Version = OPEN_VIRTUAL_DISK_VERSION_1;
    oparams.Version1.RWDepth = OPEN_VIRTUAL_DISK_RW_DEPTH_DEFAULT;

    iparams.Version = ATTACH_VIRTUAL_DISK_VERSION_1;

    ret = OpenVirtualDisk(&vst, pszVhdPath,
        VIRTUAL_DISK_ACCESS_ATTACH_RW | VIRTUAL_DISK_ACCESS_GET_INFO | VIRTUAL_DISK_ACCESS_DETACH,
        OPEN_VIRTUAL_DISK_FLAG_NONE, &oparams, &hVhd);

    if (ERROR_SUCCESS == ret) 
    {
        ULONG sizePhysicalDisk;
        printf("success opening vdisk...\n");
        memset(pszPhysicalDiskPath, 0, sizeof (wchar_t) * PHYS_PATH_LEN);
        sizePhysicalDisk = (PHYS_PATH_LEN * sizeof(wchar_t)) * 256;
        ret = GetVirtualDiskPhysicalPath(hVhd, &sizePhysicalDisk, pszPhysicalDiskPath);
        if (ERROR_SUCCESS == ret)
        {
            wprintf(L"success getting physical path %s vhdname\n", pszPhysicalDiskPath);
            bRet = TRUE;
        }
        else
        {
            printf("failed to get vhd physical info %d\n", ret);
            PrintErrorMessage(GetLastError());
        }
    } 
    else 
    {
        printf("failed to open vdisk...err 0x%x\n", ret);
        PrintErrorMessage(GetLastError());
    }

    if (INVALID_HANDLE_VALUE != hVhd) 
    {
        CloseHandle(hVhd);
    }

    return bRet;
}
Exemple #11
0
BOOL OpenAndAttachVHD(PCWSTR pszVhdPath)
{
    BOOL bRet = FALSE;
    HANDLE hVhd = INVALID_HANDLE_VALUE;
    DWORD ret;
    OPEN_VIRTUAL_DISK_PARAMETERS oparams;
    ATTACH_VIRTUAL_DISK_PARAMETERS iparams;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"OpenAndAttachVHD %s\n", pszVhdPath);

    oparams.Version = OPEN_VIRTUAL_DISK_VERSION_1;
    oparams.Version1.RWDepth = OPEN_VIRTUAL_DISK_RW_DEPTH_DEFAULT;

    iparams.Version = ATTACH_VIRTUAL_DISK_VERSION_1;

    ret = OpenVirtualDisk(&vst, pszVhdPath,
        VIRTUAL_DISK_ACCESS_ATTACH_RW | VIRTUAL_DISK_ACCESS_GET_INFO | VIRTUAL_DISK_ACCESS_DETACH,
        OPEN_VIRTUAL_DISK_FLAG_NONE, &oparams, &hVhd);

    if (ERROR_SUCCESS == ret) 
    {
        printf("success opening vdisk...\n");
        ret = AttachVirtualDisk(hVhd, NULL, 
            ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME, 0, &iparams, NULL);

        if (ERROR_SUCCESS == ret) 
        {
            printf("success attaching vdisk...\n");
        }
        else
        {
            printf("failed to attach vdisk...err 0x%x\n", ret);
            PrintErrorMessage(GetLastError());
            bRet = FALSE;
        }
    }
    else
    {
        printf("failed to open vdisk...err 0x%x\n", ret);
        PrintErrorMessage(GetLastError());
        bRet = FALSE;
    }

    if (INVALID_HANDLE_VALUE != hVhd)
    {
        CloseHandle(hVhd);
    }

    return bRet;
}
Exemple #12
0
BOOL OpenAndDetachVHD(PCWSTR pszVhdPath)
{
    BOOL bRet = FALSE;
    DWORD ret;
    DETACH_VIRTUAL_DISK_FLAG Flags;
    HANDLE hVhd = INVALID_HANDLE_VALUE;
    OPEN_VIRTUAL_DISK_PARAMETERS oparams;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"OpenAndDetachVHD %s\n", pszVhdPath);

    oparams.Version = OPEN_VIRTUAL_DISK_VERSION_1;
    oparams.Version1.RWDepth = OPEN_VIRTUAL_DISK_RW_DEPTH_DEFAULT;

    ret = OpenVirtualDisk(&vst, pszVhdPath,
        VIRTUAL_DISK_ACCESS_DETACH,
        OPEN_VIRTUAL_DISK_FLAG_NONE, NULL /*&oparams*/, &hVhd);

    if (ERROR_SUCCESS == ret) 
    {
        printf("success opening vdisk...\n");
        Flags = DETACH_VIRTUAL_DISK_FLAG_NONE;
        ret = DetachVirtualDisk(hVhd, Flags, 0);
        if (ERROR_SUCCESS == ret)
        {
            printf("success detaching vdisk...\n");
        }
        else
        {
            printf("failed to detach vdisk... %d\n", ret);
            PrintErrorMessage(GetLastError());
            bRet = FALSE;
        }
    }
    else
    {
        printf("failed to open vdisk...err %d\n", ret);
        PrintErrorMessage(GetLastError());
        bRet = FALSE;
    }

    if (INVALID_HANDLE_VALUE != hVhd)
    {
        CloseHandle(hVhd);
    }

    return bRet;
}
void Preprocessor::ParseIf( LexemList& directive, std::string& name_out )
{
    directive.pop_front();
    if( directive.empty() )
    {
        PrintErrorMessage( "Expected argument." );
        return;
    }
    name_out = directive.begin()->Value;
    directive.pop_front();
    if( !directive.empty() )
        PrintErrorMessage( "Too many arguments." );
}
Exemple #14
0
int OpenAndSetVHDInfo(PCWSTR pszVhdPath, PCWSTR pszGuid, GUID *Guid)
{
    BOOL bRet = FALSE;
    DWORD ret;
    HANDLE hVhd;
    ULONG InfoSize;
    SET_VIRTUAL_DISK_INFO SetInfo;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"OpenAndSetVHDInfo %s GUID %s\n", pszVhdPath, pszGuid);

    ret = OpenVirtualDisk(&vst, pszVhdPath, 
        VIRTUAL_DISK_ACCESS_ALL, OPEN_VIRTUAL_DISK_FLAG_NONE, 
        NULL, &hVhd);

    if (ERROR_SUCCESS == ret) 
    {
        printf("success opening vdisk...\n");

        SetInfo.Version = SET_VIRTUAL_DISK_INFO_IDENTIFIER;
        InfoSize = sizeof(SetInfo);
        SetInfo.UniqueIdentifier = zGuid; //*Guid;

        ret = SetVirtualDiskInformation(hVhd, &SetInfo);
        if (ret == ERROR_SUCCESS) 
        {
            printf("success setting vhd info\n");
        }
        else
        {
            printf("failed to set vhd info %d\n", ret);
            PrintErrorMessage(GetLastError());
        }
    }
    else
    {
        printf("failed to open vdisk...err %d\n", ret);
        PrintErrorMessage(GetLastError());
    }

    if (INVALID_HANDLE_VALUE != hVhd) 
    {
        CloseHandle(hVhd);
    }

    return bRet;
}
Exemple #15
0
// Expanding a virtual disk requires that the virtual disk be detached during 
// the operation.
BOOL OpenAndExpandVHD(PCWSTR pszVhdPath, ULONG newSizeMB)
{
    BOOL bRet = FALSE;
    DWORD ret;
    HANDLE hVhd = INVALID_HANDLE_VALUE;
    EXPAND_VIRTUAL_DISK_PARAMETERS xparams;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"OpenAndExpandVHD %s, new size (MB) %d\n", pszVhdPath, newSizeMB);

    ret = OpenVirtualDisk(&vst, pszVhdPath,
        VIRTUAL_DISK_ACCESS_METAOPS,
        OPEN_VIRTUAL_DISK_FLAG_NONE, NULL, &hVhd);

    if (ERROR_SUCCESS == ret) 
    {
        printf("success opening vdisk...\n");
        xparams.Version = EXPAND_VIRTUAL_DISK_VERSION_1;
        xparams.Version1.NewSize = newSizeMB * 1024 * 1024;

        ret = ExpandVirtualDisk(hVhd, EXPAND_VIRTUAL_DISK_FLAG_NONE, &xparams, 0);

        if (ERROR_SUCCESS == ret) 
        {
            printf("success expanding vdisk...\n");
        }
        else
        {
            printf("failed to expand vdisk... %d\n", ret);
            PrintErrorMessage(GetLastError());
            bRet = FALSE;
        }
    }
    else
    {
        printf("failed to open vdisk...err %d\n", ret);
        PrintErrorMessage(GetLastError());
        bRet = FALSE;
    }

    if (INVALID_HANDLE_VALUE != hVhd)
    {
        CloseHandle(hVhd);
    }

    return bRet;
}
static void WriteFile( char* fileName, void* data, int dataToWrite ) {
	HANDLE fileHandle;
	//TODO: look into other options, such as: Overlapped, No_Bufffering, and Random_Access
	fileHandle = CreateFile( 
		fileName, 
		GENERIC_WRITE, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, 
		0, 
		CREATE_NEW, 
		FILE_ATTRIBUTE_NORMAL, 
		0 
	);
	if( fileHandle == INVALID_HANDLE_VALUE ) {
		fileHandle = CreateFile(
			fileName, 
			GENERIC_WRITE, 
			FILE_SHARE_WRITE,
			0,
			TRUNCATE_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			0
		);

		if( fileHandle == INVALID_HANDLE_VALUE ) {
			PrintErrorMessage( GetLastError() );
			printf("Did not write to file %s\n", fileName );
			return;
		}
	}

	DWORD bytesWritten = 0;
	DWORD writeSuccess = WriteFile( 
		fileHandle, 
		data, 
		dataToWrite, 
		&bytesWritten, 
		NULL //NOT NULL if i ever do overlapped stuff according to msdn
	);

	if( writeSuccess != 1 ) {
		PrintErrorMessage( GetLastError() );
		printf("Did not write to file %s\n", fileName );
		return;
	}

	//Close
	BOOL closeReturnValue = CloseHandle( fileHandle );
	assert( closeReturnValue );
}
Exemple #17
0
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
	This function prints information of local device
Arguments:
	void
Return:
	void 
---------------------------------------------------------------------------*/
void Test_Print_Local_Info(void)
{
	int j = 0;
	BTUINT8 szName[BTSDK_DEVNAME_LEN] = {0};
	BTUINT8 szBDAddr[BTSDK_BDADDR_LEN] = {0};
	BTUINT32 ulDevClass = 0;
	BTUINT16 usMode = 0;
	BTUINT16 usLen = BTSDK_DEVNAME_LEN;

	printf("\n");

	/* display the local device name */
	PrintErrorMessage(Btsdk_GetLocalName(szName, &usLen), BTSDK_TRUE);
	printf("Local Name = \"%s\"\n", szName);

	/* display the Bluetooth Address of the local device */
	PrintErrorMessage(Btsdk_GetLocalDeviceAddress(szBDAddr), BTSDK_TRUE);
	printf("BD Addr: ");
	for(j = 5; j > 0; j--)
	{
		printf("%02X:", szBDAddr[j]);
	}
	printf("%02X\n", szBDAddr[0]);

	/* display the device class of the local device */
	PrintErrorMessage(Btsdk_GetLocalDeviceClass(&ulDevClass), BTSDK_TRUE);
	printf("Device Class: %08lX\n", ulDevClass);

	/* display the discovery mode of the local device */
	PrintErrorMessage(Btsdk_GetDiscoveryMode(&usMode), BTSDK_TRUE);
	printf("Discovery Mode: ");
	if (usMode & BTSDK_GENERAL_DISCOVERABLE)
	{
		printf("GENERAL_DISCOVERABLE |");
	}
	if (usMode & BTSDK_LIMITED_DISCOVERABLE)
	{
		printf(" LIMITED_DISCOVERABLE |");
	}
	if (usMode & BTSDK_CONNECTABLE)
	{
		printf(" CONNECTABLE |");
	}
	if (usMode & BTSDK_PAIRABLE)
	{
		printf(" PAIRABLE\n");
	}
	printf("\n");	
}
void
AsyncChannel::ReportConnectionError(const char* channelName) const
{
    const char* errorMsg;
    switch (mChannelState) {
    case ChannelClosed:
        errorMsg = "Closed channel: cannot send/recv";
        break;
    case ChannelOpening:
        errorMsg = "Opening channel: not yet ready for send/recv";
        break;
    case ChannelTimeout:
        errorMsg = "Channel timeout: cannot send/recv";
        break;
    case ChannelClosing:
        errorMsg = "Channel closing: too late to send/recv, messages will be lost";
        break;
    case ChannelError:
        errorMsg = "Channel error: cannot send/recv";
        break;

    default:
        NS_RUNTIMEABORT("unreached");
    }

    PrintErrorMessage(mChild, channelName, errorMsg);

    mListener->OnProcessingError(MsgDropped);
}
static
void BubbleSortForwardList(My402List *pList)
{
    My402ListElem *elem=NULL;
    int i=0;

    if (My402ListLength(pList) == 0) {
        fprintf(stderr, "List is empty!");
        PrintErrorMessage();
        exit(1);
    }
    for (i=0; i < My402ListLength(pList); i++) {
        int j=0, something_swapped=FALSE;
        My402ListElem *next_elem=NULL;

        for (elem=My402ListFirst(pList), j=0; j < My402ListLength(pList)-i-1; elem=next_elem, j++) {
           unsigned int cur_val=(unsigned int)((TransactionElem *)(elem->obj))->eleTime, next_val=0;

            next_elem=My402ListNext(pList, elem);
            next_val = (unsigned int)((TransactionElem *)(next_elem->obj))->eleTime;

            if (cur_val > next_val) {
                BubbleForward(pList, &elem, &next_elem);
                something_swapped = TRUE;
            }
        }
        if (!something_swapped) break;
    }
}
// ====================================================================================================
// Include File
// ====================================================================================================
bool LuaManager::IncludeFile(char* sPath)
{
	lua_State* L = State();

	// Load File
	int status = luaL_loadfile(L, sPath);
	m_bSuccess = (status == 0);

	// Check for errors
	if (!Success())
	{
		// Traceback
		lua->GetGlobal("debug");
		lua->GetField("traceback");
		lua->ProtectedCall(0, 1);
		lua->Remove(-3);
		lua->Remove(-2);

		// Error Message
		char eMsg[364];
		sprintf(eMsg, "%s\n%s", lua->GetString(-2), lua->GetString(-1));
		PrintErrorMessage(eMsg, true, true);

		lua->Pop(2);		
		return false;
	}

	// Execute File
	bool bStatus = ProtectedCall(0, LUA_MULTRET);
	lua->Pop();
	return bStatus;
}
Exemple #21
0
Fichier : enrol.c Projet : rolk/ug
INT NS_DIM_PREFIX InitEnrol ()
{
  /* install the /Formats directory */
  if (ChangeEnvDir("/")==NULL)
  {
    PrintErrorMessage('F',"InitEnrol","could not changedir to root");
    return(__LINE__);
  }
  theFormatDirID = GetNewEnvDirID();
  if (MakeEnvItem("Formats",theFormatDirID,sizeof(ENVDIR))==NULL)
  {
    PrintErrorMessage('F',"InitEnrol","could not install '/Formats' dir");
    return(__LINE__);
  }
  theSymbolVarID = GetNewEnvVarID();

  return (GM_OK);
}
int main(int argc, char *argv[])
{
    FILE *fp = NULL;
    My402List *myList = NULL;
    myList = (My402List *)malloc(sizeof(My402List));
    char *dir = argv[2];
    DIR* directory = NULL;
    if(myList == NULL) {
			fprintf(stderr,"Memory allocation for the list failed!");
			PrintErrorMessage();
	}
	(void)My402ListInit(myList);
	if(argc < 2) {
		fprintf(stderr,"Error: Too less arguments\n");
		exit(1);
	} if(argc > 3) {
		fprintf(stderr,"Error: Too many arguments\n");
		exit(1);
	}	
	if(argv[1][0] == '-') {
		fprintf(stderr,"Cannot have \'-\' in the argument\n");
		exit(1);
	}
	if(argc >= 2) {
		if(strcmp(argv[1],"sort") == 0) {
			if(argc == 2) {
				fp = stdin;
				ReadFileInput(fp,myList);
				BubbleSortForwardList(myList);
				PrintList(myList);
				fclose(fp);
			} 
			if(argc == 3) {
				directory = opendir(dir);
				if(directory != NULL)
				{
					closedir(directory);
					fprintf(stderr,"Error: Given path is a directory\n");
					exit(1);
				}    
				fp = fopen(argv[2],"r");
				if(fp==NULL) {
						perror("Error ");
						exit(1);
				} 
				ReadFileInput(fp,myList);
				fclose(fp);
				BubbleSortForwardList(myList);
				PrintList(myList);
			}
		} else {
			fprintf(stderr,"Error: \'sort\' should be the second argument\n");
			exit(1);
		}
	}
	return 0;
}
Preprocessor::LLITR Preprocessor::ParseDefineArguments( LLITR itr, LLITR end, LexemList& lexems, std::vector<LexemList>& args )
{
    if( itr == end || itr->Value != "(" )
    {
        PrintErrorMessage( "Expected argument list." );
        return itr;
    }
    LLITR begin_erase = itr;
    ++itr;

    while( itr != end )
    {
        LexemList argument;
        LLITR     prev = itr;
        itr = ParseStatement( itr, end, argument );
        if( itr == prev )
            return itr;

        args.push_back( argument );

        if( itr == end )
        {
            PrintErrorMessage( "0x0FA1 Unexpected end of file." );
            return itr;
        }
        if( itr->Value == "," )
        {
            ++itr;
            if( itr == end )
            {
                PrintErrorMessage( "0x0FA2 Unexpected end of file." );
                return itr;
            }
            continue;
        }
        if( itr->Value == ")" )
        {
            ++itr;
            break;
        }
    }

    return lexems.erase( begin_erase, itr );
}
Exemple #24
0
void FWindow::Linux_SetStyle(GLuint WindowStyle)
{
	switch(WindowStyle)
	{
		case WINDOWSTYLE_DEFAULT:
			{
				Decorators = (1L << 2);
				CurrentWindowStyle = LINUX_DECORATOR_MOVE | LINUX_DECORATOR_CLOSE | 
					LINUX_DECORATOR_MAXIMIZE | LINUX_DECORATOR_MINIMIZE; 
				long Hints[5] = {LINUX_FUNCTION | LINUX_DECORATOR, CurrentWindowStyle, Decorators, 0, 0};

				XChangeProperty(WindowManager::GetDisplay(), WindowHandle, AtomHints, XA_ATOM, 32, PropModeReplace, 
						(unsigned char*)Hints, 5);

				XMapWindow(WindowManager::GetDisplay(), WindowHandle);


				break;
			}

		case WINDOWSTYLE_BARE:
			{
				Decorators = (1L << 2);
				CurrentWindowStyle = (1L << 2);
				long Hints[5] = {LINUX_FUNCTION | LINUX_DECORATOR, CurrentWindowStyle, Decorators, 0, 0};

				XChangeProperty(WindowManager::GetDisplay(), WindowHandle, AtomHints, XA_ATOM, 32, PropModeReplace, 
						(unsigned char*)Hints, 5);

				XMapWindow(WindowManager::GetDisplay(), WindowHandle);


				break;
			}

		case WINDOWSTYLE_POPUP:
			{
				Decorators = 0;
				CurrentWindowStyle = (1L << 2);
				long Hints[5] = {LINUX_FUNCTION | LINUX_DECORATOR, CurrentWindowStyle, Decorators, 0, 0};

				XChangeProperty(WindowManager::GetDisplay(), WindowHandle, AtomHints, XA_ATOM, 32, PropModeReplace, 
						(unsigned char*)Hints, 5);

				XMapWindow(WindowManager::GetDisplay(), WindowHandle);

				break;
			}

			default:
			{
				PrintErrorMessage(ERROR_INVALIDWINDOWSTYLE);
				break;
			}
	}
}	
Exemple #25
0
TApiStatus GetInterfacesOnNetworkElement(TNetworkElement* element)
{
    onep_status_t rc;
    unsigned count = 0;
    onep_interface_filter_t* intf_filter = NULL;

    rc = onep_interface_filter_new(&intf_filter);
    if (rc != ONEP_OK)
    {
        PrintErrorMessage("GetInterfacesOnNetworkElement", onep_strerror(rc));
        return API_ERROR;
    }
    rc = onep_element_get_interface_list(element->ne, intf_filter, &(element->interfaces));
    if (rc != ONEP_OK)
    {
        PrintErrorMessage("GetInterfacesOnNetworkElement", onep_strerror(rc));
        return API_ERROR;
    }
    rc = onep_collection_get_size(element->interfaces, &count);
    if (rc != ONEP_OK)
    {
        PrintErrorMessage("GetInterfacesOnNetworkElement", onep_strerror(rc));
        return API_ERROR;
    }
    if (count <= 0)
    {
        PrintErrorMessage("GetInterfacesOnNetworkElement", "no interfaces available");
        return API_ERROR;
    }

    if(intf_filter)
    {
        rc = onep_interface_filter_destroy(&intf_filter);
        if(rc != ONEP_OK)
        {
            // Only warning
            PrintErrorMessage("GetInterfacesOnNetworkElement", "Destroy: interface filter");
        }
    }

    return API_OK;
}
Exemple #26
0
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
	This function prints other information of remote device
Arguments:
	BTDEVHDL dev_hdl: [in] device handle
Return:
	void 
---------------------------------------------------------------------------*/
void GetConnectionInfo(BTDEVHDL dev_hdl)
{
	BTUINT8 ucRssi = 0;
	BTUINT16 usRole = 0;
	BTUINT16 usTimeout = 0;
	BTUINT32 ulResult = BTSDK_OK;
	/*Before calling this function, please make sure a connection has been established.*/
	ulResult = Btsdk_GetRemoteRSSI(dev_hdl, &ucRssi);
	PrintErrorMessage(ulResult, BTSDK_TRUE);
	if (BTSDK_OK == ulResult)
	{
		printf("RSSI: %04X\n", ucRssi);
		ulResult = Btsdk_GetRemoteDeviceRole(dev_hdl, &usRole);
		PrintErrorMessage(ulResult, BTSDK_TRUE);
		printf("Role: %04X\n", usRole);
		ulResult = Btsdk_GetSupervisionTimeout(dev_hdl, &usTimeout);
		PrintErrorMessage(ulResult, BTSDK_TRUE);
		printf("Super Timeout: %04X\n", usTimeout);
	}
}
BOOL CallSetSystemTimeAdjustment(DWORD dwTimeAdjustment) {
	HANDLE hToken;
	BOOL bTimeAdjustmentDisabled = FALSE;

	if (dwTimeAdjustment == 0)
		bTimeAdjustmentDisabled = TRUE;
//	else
//		dwTimeAdjustment = atoi(argv[2]); // 100ns

	/* Get hToken */
	if (!OpenProcessToken(GetCurrentProcess(),
			TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
		PrintErrorMessage((__FILE__), "OpenProcessToken()", __LINE__);
		exit(1);
	}
	
	/* enable SE_SYSTEMTIME_NAME Privilege */
	if (!SetPrivilege(hToken, SE_SYSTEMTIME_NAME, TRUE)) {
	    CloseHandle(hToken);
		PrintErrorMessage((__FILE__), "SetPrivilege(hToken, SE_SYSTEMTIME_NAME, TRUE)", __LINE__);
		exit(1);
	}

	CloseHandle(hToken);

	/* Call SetSystemTimeAdjustment() */
	printf("SetSystemTimeAdjustment() Calling...\n");
	if (!SetSystemTimeAdjustment(dwTimeAdjustment, bTimeAdjustmentDisabled)) {
		if (bTimeAdjustmentDisabled)
			PrintErrorMessage((__FILE__), "SetSystemTimeAdjustment(0, TRUE)", __LINE__);
		else
			PrintErrorMessage((__FILE__), "SetSystemTimeAdjustment(dwTimeAdjustment, FALSE)", __LINE__);
		exit(1);
	}
	else {
		printf("dwTimeAdjustment: %ld [100-nanosecond unit]\n", dwTimeAdjustment);
		printf("bTimeAdjustmentDisabled : %s \n", bTimeAdjustmentDisabled ? "True (Sync RTC see KB232488)" : "False (Ignore RTC)");
	}
	return TRUE;
}
int main(int argc, char *argv[])
{
    void *hDevice;
    FTRSCAN_IMAGE_SIZE ImageSize;
    unsigned char *pBuffer;
    int i;

    hDevice = ftrScanOpenDevice();
    if( hDevice == NULL )
    {
        printf("Failed to open device!\n");
        return -1;
    }

    if( !ftrScanGetImageSize( hDevice, &ImageSize ) )
    {
        printf("Failed to get image size\n");
        ftrScanCloseDevice( hDevice );
        return -1;
    }
    else
    {
        printf("Image size is %d\n", ImageSize.nImageSize);
        pBuffer = (unsigned char *)malloc( ImageSize.nImageSize );
        printf("Please put your finger on the scanner:\n");
        while(1)
        {
            if( ftrScanIsFingerPresent( hDevice, NULL ) )
                break;
            for(i=0; i<100; i++);	//sleep
        }
        printf("Capturing fingerprint ......\n");
        while(1)
        {
            if( ftrScanGetFrame(hDevice, pBuffer, NULL) )
            {
                printf("Done!\nWriting to file......\n");
                write_bmp_file( pBuffer, ImageSize.nWidth, ImageSize.nHeight );
                break;
            }
            else
            {
                PrintErrorMessage( ftrScanGetLastError() );
                for(i=0; i<100; i++);
            }
        }
        free( pBuffer );
    }

    ftrScanCloseDevice( hDevice );
    return 0;
}
Exemple #29
0
BOOL CreateVHD_Fixed(PCWSTR pszVhdPath, ULONG sizeInMB)
{
    BOOL bRet = FALSE;
    HANDLE hvhd;
    CREATE_VIRTUAL_DISK_PARAMETERS  params;
    VIRTUAL_DISK_ACCESS_MASK        mask;
    VIRTUAL_STORAGE_TYPE            vst =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    wprintf(L"CreateVHD_Fixed %s, size (MB) %d\n", pszVhdPath, sizeInMB);

    params.Version1.UniqueId            = GUID_NULL;
    params.Version1.BlockSizeInBytes    = 0;
    params.Version1.MaximumSize		    = sizeInMB * 1024 * 1024;
    params.Version1.ParentPath		    = NULL;
    params.Version1.SourcePath          = NULL;
    params.Version1.SectorSizeInBytes   = 512;
    params.Version					    = CREATE_VIRTUAL_DISK_VERSION_1;
    mask                                = VIRTUAL_DISK_ACCESS_CREATE;

    DWORD ret = CreateVirtualDisk(&vst, 
        pszVhdPath, 
        mask, 
        NULL, 
        // To create a dynamic disk, use CREATE_VIRTUAL_DISK_FLAG_NONE instead.
        CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION, 
        0, 
        &params, 
        NULL, 
        &hvhd);

    if (ret == ERROR_SUCCESS)
    {
        bRet = TRUE;
    }
    else
    {
        bRet = FALSE;
        printf("failed to create vdisk...err 0x%x\n", ret);
        PrintErrorMessage(GetLastError());
    }

    if (INVALID_HANDLE_VALUE != hvhd)
    {
        CloseHandle(hvhd);
    }

    return bRet;
}
Exemple #30
0
INT NS_DIM_PREFIX InitDom ()
{
  /* change to root directory */
  if (ChangeEnvDir("/")==NULL)
  {
    PrintErrorMessage('F',"InitLgm_Domain","could not changedir to root");
    return(__LINE__);
  }

  /* install the /LGM_BVP directory */
  theBVPDirID = GetNewEnvDirID();
  if (MakeEnvItem("LGM_BVP",theBVPDirID,sizeof(ENVDIR))==NULL)
  {
    PrintErrorMessage('F',"InitLgm_Domain","could not install '/LGM_BVP' dir");
    return(__LINE__);
  }
  theLGMDomainVarID = GetNewEnvVarID();

  /* change to root directory */
  if (ChangeEnvDir("/")==NULL)
  {
    PrintErrorMessage('F',"InitLgm_Domain","could not changedir to root");
    return(__LINE__);
  }

  /* install the /LGM_PROBLEM directory */
  theProblemDirID = GetNewEnvDirID();
  if (MakeEnvItem("LGM_PROBLEM",theProblemDirID,sizeof(ENVDIR))==NULL)
  {
    PrintErrorMessage('F',"InitLgm_Domain","could not install '/LGM_PROBLEM' dir");
    return(__LINE__);
  }
  theProblemVarID = GetNewEnvVarID();

  /* init load procedures */
  if (InitLGMLoad()) return (1);

  return (0);
}