3e58264f30d86001f0203dcf31b64140db8570a0
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Android / src / org / iotivity / service / ppm / OnGetBelkinplug.java
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 /// @file OnGetBelkinplug.java
22
23 /// @brief This class is OnGetListener for Belkinplug.
24
25 package org.iotivity.service.ppm;
26
27 import java.util.List;
28
29 import org.iotivity.base.ErrorCode;
30 import org.iotivity.base.OcException;
31 import org.iotivity.base.OcHeaderOption;
32 import org.iotivity.base.OcRepresentation;
33 import org.iotivity.base.OcResource;
34
35 import android.util.Log;
36
37 public class OnGetBelkinplug implements OcResource.OnGetListener {
38     final private static String TAG = "OnGetBelkinplug";
39
40     @Override
41     public void onGetCompleted(List<OcHeaderOption> headerOptions,
42             OcRepresentation rep) {
43         Log.i(TAG, "GET request Belkin wemo plug was successful");
44         Log.i(TAG, "Resource URI : " + rep.getUri());
45         Log.i(TAG, "power : " + MainActivity.belkinplug.m_power);
46
47         try{
48             MainActivity.belkinplug.m_name = rep.getValue("name");
49             MainActivity.belkinplug.m_power = rep.getValue("power");
50             MainActivity.belkinplug.m_bright = rep.getValue("brightness");
51             MainActivity.belkinplug.m_color = rep.getValue("color");
52             MainActivity.belkinplug.m_uri = rep.getValue("uri");
53         } catch (OcException e) {
54             Log.e(TAG, e.getMessage());
55         }
56
57         Log.i(TAG, "name : " + MainActivity.belkinplug.m_name);
58         Log.i(TAG, "power : " + MainActivity.belkinplug.m_power);
59         Log.i(TAG, "brightness : " + MainActivity.belkinplug.m_bright);
60         Log.i(TAG, "color : " + MainActivity.belkinplug.m_color);
61         Log.i(TAG, "uri : " + MainActivity.belkinplug.m_uri);
62
63         Log.e(TAG, "updating display from thread");
64         MainActivity.mActivity.runOnUiThread(new Runnable() {
65             @Override
66             public void run() {
67                 MainActivity.updateBelkinStatus();
68             }
69         });
70     }
71
72     @Override
73     public void onGetFailed(Throwable ex) {
74         if (ex instanceof OcException) {
75             OcException ocEx = (OcException) ex;
76             ErrorCode errCode = ocEx.getErrorCode();
77         }
78         Log.e(TAG, ex.toString());
79     }
80 }