Merge test folder of test branch
[iotivity.git] / test / src / iBtestapp / modules / ic / android / src / org / iotivity / test / ic / app / ICResourceDirectoryCommonAdapter.java
1 /******************************************************************
2  *
3  * Copyright 2017 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 package org.iotivity.test.ic.app;
22
23 import java.util.List;
24 import android.util.Log;
25
26 import org.iotivity.base.OcAccountManager.OnDeleteListener;
27 import org.iotivity.base.OcAccountManager.OnGetListener;
28 import org.iotivity.base.OcConnectivityType;
29 import org.iotivity.base.OcRepresentation;
30 import org.iotivity.base.OcResource;
31 import org.iotivity.base.OcPlatform;
32 import org.iotivity.base.OcException;
33 import org.iotivity.base.OcAccountManager.OnObserveListener;
34 import org.iotivity.base.PlatformConfig;
35 import org.iotivity.base.ServiceType;
36 import org.iotivity.base.ModeType;
37 import org.iotivity.base.QualityOfService;
38 import org.iotivity.base.EntityHandlerResult;
39 import org.iotivity.base.OcResourceRequest;
40 import org.iotivity.base.ResourceProperty;
41 import org.iotivity.base.OcResourceHandle;
42 import org.iotivity.base.OcAccountManager.OnPostListener;
43 import org.iotivity.base.OcHeaderOption;
44 import org.iotivity.base.ErrorCode;
45 import org.iotivity.base.OcRDClient;
46 import org.iotivity.base.OcAccountManager;
47
48 import static org.iotivity.test.ic.app.ICUtility.*;
49 import org.iotivity.service.testapp.framework.Base;
50
51 public class ICResourceDirectoryCommonAdapter extends Base
52         implements OcRDClient.OnPublishResourceListener,
53         OcRDClient.OnDeleteResourceListener, OcResource.OnObserveListener,
54         OcPlatform.OnResourceFoundListener {
55
56     public static boolean    isOnPublishResourceCompleted = false;
57     public static boolean    onDeleteResourceCompleted    = false;
58     public static OcResource mFoundResource               = null;
59
60     public ICResourceDirectoryCommonAdapter() {
61
62     }
63
64     @Override
65     public void onObserveCompleted(List<OcHeaderOption> arg0,
66             OcRepresentation arg1, int arg2) {
67         showOutPut("Observe Completed.");
68     }
69
70     @Override
71     public void onObserveFailed(Throwable arg0) {
72         showOutPut("Observed Failed");
73     }
74
75     @Override
76     public void onDeleteResourceCompleted(int resultCode) {
77         showOutPut("onDeleteResourceCompleted, result is " + resultCode);
78         onDeleteResourceCompleted = true;
79     }
80
81     public void onDeleteResourceFailed(Throwable arg0) {
82         showOutPut("onDeleteResource failed");
83         onDeleteResourceCompleted = true;
84     }
85
86     @Override
87     public void onPublishResourceCompleted(OcRepresentation ocRepresentation) {
88         showOutPut("onPublishResourceCompleted");
89         isOnPublishResourceCompleted = true;
90         for (OcRepresentation child : ocRepresentation.getChildren()) {
91             try {
92                 System.out.println(
93                         "\tPublished Resource URI : " + child.getValue("href"));
94             } catch (OcException e) {
95                 e.printStackTrace();
96             }
97         }
98     }
99
100     @Override
101     public void onPublishResourceFailed(Throwable throwable) {
102         showOutPut("onPublishResourceFailed has failed");
103         isOnPublishResourceCompleted = true;
104     }
105
106     @Override
107     public void onResourceFound(OcResource ocResource) {
108         final String resourceUri = ocResource.getUri();
109
110         if (mFoundResource == null) {
111             if (resourceUri.contains("/a/light")) {
112                 showOutPut("onResourceFound : " + ocResource.getUri());
113                 mFoundResource = ocResource;
114             }
115         }
116     }
117
118     @Override
119     public void onFindResourceFailed(Throwable throwable, String uri) {
120         showOutPut("findResource request has failed");
121     }
122 }