Beispiel #1
0
/* INFO: */
static int ApiDeviceCreateActionBinding(
		const unsigned int inpServiceIndex,
		const char * const inpActionName,
		const StructuresDynamicActionFunction inpActionFunction) {
	unsigned int localActionIndex = { 0 };
	unsigned int localActionCount = { 0 };
	const char * localActionName = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(ApiDeviceGetServiceActionCount(inpServiceIndex,
		(& localActionCount)));

	for(; localActionIndex < localActionCount; ++localActionIndex) {
		CHECK(ApiDeviceGetServiceActionName(inpServiceIndex,
			localActionIndex, (& localActionName)));

		if(! strcmp(localActionName, inpActionName)) {
			CHECK(ApiDeviceSetActionFunction(inpServiceIndex,
				localActionIndex, inpActionFunction));

			return NO_ERROR;
		}
	}

	return ERROR;
}
HRESULT SMPortOutputQueue::Flush(SMThread& Thread, DWORD dwTimeout /*= DEFAULT_FLUSH_TIMEOUT*/)
{
    HRESULT hr = S_OK;

    // Verify that the queue has been initialized
    CHECK_INITIALIZED(Flush);

    SMTimer Timer;
    bool bDone = false;
    while (!bDone && Thread.IsPermittedToRun() && m_Port.IsOpen())
    {
        // Need atomic access to queue
        SMSingleLock SingleLock(&m_QueueMutex);
        SingleLock.Lock();
        bDone = m_Queue.empty();
        SingleLock.Unlock();

        // Sleep for a while, even if the queue is now empty (in order to allow
        // for the last message removed to be fully transmitted).
        ::Sleep(100);
        if (!bDone && (Timer.ElapsedSeconds() >= dwTimeout))
        {
            bDone = true;
            hr = E_FAIL;
            SM_LOG_NAME(hr, 1, "SMPortOutputQueue::Flush(): Timed-out waiting for queue to become empty!");
        }
    }

    return hr;
}
Beispiel #3
0
// Delete all texture information associated with a buffer. The OpenGL texture
// itself is only deleted if it was actually allocated by Halide and not
// provided by the host application.
EXPORT int halide_opengl_dev_free(void *user_context, buffer_t *buf) {
    CHECK_INITIALIZED(1);

    GLuint tex = get_texture_id(buf);
    if (tex == 0) {
        return 0;
    }

    // Look up corresponding HalideOpenGLTexture and unlink it from the list.
    HalideOpenGLTexture **ptr = &ST.textures;
    HalideOpenGLTexture *texinfo = *ptr;
    for (; texinfo != NULL; ptr = &texinfo->next, texinfo = *ptr) {
        if (texinfo->id == tex) {
            *ptr = texinfo->next;
            texinfo->next = NULL;
            break;
        }
    }
    if (!texinfo) {
        halide_error(user_context, "Internal error: texture not found");
        return 1;
    }

    // Delete texture if it was allocated by us.
    if (texinfo->halide_allocated) {
        ST.DeleteTextures(1, &tex);
        CHECK_GLERROR(1);
        buf->dev = 0;
    }

    free(texinfo);
    return 0;
}
Beispiel #4
0
/* INFO: */
static int DeviceListMutexInit() {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(pthread_mutex_init((& staticDeviceListMutex), 0));

	return NO_ERROR;
}
Beispiel #5
0
/* INFO: */
static int DeviceListMutexDestroy() {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(pthread_mutex_destroy(& staticDeviceListMutex));

	return NO_ERROR;
}
Beispiel #6
0
IMPLEMENT_DEBUG_FUNCENTRY_4(CGDODatabase,get_ObjectsDef,VARIANT, vIndex, VARIANT_BOOL, fCreate, BSTR, Type, ITRiASObjects**, ppIObjectsDef) 
{
	CHECKOUTPOINTER(ppIObjectsDef);
	COM_TRY {
		CHECK_INITIALIZED();

	WTRiASObjects	pTRiASObjects;
	CComVariant	vItem;

		RETURN_FAILED_HRESULT(EnsureObjectsColl());
	
	HRESULT hr = m_pGDOObjectsCollection -> Item (vIndex, CLEARED(vItem));

		if (SUCCEEDED(hr)) 
			pTRiASObjects = V_DISPATCH(&vItem);
		else if (TRIASDB_E_UNKNOWN_OBJECTS == hr && fCreate) {
		WTRiASObjectsCollection	pTRiASObjectsCollection;
		
			ERROR_FAILED_HRESULT(m_pGDOObjectsCollection -> QueryInterface (pTRiASObjectsCollection.ppi()), E_FAIL);
			ERROR_FAILED_HRESULT(pTRiASObjectsCollection -> Add (V_BSTR(&vIndex), Type, pTRiASObjects.ppi()), E_FAIL);
		} else 
			return hr;

		*ppIObjectsDef = pTRiASObjects.detach();
	} COM_CATCH;
	return S_OK;
}
Beispiel #7
0
/* INFO: */
int DeviceListPrintList() {
	StructuresDynamicNode * localNode = { 0 };
	unsigned int localDeviceNumber = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	++localDeviceNumber;

	CHECK(ConsolePrint(DEVICE_LIST_PRINT_LIST_STRING));

	CHECK(DeviceListMutexLock());
	{
		localNode = globalDeviceList;

		while(localNode) {
			CHECK(ConsolePrint(
				DEVICE_LIST_PRINT_LIST_ENTRY_FORMATTER,
				localDeviceNumber, localNode->device->
				friendlyName, localNode->device->
				uniqueDeviceName));
			localNode = localNode->next;

			++localDeviceNumber;
		}
	}
	CHECK(DeviceListMutexUnlock());

	CHECK(ConsolePrint(DEVICE_LIST_NEW_LINE_STRING));

	return NO_ERROR;
}
Beispiel #8
0
/* INFO: */
int DeviceListUpdateTimeoutIfDeviceAlreadyKnown(
		const char * const inpUniqueDeviceName,
		const unsigned int inpAdvertisementTimeout,
		bool * const inpAlreadyKnownFlag) {
	StructuresDynamicNode * localNode = { 0 };
	bool localAlreadyKnownFlag = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListMutexLock());
	{
		localNode = globalDeviceList;

		while(localNode) {
			if(! strcmp(inpUniqueDeviceName, localNode->device->
					uniqueDeviceName)) {
				localNode->advertisementTimeout =
					inpAdvertisementTimeout;
				localAlreadyKnownFlag = true;

				break;
			}

			localNode = localNode->next;
		}
	}
	CHECK(DeviceListMutexUnlock());

	(* inpAlreadyKnownFlag) = localAlreadyKnownFlag;

	return NO_ERROR;
}
Beispiel #9
0
/* INFO: */
int DeviceListMutexUnlock() {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(pthread_mutex_unlock(& staticDeviceListMutex));

	return NO_ERROR;
}
Beispiel #10
0
/* INFO: */
static int DeviceListCreateNode(StructuresDynamicNode ** const inpDeviceNode,
		const char * const inpDescriptionDocumentURL,
		const unsigned int inpAdvertisementTimeout,
		StructuresDynamicDevice * const inpDeviceStructure) {
	StructuresDynamicNode * localDeviceNode = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListSubscribeServices(inpDeviceStructure->
		serviceArray, inpDeviceStructure->serviceCount,
		inpAdvertisementTimeout));

	localDeviceNode = malloc(sizeof(StructuresDynamicNode));

	CHECK_MALLOCED(localDeviceNode);

	localDeviceNode->descriptionDocumentURL = UtilsStringDuplicate(
		inpDescriptionDocumentURL);
	localDeviceNode->advertisementTimeout = inpAdvertisementTimeout;
	localDeviceNode->device = inpDeviceStructure;
	localDeviceNode->next = 0;

	(* inpDeviceNode) = localDeviceNode;

	return NO_ERROR;
}
Beispiel #11
0
/* INFO: */
int ApiDeviceGetDeviceServiceCount(
		unsigned int * const inpDeviceServiceCountBuffer) {
	CHECK_INITIALIZED(staticInitializedFlag);

	(* inpDeviceServiceCountBuffer) = staticStructuresDynamicDevice->
		serviceCount;

	return NO_ERROR;
}
Beispiel #12
0
/* INFO: */
int ApiDeviceGetUniqueDeviceName(
		const char ** const inpUniqueDeviceNameBuffer) {
	CHECK_INITIALIZED(staticInitializedFlag);

	(* inpUniqueDeviceNameBuffer) = staticStructuresDynamicDevice->
		uniqueDeviceName;

	return NO_ERROR;
}
Beispiel #13
0
/* INFO: */
int DeviceListDestroy() {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListMutexDestroy());

	staticInitializedFlag = false;

	return NO_ERROR;
}
Beispiel #14
0
/* INFO: */
int ApiDeviceDestroy() {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(XmlParserDestroyDynamicStructureDevice(
		staticStructuresDynamicDevice));

	staticInitializedFlag = false;

	return NO_ERROR;
}
Beispiel #15
0
/* INFO: */
int ApiDeviceGetServiceActionCount(
		const unsigned int inpServiceIndex,
		unsigned int * const inpDeviceActionCountBuffer) {
	CHECK_INITIALIZED(staticInitializedFlag);

	(* inpDeviceActionCountBuffer) = staticStructuresDynamicDevice->
		serviceArray[inpServiceIndex].actionCount;

	return NO_ERROR;
}
Beispiel #16
0
/* INFO: */
int ApiDeviceGetServiceId(
		const unsigned int inpServiceIndex,
		const char ** const inpServiceIdBuffer) {
	CHECK_INITIALIZED(staticInitializedFlag);

	(* inpServiceIdBuffer) = staticStructuresDynamicDevice->
		serviceArray[inpServiceIndex].serviceId;

	return NO_ERROR;
}
Beispiel #17
0
/* INFO: */
static int ApiDeviceSetActionFunction(
		const unsigned int inpServiceIndex,
		const unsigned int inpActionIndex,
		const StructuresDynamicActionFunction inpActionFunction) {
	CHECK_INITIALIZED(staticInitializedFlag);

	staticStructuresDynamicDevice->serviceArray[inpServiceIndex].
		actionArray[inpActionIndex].function = inpActionFunction;

	return NO_ERROR;
}
Beispiel #18
0
/* INFO: */
static int DeviceListDestroyNode(StructuresDynamicNode * const inpNode) {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListUnsubscribeServices(inpNode->device->serviceArray,
		inpNode->device->serviceCount));
	CHECK(XmlParserDestroyDynamicStructureDevice(inpNode->device));

	free(inpNode->descriptionDocumentURL);
	free(inpNode);

	return NO_ERROR;
}
Beispiel #19
0
/* INFO: */
int ApiDeviceGetServiceStateVariableValueArray(
		const unsigned int inpServiceIndex,
		char * const ** const inpStateVariableValuesBuffer) {
	CHECK_INITIALIZED(staticInitializedFlag);

	/* TODO: Why casting is used? */
	(* inpStateVariableValuesBuffer) = (char ** const)
		staticStructuresDynamicDevice->serviceArray[inpServiceIndex].
		stateVariableValueArray;

	return NO_ERROR;	
}
Beispiel #20
0
/* TODO: This is logic funtion. This function should not be stored in this
         scope. */
