示例#1
0
// puts a buffer of size samples to the device
int android_AudioOut(OPENSL_STREAM* p, const short* buffer, int size)
{
	assert(p);
	assert(buffer);
	assert(size > 0);

	/* Assure, that the queue is not full. */
	if (p->queuesize <= Queue_Count(p->queue)
	    && WaitForSingleObject(p->queue->event, INFINITE) == WAIT_FAILED)
	{
		DEBUG_SND("WaitForSingleObject failed!");
		return -1;
	}

	void* data = calloc(size, sizeof(short));

	if (!data)
	{
		DEBUG_SND("unable to allocate a buffer");
		return -1;
	}

	memcpy(data, buffer, size * sizeof(short));
	Queue_Enqueue(p->queue, data);
	(*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue,
	                                   data, sizeof(short) * size);
	return size;
}
示例#2
0
文件: rpc.c 项目: awakecoding/FreeRDS
void pbrcp_call_method_async(pbRPCContext* context, UINT32 type, pbRPCPayload* request,
		pbRpcResponseCallback callback, void *callback_args)
{
	UINT32 tag;
	pbRPCTransaction* ta;
	FDSAPI_MSG_PACKET* msg;

	if (!context->isConnected)
	{
		callback(PBRCP_TRANSPORT_ERROR, 0, callback_args);
		return;
	}

	ta = (pbRPCTransaction*) calloc(1, sizeof(pbRPCTransaction));
	ta->freeAfterResponse = TRUE;
	ta->responseCallback = callback;
	ta->callbackArg = callback_args;

	tag = pbrpc_getTag(context);

	msg = pbrpc_message_new();

	msg->callId = tag;
	msg->status = FDSAPI_STATUS_SUCCESS;
	msg->buffer = request->buffer;
	msg->length = request->length;
	msg->msgType = FDSAPI_REQUEST_ID(type);

	ListDictionary_Add(context->transactions, (void*)((UINT_PTR)(msg->callId)), ta);
	Queue_Enqueue(context->writeQueue, msg);
}
示例#3
0
// this callback handler is called every time a buffer finishes recording
void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
{
	queue_element *e;

  OPENSL_STREAM *p = (OPENSL_STREAM *) context;
	
	DEBUG_DVC("p=%p", p);

	assert(p);
	assert(p->next);
	assert(p->prep);
	assert(p->queue);

	e = calloc(1, sizeof(queue_element));
	e->data = calloc(p->buffersize, p->bits_per_sample / 8);
	e->size = p->buffersize * p->bits_per_sample / 8;

	Queue_Enqueue(p->queue, p->next);
	p->next = p->prep;
	p->prep = e;

  (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, 
			e->data, e->size);

}
示例#4
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;
}
示例#5
0
void tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pChannelCallback,
	UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions,
	UINT32 data_size, BYTE* data)
{
	TSMF_SAMPLE* sample;

	WaitForSingleObject(tsmf_mutex, INFINITE);
	
	if (TERMINATING)
	{
		ReleaseMutex(tsmf_mutex);
		return;
	}
	
	ReleaseMutex(tsmf_mutex);

	sample = (TSMF_SAMPLE*) malloc(sizeof(TSMF_SAMPLE));
	ZeroMemory(sample, sizeof(TSMF_SAMPLE));

	sample->sample_id = sample_id;
	sample->start_time = start_time;
	sample->end_time = end_time;
	sample->duration = duration;
	sample->extensions = extensions;
	sample->stream = stream;
	sample->channel_callback = pChannelCallback;
	sample->data_size = data_size;
	sample->data = malloc(data_size + TSMF_BUFFER_PADDING_SIZE);
	ZeroMemory(sample->data, data_size + TSMF_BUFFER_PADDING_SIZE);
	CopyMemory(sample->data, data, data_size);

	Queue_Enqueue(stream->sample_list, sample);
}
示例#6
0
static BOOL tsmf_sample_queue_ack(TSMF_SAMPLE* sample)
{
	if (!sample)
		return FALSE;

	if (!sample->stream)
		return FALSE;

	return Queue_Enqueue(sample->stream->sample_ack_list, sample);
}
示例#7
0
static void tsmf_sample_queue_ack(TSMF_SAMPLE* sample)
{
	if (!sample)
		return;

	if (!sample->stream)
		return;

	Queue_Enqueue(sample->stream->sample_ack_list, sample);
}
示例#8
0
文件: main.c 项目: leolimabh/qwoma
void queueTest()
{
    uint32_t i;
    char text[20];

    for (i = 0; i < 30; i++)
    {
        Queue_Enqueue(&queue, sprintf(text, "Entry [%d]", i), text);
        Queue_Enqueue(&queue2, sprintf(text, "Entry [%d]", i), text);
    }

    printf("First queue[%d][%d]:\n", Queue_MaxQueueSize(&queue),
           Queue_MaxStrSize(&queue));
    while (Queue_HasNext(&queue))
        printf("%s\n", Queue_Dequeue(&queue));

    printf("Second queue[%d][%d]:\n", Queue_MaxQueueSize(&queue2),
           Queue_MaxStrSize(&queue2));
    while (Queue_HasNext(&queue2))
        printf("%s\n", Queue_Dequeue(&queue2));
}
示例#9
0
void* smartcard_process_irp_worker_proc(IRP* irp)
{
	SMARTCARD_DEVICE* smartcard;

	smartcard = (SMARTCARD_DEVICE*) irp->device;

	smartcard_irp_device_control(smartcard, irp);

	Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp);

	ExitThread(0);
	return NULL;
}
示例#10
0
int d(int mat[], int i, int j, int n, int m) {
    int mn = m * n;
    int iter;
    int ans = 0;
    int c;
    if (mat[i * m + j] == 1) {
        return 0;
    }
    int mark[34225];
    for (iter = 0; iter < 34225; iter++) {
        mark[iter] = 0;
    }
    struct Queue* Q = Queue_Create();
    Queue_Enqueue(Q, i * m + j);
    Queue_Enqueue(Q, -1);
    mark[i * m + j] += 1;
    while (1) {
        c = Queue_Dequeue(Q);
        if (c == -1) {
            Queue_Enqueue(Q, -1);
            ans += 1;
            continue;
        }
        if ((c % m) && (!mark[c - 1])) {
            if (mat[c - 1] == 1) {
                return ans + 1;
            }
            Queue_Enqueue(Q, c - 1);
            mark[c - 1] += 1;
        }
        if (((c + 1) % m) && (!mark[c + 1])) {
            if (mat[c + 1] == 1) {
                return ans + 1;
            }
            Queue_Enqueue(Q, c + 1);
            mark[c + 1] += 1;
        }
        if (((0 <= (c + m)) && ((c + m) < mn)) && (!mark[c + m])) {
            if (mat[c + m] == 1) {
                return ans + 1;
            }
            Queue_Enqueue(Q, c + m);
            mark[c + m] += 1;
        }
        if (((0 <= (c - m)) && ((c - m) < mn)) && (!mark[c - m])) {
            if (mat[c - m] == 1) {
                return ans + 1;
            }
            Queue_Enqueue(Q, c - m);
            mark[c - m] += 1;
        }
    }
}
示例#11
0
int main() {
    queue_t *q = (queue_t*)malloc(sizeof(queue_t));
    Queue_Init(q);

    int i, t;
    for (i = 0; i < 20; i++) {
        Queue_Enqueue(q, i);
        printf("Enqueue: %d\n", i);
    }
    for (i = 0; i < 10; i++) {
        Queue_Dequeue(q, &t);
        printf("Dequeue: %d\n", t);
    }

    return 0;
}
void *ContextManager_Consumer(void *_self)
{
      ContextManager *self = (ContextManager*)_self;
	  Queue *q = self->incoming_queue;
      while(true)
	  {
		  while(Queue_Empty(q))
			  pthread_yield();
		  void *data = Queue_Dequeue(q);
		  if(data == NULL)
			  break;
		  printf("Enqueueing data!\n");
		  Queue_Enqueue(self->outgoing_queue, data);
	  }
	  printf("Consumer queue shut down\n");
      return NULL;
}
示例#13
0
int rpc_send_enqueue_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
{
	RPC_PDU* pdu;

	pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
	pdu->s = Stream_New(buffer, length);

	Queue_Enqueue(rpc->client->SendQueue, pdu);

	if (rpc->client->SynchronousSend)
	{
		WaitForSingleObject(rpc->client->PduSentEvent, INFINITE);
		ResetEvent(rpc->client->PduSentEvent);
	}

	return 0;
}
示例#14
0
BOOL tsmf_stream_push_sample(TSMF_STREAM* stream,
                             IWTSVirtualChannelCallback* pChannelCallback,
                             UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration,
                             UINT32 extensions,
                             UINT32 data_size, BYTE* data)
{
	TSMF_SAMPLE* sample;
	SetEvent(stream->ready);

	if (TERMINATING)
		return TRUE;

	sample = (TSMF_SAMPLE*) calloc(1, sizeof(TSMF_SAMPLE));

	if (!sample)
	{
		WLog_ERR(TAG, "calloc sample failed!");
		return FALSE;
	}

	sample->sample_id = sample_id;
	sample->start_time = start_time;
	sample->end_time = end_time;
	sample->duration = duration;
	sample->extensions = extensions;

	if ((sample->extensions & 0x00000080) || (sample->extensions & 0x00000040))
		sample->invalidTimestamps = TRUE;
	else
		sample->invalidTimestamps = FALSE;

	sample->stream = stream;
	sample->channel_callback = pChannelCallback;
	sample->data_size = data_size;
	sample->data = calloc(1, data_size + TSMF_BUFFER_PADDING_SIZE);

	if (!sample->data)
	{
		WLog_ERR(TAG, "calloc sample->data failed!");
		free(sample);
		return FALSE;
	}

	CopyMemory(sample->data, data, data_size);
	return Queue_Enqueue(stream->sample_list, sample);
}
示例#15
0
void* smartcard_process_irp_worker_proc(SMARTCARD_OPERATION* operation)
{
	IRP* irp;
	UINT32 status;
	SMARTCARD_DEVICE* smartcard;

	irp = operation->irp;
	smartcard = (SMARTCARD_DEVICE*) irp->device;

	status = smartcard_irp_device_control_call(smartcard, operation);

	Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp);

	free(operation);

	ExitThread(0);
	return NULL;
}
示例#16
0
void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
{
	DWORD nCount;
	DWORD status;
	HANDLE hEvents[2];
	wMessage message;
	SMARTCARD_DEVICE* smartcard;
	SMARTCARD_OPERATION* operation;

	smartcard = pContext->smartcard;

	nCount = 0;
	hEvents[nCount++] = MessageQueue_Event(pContext->IrpQueue);

	while (1)
	{
		status = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);

		if (WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0) == WAIT_OBJECT_0)
		{
			if (!MessageQueue_Peek(pContext->IrpQueue, &message, TRUE))
				break;

			if (message.id == WMQ_QUIT)
				break;

			operation = (SMARTCARD_OPERATION*) message.wParam;

			if (operation)
			{
				status = smartcard_irp_device_control_call(smartcard, operation);

				Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) operation->irp);

				free(operation);
			}
		}
	}

	ExitThread(0);
	return NULL;
}
示例#17
0
int rpc_send_enqueue_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
{
	RPC_PDU* pdu;
	int status;
	pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));

	if (!pdu)
	{
		free(buffer);
		return -1;
	}

	pdu->s = Stream_New(buffer, length);

	if (!pdu->s)
		goto out_free;

	if (!Queue_Enqueue(rpc->client->SendQueue, pdu))
		goto out_free_stream;

	if (rpc->client->SynchronousSend)
	{
		status = WaitForSingleObject(rpc->client->PduSentEvent, SYNCHRONOUS_TIMEOUT);

		if (status == WAIT_TIMEOUT)
		{
			WLog_ERR(TAG, "timed out waiting for pdu sent event %p", rpc->client->PduSentEvent);
			return -1;
		}

		ResetEvent(rpc->client->PduSentEvent);
	}

	return 0;
