2 *******************************************************************
4 * Copyright 2015 Intel Corporation.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.base.examples;
25 import android.content.Context;
26 import android.content.Intent;
27 import android.util.Log;
29 import org.iotivity.base.OcException;
30 import org.iotivity.base.OcPlatform;
31 import org.iotivity.base.OcResourceHandle;
32 import org.iotivity.base.ResourceProperty;
34 import java.util.EnumSet;
40 * FridgeResource is a sample OIC server resource created by the refrigerator.
42 public class FridgeResource extends Resource {
43 FridgeResource(Context context) {
45 registerFridgeResource();
48 private void registerFridgeResource() {
50 logMessage(TAG + "RegisterFridgeResource " + FRIDGE_URI +
51 " : " + FRIDGE_TYPENAME);
52 mResourceHandle = OcPlatform.registerResource(
55 OcPlatform.GROUP_INTERFACE,
57 EnumSet.of(ResourceProperty.DISCOVERABLE));
58 } catch (OcException e) {
59 logMessage(TAG + "FridgeResource register error: " + e.getMessage());
60 Log.e(TAG, e.getMessage());
62 logMessage("-----------------------------------------------------");
65 public OcResourceHandle getHandle() {
66 return mResourceHandle;
69 //******************************************************************************
70 // End of the OIC specific code
71 //******************************************************************************
72 private Context mContext;
73 public static final String FRIDGE_URI = "/fridge/group";
74 public static final String FRIDGE_TYPENAME = "intel.fridge.group";
75 private static String TAG = "FridgeResource: ";
77 private void logMessage(String msg) {
78 Intent intent = new Intent(Resource.INTENT);
79 intent.putExtra("message", msg);
80 mContext.sendBroadcast(intent);