Example #1
0
void tsmf_stream_free(TSMF_STREAM* stream)
{
	TSMF_PRESENTATION* presentation = stream->presentation;

	tsmf_stream_stop(stream);
	tsmf_stream_flush(stream);

	WaitForSingleObject(presentation->mutex, INFINITE);
	list_remove(presentation->stream_list, stream);
	ReleaseMutex(presentation->mutex);

	Queue_Free(stream->sample_list);
	Queue_Free(stream->sample_ack_list);

	if (stream->decoder)
	{
		stream->decoder->Free(stream->decoder);
		stream->decoder = 0;
	}

	SetEvent(stream->thread);

	free(stream);
	stream = 0;
}
Example #2
0
void _tsmf_stream_free(TSMF_STREAM *stream)
{
	assert(stream);
	tsmf_stream_stop(stream);
	tsmf_stream_flush(stream);
	SetEvent(stream->stopEvent);

	if (stream->play_thread)
	{
		WaitForSingleObject(stream->play_thread, INFINITE);
		CloseHandle(stream->play_thread);
		stream->play_thread = NULL;
	}

	if (stream->ack_thread)
	{
		WaitForSingleObject(stream->ack_thread, INFINITE);
		CloseHandle(stream->ack_thread);
		stream->ack_thread = NULL;
	}

	Queue_Free(stream->sample_list);
	Queue_Free(stream->sample_ack_list);

	if (stream->decoder && stream->decoder->Free)
	{
		stream->decoder->Free(stream->decoder);
		stream->decoder = NULL;
	}

	CloseHandle(stream->stopEvent);
	CloseHandle(stream->ready);
	memset(stream, 0, sizeof(TSMF_STREAM));
	free(stream);
}
Example #3
0
void transport_free(rdpTransport* transport)
{
	if (transport != NULL)
	{
		if (transport->ReceiveBuffer)
			stream_free(transport->ReceiveBuffer);

		stream_free(transport->ReceiveStream);
		stream_free(transport->SendStream);
		CloseHandle(transport->ReceiveEvent);

		if (transport->TlsIn)
			tls_free(transport->TlsIn);

		if (transport->TlsOut != transport->TlsIn)
			tls_free(transport->TlsOut);

		tcp_free(transport->TcpIn);

		if (transport->TcpOut != transport->TcpIn)
			tcp_free(transport->TcpOut);

		tsg_free(transport->tsg);

		Queue_Free(transport->ReceivePool);
		Queue_Free(transport->ReceiveQueue);

		free(transport);
	}
}
Example #4
0
int rpc_client_free(rdpRpc* rpc)
{
	RpcClient* client;

	client = rpc->client;

	if (client)
	{
		Queue_Free(client->SendQueue);

		if (client->RecvFrag)
			rpc_fragment_free(client->RecvFrag);

		Queue_Free(client->FragmentPool);
		Queue_Free(client->FragmentQueue);

		if (client->pdu)
			rpc_pdu_free(client->pdu);

		Queue_Free(client->ReceivePool);
		Queue_Free(client->ReceiveQueue);

		ArrayList_Free(client->ClientCallList);

		CloseHandle(client->StopEvent);
		CloseHandle(client->PduSentEvent);

		CloseHandle(client->Thread);

		free(client);
	}

	return 0;
}
Example #5
0
void _tsmf_stream_free(void* obj)
{
	TSMF_STREAM* stream = (TSMF_STREAM*)obj;

	if (!stream)
		return;

	tsmf_stream_stop(stream);
	SetEvent(stream->stopEvent);

	if (stream->play_thread)
	{
		if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED)
		{
			WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", GetLastError());
			return;
		}

		CloseHandle(stream->play_thread);
		stream->play_thread = NULL;
	}

	if (stream->ack_thread)
	{
		if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED)
		{
			WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", GetLastError());
			return;
		}

		CloseHandle(stream->ack_thread);
		stream->ack_thread = NULL;
	}

	Queue_Free(stream->sample_list);
	Queue_Free(stream->sample_ack_list);

	if (stream->decoder && stream->decoder->Free)
	{
		stream->decoder->Free(stream->decoder);
		stream->decoder = NULL;
	}

	CloseHandle(stream->stopEvent);
	CloseHandle(stream->ready);
	ZeroMemory(stream, sizeof(TSMF_STREAM));
	free(stream);
}
Example #6
0
File: pool.c Project: cgull/FreeRDP
VOID CloseThreadpool(PTP_POOL ptpp)
{
#ifdef _WIN32
    module_init();

    if (pCloseThreadpool)
        pCloseThreadpool(ptpp);
#else
    SetEvent(ptpp->TerminateEvent);

    ArrayList_Free(ptpp->Threads);
    Queue_Free(ptpp->PendingQueue);
    CountdownEvent_Free(ptpp->WorkComplete);
    CloseHandle(ptpp->TerminateEvent);

    if (ptpp == &DEFAULT_POOL)
    {
        ptpp->Threads = NULL;
        ptpp->PendingQueue = NULL;
        ptpp->WorkComplete = NULL;
        ptpp->TerminateEvent = NULL;
    }
    else
    {
        free(ptpp);
    }
#endif
}
Example #7
0
static void serial_free(DEVICE* device)
{
	SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device;

	DEBUG_SVC("freeing device");

	/* Stop thread */
	SetEvent(serial->stopEvent);
	if(serial->mthread)
	{
		TerminateThread(serial->mthread, 0);
		WaitForSingleObject(serial->mthread, INFINITE);
		CloseHandle(serial->mthread);
	}
	WaitForSingleObject(serial->thread, INFINITE);

	serial_tty_free(serial->tty);

	/* Clean up resources */
	Stream_Free(serial->device.data, TRUE);
	Queue_Free(serial->queue);
	list_free(serial->pending_irps);
	CloseHandle(serial->stopEvent);
	CloseHandle(serial->newEvent);
	CloseHandle(serial->thread);
	free(serial);
}
Example #8
0
int TestQueue(int argc, char* argv[])
{
    int item;
    int index;
    int count;
    wQueue* queue;

    queue = Queue_New(TRUE, -1, -1);

    for (index = 1; index <= 10; index++)
    {
        Queue_Enqueue(queue, (void*) (size_t) index);
    }

    count = Queue_Count(queue);

    printf("queue count: %d\n", count);

    for (index = 1; index <= 10; index++)
    {
        item = (int) (size_t) Queue_Dequeue(queue);

        if (item != index)
            return -1;
    }

    Queue_Clear(queue);
    Queue_Free(queue);

    return 0;
}
Example #9
0
static void smartcard_free(DEVICE* device)
{
	SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;

	if (smartcard->IrpQueue)
	{
		if (MessageQueue_PostQuit(smartcard->IrpQueue, 0))
			WaitForSingleObject(smartcard->thread, INFINITE);

		MessageQueue_Free(smartcard->IrpQueue);
		smartcard->IrpQueue = NULL;

		CloseHandle(smartcard->thread);
		smartcard->thread = NULL;
	}

	if (smartcard->device.data)
	{
		Stream_Free(smartcard->device.data, TRUE);
		smartcard->device.data = NULL;
	}

	ListDictionary_Free(smartcard->rgSCardContextList);
	ListDictionary_Free(smartcard->rgOutstandingMessages);
	Queue_Free(smartcard->CompletedIrpQueue);

	if (smartcard->StartedEvent)
	{
		SCardReleaseStartedEvent();
		smartcard->StartedEvent = NULL;
	}

	free(device);
}
Example #10
0
// close the android audio device
void android_CloseRecDevice(OPENSL_STREAM *p)
{
	DEBUG_DVC("p=%p", p);

  if (p == NULL)
    return;

	if (p->queue)
	{
		while (Queue_Count(p->queue) > 0)
		{
			queue_element *e = Queue_Dequeue(p->queue);
			free(e->data);
			free(e);
		}
		Queue_Free(p->queue);
	}

	if (p->next)
	{
		free(p->next->data);
		free(p->next);
	}

	if (p->prep)
	{
		free(p->prep->data);
		free(p->prep);
	}

  openSLDestroyEngine(p);

  free(p);
}
Example #11
0
VOID winpr_CloseThreadpool(PTP_POOL ptpp)
{
#ifdef _WIN32
	InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
	if (pCloseThreadpool)
	{
		pCloseThreadpool(ptpp);
		return;
	}
#endif
	SetEvent(ptpp->TerminateEvent);

	ArrayList_Free(ptpp->Threads);
	Queue_Free(ptpp->PendingQueue);
	CountdownEvent_Free(ptpp->WorkComplete);
	CloseHandle(ptpp->TerminateEvent);

	if (ptpp == &DEFAULT_POOL)
	{
		ptpp->Threads = NULL;
		ptpp->PendingQueue = NULL;
		ptpp->WorkComplete = NULL;
		ptpp->TerminateEvent = NULL;
	}
	else
	{
		free(ptpp);
	}
}
Example #12
0
File: pool.c Project: cgull/FreeRDP
static BOOL InitializeThreadpool(PTP_POOL pool)
{
    int index;
    HANDLE thread;

    if (pool->Threads)
        return TRUE;

    pool->Minimum = 0;
    pool->Maximum = 500;

    if (!(pool->PendingQueue = Queue_New(TRUE, -1, -1)))
        goto fail_queue_new;

    if (!(pool->WorkComplete = CountdownEvent_New(0)))
        goto fail_countdown_event;

    if (!(pool->TerminateEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
        goto fail_terminate_event;

    if (!(pool->Threads = ArrayList_New(TRUE)))
        goto fail_thread_array;

    pool->Threads->object.fnObjectFree = threads_close;

    for (index = 0; index < 4; index++)
    {
        if (!(thread = CreateThread(NULL, 0,
                                    (LPTHREAD_START_ROUTINE) thread_pool_work_func,
                                    (void*) pool, 0, NULL)))
        {
            goto fail_create_threads;
        }

        if (ArrayList_Add(pool->Threads, thread) < 0)
            goto fail_create_threads;
    }

    return TRUE;

fail_create_threads:
    SetEvent(pool->TerminateEvent);
    ArrayList_Free(pool->Threads);
    pool->Threads = NULL;
fail_thread_array:
    CloseHandle(pool->TerminateEvent);
    pool->TerminateEvent = NULL;
fail_terminate_event:
    CountdownEvent_Free(pool->WorkComplete);
    pool->WorkComplete = NULL;
fail_countdown_event:
    Queue_Free(pool->PendingQueue);
    pool->WorkComplete = NULL;
fail_queue_new:

    return FALSE;

}
Example #13
0
void pbrpc_server_free(pbRPCContext* context)
{
	if (!context)
		return;

	CloseHandle(context->stopEvent);
	CloseHandle(context->thread);
	ListDictionary_Free(context->transactions);
	Queue_Free(context->writeQueue);

	free(context);
}
Example #14
0
// close the android audio device
void android_CloseAudioDevice(OPENSL_STREAM* p)
{
	if (p == NULL)
		return;

	openSLDestroyEngine(p);

	if (p->queue)
		Queue_Free(p->queue);

	free(p);
}
Example #15
0
void rfx_context_free(RFX_CONTEXT* context)
{
	free(context->quants);

	Queue_Free(context->priv->TilePool);
	Queue_Free(context->priv->TileQueue);

	rfx_profiler_print(context);
	rfx_profiler_free(context);

	if (context->priv->UseThreads)
	{
		CloseThreadpool(context->priv->ThreadPool);
		DestroyThreadpoolEnvironment(&context->priv->ThreadPoolEnv);
	}

	BufferPool_Free(context->priv->BufferPool);

	free(context->priv);
	free(context);
}
Example #16
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT smartcard_free(DEVICE* device)
{
	UINT error;
	SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;

	/**
	 * Calling smartcard_release_all_contexts to unblock all operations waiting for transactions
	 * to unlock.
	 */

	smartcard_release_all_contexts(smartcard);

	/* Stopping all threads and cancelling all IRPs */

	if (smartcard->IrpQueue)
	{
		if (MessageQueue_PostQuit(smartcard->IrpQueue, 0) && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED))
		{
			error = GetLastError();
			WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
			return error;
		}

		MessageQueue_Free(smartcard->IrpQueue);
		smartcard->IrpQueue = NULL;

		CloseHandle(smartcard->thread);
		smartcard->thread = NULL;
	}

	if (smartcard->device.data)
	{
		Stream_Free(smartcard->device.data, TRUE);
		smartcard->device.data = NULL;
	}

	ListDictionary_Free(smartcard->rgSCardContextList);
	ListDictionary_Free(smartcard->rgOutstandingMessages);
	Queue_Free(smartcard->CompletedIrpQueue);

	if (smartcard->StartedEvent)
	{
		SCardReleaseStartedEvent();
		smartcard->StartedEvent = NULL;
	}

	free(device);

	return CHANNEL_RC_OK;
}
Example #17
0
void rfx_context_free(RFX_CONTEXT* context)
{
	free(context->quants);

	Queue_Free(context->priv->TilePool);
	Queue_Free(context->priv->TileQueue);

	rfx_profiler_print(context);
	rfx_profiler_free(context);

	if (context->priv->UseThreads)
	{
		CloseThreadpool(context->priv->ThreadPool);
		DestroyThreadpoolEnvironment(&context->priv->ThreadPoolEnv);
#ifdef WITH_PROFILER
		fprintf(stderr, "\nWARNING: Profiling results probably unusable with multithreaded RemoteFX codec!\n");
#endif
	}

	BufferPool_Free(context->priv->BufferPool);

	free(context->priv);
	free(context);
}
Example #18
0
static void smartcard_free(DEVICE* device)
{
	SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;

	MessageQueue_PostQuit(smartcard->IrpQueue, 0);
	WaitForSingleObject(smartcard->thread, INFINITE);

	CloseHandle(smartcard->thread);

	Stream_Free(smartcard->device.data, TRUE);

	MessageQueue_Free(smartcard->IrpQueue);
	ListDictionary_Free(smartcard->rgSCardContextList);
	ListDictionary_Free(smartcard->rgOutstandingMessages);
	Queue_Free(smartcard->CompletedIrpQueue);

	free(device);
}
Example #19
0
VideoClientContextPriv *VideoClientContextPriv_new(VideoClientContext *video)
{
	VideoClientContextPriv *ret = calloc(1, sizeof(*ret));
	if (!ret)
		return NULL;

	ret->frames = Queue_New(TRUE, 10, 2);
	if (!ret->frames)
	{
		WLog_ERR(TAG, "unable to allocate frames queue");
		goto error_frames;
	}

	ret->surfacePool = BufferPool_New(FALSE, 0, 16);
	if (!ret->surfacePool)
	{
		WLog_ERR(TAG, "unable to create surface pool");
		goto error_surfacePool;
	}

	if (!InitializeCriticalSectionAndSpinCount(&ret->framesLock, 4 * 1000))
	{
		WLog_ERR(TAG, "unable to initialize frames lock");
		goto error_spinlock;
	}

	ret->video = video;

	 /* don't set to unlimited so that we have the chance to send a feedback in
	  * the first second (for servers that want feedback directly)
	  */
	ret->lastSentRate = 30;
	return ret;

error_spinlock:
	BufferPool_Free(ret->surfacePool);
error_surfacePool:
	Queue_Free(ret->frames);
error_frames:
	free(ret);
	return NULL;
}
Example #20
0
static void VideoClientContextPriv_free(VideoClientContextPriv *priv)
{
	EnterCriticalSection(&priv->framesLock);
	while (Queue_Count(priv->frames))
	{
		VideoFrame *frame = Queue_Dequeue(priv->frames);
		if (frame)
			VideoFrame_free(&frame);
	}

	Queue_Free(priv->frames);
	LeaveCriticalSection(&priv->framesLock);

	DeleteCriticalSection(&priv->framesLock);

	if (priv->currentPresentation)
		PresentationContext_unref(priv->currentPresentation);

	BufferPool_Free(priv->surfacePool);
	free(priv);
}
Example #21
0
AwaError AwaServerSession_Free(AwaServerSession ** session)
{
    AwaError result = AwaError_Success;
    if ((session != NULL) && (*session != NULL))
    {
        SessionCommon_Free(&((*session)->SessionCommon));
        (*session)->SessionCommon = NULL;

        Map_ForEach((*session)->Observers, RemoveObservationLinkToSession, NULL);
        Map_Free(&(*session)->Observers);
        Queue_Free(&((*session)->NotificationQueue));

        // Free the session itself
        LogFree("AwaServerSession", *session);
        Awa_MemSafeFree(*session);
        *session = NULL;
    }
    else
    {
        result = LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL");
    }
    return result;
}
Example #22
0
static UINT smartcard_free_(SMARTCARD_DEVICE* smartcard)
{
	if (!smartcard)
		return CHANNEL_RC_OK;

	if (smartcard->IrpQueue)
	{
		MessageQueue_Free(smartcard->IrpQueue);
		CloseHandle(smartcard->thread);
	}

	Stream_Free(smartcard->device.data, TRUE);
	LinkedList_Free(smartcard->names);
	ListDictionary_Free(smartcard->rgSCardContextList);
	ListDictionary_Free(smartcard->rgOutstandingMessages);
	Queue_Free(smartcard->CompletedIrpQueue);

	if (smartcard->StartedEvent)
		SCardReleaseStartedEvent();

	free(smartcard);
	return CHANNEL_RC_OK;
}
Example #23
0
TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, rdpContext* rdpcontext)
{
	TSMF_STREAM* stream;
	stream = tsmf_stream_find_by_id(presentation, stream_id);

	if (stream)
	{
		WLog_ERR(TAG, "duplicated stream id %d!", stream_id);
		return NULL;
	}

	stream = (TSMF_STREAM*) calloc(1, sizeof(TSMF_STREAM));
	if (!stream)
	{
		WLog_ERR(TAG, "Calloc failed");
		return NULL;
	}

	stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL;
	stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL;
	stream->currentBufferLevel = 1;

	stream->seeking = FALSE;
	stream->eos = 0;
	stream->eos_message_id = 0;
	stream->eos_channel_callback = NULL;
	stream->stream_id = stream_id;
	stream->presentation = presentation;
	stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	if (!stream->stopEvent)
		goto error_stopEvent;
	stream->ready = CreateEvent(NULL, TRUE, TRUE, NULL);
	if (!stream->ready)
		goto error_ready;
	stream->sample_list = Queue_New(TRUE, -1, -1);
	if (!stream->sample_list)
		goto error_sample_list;
	stream->sample_list->object.fnObjectFree = tsmf_sample_free;
	stream->sample_ack_list = Queue_New(TRUE, -1, -1);
	if (!stream->sample_ack_list)
		goto error_sample_ack_list;
	stream->sample_ack_list->object.fnObjectFree = tsmf_sample_free;

	stream->play_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, CREATE_SUSPENDED, NULL);
	stream->ack_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, CREATE_SUSPENDED, NULL);

	stream->rdpcontext = rdpcontext;

	return stream;

