1 //******************************************************************
3 // Copyright 2015 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 /// @file OnGetBelkinplug.java
23 /// @brief This class is OnGetListener for Belkinplug.
25 package org.iotivity.service.ppm;
27 import java.util.List;
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;
35 import android.util.Log;
37 public class OnGetBelkinplug implements OcResource.OnGetListener {
38 final private static String TAG = "PPMSampleApp : OnGetBelkinplug";
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);
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());
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);
63 Log.e(TAG, "updating display from thread");
64 MainActivity.mActivity.runOnUiThread(new Runnable() {
67 MainActivity.updateBelkinStatus();
73 public void onGetFailed(Throwable ex) {
74 if (ex instanceof OcException) {
75 OcException ocEx = (OcException) ex;
76 ErrorCode errCode = ocEx.getErrorCode();
78 Log.e(TAG, ex.toString());