import java.util.Vector;
/**
- * @class Provider
- * @brief This class provides implementation of Notification Provider object.
- */
-public class Provider
-{
+ *
+ * This class provides implementation of Notification Provider object.
+ *
+ */
+public class Provider {
+
private static final String LOG_TAG = "ConsumerService_Provider";
/**
- * ProviderState of Notification resource
- */
- public enum ProviderState
- {
+ * Enum for defining different state of provider object
+ */
+ public enum ProviderState {
ALLOW(1),
DENY(2),
TOPIC(3),
STOPPED(12);
+
private int state;
- private ProviderState(int state)
- {
+ private ProviderState(int state) {
this.state = state;
}
- public int getProviderState()
- {
+ public int getProviderState() {
return this.state;
}
};
- public String mProviderId = null;
- private long mNativeHandle = 0;
+ private String mProviderId = null;
+ private long mNativeHandle = 0;
/**
- * Constructor of Provider.
- * @param providerId - providerId of Provider.
- */
- public Provider(String providerId)
- {
- Log.i (LOG_TAG, "Provider()");
+ * Constructor of Provider.
+ *
+ * @param providerId
+ * unique Id of Provider
+ */
+ public Provider(String providerId) {
+ Log.i(LOG_TAG, "Provider()");
mProviderId = providerId;
}
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ nativeDispose();
+ } catch (Throwable t) {
+ throw t;
+ } finally {
+ super.finalize();
+ }
+ }
/**
- * API for getting providerId.
- * @return ConsumerId as string.
- */
- public String getProviderId()
- {
- return mProviderId ;
+ * API for getting providerId
+ *
+ * @return ConsumerId as string
+ */
+ public String getProviderId() {
+ return mProviderId;
}
/**
- * API for getting for getting Topic List.
- * @return TopicsList.
- */
- public TopicsList getTopicList() throws NSException
- {
+ * API for getting for getting Topic List
+ *
+ * @return TopicsList
+ */
+ public TopicsList getTopicList() throws NSException {
return nativeGetTopicList();
}
/**
- * API for getting for getting ProviderState.
- * @return ProviderState.
- */
- public ProviderState getProviderState() throws NSException
- {
+ * API for getting for getting ProviderState
+ *
+ * @return ProviderState
+ */
+ public ProviderState getProviderState() throws NSException {
return nativeGetProviderState();
}
/**
- * API for for requesting subscription of Notification service.
- */
- public void subscribe() throws NSException
- {
+ * API for requesting subscription of Notification service
+ * This API should be called with a valid Provider object obtained from Discovery callback.
+ * The API should not be called when the Provider is in STOPPED state.
+ *
+ * Discovery APIs to discover Providers are as below.
+ * Start/rescanProvider for D2D,
+ * enableRemoteService for D2S,
+ *
+ * @throws NSException failure to subscribe
+ */
+ public void subscribe() throws NSException {
nativeSubscribe();
}
/**
- * API for for requesting subscription status from Provider of Notification service.
- */
- public boolean isSubscribed () throws NSException
- {
+ * API for requesting unsubscription of Notification service
+ *
+ * This API should be called with a valid Provider object obtained from Discovery callback.
+ * The API should not be called when the Provider is in STOPPED state.
+ *
+ * @throws NSException failure to subscribe
+ */
+ public void unsubscribe() throws NSException {
+ nativeUnsubscribe();
+ }
+
+ /**
+ * API for requesting subscription status from Provider of Notification
+ * service
+ */
+ public boolean isSubscribed() throws NSException {
return nativeIsSubscribed();
}
/**
- * This method is for Sending SyncInfo of Notification service.
- * @param messageId - id of message.
- * @param syncType - SyncType of Notification service.
- */
- public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
- {
+ * This method is for Sending SyncInfo of Notification service.
+ *
+ * @param messageId
+ * unique Id of message
+ * @param syncType
+ * SyncType of Notification service
+ */
+ public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType)
+ throws NSException {
nativeSendSyncInfo(messageId, syncType.ordinal());
}
/**
- * This method is for registering for listeners of Notification .
- * @param onProviderStateListener - OnProviderStateListener callback Interface.
- * @param onMessageReceivedListner - OnMessageReceivedListner callback Interface.
- * @param onSyncInfoReceivedListner - OnSyncInfoReceivedListner callback Interface.
- */
+ * This method is for registering for listeners of Notification .
+ *
+ * @param onProviderStateListener
+ * OnProviderStateListener callback Interface
+ * @param onMessageReceivedListner
+ * OnMessageReceivedListner callback Interface
+ * @param onSyncInfoReceivedListner
+ * OnSyncInfoReceivedListner callback Interface
+ */
public void setListener(OnProviderStateListener onProviderStateListener,
- OnMessageReceivedListner onMessageReceivedListner,
- OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
- {
- nativeSetListener(onProviderStateListener, onMessageReceivedListner, onSyncInfoReceivedListner);
+ OnMessageReceivedListener onMessageReceivedListener,
+ OnSyncInfoReceivedListener onSyncInfoReceivedListener)
+ throws NSException {
+ nativeSetListener(onProviderStateListener, onMessageReceivedListener,
+ onSyncInfoReceivedListener);
}
/**
- * Update Topic list that is wanted to be subscribed from provider
- * @param topicsList - TopicsList of interested Topics.
- * @return :: result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
- */
- public int updateTopicList(TopicsList topicsList) throws NSException
- {
- return nativeUpdateTopicList(topicsList);
+ * Update Topic list that is wanted to be subscribed from provider
+ *
+ * @param topicsList
+ * TopicsList of interested Topics
+ *
+ * @throws NSException failure to update topic list.
+ */
+ public void updateTopicList(TopicsList topicsList) throws NSException {
+ nativeUpdateTopicList(topicsList);
}
/**
- * Interface to implement callback function to receive provider state information
- */
- public interface OnProviderStateListener
- {
+ * Interface to implement callback function to receive provider state
+ * information
+ */
+ public interface OnProviderStateListener {
+
/**
- * Callback function to receive provider state information
- * @param state - ProviderState
- */
+ * Callback function to receive provider state information
+ *
+ * @param state
+ * ProviderState
+ */
public void onProviderStateReceived(ProviderState state);
}
/**
- * Interface to implement callback function to receive Notification Message
- */
- public interface OnMessageReceivedListner
- {
+ * Interface to implement callback function to receive Notification Message
+ */
+ public interface OnMessageReceivedListener {
+
/**
- * Callback function to receive Notification Message
- * @param message - Notification Message
- */
+ * Callback function to receive Notification Message.
+ *
+ * @param message
+ * Notification Message
+ */
public void onMessageReceived(Message message);
}
/**
- * Interface to implement callback function to receive message read synchronization
- */
- public interface OnSyncInfoReceivedListner
- {
+ * Interface to implement callback function to receive message read
+ * synchronization
+ */
+ public interface OnSyncInfoReceivedListener {
+
/**
- * Callback function to receive message read synchronization
- * @param sync - SyncInfo
- */
+ * Callback function to receive message read synchronization
+ *
+ * @param sync
+ * SyncInfo
+ */
public void onSyncInfoReceived(SyncInfo sync);
}
private native void nativeSubscribe() throws NSException;
- private native void nativeSendSyncInfo(long messageId, int syncType) throws NSException;
- private native void nativeSetListener(OnProviderStateListener onProviderStateListener,
- OnMessageReceivedListner onMessageReceivedListner,
- OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException;
- public native TopicsList nativeGetTopicList() throws NSException;
- private native int nativeUpdateTopicList(TopicsList topicsList) throws NSException;
+ private native void nativeUnsubscribe() throws NSException;
+
+ private native void nativeSendSyncInfo(long messageId, int syncType)
+ throws NSException;
+
+ private native void nativeSetListener(
+ OnProviderStateListener onProviderStateListener,
+ OnMessageReceivedListener onMessageReceivedListener,
+ OnSyncInfoReceivedListener onSyncInfoReceivedListener)
+ throws NSException;
+
+ private native TopicsList nativeGetTopicList() throws NSException;
+
+ private native void nativeUpdateTopicList(TopicsList topicsList)
+ throws NSException;
+
private native ProviderState nativeGetProviderState() throws NSException;
- public native boolean nativeIsSubscribed() throws NSException;
+
+ private native boolean nativeIsSubscribed() throws NSException;
+
+ private native void nativeDispose();
}