コード例 #1
0
    foreach (QString objStr, strList) {
        // Add defaults
        UAVObject *obj = objManager->getObject(objStr);
        Q_ASSERT(obj);
        UAVObject::Metadata mdataDefault = obj->getDefaultMetadata();
        QModelIndex index = schedulerModel->index(rowIndex,0, QModelIndex());
        schedulerModel->setData(index, QString("%1ms").arg(mdataDefault.flightTelemetryUpdatePeriod));

        // Save default metadata for later use
        defaultMdata.insert(obj->getName().append("Meta"), mdataDefault);

        // Connect live values to the "Current" column
        UAVDataObject *dobj = dynamic_cast<UAVDataObject*>(obj);
        Q_ASSERT(dobj);
        UAVMetaObject *mobj = dobj->getMetaObject();
        connect(mobj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateCurrentColumn(UAVObject*)));

        // Updates the "Current" column with the live value
        updateCurrentColumn(mobj);
        rowIndex++;
    }
コード例 #2
0
/**
 * Register an object with the manager. This function must be called for all newly created instances.
 * A new instance can be created directly by instantiating a new object or by calling clone() of
 * an existing object. The object will be registered and will be properly initialized so that it can accept
 * updates.
 */
bool UAVObjectManager::registerObject(UAVDataObject *obj)
{
    QMutexLocker locker(mutex);

    // Check if this object type is already in the list
    for (int objidx = 0; objidx < objects.length(); ++objidx) {
        // Check if the object ID is in the list
        if (objects[objidx].length() > 0 && objects[objidx][0]->getObjID() == obj->getObjID()) {
            // Check if this is a single instance object, if yes we can not add a new instance
            if (obj->isSingleInstance()) {
                return false;
            }
            // The object type has alredy been added, so now we need to initialize the new instance with the appropriate id
            // There is a single metaobject for all object instances of this type, so no need to create a new one
            // Get object type metaobject from existing instance
            UAVDataObject *refObj = dynamic_cast<UAVDataObject *>(objects[objidx][0]);
            if (refObj == NULL) {
                return false;
            }
            UAVMetaObject *mobj = refObj->getMetaObject();
            // If the instance ID is specified and not at the default value (0) then we need to make sure
            // that there are no gaps in the instance list. If gaps are found then then additional instances
            // will be created.
            if ((obj->getInstID() > 0) && (obj->getInstID() < MAX_INSTANCES)) {
                for (int instidx = 0; instidx < objects[objidx].length(); ++instidx) {
                    if (objects[objidx][instidx]->getInstID() == obj->getInstID()) {
                        // Instance conflict, do not add
                        return false;
                    }
                }
                // Check if there are any gaps between the requested instance ID and the ones in the list,
                // if any then create the missing instances.
                for (quint32 instidx = objects[objidx].length(); instidx < obj->getInstID(); ++instidx) {
                    UAVDataObject *cobj = obj->clone(instidx);
                    cobj->initialize(mobj);
                    objects[objidx].append(cobj);
                    getObject(cobj->getObjID())->emitNewInstance(cobj);
                    emit newInstance(cobj);
                }
                // Finally, initialize the actual object instance
                obj->initialize(mobj);
            } else if (obj->getInstID() == 0) {
                // Assign the next available ID and initialize the object instance
                obj->initialize(objects[objidx].length(), mobj);
            } else {
                return false;
            }
            // Add the actual object instance in the list
            objects[objidx].append(obj);
            getObject(obj->getObjID())->emitNewInstance(obj);
            emit newInstance(obj);
            return true;
        }
    }
    // If this point is reached then this is the first time this object type (ID) is added in the list
    // create a new list of the instances, add in the object collection and create the object's metaobject
    // Create metaobject
    QString mname = obj->getName();
    mname.append("Meta");
    UAVMetaObject *mobj = new UAVMetaObject(obj->getObjID() + 1, mname, obj);
    // Initialize object
    obj->initialize(0, mobj);
    // Add to list
    addObject(obj);
    addObject(mobj);
    return true;
}