/** * Implementation of the functionality related to discovering remote apps which are hosting chat * channels. We expect that this method will only be called in the context of the AllJoyn bus * handler thread; and while we are in the CONNECTED state. Since this is a core bit of * functionalty for the "use" side of the app, we always do this at startup. */ private void doStartDiscovery() { Log.i(TAG, "doStartDiscovery()"); assert (mBusAttachmentState == BusAttachmentState.CONNECTED); Status status = mBus.findAdvertisedName(NAME_PREFIX); if (status == Status.OK) { mBusAttachmentState = BusAttachmentState.DISCOVERING; return; } else { mActivity.alljoynError( MainActivity.Module.USE, "Unable to start finding advertised names: (" + status + ")"); return; } }
/** * Implementation of the functionality related to connecting our app to the AllJoyn bus. We expect * that this method will only be called in the context of the AllJoyn bus handler thread; and * while we are in the DISCONNECTED state. */ private void doConnect() { Log.i(TAG, "doConnect()"); org.alljoyn.bus.alljoyn.DaemonInit.PrepareDaemon(getApplicationContext()); assert (mBusAttachmentState == BusAttachmentState.DISCONNECTED); mBus.useOSLogging(true); mBus.setDebugLevel("ALLJOYN_JAVA", 7); mBus.registerBusListener(mBusListener); mBus.registerAboutListener(mTestListener); /* * To make a service available to other AllJoyn peers, first * register a BusObject with the BusAttachment at a specific * object path. Our service is implemented by the ChatService * BusObject found at the "/chatService" object path. */ // Status status = mBus.registerBusObject(mChatService, OBJECT_PATH); // if (Status.OK != status) { // mChatApplication.alljoynError(ChatApplication.Module.HOST, "Unable to register the chat bus // object: (" + status + ")"); // return; // } Status status = mBus.connect(); if (status != Status.OK) { mActivity.alljoynError( MainActivity.Module.GENERAL, "Unable to connect to the bus: (" + status + ")"); return; } status = mBus.registerSignalHandlers(this); if (status != Status.OK) { mActivity.alljoynError( MainActivity.Module.GENERAL, "Unable to register signal handlers: (" + status + ")"); return; } mBusAttachmentState = BusAttachmentState.CONNECTED; }