Properly defined URI & Resource Type values for Presence Advertisement.
[contrib/iotivity.git] / android / SimpleClient / app / src / main / java / org / iotivity / simpleclient / OnObserve.java
1 //******************************************************************
2 //
3 // Copyright 2014 MediaTek All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 package org.iotivity.simpleclient;
22
23 import android.util.Log;
24
25 import org.iotivity.base.AbstractObserveCallback;
26 import org.iotivity.base.OCHeaderOption;
27 import org.iotivity.base.OCRepresentation;
28 import org.iotivity.base.OCStackResult;
29
30 public class OnObserve extends AbstractObserveCallback {
31     final private static String TAG = "OnObserve";
32
33     public void Callback(OCHeaderOption[] options, OCRepresentation rep, int eCode, int seqNum) {
34         if(eCode == OCStackResult.OC_STACK_OK) {
35             {
36                 Log.i(TAG, "OBSERVE RESULT :");
37                 Log.i(TAG, "SequenceNumber : " + seqNum);
38
39                 SimpleClient.mylight.m_state = rep.getValueBool("state");
40                 Log.i(TAG, "state : " + SimpleClient.mylight.m_state);
41                 SimpleClient.mylight.m_power = rep.getValueInt("power");
42                 Log.i(TAG, "power : " + SimpleClient.mylight.m_power);
43                 SimpleClient.mylight.m_name = rep.getValueString("name");
44                 Log.i(TAG, "name  : " + SimpleClient.mylight.m_name);
45
46                 new SimpleToast().execute(
47                         "state : " + SimpleClient.mylight.m_state +
48                                 "\npower : " + SimpleClient.mylight.m_power +
49                                 "\nname  : " + SimpleClient.mylight.m_name
50                 );
51
52                 if(SimpleClient.observe_count() > 5) {
53                     Log.i(TAG, "Cancelling Observe ...");
54                     OCStackResult result = SimpleClient.curResource.cancelObserve();
55                     Log.i(TAG, "Cancel result : " + result);
56                     try {
57                         Thread.sleep(10000); // 10 sec
58                     } catch (InterruptedException e) {
59                         // TODO Auto-generated catch block
60                         e.printStackTrace();
61                     }
62                     Log.i(TAG, "DONE");
63                     new SimpleToast().execute(
64                             "DONE"
65                     );
66                 }
67
68             }
69         }
70         else {
71             Log.e(TAG, "onPut Response error : " + eCode);
72         }
73
74     }
75 }