/** * Listen for messages that match a specific message identifier. * <P> * This function calls the native API to listen for incoming messages and * optionally registers a user-supplied callback. The callback is invoked when * a message has has added to the message pool. * <P> * The callback function will be called with the incoming CBS and the user * supplied data (userData). * <P> * The message is retained in the message pool until * <code>jsr120_cbs_pool_get_next_msg()</code> is called. * * When <code>NULL</code> is supplied as a callback function, messages will be * added to the message pool, but no listener will be called.. * * @param msgID The message identifier to be matched. * @param listener The CBS listener. * @param userData Any special data associated with the listener. * @param listeners List of listeners in which to be registered. * * @return <code>WMA_OK</code> if successful; <code>WMA_ERR</code> if the * identifier has already been registered or if native registration failed. */ static WMA_STATUS jsr120_cbs_register_msgID(jchar msgID, SuiteIdType msid, cbs_listener_t* listener, void* userData, ListElement **listeners) { /* Assume no success in registering the message ID. */ WMA_STATUS ok = WMA_ERR; if (jsr120_cbs_is_msgID_registered(msgID, *listeners) == WMA_ERR) { ok = jsr120_add_cbs_listening_msgID(msgID); jsr120_list_new_by_number(listeners, msgID, msid, userData, (void*)listener); } return ok; }
/** * Add a CBS message to the message pool. If the pool is full (i.e., there are * at least <code>MAX_CBS_MESSAGES_IN_POOL</code>), then the oldest messages are * discarded. * * @param cbsMessage The CBS message to be added. * * @return <code>WMA_OK</code> if the message was successfully added to the pool. * <code>WMA_ERR</code>, otherwise. * */ WMA_STATUS jsr120_cbs_pool_add_msg(CbsMessage* cbsMessage) { ListElement* newItem; /* If there is no message to add, bail out. */ if (cbsMessage == NULL) { return WMA_ERR; } /* Make room for this message, if necessary. */ jsr120_cbs_pool_check_quota(); /* Create the new pool item and add it to the pool. */ newItem = jsr120_list_new_by_number(NULL, cbsMessage->msgID, UNUSED_APP_ID, (void*)cbsMessage, 0); jsr120_list_add_last(&CBSPool_messages, newItem); jsr120_cbs_pool_increase_count(); return WMA_OK; }