示例#1
0
/*
 * Class:     org_alljoyn_bus_samples_simpleservice_Service
 * Method:    stopService
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_org_alljoyn_bus_samples_simpleservice_Service_stopService(JNIEnv* env, jobject jobj, jstring jServiceName)
{
    if (!s_bus) {
        return;
    }

    jboolean isCopy;
    const char* serviceNameStr = env->GetStringUTFChars(jServiceName, &isCopy);
    qcc::String serviceName(SIMPLE_SERVICE_WELL_KNOWN_NAME_PREFIX);
    serviceName += serviceNameStr;

    /* Stop advertising the name */
    QStatus status = s_bus->CancelAdvertiseName(serviceName.c_str(), TRANSPORT_ANY);
    if (status != ER_OK) {
        LOGE("CancelAdvertiseName failed with %s", QCC_StatusText(status));
    }

    /* Release the name */
    status =  s_bus->ReleaseName(serviceName.c_str());
    if (status != ER_OK) {
        LOGE("ReleaseName failed with %s", QCC_StatusText(status));
    }

    env->ReleaseStringUTFChars(jServiceName, serviceNameStr);
    env->DeleteLocalRef(jServiceName);
    return;
}
void NotificationReceiverTestImpl::setApplications(qcc::String const& listOfApps) {
    std::istringstream iss(listOfApps.c_str());
    std::string singleAppName;
    while (std::getline(iss, singleAppName, ';')) {
        m_Applications.push_back(singleAppName.c_str());
    }
}
示例#3
0
 void CancelAdvertise() {
     uint32_t disposition = 0;
     Message reply(*s_bus);
     const ProxyBusObject& alljoynObj = bus.GetAllJoynProxyObj();
     MsgArg args;
     args.Set("s", wellKnownName.c_str());
     QStatus status = alljoynObj.MethodCall(org::alljoyn::Bus::InterfaceName,
                                            "CancelAdvertiseName",
                                            &args,
                                            1,
                                            reply,
                                            5000);
     if (ER_OK == status) {
         disposition = reply->GetArg(0)->v_uint32;
     }
     if ((ER_OK != status) || (disposition != ALLJOYN_CANCELADVERTISENAME_REPLY_SUCCESS)) {
         LOGE("Failed to cancel advertise name %s (%s)", wellKnownName.c_str(), QCC_StatusText(status));
     }
 }
示例#4
0
JNIEXPORT jboolean JNICALL Java_org_alljoyn_bus_samples_chat_Chat_advertise(JNIEnv* env,
                                                                            jobject jobj,
                                                                            jstring advertiseStrObj)
{
    const char* advertisedNameStr = NULL;
    QStatus status;
    SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, true, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);
    SessionPort sp = CHAT_PORT;

    s_advertisedName = "";
    advertisedNameStr = env->GetStringUTFChars(advertiseStrObj, NULL);
    if (!advertisedNameStr) {
        LOGE("GetStringUTFChars failed");
        status = ER_FAIL;
        goto exit;
    }
    s_advertisedName += NAME_PREFIX;
    s_advertisedName += ".";
    s_advertisedName += advertisedNameStr;

    /* Request name */
    status = s_bus->RequestName(s_advertisedName.c_str(), DBUS_NAME_FLAG_DO_NOT_QUEUE);
    if (ER_OK != status) {
        LOGE("RequestName(%s) failed (status=%s)\n", s_advertisedName.c_str(), QCC_StatusText(status));
        goto exit;
    }
    LOGD("\n Request Name was successful");

    /* Bind the session port*/
    status = s_bus->BindSessionPort(sp, opts, *s_busListener);
    if (ER_OK != status) {
        LOGE("BindSessionPort failed (%s)\n", QCC_StatusText(status));
        goto exit;
    }
    LOGD("\n Bind Session Port to %u was successful \n", CHAT_PORT);

    /* Advertise the name */
    status = s_bus->AdvertiseName(s_advertisedName.c_str(), opts.transports);
    if (status != ER_OK) {
        LOGD("Failed to advertise name %s (%s) \n", s_advertisedName.c_str(), QCC_StatusText(status));
        goto exit;
    }
    LOGD("\n Name %s was successfully advertised", s_advertisedName.c_str());

exit:
    if (ER_OK != status) {
        s_bus->CancelAdvertiseName(s_advertisedName.c_str(), opts.transports);
        s_bus->UnbindSessionPort(sp);
        s_bus->ReleaseName(s_advertisedName.c_str());
    }
    if (advertisedNameStr) {
        env->ReleaseStringUTFChars(advertiseStrObj, advertisedNameStr);
    }
    return (jboolean) (ER_OK == status);
}
示例#5
0
 /** Release the well-known name if it was acquired */
 void ReleaseName() {
     if (s_bus && isNameAcquired) {
         uint32_t disposition = 0;
         isNameAcquired = false;
         const ProxyBusObject& dbusObj = bus.GetDBusProxyObj();
         Message reply(*s_bus);
         MsgArg arg;
         arg.Set("s", wellKnownName.c_str());
         QStatus status = dbusObj.MethodCall(org::freedesktop::DBus::InterfaceName,
                                             "ReleaseName",
                                             &arg,
                                             1,
                                             reply,
                                             5000);
         if (ER_OK == status) {
             disposition = reply->GetArg(0)->v_uint32;
         }
         if ((ER_OK != status) || (disposition != DBUS_RELEASE_NAME_REPLY_RELEASED)) {
             LOGE("Failed to release name %s (%s, disposition=%d)", wellKnownName.c_str(), QCC_StatusText(status), disposition);
         }
     }
 }
