示例#1
0
int main()
{
	MsgClusterMgr msg_cluster_mgr;
	printf("Start the Node...\n");

	unsigned short ret = msg_cluster_mgr.start();
	if (CHECK_FAILURE(ret))
	{
		fprintf(stderr, "Fail to initialize...\n");
		exit(EXIT_FAILURE);
	}

	getchar();
	ret = msg_cluster_mgr.wait_to_stop();
	if (CHECK_FAILURE(ret))
	{
		fprintf(stderr, "Fail to waiting for stop...\n");
		exit(EXIT_FAILURE);
	}

	getchar();
	printf("The Node is Stopped......\n");

	exit(EXIT_SUCCESS);
}
unsigned short MsgDumperSyslog::initialize(const char* current_working_directory, void* config)
{
	WRITE_DEBUG_SYSLOG("Initialize the MsgDumperSyslog object......");

// Parse the config file first
	unsigned short ret = parse_config(current_working_directory, "syslog");
	if (CHECK_FAILURE(ret))
		return ret;

// Get the facility number
	ret = get_facility_number();
	if (CHECK_FAILURE(ret))
		return ret;

	return MSG_DUMPER_SUCCESS;
}
示例#3
0
/**
This function assumes that there are 4 buttons that can be read from the HID device which represent the button's usages values.
This will not be true for all HID Devices. If you want to use this function, you must modify it for the correct number of buttons.
Furthermore, you need to update nesmapping.h, or include a different mapping file, which holds constants for the button mapping.
(You'll have to figure out the button mapping experimentally using log statements or breakpoints)
**/
int Controller::getButtonInput(bool * pValues)
{
	DWORD readbytecount = 0;
	_succ = ReadFile(
		_controllerHandle,
		_pInputReport,
		_pCaps->InputReportByteLength,
		&readbytecount,
		nullptr
		);

	CHECK_FAILURE(_succ, BUTTON_INPUT_FAILURE);


	ULONG numButtonUsages = _pButtonCaps->Range.UsageMax - _pButtonCaps->Range.UsageMin + 1;

	//use the input report to generate button usage data
	HidP_GetUsages(HidP_Input, _pButtonCaps[0].UsagePage, _pButtonCaps[0].LinkCollection, _pButtonUsages, &numButtonUsages, _pPreparsedData, _pInputReport, _pCaps->InputReportByteLength);
	
	//reset button values to 0
	for (unsigned int i = 0; i < NUM_BUTTONS; i++)
	{
		pValues[i] = false;
	}

	//every button that is currently pressed will have it's ID in the _pButtonUsages array
	for (unsigned int i = 0; i < numButtonUsages; i++)
	{
		USAGE dat = _pButtonUsages[i];
		switch (dat)
		{
		case BUTTON_A:
			pValues[BUTTON_A_INDEX] = true;
				break;
		case BUTTON_B:
			pValues[BUTTON_B_INDEX] = true;
				break;
		case BUTTON_SELECT:
			pValues[BUTTON_SELECT_INDEX] = true;
				break;
		case BUTTON_START:
			pValues[BUTTON_START_INDEX] = true;
				break;
			default:
			break;
		}
	}
	return numButtonUsages;



BUTTON_INPUT_FAILURE:
	return -1;

}
示例#4
0
/**
	This function assumes that there are 2 values that can be read from the HID device which represent the DPad's state.
	This will not be true for all HID Devices. If you want to use this function, you must modify it for the correct value count.
	Furthermore, you need to update nesmapping.h, or include a different mapping file, which holds constants for the button mapping.
	(You'll have to figure out the button mapping experimentally using log statements or breakpoints)
 **/
int Controller::getDPadInput(bool * pValues)
{
	DWORD readbytecount = 0;
	_succ = ReadFile(
		_controllerHandle,
		_pInputReport,
		_pCaps->InputReportByteLength,
		&readbytecount,
		nullptr
		);

	CHECK_FAILURE(_succ, DPAD_INPUT_FAILURE);

	//use the input report to generate button usage data
	LONG value = 0;

	//reset direction flags
	for (int i = 0; i < NUM_DIRECTIONS; i++)
	{
		pValues[i] = false;
	}

	for (int valIt = 0; valIt < _pCaps->NumberInputValueCaps; valIt++)
	{
		HidP_GetUsageValue(HidP_Input, _pValueCaps[valIt].UsagePage, _pValueCaps[valIt].LinkCollection, _pValueCaps[valIt].Range.UsageMin, (PULONG)&value, _pPreparsedData,
			_pInputReport, readbytecount
			);

		if (valIt == 0)
		{
			switch (value)
			{
			case DPAD_UP:
				pValues[DPAD_UP_INDEX] = true;
				break;
			case DPAD_DOWN:
				pValues[DPAD_DOWN_INDEX] = true;
				break;
			default:
				break;
			}
		}
		else
		{
			switch (value)
			{
			case DPAD_RIGHT:
				pValues[DPAD_RIGHT_INDEX] = true;
				break;
			case DPAD_LEFT:
				pValues[DPAD_LEFT_INDEX] = true;
				break;
			default:
				break;
			}
		}

	}

	return _pCaps->NumberInputValueCaps;

DPAD_INPUT_FAILURE:
		return -1;

}
示例#5
0
unsigned short RunWebSchedule::parse_time_range(const char* time_range_str)
{
	if (time_range_str == NULL)
	{
		WRITE_ERR_SYSLOG("Invalid argument: time_range_str");
		return DOIT_FAILURE_INVALID_ARGUMENT;
	}

	char* tok = NULL;

	char* time_range_str_tmp = new char[strlen(time_range_str) + 1];
	if (time_range_str_tmp == NULL)
	{
		WRITE_ERR_SYSLOG("Fail to allocate the memory: time_range_str_tmp");
		return DOIT_FAILURE_INSUFFICIENT_MEMORY;
	}
	memset(time_range_str_tmp, 0x0, sizeof(char) * (strlen(time_range_str) + 1));
	strcpy(time_range_str_tmp, time_range_str);

	unsigned short ret = DOIT_SUCCESS;
	tok = strtok(time_range_str_tmp, " ");
	int day_of_week_index = -1;
	while (tok != NULL)
	{
		WRITE_DEBUG_FORMAT_SYSLOG(DOIT_LONG_STRING_SIZE, "New tok: %s", tok);
		if (day_of_week_index == -1)
		{
// Parse the day of the week
			for (int i = 0 ; i < sizeof(day_of_week_str) / sizeof(day_of_week_str[0]) ; i++)
			{
				if (strcmp(tok, day_of_week_str[i]) == 0)
				{
					day_of_week_index = i;
					break;
				}
			}
			if (day_of_week_index == -1)
			{
				WRITE_ERR_FORMAT_SYSLOG(DOIT_LONG_STRING_SIZE, "Fail to parse the day of the week: %s", tok);
				ret = DOIT_FAILURE_INVALID_ARGUMENT;
				break;
			}
		}
		else
		{
// Parse the time range in each day
			ret = add_new_schedule((DAY_OF_WEEK)day_of_week_index, tok);
			if (CHECK_FAILURE(ret))
				break;
		}
		tok = strtok(NULL, " ");
	}
	WRITE_DEBUG_SYSLOG("Token is NULL");

	if (time_range_str_tmp != NULL)
	{
		delete[] time_range_str_tmp;
		time_range_str_tmp = NULL;
	}
	return ret;
}