コード例 #1
0
TInt CDatabaseManagerServerSession::SetInterfaceDefaultL(const RMessage2& aMessage)
    {
    TInt ret;
    HBufC* serviceNameBuf = HBufC::New(aMessage.GetDesLength(0));
    HBufC* interfaceNameBuf = HBufC::New(aMessage.GetDesLength(1));
    if (!serviceNameBuf || !interfaceNameBuf)
        return KErrNoMemory;

    TPtr ptrToBuf(serviceNameBuf->Des());
    TPtr ptrToBuf2(interfaceNameBuf->Des());
    
    TRAP(ret, aMessage.ReadL(0, ptrToBuf));
    TRAPD(ret2, aMessage.ReadL(1, ptrToBuf2));
    if (ret != KErrNone || ret2 != KErrNone)
        {
        iDb->lastError().setError(DBError::UnknownError);
        aMessage.Write(2, LastErrorCode());
        delete serviceNameBuf;
        delete interfaceNameBuf;
        return (ret == KErrNone) ? ret2 : ret;
        }

    QString serviceName = QString::fromUtf16(ptrToBuf.Ptr(), ptrToBuf.Length());
    QString interfaceName = QString::fromUtf16(ptrToBuf2.Ptr(), ptrToBuf2.Length());
    
    QList<QServiceInterfaceDescriptor> descriptors;
    QServiceFilter filter;
    filter.setServiceName(serviceName);
    filter.setInterface(interfaceName);
    // Nothing should be returned, because we are checking on nonexistent service
    descriptors = iDb->getInterfaces(filter);

    //find the descriptor with the latest version
    int latestIndex = 0;
        for (int i = 1; i < descriptors.count(); ++i) {
            if (lessThan(descriptors[latestIndex], descriptors[i]))
                latestIndex = i;
    }

    if (!descriptors.isEmpty()) {
        iDb->setInterfaceDefault(descriptors[latestIndex]);     
    }
    else {
        aMessage.Write(2, TError(DBError::NotFound));
        delete serviceNameBuf;
        delete interfaceNameBuf;
        return KErrNotFound;
    }

    aMessage.Write(2, LastErrorCode());
    delete serviceNameBuf;
    delete interfaceNameBuf;
    
    return ret;
    }
コード例 #2
0
/*
 * This is the slot for Invoke Button, which loads the OOP service
 * and then invokes the Remote Method provided by the service.
 */