int DeviceListRefresh() {
	const char * localDeviceType = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListRemoveAll());
	CHECK(ApiControllerGetDeviceType(& localDeviceType));
	CHECK(HandleControllerSearchAsync(localDeviceType,
		DEVICE_LIST_SEARCH_TIME_INTERVAL));

	return NO_ERROR;
}
Beispiel #21
0
/* INFO: */
int ApiDeviceGetServiceActionFunction(
		const unsigned int inpServiceIndex,
		const unsigned int inpActionIndex,
		StructuresDynamicActionFunction * const inpActionFunctionBuffer) {
	CHECK_INITIALIZED(staticInitializedFlag);

	(* inpActionFunctionBuffer) = staticStructuresDynamicDevice->
		serviceArray[inpServiceIndex].actionArray[inpActionIndex].
		function;

	return NO_ERROR;
}
Beispiel #22
0
/* INFO: */
int DeviceListRemoveDevice(const char * const inpUniqueDeviceName) {
	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListMutexLock());
	{
		CHECK(DeviceListRemoveNode(inpUniqueDeviceName));
	}
	CHECK(DeviceListMutexUnlock());

	//CHECK(DeviceListPrintList());

	return NO_ERROR;
}
Beispiel #23
0
/* INFO: */
static int DeviceListUnsubscribeServices(
		StructuresDynamicService * const inpServiceArray,
		const unsigned int inpServiceCount) {
	unsigned int localServiceIndex = { 0 };
	Upnp_SID * localSubscriptionId = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);
	
	for(; localServiceIndex < inpServiceCount; ++localServiceIndex) {
		localSubscriptionId = (& inpServiceArray[localServiceIndex].
			subscriptionId);
		
		CHECK(HandleControllerUnsubscribe(* localSubscriptionId));
	}

	return NO_ERROR;
}
Beispiel #24
0
// Release all data allocated by the runtime.
//
// The OpenGL context itself is generally managed by the host application, so
// we leave it untouched.
EXPORT void halide_opengl_release(void *user_context) {
    CHECK_INITIALIZED();
    ST.DeleteShader(ST.vertex_shader_id);
    ST.DeleteFramebuffers(1, &ST.framebuffer_id);

    HalideOpenGLKernel *cur = ST.kernels;
    while (cur) {
        HalideOpenGLKernel *next = cur->next;
        halide_opengl_delete_kernel(user_context, cur);
        cur = next;
    }

    // Delete all textures that were allocated by us.
    HalideOpenGLTexture *tex = ST.textures;
    int freed_textures = 0;
    while (tex) {
        HalideOpenGLTexture *next = tex->next;
        if (tex->halide_allocated) {
            ST.DeleteTextures(1, &tex->id);
            CHECK_GLERROR();
            freed_textures++;
        }
        free(tex);
        tex = next;
    }
#ifdef DEBUG
    if (freed_textures > 0) {
        halide_printf(user_context,
            "halide_opengl_release: deleted %d dangling texture(s).\n",
            freed_textures);
    }
#endif

    ST.DeleteBuffers(1, &ST.vertex_buffer);
    ST.DeleteBuffers(1, &ST.element_buffer);

    ST.vertex_shader_id = 0;
    ST.framebuffer_id = 0;
    ST.vertex_buffer = 0;
    ST.element_buffer = 0;
    ST.kernels = NULL;
    ST.textures = NULL;
    ST.initialized = false;
}
Beispiel #25
0
/* INFO: */
int ApiDeviceSetServiceStateVariableValue(
		const unsigned int inpServiceIndex,
		const unsigned int inpStateVariableIndex,
		const char * const inpStateVariableValue) {
	char ** localStateVariableValue = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	localStateVariableValue = (& staticStructuresDynamicDevice->
		serviceArray[inpServiceIndex].
		stateVariableValueArray[inpStateVariableIndex]);

	free(* localStateVariableValue);

	(* localStateVariableValue) = UtilsStringDuplicate(
		inpStateVariableValue);

	return NO_ERROR;
}
Beispiel #26
0
/* TODO: This function should be moved to more "logic" module (maybe
         core_controller)*/
