AJ_Status AJServices_ConnectedHandler(AJ_BusAttachment* busAttachment) { AJ_BusSetPasswordCallback(busAttachment, PasswordCallback); /* Configure timeout for the link to the Router bus */ AJ_SetBusLinkTimeout(busAttachment, 60); // 60 seconds AJ_Status status = AJ_OK; status = AJ_About_ConnectedHandler(busAttachment); if (status != AJ_OK) { goto ErrorExit; } #ifdef CONFIG_SERVICE status = AJCFG_ConnectedHandler(busAttachment); if (status != AJ_OK) { goto ErrorExit; } #endif #ifdef ONBOARDING_SERVICE status = AJOBS_ConnectedHandler(busAttachment); if (status != AJ_OK) { goto ErrorExit; } #endif #ifdef NOTIFICATION_SERVICE_PRODUCER status = AJNS_Producer_ConnectedHandler(busAttachment); if (status != AJ_OK) { goto ErrorExit; } #endif #ifdef CONTROLPANEL_SERVICE status = AJCPS_ConnectedHandler(busAttachment); if (status != AJ_OK) { goto ErrorExit; } #endif #ifdef NOTIFICATION_SERVICE_CONSUMER status = AJNS_Consumer_ConnectedHandler(busAttachment); if (status != AJ_OK) { goto ErrorExit; } #endif return status; ErrorExit: AJ_AlwaysPrintf(("Service ConnectedHandler returned an error %s\n", (AJ_StatusText(status)))); return status; }
AJ_Status AJS_AttachAllJoyn(AJ_BusAttachment* aj) { AJ_Status status; uint8_t isConnected = FALSE; uint32_t linkTO = LINK_TO; size_t sapSz; /* * Initialize the onboarding service */ sapSz = min(sizeof(obSettings.AJOBS_SoftAPSSID), sizeof(softAPSSID)); memcpy((char*)obSettings.AJOBS_SoftAPSSID, softAPSSID, sapSz); status = AJOBS_Start(&obSettings); if (status != AJ_OK) { goto Exit; } AJ_InfoPrintf(("Attempting to attach to AllJoyn\n")); while (!isConnected) { status = AJSVC_RoutingNodeConnect(aj, busNode, CONNECT_TO, CONNECT_PAUSE, linkTO, &isConnected); if (status != AJ_ERR_TIMEOUT) { break; } } if (isConnected) { status = AJS_ServicesInit(aj); if (status != AJ_OK) { AJ_ErrPrintf(("Failed to initialize services")); } } if (isConnected && (AJOBS_GetState() != AJOBS_STATE_CONFIGURED_VALIDATED)) { /* * Kick of onboarding */ status = AJ_BusBindSessionPort(aj, ONBOARDING_PORT, NULL, 0); /* * Allow onboarding service to run its course */ while (status == AJ_OK) { AJ_Message msg; status = AJ_UnmarshalMsg(aj, &msg, MSG_TO); if (status == AJ_ERR_NO_MATCH) { /* * Discard unknown messages */ status = AJ_CloseMsg(&msg); continue; } if (status == AJ_ERR_TIMEOUT) { /* * Check the link is still up */ status = AJ_BusLinkStateProc(aj); if (status == AJ_OK) { continue; } } if (status != AJ_OK) { break; } switch (msg.msgId) { case AJ_REPLY_ID(AJ_METHOD_BIND_SESSION_PORT): AJ_AboutInit(aj, ONBOARDING_PORT); break; case AJ_METHOD_ACCEPT_SESSION: /* * TODO - check that the port number is correct */ status = AJ_BusReplyAcceptSession(&msg, TRUE); if (status == AJ_OK) { status = AJOBS_ConnectedHandler(aj); } break; default: /* * Let the service message handlers have first dibs on the message */ status = AJS_ServicesMsgHandler(&msg); if (status == AJ_ERR_NO_MATCH) { /* * Pass the unhandled message to the standard bus handler */ status = AJ_BusHandleBusMessage(&msg); if (status == AJ_ERR_NO_MATCH) { AJ_ErrPrintf(("Discarding unhandled message\n")); status = AJ_OK; } } break; } /* * Let the link monitor know we are receiving messages */ AJ_NotifyLinkActive(); /* * Free resources used by the message */ AJ_CloseMsg(&msg); if (AJOBS_GetState() == AJOBS_STATE_CONFIGURED_VALIDATED) { AJ_InfoPrintf(("Onboarding completed\n")); break; } AJ_InfoPrintf(("Onboarding continuing\n")); } /* * If we got an error during onboarding we should restart */ if (status != AJ_OK) { status = AJ_ERR_RESTART; } } /* * If all went well let the services know we are connected */ if (isConnected && (status == AJ_OK)) { /* * Add match rules to subscribe to session related signals */ status = AJ_BusSetSignalRuleFlags(aj, sessionLostMatchRule, AJ_BUS_SIGNAL_ALLOW, AJ_FLAG_NO_REPLY_EXPECTED); if (status == AJ_OK) { status = AJSVC_ConnectedHandler(aj); } } Exit: return status; }