void sfwtestclient::invokeButtonClicked()
{
    ui.textEditBox->clear();
    
    QServiceManager serviceManager;
    QServiceFilter serviceFilter;
    serviceFilter.setServiceName("SfwTestService");
    serviceFilter.setInterface("com.nokia.qt.SfwTest");
    
    QList<QServiceInterfaceDescriptor> interfaceList;
    interfaceList = serviceManager.findInterfaces(serviceFilter);
    
    if(!interfaceList.count()) {
        ui.textEditBox->setText("No Interfaces Found\n");
        return;
    }
    
    if(interfaceList.count() > 1) {
        ui.textEditBox->setText("Multiple Interfaces Found\n");
        return;
    }
    ui.textEditBox->setText("Loading Interface...\n");
    
    QObject *sfwTestService = NULL;

    sfwTestService = serviceManager.loadInterface(interfaceList.at(0));

    if (sfwTestService) {
        ui.textEditBox->setText("Loading Interface: Success\n");
        ui.textEditBox->setText("Invoking Interface Method: getServiceCount...\n");
        int result = 0;
        
        QMetaObject::invokeMethod(sfwTestService, "getServiceCount", Q_RETURN_ARG(int, result));
    
        if (!result) {
            ui.textEditBox->setText("Invoke Interface Method getServiceCount: No Services Found\n");
        }
        else {
            QString fmtString;
            ui.textEditBox->setText(fmtString.sprintf("Invoke Interface Method getServiceCount: Found %d Services\n",result));
        }
        delete sfwTestService;
        sfwTestService = NULL;

    }
    else {
コード例 #3
0
void tst_QServiceFilter::streamTest()
{
    QByteArray byteArray;
    QBuffer buffer(&byteArray);
    buffer.open(QIODevice::ReadWrite);
    QDataStream stream(&buffer);

    QServiceFilter emptyFilter;
    QCOMPARE(emptyFilter.majorVersion(), -1);
    QCOMPARE(emptyFilter.minorVersion(), -1);
    QCOMPARE(emptyFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(emptyFilter.serviceName(), QString(""));
    QCOMPARE(emptyFilter.interfaceName(), QString(""));
    QCOMPARE(emptyFilter.customAttribute("key1"), QString());
    QCOMPARE(emptyFilter.capabilities(), QStringList());
    QCOMPARE(emptyFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum);

    buffer.seek(0);
    stream << emptyFilter;
    
    QServiceFilter tempFilter;
    QCOMPARE(tempFilter.majorVersion(), -1);
    QCOMPARE(tempFilter.minorVersion(), -1);
    QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(tempFilter.serviceName(), QString(""));
    QCOMPARE(tempFilter.interfaceName(), QString(""));
    QCOMPARE(tempFilter.customAttribute("key1"), QString());
    QCOMPARE(tempFilter.capabilities(), QStringList());
    QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum);

    buffer.seek(0);
    stream >> tempFilter;
    
    QCOMPARE(tempFilter.majorVersion(), -1);
    QCOMPARE(tempFilter.minorVersion(), -1);
    QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(tempFilter.serviceName(), QString(""));
    QCOMPARE(tempFilter.interfaceName(), QString(""));
    QCOMPARE(tempFilter.customAttribute("key1"), QString());
    QCOMPARE(tempFilter.capabilities(), QStringList());
    QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum);
   
    //assign filter to new filter via constructor
    tempFilter.setInterface("com.nokia.qt.valid", "4.77", QServiceFilter::ExactVersionMatch);
    tempFilter.setServiceName("ServiceName");
    tempFilter.setCustomAttribute("key1", "value1");
    tempFilter.setCapabilities(QServiceFilter::MatchLoadable, QStringList() << "execute" << "delete");
    QCOMPARE(tempFilter.majorVersion(), 4);
    QCOMPARE(tempFilter.minorVersion(), 77);
    QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch);
    QCOMPARE(tempFilter.serviceName(), QString("ServiceName"));
    QCOMPARE(tempFilter.interfaceName(), QString("com.nokia.qt.valid"));
    QCOMPARE(tempFilter.customAttribute("key1"), QString("value1"));
    QCOMPARE(tempFilter.capabilities(), (QStringList()<<"execute" << "delete"));
    QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable);
    buffer.seek(0);
    stream << tempFilter;

    QServiceFilter constructFilter;
    buffer.seek(0);
    stream >> constructFilter;
    QCOMPARE(constructFilter.majorVersion(), 4);
    QCOMPARE(constructFilter.minorVersion(), 77);
    QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch);
    QCOMPARE(constructFilter.serviceName(), QString("ServiceName"));
    QCOMPARE(constructFilter.interfaceName(), QString("com.nokia.qt.valid"));
    QCOMPARE(constructFilter.customAttribute("key1"), QString("value1"));
    QCOMPARE(constructFilter.capabilities(), (QStringList()<<"execute" << "delete"));
    QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable);

    //assign empty filter to filter with values

    buffer.seek(0);
    stream << emptyFilter;
    buffer.seek(0);
    stream >> constructFilter;
    QCOMPARE(constructFilter.majorVersion(), -1);
    QCOMPARE(constructFilter.minorVersion(), -1);
    QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(constructFilter.serviceName(), QString(""));
    QCOMPARE(constructFilter.interfaceName(), QString(""));
    QCOMPARE(constructFilter.customAttribute("key1"), QString());
    QCOMPARE(constructFilter.capabilities(), QStringList());
    QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum);
}
コード例 #4
0
void tst_QServiceFilter::setInterface()
{
    //don't separate this out into test_data() function as we test the behavior
    //on the same filter object
    QServiceFilter filter;
    QCOMPARE(filter.majorVersion(), -1);
    QCOMPARE(filter.minorVersion(), -1);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString());

    filter.setInterface("com.nokia.qt.text", "1.0", QServiceFilter::ExactVersionMatch);

    QCOMPARE(filter.majorVersion(), 1);
    QCOMPARE(filter.minorVersion(), 0);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::ExactVersionMatch);
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.text"));

    filter.setInterface("com.nokia.qt.text", "1.5", QServiceFilter::MinimumVersionMatch);

    QCOMPARE(filter.majorVersion(), 1);
    QCOMPARE(filter.minorVersion(), 5);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.text"));

    //invalid version tag -> ignore the call
    filter.setInterface("com.nokia.qt.label", "f.0", QServiceFilter::ExactVersionMatch);

    QCOMPARE(filter.majorVersion(), 1);
    QCOMPARE(filter.minorVersion(), 5);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); //default
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.text"));

    //empty version tag -> reset version
    filter.setInterface("com.nokia.qt.label", "", QServiceFilter::ExactVersionMatch);

    QCOMPARE(filter.majorVersion(), -1);
    QCOMPARE(filter.minorVersion(), -1);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::ExactVersionMatch); //default
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.label"));

    //empty.interfaceName() tag -> ignore the call
    filter.setInterface("", "4.5", QServiceFilter::MinimumVersionMatch);

    QCOMPARE(filter.majorVersion(), -1);
    QCOMPARE(filter.minorVersion(), -1);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::ExactVersionMatch); //default
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.label"));
    
    //set a valid 
    filter.setInterface("com.nokia.qt.valid", "4.77", QServiceFilter::ExactVersionMatch);

    QCOMPARE(filter.majorVersion(), 4);
    QCOMPARE(filter.minorVersion(), 77);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::ExactVersionMatch);
    QCOMPARE(filter.serviceName(), QString());
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.valid"));

    filter.setServiceName("myService");
    QCOMPARE(filter.majorVersion(), 4);
    QCOMPARE(filter.minorVersion(), 77);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::ExactVersionMatch);
    QCOMPARE(filter.serviceName(), QString("myService"));
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.valid"));

    //test default constructed version and matching rule
    filter.setInterface("com.nokia.qt.valid2");
    QCOMPARE(filter.majorVersion(), -1);
    QCOMPARE(filter.minorVersion(), -1);
    QCOMPARE(filter.versionMatchRule(), QServiceFilter::MinimumVersionMatch);
    QCOMPARE(filter.serviceName(), QString("myService"));
    QCOMPARE(filter.interfaceName(), QString("com.nokia.qt.valid2"));
}