1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 package org.iotivity.service.ns.sample.provider;
23 import android.util.Log;
25 import org.iotivity.service.ns.common.Message;
26 import org.iotivity.service.ns.common.SyncInfo;
27 import org.iotivity.service.ns.consumer.ConsumerService;
28 import org.iotivity.service.ns.consumer.Provider;
30 import java.util.concurrent.CountDownLatch;
32 class ConsumerSimulator implements ConsumerService.OnProviderDiscoveredListener,
33 Provider.OnProviderStateListener, Provider.OnMessageReceivedListener,
34 Provider.OnSyncInfoReceivedListener {
35 private String TAG = "Consumer Simulator";
36 private Provider mProvider;
37 private CountDownLatch mLockObject;
38 private Response mResponse;
39 private String mExpectCb;
41 public void set(CountDownLatch lockObject, Response response, String name) {
42 Log.i(TAG, "Setting lock Simulator: ");
43 mLockObject = lockObject;
49 public void onProviderDiscovered(Provider provider) {
52 provider.setListener(this, this, this);
53 if (!provider.isSubscribed()) {
56 } catch (Exception e) {
63 public void onProviderStateReceived(Provider.ProviderState providerState) {
67 public void onMessageReceived(Message message) {
68 if (mExpectCb == "msg") {
70 mLockObject.countDown();
75 public void onSyncInfoReceived(SyncInfo syncInfo) {
76 if (mExpectCb == "sync") {
78 mLockObject.countDown();
82 public void sendSyncInfo(long id, SyncInfo.SyncType type) {
84 mProvider.sendSyncInfo(id, type);
85 } catch (Exception e) {