Пример #1
0
/**
 * Internal send_command implementation
 *
 * timeoutMsec == 0 means infinite timeout
 */
static int at_send_command_full (const char *command, ATCommandType type,
                                 const char *responsePrefix, const char *smspdu,
                                 long long timeoutMsec, ATResponse **pp_outResponse)
{
    int err;

    if (0 != pthread_equal(s_tid_reader, pthread_self())) {
        /* cannot be called from reader thread */
        return AT_ERROR_INVALID_THREAD;
    }

    pthread_mutex_lock(&s_commandmutex);

    err = at_send_command_full_nolock(command, type,
                                      responsePrefix, smspdu,
                                      timeoutMsec, pp_outResponse);

    pthread_mutex_unlock(&s_commandmutex);

    if (err == AT_ERROR_TIMEOUT && s_onTimeout != NULL) {
        s_onTimeout();
    }

    return err;
}
Пример #2
0
/**
 * Internal send_command implementation
 *
 * timeoutMsec == 0 means infinite timeout
 */
static int at_send_command_full(const char *command, ATCommandType type,
				const char *responsePrefix, const char *smspdu,
				long long timeoutMsec, ATResponse **pp_outResponse, RILChannelCtx *p_channel)
{
	int err;

	if (0 != pthread_equal(p_channel->tid_reader, pthread_self())) {
		/* cannot be called from reader thread */
		RLOGD("Invalid Thread: send on %s, reader:%lu, self: %lu", p_channel->myName, p_channel->tid_reader, pthread_self());
		return AT_ERROR_INVALID_THREAD;
	}

	if (0 != p_channel->tid_myProxy) {
		/* This channel is occupied by some proxy */
		RLOGD("Occupied Thread: %s send on %s, pthread_self(): %lu, tid: %lu", command, p_channel->myName, pthread_self(), p_channel->tid_myProxy);
		assert(0);
		return AT_ERROR_INVALID_THREAD;
	}

	pthread_mutex_lock(&p_channel->commandmutex);

	/* Assign owner proxy */
	p_channel->tid_myProxy = pthread_self();

	RLOGD("AT send on %s, tid:%lu", p_channel->myName, p_channel->tid_myProxy);

	err = at_send_command_full_nolock(command, type, responsePrefix, smspdu, timeoutMsec, pp_outResponse, p_channel);

	RLOGD("response received on %s, tid:%lu", p_channel->myName, p_channel->tid_myProxy);

	/* Release the proxy */
	p_channel->tid_myProxy = 0;

	pthread_mutex_unlock(&p_channel->commandmutex);

	if (err == AT_ERROR_TIMEOUT && s_onTimeout != NULL)
		s_onTimeout(p_channel);

	return err;
}