added code to close the netlink socket.
[contrib/iotivity.git] / android / examples / fridgegroupserver / src / main / java / org / iotivity / base / examples / FridgeResource.java
1 /*
2  *******************************************************************
3  *
4  * Copyright 2015 Intel Corporation.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base.examples;
24
25 import android.content.Context;
26 import android.content.Intent;
27 import android.util.Log;
28
29 import org.iotivity.base.OcException;
30 import org.iotivity.base.OcPlatform;
31 import org.iotivity.base.OcResourceHandle;
32 import org.iotivity.base.ResourceProperty;
33
34 import java.util.EnumSet;
35
36
37 /**
38  * FridgeResource
39  * <p/>
40  * FridgeResource is a sample OIC server resource created by the refrigerator.
41  */
42 public class FridgeResource extends Resource {
43     FridgeResource(Context context) {
44         mContext = context;
45         registerFridgeResource();
46     }
47
48     private void registerFridgeResource() {
49         try {
50             logMessage(TAG + "RegisterFridgeResource " + FRIDGE_URI +
51                     " : " + FRIDGE_TYPENAME);
52             mResourceHandle = OcPlatform.registerResource(
53                     FRIDGE_URI,
54                     FRIDGE_TYPENAME,
55                     OcPlatform.GROUP_INTERFACE,
56                     null,
57                     EnumSet.of(ResourceProperty.DISCOVERABLE));
58         } catch (OcException e) {
59             logMessage(TAG + "FridgeResource register error: " + e.getMessage());
60             Log.e(TAG, e.getMessage());
61         }
62         logMessage("-----------------------------------------------------");
63     }
64
65     public OcResourceHandle getHandle() {
66         return mResourceHandle;
67     }
68
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: ";
76
77     private void logMessage(String msg) {
78         Intent intent = new Intent(Resource.INTENT);
79         intent.putExtra("message", msg);
80         mContext.sendBroadcast(intent);
81     }
82 }