out_free_stream:
	Stream_Free(pdu->s, TRUE);
out_free:
	free(pdu);
	return -1;
}
示例#18
0
void tsmf_stream_push_sample(TSMF_STREAM *stream, IWTSVirtualChannelCallback *pChannelCallback,
							 UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions,
							 UINT32 data_size, BYTE *data)
{
	TSMF_SAMPLE *sample;
	SetEvent(stream->ready);

	if (TERMINATING)
		return;

	sample = (TSMF_SAMPLE *) calloc(1, sizeof(TSMF_SAMPLE));

	if (!sample)
	{
		CLOG_ERR("calloc failed!");
		return;
	}

	sample->sample_id = sample_id;
	sample->start_time = start_time;
	sample->end_time = end_time;
	sample->duration = duration;
	sample->extensions = extensions;
	sample->stream = stream;
	sample->channel_callback = pChannelCallback;
	sample->data_size = data_size;
	sample->data = calloc(1, data_size + TSMF_BUFFER_PADDING_SIZE);

	if (!sample->data)
	{
		CLOG_ERR("calloc failed!");
		free(sample);
		return;
	}

	CopyMemory(sample->data, data, data_size);
	Queue_Enqueue(stream->sample_list, sample);
}
示例#19
0
VOID SubmitThreadpoolWork(PTP_WORK pwk)
{
#ifdef _WIN32
	module_init();

	if (pSubmitThreadpoolWork)
		pSubmitThreadpoolWork(pwk);

#else
	PTP_POOL pool;
	PTP_CALLBACK_INSTANCE callbackInstance;
	pool = pwk->CallbackEnvironment->Pool;
	callbackInstance = (PTP_CALLBACK_INSTANCE) malloc(sizeof(TP_CALLBACK_INSTANCE));

	if (callbackInstance)
	{
		callbackInstance->Work = pwk;
		CountdownEvent_AddCount(pool->WorkComplete, 1);
		Queue_Enqueue(pool->PendingQueue, callbackInstance);
	}

#endif
}
示例#20
0
文件: rfx.c 项目: nour8394/FreeRDP
int rfx_tile_pool_return(RFX_CONTEXT* context, RFX_TILE* tile)
{
	Queue_Enqueue(context->priv->TilePool, tile);
	return 0;
}
示例#21
0
static void serial_irp_request(DEVICE* device, IRP* irp)
{
	SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device;

	Queue_Enqueue(serial->queue, irp);
}
示例#22
0
int rpc_client_on_fragment_received_event(rdpRpc* rpc)
{
	BYTE* buffer;
	UINT32 StubOffset;
	UINT32 StubLength;
	wStream* fragment;
	rpcconn_hdr_t* header;
	freerdp* instance;

	instance = (freerdp*) rpc->transport->settings->instance;

	if (!rpc->client->pdu)
		rpc->client->pdu = rpc_client_receive_pool_take(rpc);

	fragment = Queue_Dequeue(rpc->client->FragmentQueue);

	buffer = (BYTE*) Stream_Buffer(fragment);
	header = (rpcconn_hdr_t*) Stream_Buffer(fragment);

	if (rpc->State < RPC_CLIENT_STATE_CONTEXT_NEGOTIATED)
	{
		rpc->client->pdu->Flags = 0;
		rpc->client->pdu->CallId = header->common.call_id;

		Stream_EnsureCapacity(rpc->client->pdu->s, Stream_Length(fragment));
		Stream_Write(rpc->client->pdu->s, buffer, Stream_Length(fragment));
		Stream_Length(rpc->client->pdu->s) = Stream_GetPosition(rpc->client->pdu->s);

		rpc_client_fragment_pool_return(rpc, fragment);

		Queue_Enqueue(rpc->client->ReceiveQueue, rpc->client->pdu);
		SetEvent(rpc->transport->ReceiveEvent);
		rpc->client->pdu = NULL;

		return 0;
	}

	if (header->common.ptype == PTYPE_RTS)
	{
		if (rpc->VirtualConnection->State >= VIRTUAL_CONNECTION_STATE_OPENED)
		{
			//fprintf(stderr, "Receiving Out-of-Sequence RTS PDU\n");
			rts_recv_out_of_sequence_pdu(rpc, buffer, header->common.frag_length);

			rpc_client_fragment_pool_return(rpc, fragment);
		}
		else
		{
			fprintf(stderr, "warning: unhandled RTS PDU\n");
		}

		return 0;
	}
	else if (header->common.ptype == PTYPE_FAULT)
	{
		rpc_recv_fault_pdu(header);
		return -1;
	}

	if (header->common.ptype != PTYPE_RESPONSE)
	{
		fprintf(stderr, "Unexpected RPC PDU type: %d\n", header->common.ptype);
		return -1;
	}

	rpc->VirtualConnection->DefaultOutChannel->BytesReceived += header->common.frag_length;
	rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow -= header->common.frag_length;

	if (!rpc_get_stub_data_info(rpc, buffer, &StubOffset, &StubLength))
	{
		fprintf(stderr, "rpc_recv_pdu_fragment: expected stub\n");
		return -1;
	}

	if (StubLength == 4)
	{
		//fprintf(stderr, "Ignoring TsProxySendToServer Response\n");
		printf("Got stub length 4 with flags %d and callid %d\n", header->common.pfc_flags, header->common.call_id);

		/* received a disconnect request from the server? */
		if ((header->common.call_id == rpc->PipeCallId) && (header->common.pfc_flags & PFC_LAST_FRAG))
		{
			TerminateEventArgs e;

			instance->context->rdp->disconnect = TRUE;
			rpc->transport->tsg->state = TSG_STATE_TUNNEL_CLOSE_PENDING;

			EventArgsInit(&e, "freerdp");
			e.code = 0;
			PubSub_OnTerminate(instance->context->pubSub, instance->context, &e);
		}

		rpc_client_fragment_pool_return(rpc, fragment);
		return 0;
	}

	Stream_EnsureCapacity(rpc->client->pdu->s, header->response.alloc_hint);
	buffer = (BYTE*) Stream_Buffer(fragment);
	header = (rpcconn_hdr_t*) Stream_Buffer(fragment);

	if (rpc->StubFragCount == 0)
		rpc->StubCallId = header->common.call_id;

	if (rpc->StubCallId != header->common.call_id)
	{
		fprintf(stderr, "invalid call_id: actual: %d, expected: %d, frag_count: %d\n",
				rpc->StubCallId, header->common.call_id, rpc->StubFragCount);
	}

	Stream_Write(rpc->client->pdu->s, &buffer[StubOffset], StubLength);
	rpc->StubFragCount++;

	rpc_client_fragment_pool_return(rpc, fragment);

	if (rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow < (rpc->ReceiveWindow / 2))
	{
		//fprintf(stderr, "Sending Flow Control Ack PDU\n");
		rts_send_flow_control_ack_pdu(rpc);
	}

	/**
	 * If alloc_hint is set to a nonzero value and a request or a response is fragmented into multiple
	 * PDUs, implementations of these extensions SHOULD set the alloc_hint field in every PDU to be the
	 * combined stub data length of all remaining fragment PDUs.
	 */

	if (header->response.alloc_hint == StubLength)
	{
		rpc->client->pdu->Flags = RPC_PDU_FLAG_STUB;
		rpc->client->pdu->CallId = rpc->StubCallId;

		Stream_Length(rpc->client->pdu->s) = Stream_GetPosition(rpc->client->pdu->s);

		rpc->StubFragCount = 0;
		rpc->StubCallId = 0;

		Queue_Enqueue(rpc->client->ReceiveQueue, rpc->client->pdu);

		rpc->client->pdu = NULL;

		return 0;
	}

	return 0;
}
示例#23
0
int rpc_client_receive_pool_return(rdpRpc* rpc, RPC_PDU* pdu)
{
	Queue_Enqueue(rpc->client->ReceivePool, pdu);
	return 0;
}
示例#24
0
int rpc_client_fragment_pool_return(rdpRpc* rpc, wStream* fragment)
{
	Queue_Enqueue(rpc->client->FragmentPool, fragment);
	return 0;
}
示例#25
0
void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
{
	DWORD nCount;
	LONG status = 0;
	DWORD waitStatus;
	HANDLE hEvents[2];
	wMessage message;
	SMARTCARD_DEVICE* smartcard;
	SMARTCARD_OPERATION* operation;
	UINT error = CHANNEL_RC_OK;

	smartcard = pContext->smartcard;

	nCount = 0;
	hEvents[nCount++] = MessageQueue_Event(pContext->IrpQueue);

	while (1)
	{
		waitStatus = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);

		if (waitStatus == WAIT_FAILED)
		{
			error = GetLastError();
			WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
			break;
		}

		waitStatus = WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0);

		if (waitStatus == WAIT_FAILED)
		{
			error = GetLastError();
			WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
			break;
		}

		if (waitStatus == WAIT_OBJECT_0)
		{
			if (!MessageQueue_Peek(pContext->IrpQueue, &message, TRUE))
			{
				WLog_ERR(TAG, "MessageQueue_Peek failed!");
				status = ERROR_INTERNAL_ERROR;
				break;
			}


			if (message.id == WMQ_QUIT)
				break;

			operation = (SMARTCARD_OPERATION*) message.wParam;

			if (operation)
			{
				if ((status = smartcard_irp_device_control_call(smartcard, operation)))
				{
					WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu", status);
					break;
				}

				if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) operation->irp))
				{
					WLog_ERR(TAG, "Queue_Enqueue failed!");
					status = ERROR_INTERNAL_ERROR;
					break;

				}

				free(operation);
			}
		}
	}

	if (status && smartcard->rdpcontext)
		setChannelError(smartcard->rdpcontext, error, "smartcard_context_thread reported an error");

	ExitThread((DWORD)status);
	return NULL;
}
示例#26
0
int rpc_client_on_read_event(rdpRpc* rpc)
{
	int position;
	int status = -1;
	rpcconn_common_hdr_t* header;

	if (!rpc->client->RecvFrag)
		rpc->client->RecvFrag = rpc_client_fragment_pool_take(rpc);

	position = Stream_GetPosition(rpc->client->RecvFrag);

	if (Stream_GetPosition(rpc->client->RecvFrag) < RPC_COMMON_FIELDS_LENGTH)
	{
		status = rpc_out_read(rpc, Stream_Pointer(rpc->client->RecvFrag),
				RPC_COMMON_FIELDS_LENGTH - Stream_GetPosition(rpc->client->RecvFrag));

		if (status < 0)
		{
			fprintf(stderr, "rpc_client_frag_read: error reading header\n");
			return -1;
		}

		Stream_Seek(rpc->client->RecvFrag, status);
	}

	if (Stream_GetPosition(rpc->client->RecvFrag) >= RPC_COMMON_FIELDS_LENGTH)
	{
		header = (rpcconn_common_hdr_t*) Stream_Buffer(rpc->client->RecvFrag);

		if (header->frag_length > rpc->max_recv_frag)
		{
			fprintf(stderr, "rpc_client_frag_read: invalid fragment size: %d (max: %d)\n",
					header->frag_length, rpc->max_recv_frag);
			winpr_HexDump(Stream_Buffer(rpc->client->RecvFrag), Stream_GetPosition(rpc->client->RecvFrag));
			return -1;
		}

		if (Stream_GetPosition(rpc->client->RecvFrag) < header->frag_length)
		{
			status = rpc_out_read(rpc, Stream_Pointer(rpc->client->RecvFrag),
					header->frag_length - Stream_GetPosition(rpc->client->RecvFrag));

			if (status < 0)
			{
				fprintf(stderr, "rpc_client_frag_read: error reading fragment body\n");
				return -1;
			}

			Stream_Seek(rpc->client->RecvFrag, status);
		}
	}
	else
	{
		return status;
	}

	if (status < 0)
		return -1;

	status = Stream_GetPosition(rpc->client->RecvFrag) - position;

	if (Stream_GetPosition(rpc->client->RecvFrag) >= header->frag_length)
	{
		/* complete fragment received */

		Stream_Length(rpc->client->RecvFrag) = Stream_GetPosition(rpc->client->RecvFrag);
		Stream_SetPosition(rpc->client->RecvFrag, 0);

		Queue_Enqueue(rpc->client->FragmentQueue, rpc->client->RecvFrag);
		rpc->client->RecvFrag = NULL;

		rpc_client_on_fragment_received_event(rpc);
	}

	return status;
}
void ContextManager_AddTask(ContextManager *self, void *data, void (callback_func)(void*))
{
      Queue_Enqueue(self->incoming_queue, data);
}
void ContextManager_ShutdownQueues(ContextManager *self)
{
      Queue_Enqueue(self->incoming_queue, NULL);
      Queue_Enqueue(self->outgoing_queue, NULL);
}
示例#29
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
UINT smartcard_process_irp(SMARTCARD_DEVICE* smartcard, IRP* irp)
{
	void* key;
	LONG status;
	BOOL asyncIrp = FALSE;
	SMARTCARD_CONTEXT* pContext = NULL;
	SMARTCARD_OPERATION* operation = NULL;

	key = (void*) (size_t) irp->CompletionId;
	if (!ListDictionary_Add(smartcard->rgOutstandingMessages, key, irp))
	{
		WLog_ERR(TAG, "ListDictionary_Add failed!");
		return ERROR_INTERNAL_ERROR;
	}

	if (irp->MajorFunction == IRP_MJ_DEVICE_CONTROL)
	{
		operation = (SMARTCARD_OPERATION*) calloc(1, sizeof(SMARTCARD_OPERATION));

		if (!operation)
		{
			WLog_ERR(TAG, "calloc failed!");
			return CHANNEL_RC_NO_MEMORY;
		}

		operation->irp = irp;

		status = smartcard_irp_device_control_decode(smartcard, operation);

		if (status != SCARD_S_SUCCESS)
		{
			irp->IoStatus = (UINT32)STATUS_UNSUCCESSFUL;

			if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
			{
				WLog_ERR(TAG, "Queue_Enqueue failed!");
				return ERROR_INTERNAL_ERROR;
			}

			return CHANNEL_RC_OK;
		}

		asyncIrp = TRUE;

		/**
		 * The following matches mstsc's behavior of processing
		 * only certain requests asynchronously while processing
		 * those expected to return fast synchronously.
		 */

		switch (operation->ioControlCode)
		{
			case SCARD_IOCTL_ESTABLISHCONTEXT:
			case SCARD_IOCTL_RELEASECONTEXT:
			case SCARD_IOCTL_ISVALIDCONTEXT:
			case SCARD_IOCTL_LISTREADERGROUPSA:
			case SCARD_IOCTL_LISTREADERGROUPSW:
			case SCARD_IOCTL_LISTREADERSA:
			case SCARD_IOCTL_LISTREADERSW:
			case SCARD_IOCTL_INTRODUCEREADERGROUPA:
			case SCARD_IOCTL_INTRODUCEREADERGROUPW:
			case SCARD_IOCTL_FORGETREADERGROUPA:
			case SCARD_IOCTL_FORGETREADERGROUPW:
			case SCARD_IOCTL_INTRODUCEREADERA:
			case SCARD_IOCTL_INTRODUCEREADERW:
			case SCARD_IOCTL_FORGETREADERA:
			case SCARD_IOCTL_FORGETREADERW:
			case SCARD_IOCTL_ADDREADERTOGROUPA:
			case SCARD_IOCTL_ADDREADERTOGROUPW:
			case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
			case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
			case SCARD_IOCTL_LOCATECARDSA:
			case SCARD_IOCTL_LOCATECARDSW:
			case SCARD_IOCTL_LOCATECARDSBYATRA:
			case SCARD_IOCTL_LOCATECARDSBYATRW:
			case SCARD_IOCTL_CANCEL:
			case SCARD_IOCTL_READCACHEA:
			case SCARD_IOCTL_READCACHEW:
			case SCARD_IOCTL_WRITECACHEA:
			case SCARD_IOCTL_WRITECACHEW:
			case SCARD_IOCTL_GETREADERICON:
			case SCARD_IOCTL_GETDEVICETYPEID:
				asyncIrp = FALSE;
				break;

			case SCARD_IOCTL_GETSTATUSCHANGEA:
			case SCARD_IOCTL_GETSTATUSCHANGEW:
				asyncIrp = TRUE;
				break;

			case SCARD_IOCTL_CONNECTA:
			case SCARD_IOCTL_CONNECTW:
			case SCARD_IOCTL_RECONNECT:
			case SCARD_IOCTL_DISCONNECT:
			case SCARD_IOCTL_BEGINTRANSACTION:
			case SCARD_IOCTL_ENDTRANSACTION:
			case SCARD_IOCTL_STATE:
			case SCARD_IOCTL_STATUSA:
			case SCARD_IOCTL_STATUSW:
			case SCARD_IOCTL_TRANSMIT:
			case SCARD_IOCTL_CONTROL:
			case SCARD_IOCTL_GETATTRIB:
			case SCARD_IOCTL_SETATTRIB:
			case SCARD_IOCTL_GETTRANSMITCOUNT:
				asyncIrp = TRUE;
				break;

			case SCARD_IOCTL_ACCESSSTARTEDEVENT:
			case SCARD_IOCTL_RELEASESTARTEDEVENT:
				asyncIrp = FALSE;
				break;
		}

		pContext = ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) operation->hContext);

		if (!pContext)
			asyncIrp = FALSE;

		if (!asyncIrp)
		{
			if ((status = smartcard_irp_device_control_call(smartcard, operation)))
			{
				WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu!", status);
				return (UINT32)status;
			}
			if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
			{
				WLog_ERR(TAG, "Queue_Enqueue failed!");
				return ERROR_INTERNAL_ERROR;
			}
			free(operation);
		}
		else
		{
			if (pContext)
			{
				if (!MessageQueue_Post(pContext->IrpQueue, NULL, 0, (void*) operation, NULL))
				{
					WLog_ERR(TAG, "MessageQueue_Post failed!");
					return ERROR_INTERNAL_ERROR;
				}
			}
		}
	}
	else
	{
		WLog_ERR(TAG, "Unexpected SmartCard IRP: MajorFunction 0x%08X MinorFunction: 0x%08X",
				 irp->MajorFunction, irp->MinorFunction);
		irp->IoStatus = (UINT32)STATUS_NOT_SUPPORTED;

		if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
		{
			WLog_ERR(TAG, "Queue_Enqueue failed!");
			return ERROR_INTERNAL_ERROR;
		}
	}
	return CHANNEL_RC_OK;
}
示例#30
0
static void tsmf_sample_queue_ack(TSMF_SAMPLE* sample)
{
	TSMF_STREAM* stream = sample->stream;

	Queue_Enqueue(stream->sample_ack_list, sample);
}