示例#6
0
/*
 * Class:     org_alljoyn_bus_samples_simpleservice_Service
 * Method:    startService
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
 */
JNIEXPORT jboolean JNICALL Java_org_alljoyn_bus_samples_simpleservice_Service_startService(JNIEnv* env, jobject jobj,
                                                                                           jstring jServiceName, jstring packageNameStrObj)
{
    QStatus status = ER_OK;

    jboolean iscopy;
    const char* serviceNameStr = env->GetStringUTFChars(jServiceName, &iscopy);
    serviceName = "";
    serviceName += SIMPLE_SERVICE_WELL_KNOWN_NAME_PREFIX;
    serviceName += serviceNameStr;

    SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, false, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);

    const char* daemonAddr = "unix:abstract=alljoyn";

    /* Initialize AllJoyn only once */
    if (!s_bus) {
        const char* packageNameStr = env->GetStringUTFChars(packageNameStrObj, &iscopy);
        s_bus = new BusAttachment("service", true);

        /* Add org.alljoyn.samples.simple interface */
        InterfaceDescription* testIntf = NULL;
        status = s_bus->CreateInterface(SIMPLE_SERVICE_INTERFACE_NAME, testIntf);
        if (ER_OK == status) {
            testIntf->AddMethod("Ping", "s",  "s", "inStr,outStr", 0);
            testIntf->Activate();
        } else {
            LOGE("Failed to create interface %s (%s)", SIMPLE_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
        }

        /* Start the msg bus */
        if (ER_OK == status) {
            status = s_bus->Start();
        } else {
            LOGE("BusAttachment::Start failed (%s)", QCC_StatusText(status));
        }

        /* Connect to the daemon */
        if (ER_OK == status) {
            status = s_bus->Connect(daemonAddr);
            if (ER_OK != status) {
                LOGE("Connect to %s failed (%s)", daemonAddr, QCC_StatusText(status));
            }
        }

        /* Register the bus listener */
        JavaVM* vm;
        env->GetJavaVM(&vm);
        if (ER_OK == status) {
            s_busListener = new MyBusListener(vm, jobj);
            s_bus->RegisterBusListener(*s_busListener);
            LOGD("\n Bus Listener registered \n");
        }

        /* Register service object */
        s_obj = new ServiceObject(*s_bus, SIMPLE_SERVICE_OBJECT_PATH, vm, jobj);
        s_bus->RegisterBusObject(*s_obj);

        /* Bind the session port*/
        if (ER_OK == status) {
            SessionPort sp = SESSION_PORT;
            status = s_bus->BindSessionPort(sp, opts, *s_busListener);
            if (ER_OK != status) {
                LOGE("BindSessionPort failed (%s)\n", QCC_StatusText(status));
            } else {
                LOGD("\n Bind Session Port to %d was successful \n", SESSION_PORT);
            }
        }
        env->ReleaseStringUTFChars(packageNameStrObj, packageNameStr);
    }

    /* Request name */
    status = s_bus->RequestName(serviceName.c_str(), DBUS_NAME_FLAG_DO_NOT_QUEUE);
    if (ER_OK != status) {
        LOGE("RequestName(%s) failed (status=%s)\n", serviceName.c_str(), QCC_StatusText(status));
        status = (status == ER_OK) ? ER_FAIL : status;
    } else {
        LOGD("\n Request Name was successful");
    }

    /* Advertise the name */
    if (ER_OK == status) {

        status = s_bus->AdvertiseName(serviceName.c_str(), opts.transports);
        if (status != ER_OK) {
            LOGD("Failed to advertise name %s (%s) \n", serviceName.c_str(), QCC_StatusText(status));
        } else {
            LOGD("\n Name %s was successfully advertised", serviceName.c_str());
        }
    }
    env->ReleaseStringUTFChars(jServiceName, serviceNameStr);
    env->DeleteLocalRef(jServiceName);
    return (jboolean) true;
}
void NotificationReceiverTestImpl::Dismiss(const int32_t msgId, const qcc::String appId)
{
    std::cout << "Got NotificationReceiverTestImpl::Dismiss with msgId=" << msgId << " appId=" << appId.c_str() << std::endl;
}
const char* getOnOffString()
{
    printf("[INFO] Get the On/Off string = %s.\n", onOffString.c_str());
    return onOffString.c_str();
}