Ejemplo n.º 1
0
static QStatus SetupBusAttachment(BusAttachment& bus)
{
    QStatus status;
    status = bus.Start();
    QCC_ASSERT(ER_OK == status);
    status = bus.Connect();

    if (ER_OK != status) {
        return status;
    }

    status = BuildInterface(bus);
    QCC_ASSERT(ER_OK == status);

    return status;
}
Ejemplo n.º 2
0
    ScanService(BusAttachment& bus, const char* path, JavaVM* vm, jobject jobj) : BusObject(bus, path), vm(vm), jobj(jobj)
    {

        QStatus status;

        /* Add the chat interface to this object */
        const InterfaceDescription* scanIntf = bus.GetInterface(SCAN_SERVICE_INTERFACE_NAME);
        assert(scanIntf);
        AddInterface(*scanIntf);

        /* Store the Chat signal member away so it can be quickly looked up when signals are sent */
        scanMethodMember = scanIntf->GetMember("Scan");
        assert(scanMethodMember);

        const MethodEntry methodEntries[] = {
            { scanIntf->GetMember("Scan"), static_cast<MessageReceiver::MethodHandler>(&ScanService::Scan) }
        };

        status = AddMethodHandlers(methodEntries, ARRAY_SIZE(methodEntries));

        if (ER_OK != status) {
            LOGE("Failed to register method handlers for AllJoynAndroidExtService (%s)", QCC_StatusText(status));
        }

    }
Ejemplo n.º 3
0
    ChatObject(BusAttachment& bus, const char* path, JavaVM* vm, jobject jobj) : BusObject(bus, path), vm(vm), jobj(jobj)
    {
        QStatus status;

        /* Add the chat interface to this object */
        const InterfaceDescription* chatIntf = bus.GetInterface(CHAT_SERVICE_INTERFACE_NAME);
        QCC_ASSERT(chatIntf);
        AddInterface(*chatIntf);

        /* Store the Chat signal member away so it can be quickly looked up when signals are sent */
        chatSignalMember = chatIntf->GetMember("Chat");
        QCC_ASSERT(chatSignalMember);

        /* Register signal handler */
        status =  bus.RegisterSignalHandler(this,
                                            static_cast<MessageReceiver::SignalHandler>(&ChatObject::ChatSignalHandler),
                                            chatSignalMember,
                                            NULL);

        if (ER_OK != status) {
            LOGE("Failed to register s_advertisedNamesignal handler for ChatObject::Chat (%s)", QCC_StatusText(status));
        }
    }
Ejemplo n.º 4
0
/* Bus object */
ChatObject::ChatObject(BusAttachment& bus, const char* path) : BusObject(bus, path), chatSignalMember(NULL)
{
    QStatus status;

    /* Add the chat interface to this object */
    const InterfaceDescription* chatIntf = bus.GetInterface(CHAT_SERVICE_INTERFACE_NAME);
    assert(chatIntf);
    AddInterface(*chatIntf);

    /* Store the Chat signal member away so it can be quickly looked up when signals are sent */
    chatSignalMember = chatIntf->GetMember("Chat");
    assert(chatSignalMember);

    /* Register signal handler */
    status =  bus.RegisterSignalHandler(this,
                                        static_cast<MessageReceiver::SignalHandler>(&ChatObject::ChatSignalHandler),
                                        chatSignalMember,
                                        NULL);

    if (ER_OK != status) {
        NotifyUser(MSG_ERROR, "Failed to register signal handler for ChatObject::Chat (%s)\n", QCC_StatusText(status));
    }
}
Ejemplo n.º 5
0
    virtual void ObjectDiscovered(ProxyBusObject& proxy) {
        cout << "[listener] Door " << proxy.GetUniqueName() << ":"
             << proxy.GetPath() << " has just been discovered." << endl;

        bus->EnableConcurrentCallbacks();
        proxy.RegisterPropertiesChangedListener(INTF_NAME, props, 3, *this, NULL);

//        DoorProxy door(proxy, *bus);
        g_door = new DoorProxy(proxy, *bus);
        g_door->GetUI();
        cout<< "where must be UI_FILE" << endl;
        cout<< UI_FILE << endl;
        DrawUI();

        //PrintDoorState(door);
    }
