Ejemplo n.º 1
0
void * gRealTimeLog(void * attr) {
    Sensor* tempSensor = NULL;
    sem_t semSensorList;

    Actuator* tempActuator = NULL;
    sem_t semActuatorList;

    tempSensor = getSensorList();
    semSensorList = getSemSensor();

    tempActuator = getActuatorList();
    semActuatorList = getSemActuator();


    while (lPeriod != 0) {


        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);

        /* Lecture des capteurs */
        sem_wait(&semSensorList);

        while (tempSensor != NULL) {
            tempSensor->id[11] = '\0';
            gCommunicationSendValue(tempSensor->id, tempSensor->value);
            tempSensor = tempSensor->next;
        }


        sem_post(&semSensorList);

        /* Lecture des actionneurs */
        sem_wait(&semActuatorList);

        while (tempActuator != NULL) {
            tempActuator->id[11] = '\0';
            gCommunicationSendValue(tempActuator->id, tempActuator->status);
            tempActuator = tempActuator->next;
        }


        sem_post(&semActuatorList);

        pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

        sleep(lPeriod);

        tempSensor = getSensorList();
    }

    return (void *) NULL;
}
Ejemplo n.º 2
0
status_t BnSensorServer::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case GET_SENSOR_LIST: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            const String16& opPackageName = data.readString16();
            Vector<Sensor> v(getSensorList(opPackageName));
            size_t n = v.size();
            reply->writeUint32(static_cast<uint32_t>(n));
            for (size_t i = 0; i < n; i++) {
                reply->write(v[i]);
            }
            return NO_ERROR;
        }
        case CREATE_SENSOR_EVENT_CONNECTION: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            String8 packageName = data.readString8();
            int32_t mode = data.readInt32();
            const String16& opPackageName = data.readString16();
            sp<ISensorEventConnection> connection(createSensorEventConnection(packageName, mode,
                    opPackageName));
            reply->writeStrongBinder(IInterface::asBinder(connection));
            return NO_ERROR;
        }
        case ENABLE_DATA_INJECTION: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            int32_t ret = isDataInjectionEnabled();
            reply->writeInt32(static_cast<int32_t>(ret));
            return NO_ERROR;
        }
    }
    return BBinder::onTransact(code, data, reply, flags);
}
status_t BnSensorServer::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case GET_SENSOR_LIST: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            Vector<Sensor> v(getSensorList());
            size_t n = v.size();
            reply->writeInt32(n);
            for (size_t i=0 ; i<n ; i++) {
                reply->write(v[i]);
            }
            return NO_ERROR;
        } break;
        case CREATE_SENSOR_EVENT_CONNECTION: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            sp<ISensorEventConnection> connection(createSensorEventConnection());
            reply->writeStrongBinder(connection->asBinder());
            return NO_ERROR;
        } break;
    }
    return BBinder::onTransact(code, data, reply, flags);
}