int DeviceListCheckIfWantedDeviceType(const char * const inpDeviceType,
		bool * const inpWantedFlag) {
	const char * localDeviceType = { 0 };
	bool localWantedFlag = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(ApiControllerGetDeviceType(& localDeviceType));

	if(! strcmp(inpDeviceType, localDeviceType)) {
		localWantedFlag = true;
	}
	else {
		localWantedFlag = false;
	}

	(* inpWantedFlag) = localWantedFlag;

	return NO_ERROR;
}
Beispiel #27
0
/* INFO: */
static int DeviceListSubscribeServices(
		StructuresDynamicService * const inpServiceArray,
		const unsigned int inpServiceCount,
		const unsigned int inpAdvertisementTimeout) {
	unsigned int localServiceIndex = { 0 };
	char * localEventSubUrl = { 0 };
	Upnp_SID * localSubscriptionId = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	for(; localServiceIndex < inpServiceCount; ++localServiceIndex) {
		localEventSubUrl = inpServiceArray[localServiceIndex].
			eventSubURL;
		localSubscriptionId = (& inpServiceArray[localServiceIndex].
			subscriptionId);
		
		CHECK(HandleControllerSubscribe(localEventSubUrl,
			inpAdvertisementTimeout, localSubscriptionId));
	}

	return NO_ERROR;
}
Beispiel #28
0
/* INFO: */
static int ApiDeviceBindActions(
		const unsigned int inpServiceIndex,
		const ApiDeviceActionBind * const inpActionsBindArray,
		const unsigned int inpActionCount) {
	unsigned int inpActionIndex = { 0 };
	const char * localActionName = { 0 };
	StructuresDynamicActionFunction localActionFunction = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	for(; inpActionIndex < inpActionCount; ++inpActionIndex) {
		localActionName = inpActionsBindArray[inpActionIndex].
			actionName;
		localActionFunction = inpActionsBindArray[inpActionIndex].
			actionFunction;

		CHECK(ApiDeviceCreateActionBinding(inpServiceIndex,
			localActionName, localActionFunction));
	}

	return NO_ERROR;
}
Beispiel #29
0
/* INFO: */
int DeviceListAddDevice(const char * const inpDescriptionDocumentURL,
		const unsigned int inpAdvertisementTimeout) {
	StructuresDynamicNode * localDeviceNode = { 0 };
	StructuresDynamicDevice * localStructuresDynamicDevice = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	CHECK(DeviceListMutexLock());
	{
		CHECK(XmlParserCreateDynamicStructureDeviceOnline(
			inpDescriptionDocumentURL,
			(& localStructuresDynamicDevice)));
		CHECK(DeviceListCreateNode((& localDeviceNode),
			inpDescriptionDocumentURL, inpAdvertisementTimeout,
			localStructuresDynamicDevice));
		CHECK(DeviceListAddNode(localDeviceNode));
	}
	CHECK(DeviceListMutexUnlock());

	//CHECK(DeviceListPrintList());

	return NO_ERROR;
}
Beispiel #30
0
/* INFO: */
static int ApiDeviceBindServices(
		const ApiDeviceServiceBind * const inpServicesBindArray,
		const unsigned int inpServiceCount) {
	unsigned int inpServiceIndex = { 0 };
	const ApiDeviceActionBind * localActionsBindArray = { 0 };
	unsigned int localActionsBindArraySize = { 0 };

	CHECK_INITIALIZED(staticInitializedFlag);

	for(; inpServiceIndex < inpServiceCount; ++inpServiceIndex) {
		localActionsBindArray =
			inpServicesBindArray[inpServiceIndex].
			actionsBindArray;
		localActionsBindArraySize =
			inpServicesBindArray[inpServiceIndex].
			actionsBindArraySize;

		CHECK(ApiDeviceBindActions(inpServiceIndex,
			localActionsBindArray, localActionsBindArraySize));
	}

	return NO_ERROR;
}