int main (int argc, char *argv[]) {
	// Let's register the CTRL + c signal handler.
	if(signal(SIGINT, exitHandle) == SIG_ERR) {
		std::cerr <<  "Failed to set SIGINT handler." << std::endl;
		return -1;
	}

	// Register termination handler.
	if(signal(SIGTERM, exitHandle) == SIG_ERR) {
		std::cerr <<  "Failed to set SIGTERM handler." << std::endl;
		return -1;
	}

	if(xdl::createCore(&core, argc, argv) != xdl::RET_SUCCESS) {
		return -1;
	}


	if(core->plug(xdl::XdevLPluginName("XdevLAudioAlsa"), xdl::XdevLVersion(0, 6, 0)) != xdl::RET_SUCCESS) {
		xdl::destroyCore(core);
		return -1;
	}

	alsa_playback = xdl::createModule<xdl::XdevLAudioPlayback*>(core, xdl::XdevLModuleName("XdevLAudioPlayback"), xdl::XdevLID("MyAlsaPlayback"));
	if(isModuleNotValid(alsa_playback)) {
		xdl::destroyCore(core);
		return -1;
	}

	xdl::IPXdevLAudioBuffer buffer2 = alsa_playback->createAudioBuffer(xdl::AUDIO_BUFFER_FORMAT_S16, xdl::AUDIO_SAMPLE_RATE_44100, 1, 0, nullptr);
	if(nullptr == buffer2) {
		xdl::destroyCore(core);
		return -1;
	}
	
	alsa_playback->setCallbackFunction(callback, nullptr);

	for(;;) {
		core->update();
		alsa_playback->update2();
	}

	xdl::destroyCore(core);
}
Esempio n. 2
0
int main(int argc, char **argv) {

	// Let's register the CTRL + c signal handler.
	if(signal(SIGINT, exitHandle) == SIG_ERR) {
		std::cerr <<  "Failed to set SIGINT handler." << std::endl;
		return -1;
	}

	// Register termination handler.
	if(signal(SIGTERM, exitHandle) == SIG_ERR) {
		std::cerr <<  "Failed to set SIGTERM handler." << std::endl;
		return -1;
	}

	//
	// Create the core
	//
	if(xdl::createCore(&core, argc, argv, xdl::XdevLFileName("mouse_demo.xml")) != xdl::ERR_OK) {
		return -1;
	}

	//
	// Create the window module instance.
	//
	xdl::IPXdevLWindow window = xdl::createModule<xdl::IPXdevLWindow>(core, xdl::XdevLModuleName("XdevLWindow"), xdl::XdevLID("MyWindow"));
	if(xdl::isModuleNotValid(window)) {
		xdl::destroyCore(core);
		return -1;
	}

	// This will create the window using default parameters or using the attributes provided in the XML file.
	window->create();

	// Maps the window to the display so we can see it.
	window->show();

	//
	// Create the joystick module instance.
	//
	xdl::IPXdevLMouse mouse = xdl::createModule<xdl::IPXdevLMouse>(core, xdl::XdevLModuleName("XdevLMouse"), xdl::XdevLID("MyMouse"));
	if(xdl::isModuleNotValid(mouse)) {
		xdl::destroyCore(core);
		return -1;
	}

	// Attach this mouse to the window. We have to do this otherwise the XdevLMouse module will not work.
	mouse->attach(window);

	//
	// Now we use delegates that will help us to managed events. When a specific button or axis is used
	// the delegate will call a function/member that we can use to do some stuff.
	//
	xdl::XdevLButtonIdDelegateType button0Delegate = xdl::XdevLButtonIdDelegateType::Create<&callbackButton0>();
	xdl::XdevLButtonIdDelegateType button1Delegate = xdl::XdevLButtonIdDelegateType::Create<&callbackButton1>();
	xdl::XdevLButtonIdDelegateType button2Delegate = xdl::XdevLButtonIdDelegateType::Create<&callbackButton2>();

	xdl::XdevLAxisIdDelegateType axis0Delegate = xdl::XdevLAxisIdDelegateType::Create<&callbackAxis0>();
	xdl::XdevLAxisIdDelegateType axis1Delegate = xdl::XdevLAxisIdDelegateType::Create<&callbackAxis1>();

	mouse->registerDelegate(xdl::XdevLString("BUTTON_0"), button0Delegate);
	mouse->registerDelegate(xdl::XdevLString("BUTTON_1"), button1Delegate);
	mouse->registerDelegate(xdl::XdevLString("BUTTON_2"), button2Delegate);
	mouse->registerDelegate(xdl::XdevLString("AXIS_0"), axis0Delegate);
	mouse->registerDelegate(xdl::XdevLString("AXIS_1"), axis1Delegate);

	xdl::xdl_float prev_axis_0 = mouse->getDeltaValue(xdl::AXIS_0);
	xdl::xdl_float prev_axis_1 = mouse->getDeltaValue(xdl::AXIS_1);

	// Start the main loop.
	for(;;) {

		// We need to call the update of the core manually.
		core->update();

		// Let's not use too much CPU power.
		xdl::sleep(0.001);
	}

	// We, this might be never called in this demo but I like to show
	// that the core has to be destroyed at the end. In this example
	// we quite using CTRL + C or terminating see above. :D.
	xdl::destroyCore(core);

	return 0;
}