error_add:
	SetEvent(stream->stopEvent);
	if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED)
		WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
error_ack_thread:
	SetEvent(stream->stopEvent);
	if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED)
		WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
error_play_thread:
	Queue_Free(stream->sample_ack_list);
error_sample_ack_list:
	Queue_Free(stream->sample_list);
error_sample_list:
	CloseHandle(stream->ready);
error_ready:
	CloseHandle(stream->stopEvent);
error_stopEvent:
	free(stream);
	return NULL;
}
Example #24
0
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	char* name;
	char* path;
	int length, ck;
	RDPDR_SMARTCARD* device;
	SMARTCARD_DEVICE* smartcard;

	device = (RDPDR_SMARTCARD*) pEntryPoints->device;

	name = device->Name;
	path = device->Path;

	smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE));
	if (!smartcard)
		return -1;

	smartcard->device.type = RDPDR_DTYP_SMARTCARD;
	smartcard->device.name = "SCARD";
	smartcard->device.IRPRequest = smartcard_irp_request;
	smartcard->device.Init = smartcard_init;
	smartcard->device.Free = smartcard_free;

	length = strlen(smartcard->device.name);
	smartcard->device.data = Stream_New(NULL, length + 1);
	if (!smartcard->device.data)
		goto error_device_data;

	Stream_Write(smartcard->device.data, "SCARD", 6);

	smartcard->name = NULL;
	smartcard->path = NULL;

	if (path)
	{
		smartcard->path = path;
		smartcard->name = name;
	}
	else if (name)
	{
		if (1 == sscanf(name, "%d", &ck))
			smartcard->path = name;
		else
			smartcard->name = name;
	}

	smartcard->IrpQueue = MessageQueue_New(NULL);
	if (!smartcard->IrpQueue)
		goto error_irp_queue;

	smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1);
	if (!smartcard->CompletedIrpQueue)
		goto error_completed_irp_queue;

	smartcard->rgSCardContextList = ListDictionary_New(TRUE);
	if (!smartcard->rgSCardContextList)
		goto error_context_list;

	ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree =
			(OBJECT_FREE_FN) smartcard_context_free;

	smartcard->rgOutstandingMessages = ListDictionary_New(TRUE);
	if (!smartcard->rgOutstandingMessages)
		goto error_outstanding_messages;

	smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func,
			smartcard, CREATE_SUSPENDED, NULL);
	if (!smartcard->thread)
		goto error_thread;

	pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard);

	ResumeThread(smartcard->thread);

	return 0;