Ejemplo n.º 6
0
    BasicSampleObject(BusAttachment& bus, const char* path) :
        BusObject(bus, path)
    {
        /** Add the test interface to this object */
        const InterfaceDescription* exampleIntf = bus.GetInterface(SERVICE_NAME);
        assert(exampleIntf);
        AddInterface(*exampleIntf);

        /** Register the method handlers with the object */
        const MethodEntry methodEntries[] = {
            { exampleIntf->GetMember("cat"), static_cast<MessageReceiver::MethodHandler>(&BasicSampleObject::Cat) }
        };
        QStatus status = AddMethodHandlers(methodEntries, sizeof(methodEntries) / sizeof(methodEntries[0]));
        if (ER_OK != status) {
            printf("Failed to register method handlers for BasicSampleObject");
        }
    }
Ejemplo n.º 7
0
    ServiceObject(BusAttachment& bus, const char* path, JavaVM* vm, jobject jobj)
        : BusObject(bus, path), vm(vm), jobj(jobj), isNameAcquired(false)
    {
        QStatus status;

        /* Add the service interface to this object */
        const InterfaceDescription* regTestIntf = bus.GetInterface(SIMPLE_SERVICE_INTERFACE_NAME);
        assert(regTestIntf);
        AddInterface(*regTestIntf);

        /* Register the method handlers with the object */
        const MethodEntry methodEntries[] = {
            { regTestIntf->GetMember("Ping"), static_cast<MessageReceiver::MethodHandler>(&ServiceObject::Ping) }
        };
        status = AddMethodHandlers(methodEntries, ARRAY_SIZE(methodEntries));
        if (ER_OK != status) {
            LOGE("Failed to register method handlers for ServiceObject (%s)", QCC_StatusText(status));
        }
    }
