Exemplo n.º 1
0
// General initizlization of the talker and listener library. Must be called prior to using any other TL APIs.
EXTERN_DLL_EXPORT bool openavbTLInitialize(U32 maxTL)
{
	AVB_TRACE_ENTRY(AVB_TRACE_TL);
	LOG_EAVB_CORE_VERSION();

	// CORE_TODO : This can be used to AVB stack init functionality once such a thing exists in the reference implementation
	AVB_TIME_INIT();

	gMaxTL = maxTL;

	{
		MUTEX_ATTR_HANDLE(mta);
		MUTEX_ATTR_INIT(mta);
		MUTEX_ATTR_SET_TYPE(mta, MUTEX_ATTR_TYPE_DEFAULT);
		MUTEX_ATTR_SET_NAME(mta, "gTLStateMutex");
		MUTEX_CREATE_ERR();
		MUTEX_CREATE(gTLStateMutex, mta);
		MUTEX_LOG_ERR("Error creating mutex");
	}

	gTLHandleList = calloc(1, sizeof(tl_handle_t) * gMaxTL);
	if (gTLHandleList) {
		AVB_TRACE_EXIT(AVB_TRACE_TL);
		return TRUE;
	}
	else {
		AVB_TRACE_EXIT(AVB_TRACE_TL);
		return FALSE;
	}
}
Exemplo n.º 2
0
bool startAvdecc(const char* ifname, const char **inifiles, int numfiles)
{
	AVB_TRACE_ENTRY(AVB_TRACE_AVDECC);
	LOG_EAVB_CORE_VERSION();

	// Ensure that we're running as root
	//  (need to be root to use raw sockets)
	uid_t euid = geteuid();
	if (euid != (uid_t)0) {
		fprintf(stderr, "Error: needs to run as root\n\n");
		goto error;
	}

	// Get the AVDECC configuration
	memset(&gAvdeccCfg, 0, sizeof(openavb_avdecc_cfg_t));
	openavbReadAvdeccConfig(DEFAULT_AVDECC_INI_FILE, &gAvdeccCfg);

	// Determine which interface to use.
	if (ifname) {
		strncpy(gAvdeccCfg.ifname, ifname, sizeof(gAvdeccCfg.ifname));
	} else if (gAvdeccCfg.ifname[0] == '\0') {
		AVB_LOG_ERROR("No interface specified.  Use the -I flag, or add one to " DEFAULT_AVDECC_INI_FILE ".");
		goto error;
	}

	// Read the information from the supplied INI files.
	openavb_tl_data_cfg_t * prevStream = NULL, * newStream;
	U32 i1;
	for (i1 = 0; i1 < numfiles; i1++) {

		char iniFile[1024];
		snprintf(iniFile, sizeof(iniFile), "%s", inifiles[i1]);
		// Create a new item with this INI information.
		newStream = malloc(sizeof(openavb_tl_data_cfg_t));
		if (!newStream) {
			AVB_LOG_ERROR("Out of memory");
			goto error;
		}
		memset(newStream, 0, sizeof(openavb_tl_data_cfg_t));
		if (!openavbReadTlDataIniFile(iniFile, newStream)) {
			AVB_LOGF_ERROR("Error reading ini file: %s", inifiles[i1]);
			goto error;
		}
		// Append this item to the list of items.
		if (!prevStream) {
			// First item.
			streamList = newStream;
		} else {
			// Subsequent item.
			prevStream->next = newStream;
		}
		prevStream = newStream;
	}

	/* Run AVDECC in its own thread. */
	avdeccRunning = TRUE;
	avdeccInitSucceeded = FALSE;
	int err = pthread_create(&avdeccServerHandle, NULL, avdeccServerThread, NULL);
	if (err) {
		AVB_LOGF_ERROR("Failed to start AVDECC thread: %s", strerror(err));
		goto error;
	}

	/* Wait a while to see if the thread was able to start AVDECC. */
	int i;
	for (i = 0; avdeccRunning && !avdeccInitSucceeded && i < 5000; ++i) {
		SLEEP_MSEC(1);
	}
	if (!avdeccInitSucceeded) {
		goto error;
	}

	AVB_TRACE_EXIT(AVB_TRACE_AVDECC);
	return true;

error:
	AVB_TRACE_EXIT(AVB_TRACE_AVDECC);
	return false;
}