error_thread:
	ListDictionary_Free(smartcard->rgOutstandingMessages);
error_outstanding_messages:
	ListDictionary_Free(smartcard->rgSCardContextList);
error_context_list:
	Queue_Free(smartcard->CompletedIrpQueue);
error_completed_irp_queue:
	MessageQueue_Free(smartcard->IrpQueue);
error_irp_queue:
	Stream_Free(smartcard->device.data, TRUE);
error_device_data:
	free(smartcard);
	return -1;
}
Example #25
0
TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id)
{
	TSMF_STREAM* stream;
	stream = tsmf_stream_find_by_id(presentation, stream_id);

	if (stream)
	{
		WLog_ERR(TAG, "duplicated stream id %d!", stream_id);
		return NULL;
	}

	stream = (TSMF_STREAM*) calloc(1, sizeof(TSMF_STREAM));
	if (!stream)
	{
		WLog_ERR(TAG, "Calloc failed");
		return NULL;
	}

	stream->stream_id = stream_id;
	stream->presentation = presentation;
	stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	if (!stream->stopEvent)
		goto error_stopEvent;
	stream->ready = CreateEvent(NULL, TRUE, TRUE, NULL);
	if (!stream->ready)
		goto error_ready;
	stream->sample_list = Queue_New(TRUE, -1, -1);
	if (!stream->sample_list)
		goto error_sample_list;
	stream->sample_list->object.fnObjectFree = tsmf_sample_free;
	stream->sample_ack_list = Queue_New(TRUE, -1, -1);
	if (!stream->sample_ack_list)
		goto error_sample_ack_list;
	stream->sample_ack_list->object.fnObjectFree = tsmf_sample_free;

	stream->play_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, 0, NULL);
	if (!stream->play_thread)
		goto error_play_thread;
	stream->ack_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, 0, NULL);
	if (!stream->ack_thread)
		goto error_ack_thread;

	if (ArrayList_Add(presentation->stream_list, stream) < 0)
		goto error_add;

	return stream;