Ejemplo n.º 8
0
static QStatus BuildInterface(BusAttachment& bus)
{
    QStatus status;

    InterfaceDescription* intf = NULL;
    status = bus.CreateInterface(INTF_NAME, intf);
    QCC_ASSERT(ER_OK == status);
    status = intf->AddProperty("IsOpen", "b", PROP_ACCESS_READ);
    QCC_ASSERT(ER_OK == status);
    status = intf->AddPropertyAnnotation("IsOpen", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true");
    QCC_ASSERT(ER_OK == status);
    status = intf->AddProperty("Location", "s", PROP_ACCESS_READ);
    QCC_ASSERT(ER_OK == status);
    status = intf->AddPropertyAnnotation("Location", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true");
    QCC_ASSERT(ER_OK == status);
    status = intf->AddProperty("KeyCode", "u", PROP_ACCESS_READ);
    QCC_ASSERT(ER_OK == status);
    status = intf->AddPropertyAnnotation("KeyCode", "org.freedesktop.DBus.Property.EmitsChangedSignal", "invalidates");
    QCC_ASSERT(ER_OK == status);

    status = intf->AddMethod("Open", "", "", "");
    QCC_ASSERT(ER_OK == status);
    status = intf->AddMethod("Close", "", "", "");
    QCC_ASSERT(ER_OK == status);
    status = intf->AddMethod("KnockAndRun", "", "", "", MEMBER_ANNOTATE_NO_REPLY);
    QCC_ASSERT(ER_OK == status);

    status = intf->AddMethod("GetUI", "", "s", "outStr", 0);
    QCC_ASSERT(ER_OK == status);

    status = intf->AddMethod("CallFunc", "s", "s", "in", 0);
    QCC_ASSERT(ER_OK == status);

    status = intf->AddSignal("PersonPassedThrough", "s", "name", MEMBER_ANNOTATE_SESSIONCAST);
    QCC_ASSERT(ER_OK == status);

    intf->Activate();

    return status;
}
Ejemplo n.º 9
0
    void PersonPassedThrough(const InterfaceDescription::Member* member, const char* path, Message& message) {
        QCC_UNUSED(member);

        char* name;
        string location;
        QStatus status = message->GetArgs("s", &name);
        if (ER_OK == status) {
            bus->EnableConcurrentCallbacks();
            DoorProxy door(observer->Get(message->GetSender(), path), *bus);
            if (door.IsValid()) {
                status = door.GetLocation(location);
            } else {
                cerr << "Received a signal from a door we don't know." << endl;
                status = ER_FAIL;
            }
        }
        if (ER_OK == status) {
            cout << "[listener] " << name << " passed through a door "
                 << "@location " << location << endl;
            cout << "> ";
            cout.flush();
        }
    }
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    handler = new UHandler();
    try_drawer = new TryDrawUI();
    drawer = new CDrawUI();
    if (AllJoynInit() != ER_OK) {
        printf("Ping: Error1.\n");
        exit(1);
        //return EXIT_FAILURE;
    }
//#ifdef ROUTER
    if (AllJoynRouterInit() != ER_OK) {
        AllJoynShutdown();
        printf("Ping: Error2.\n");
        exit(1);
        //return EXIT_FAILURE;
    }
//#endif

    BusAttachment* bus = new BusAttachment("door_consumer", true);

    if (ER_OK != SetupBusAttachment(*bus)) {
        printf("Ping: Error3.\n");
        exit(1);
        //return EXIT_FAILURE;
       // void DrawUI()
    }

    const char* intfname = INTF_NAME;
    Observer* obs = new Observer(*bus, &intfname, 1);
    DoorListener* listener = new DoorListener();
    listener->observer = obs;
    listener->bus = bus;
    obs->RegisterListener(*listener);
    bus->RegisterSignalHandler(listener, static_cast<MessageReceiver::SignalHandler>(&DoorListener::PersonPassedThrough), bus->GetInterface(INTF_NAME)->GetMember("PersonPassedThrough"), NULL);

//    bool done = false;
//    while (!done) { }
//            string input;
//            cout << "> ";
//            getline(cin, input);
//            done = !Parse(*bus, obs, input);
//        }

//    // Cleanup
//    obs->UnregisterAllListeners();
//    delete obs; // Must happen before deleting the original bus
//    delete listener;
//    delete bus;
//    bus = NULL;

//    //#ifdef ROUTER
//        AllJoynRouterShutdown();
//    //#endif
//        AllJoynShutdown();
//        printf("Ping: Error4.\n");
//        exit(1);
//        //return EXIT_SUCCESS;

     engine = new QQmlApplicationEngine();
    engine->load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}
Ejemplo n.º 11
0
    virtual void PropertiesChanged(ProxyBusObject& obj,
                                   const char* ifaceName,
                                   const MsgArg& changed,
                                   const MsgArg& invalidated,
                                   void* context) {
        QCC_UNUSED(ifaceName);
        QCC_UNUSED(context);
        QStatus status = ER_OK;
        bus->EnableConcurrentCallbacks();
        DoorProxy door(observer->Get(ObjectId(obj)), *bus);
        if (!door.IsValid()) {
            cerr << "Received a PropertiesChanged signal from a door we don't know." << endl;
            status = ER_FAIL;
        }
        string location;
        if (ER_OK == status) {
            status = door.GetLocation(location);
        }
        if (ER_OK == status) {
            cout << "Door @location " << location << " has updated state:" << endl;
        }

        size_t nelem = 0;
        MsgArg* elems = NULL;
        if (ER_OK == status) {
            status = changed.Get("a{sv}", &nelem, &elems);
        }
        if (ER_OK == status) {
            for (size_t i = 0; i < nelem; ++i) {
                const char* prop;
                MsgArg* val;
                status = elems[i].Get("{sv}", &prop, &val);
                if (ER_OK == status) {
                    string propname = prop;
                    if (propname == "Location") {
                        const char* newloc;
                        status = val->Get("s", &newloc);
                        if (ER_OK == status) {
                            cout << "  location: " << newloc << endl;
                        }
                    } else if (propname == "IsOpen") {
                        bool isopen;
                        status = val->Get("b", &isopen);
                        if (ER_OK == status) {
                            cout << "   is open: " << isopen << endl;
                        }
                    }
                } else {
                    break;
                }
            }
        }

        if (ER_OK == status) {
            status = invalidated.Get("as", &nelem, &elems);
        }
        if (ER_OK == status) {
            for (size_t i = 0; i < nelem; ++i) {
                char* prop;
                status = elems[i].Get("s", &prop);
                if (status == ER_OK) {
                    cout << "  invalidated " << prop << endl;
                }
            }
        }

        cout << "> ";
        cout.flush();
    }