error_add:
	SetEvent(stream->stopEvent);
	WaitForSingleObject(stream->ack_thread, INFINITE);
error_ack_thread:
	SetEvent(stream->stopEvent);
	WaitForSingleObject(stream->play_thread, INFINITE);
error_play_thread:
	Queue_Free(stream->sample_ack_list);
error_sample_ack_list:
	Queue_Free(stream->sample_list);
error_sample_list:
	CloseHandle(stream->ready);
error_ready:
	CloseHandle(stream->stopEvent);
error_stopEvent:
	free(stream);
	return NULL;
}
AwaServerSession * AwaServerSession_New(void)
{
    AwaServerSession * session = Awa_MemAlloc(sizeof(*session));
    if (session != NULL)
    {
        memset(session, 0, sizeof(*session));
        session->SessionCommon = SessionCommon_New(SessionType_Server);
        if (session->SessionCommon != NULL)
        {
            session->Observers = Map_New();
            if (session->Observers != NULL)
            {
                session->NotificationQueue = Queue_New();
                if (session->NotificationQueue != NULL)
                {
                    session->ServerEventsCallbackInfo = ServerEventsCallbackInfo_New();
                    if (session->ServerEventsCallbackInfo != NULL)
                    {
                        LogNew("AwaServerSession", session);
                    }
                    else
                    {
                        LogErrorWithEnum(AwaError_OutOfMemory, "Could not create server events");
                        Queue_Free(&session->NotificationQueue);
                        Map_Free(&session->Observers);
                        SessionCommon_Free(&session->SessionCommon);
                        Awa_MemSafeFree(session);
                        session = NULL;
                    }
                }
                else
                {
                    LogErrorWithEnum(AwaError_OutOfMemory, "Could not create notification queue");
                    Map_Free(&session->Observers);
                    SessionCommon_Free(&session->SessionCommon);
                    Awa_MemSafeFree(session);
                    session = NULL;
                }
            }
            else
            {
                LogErrorWithEnum(AwaError_OutOfMemory, "Could not create observer list");
                SessionCommon_Free(&session->SessionCommon);
                Awa_MemSafeFree(session);
                session = NULL;
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_OutOfMemory, "Could not create common session");
            SessionCommon_Free(&session->SessionCommon);
            Awa_MemSafeFree(session);
            session = NULL;
        }
    }
    else
    {
        LogErrorWithEnum(AwaError_OutOfMemory, "Could not create ServerSession");
    }
    return session;
}
Example #27
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	char* name;
	char* path;
	size_t length;
	int ck;
	RDPDR_SMARTCARD* device;
	SMARTCARD_DEVICE* smartcard;
	UINT error = CHANNEL_RC_NO_MEMORY;

	device = (RDPDR_SMARTCARD*) pEntryPoints->device;

	name = device->Name;
	path = device->Path;

	smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE));
	if (!smartcard)
	{
		WLog_ERR(TAG, "calloc failed!");
		return CHANNEL_RC_NO_MEMORY;
	}

	smartcard->device.type = RDPDR_DTYP_SMARTCARD;
	smartcard->device.name = "SCARD";
	smartcard->device.IRPRequest = smartcard_irp_request;
	smartcard->device.Init = smartcard_init;
	smartcard->device.Free = smartcard_free;
	smartcard->rdpcontext = pEntryPoints->rdpcontext;

	length = strlen(smartcard->device.name);
	smartcard->device.data = Stream_New(NULL, length + 1);
	if (!smartcard->device.data)
	{
		WLog_ERR(TAG, "Stream_New failed!");
		goto error_device_data;
	}

	Stream_Write(smartcard->device.data, "SCARD", 6);

	smartcard->name = NULL;
	smartcard->path = NULL;

	if (path)
	{
		smartcard->path = path;
		smartcard->name = name;
	}
	else if (name)
	{
		if (1 == sscanf(name, "%d", &ck))
			smartcard->path = name;
		else
			smartcard->name = name;
	}

	smartcard->IrpQueue = MessageQueue_New(NULL);
	if (!smartcard->IrpQueue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		goto error_irp_queue;
	}


	smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1);
	if (!smartcard->CompletedIrpQueue)
	{
		WLog_ERR(TAG, "Queue_New failed!");
		goto error_completed_irp_queue;
	}

	smartcard->rgSCardContextList = ListDictionary_New(TRUE);
	if (!smartcard->rgSCardContextList)
	{
		WLog_ERR(TAG, "ListDictionary_New failed!");
		goto error_context_list;
	}

	ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree =
			(OBJECT_FREE_FN) smartcard_context_free;

	smartcard->rgOutstandingMessages = ListDictionary_New(TRUE);
	if (!smartcard->rgOutstandingMessages)
	{
		WLog_ERR(TAG, "ListDictionary_New failed!");
		goto error_outstanding_messages;
	}

	if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard)))
	{
		WLog_ERR(TAG, "RegisterDevice failed!");
		goto error_outstanding_messages;
	}


	smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func,
			smartcard, CREATE_SUSPENDED, NULL);
	if (!smartcard->thread)
	{
		WLog_ERR(TAG, "ListDictionary_New failed!");
		error = ERROR_INTERNAL_ERROR;
		goto error_thread;
	}

	ResumeThread(smartcard->thread);

	return CHANNEL_RC_OK;

error_thread:
	ListDictionary_Free(smartcard->rgOutstandingMessages);
error_outstanding_messages:
	ListDictionary_Free(smartcard->rgSCardContextList);
error_context_list:
	Queue_Free(smartcard->CompletedIrpQueue);
error_completed_irp_queue:
	MessageQueue_Free(smartcard->IrpQueue);
error_irp_queue:
	Stream_Free(smartcard->device.data, TRUE);
error_device_data:
	free(smartcard);
	return error;
}