[ENROLLEE] Tizen enrollee sample application build using scons command
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / mediator / EnrolleeDevice.java
1 /**\r
2  * ***************************************************************\r
3  * <p/>\r
4  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
5  * <p/>\r
6  * <p/>\r
7  * <p/>\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  * <p/>\r
12  * http://www.apache.org/licenses/LICENSE-2.0\r
13  * <p/>\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * <p/>\r
20  * ****************************************************************\r
21  */\r
22 \r
23 package org.iotivity.service.easysetup.mediator;\r
24 \r
25 /**\r
26  * This is an abstract class represents the device being provisioned into the network. The\r
27  * device being enrolled or provisioned into the network is called Enrollee.\r
28  * Application has to extend this class and provide implementation of abstract methods according\r
29  * to the ON-BOARDING & PROVISION connectivity i.e. WiFi etc.\r
30  */\r
31 \r
32 public abstract class EnrolleeDevice {\r
33 \r
34     protected EnrolleeState mState;\r
35     private EnrolleeSetupError mError;\r
36 \r
37     protected OnBoardingConnection mConnection;\r
38     protected final ProvisioningConfig mProvConfig;\r
39     protected final OnBoardingConfig mOnBoardingConfig;\r
40 \r
41     protected OnBoardingCallback mOnBoardingCallback;\r
42     protected ProvisioningCallback mProvisioningCallback;\r
43 \r
44     /**\r
45      * @param onBoardingConfig Contains details about the connectivity to be established between\r
46      *                         the Enrollee device & Mediator device in order to perform\r
47      *                         on-boarding\r
48      * @param provConfig       Contains details about the network to which Enrollee device is\r
49      *                         going to connect.\r
50      */\r
51     protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {\r
52         mProvConfig = provConfig;\r
53         mOnBoardingConfig = onBoardingConfig;\r
54     }\r
55 \r
56     /**\r
57      * Application has to implement it according to the on boarding connectivity the device is\r
58      * having.\r
59      * This method will be called back during the easy setup process.\r
60      */\r
61     protected abstract void startOnBoardingProcess();\r
62 \r
63     /**\r
64      * This method is called back during the easy setup process if Application cancels the setup.\r
65      * Easy setup service checks the state of device and calls this function accordingly.\r
66      * Application has to provide implementation for this method to cancel the on boarding step.\r
67      */\r
68     protected abstract void stopOnBoardingProcess();\r
69 \r
70     /**\r
71      * Application has to implement it according to the type of the network device is going to\r
72      * connect or provisioned.\r
73      * This method will be called back once on-boarding of the device is successful.\r
74      *\r
75      * @param conn Contains detail about the network established between the Enrollee device &\r
76      *             Mediator device. Its implementation vary according to the connectivity type.\r
77      */\r
78     protected abstract void startProvisioningProcess(OnBoardingConnection conn);\r
79 \r
80     /**\r
81      * Once on boarding is successful concrete Enrollee class would call this method and set the\r
82      * Connection.\r
83      *\r
84      * @param conn Connectivity between Enrollee device & Mediator device.\r
85      */\r
86     protected void setConnection(OnBoardingConnection conn) {\r
87         mConnection = conn;\r
88     }\r
89 \r
90     /**\r
91      * This method returns the OnBoardingConnection object depending on the connection type\r
92      *\r
93      * @return onBoardingConnection object\r
94      */\r
95     public OnBoardingConnection getConnection() {\r
96         return mConnection;\r
97     }\r
98 \r
99 \r
100     /**\r
101      * This method is called back by Easy setup service if on boarding needs to be done.\r
102      *\r
103      * @param onBoardingCallback This is called back once the on boarding is completed.\r
104      */\r
105     void startOnBoarding(OnBoardingCallback onBoardingCallback) {\r
106         mOnBoardingCallback = onBoardingCallback;\r
107         startOnBoardingProcess();\r
108     }\r
109 \r
110     /**\r
111      * This method is called back by Easy setup service once on boarding is successful\r
112      *\r
113      * @param provisioningCallback This is called back once the provisioning process is completed\r
114      */\r
115     void startProvisioning(ProvisioningCallback provisioningCallback) {\r
116         mProvisioningCallback = provisioningCallback;\r
117         startProvisioningProcess(mConnection);\r
118     }\r
119 \r
120     /**\r
121      * This method is used to check easy setup status\r
122      *\r
123      * @return true if successful or false\r
124      */\r
125 \r
126     public boolean isSetupSuccessful() {\r
127         return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;\r
128     }\r
129 \r
130     /**\r
131      * sets error occured during easy setup process\r
132      */\r
133     protected void setError(EnrolleeSetupError error) {\r
134         mError = error;\r
135     }\r
136 \r
137     /**\r
138      * Returns error occured during easy setup process\r
139      *\r
140      * @return True EnrolleeSetupError object\r
141      */\r
142     public EnrolleeSetupError getError() {\r
143         return mError;\r
144     }\r
145 \r
146     /**\r
147      * Gives the state of the device being enrolled during the easy setup process.\r
148      *\r
149      * @return Returns EnrolleeState object\r
150      */\r
151     public EnrolleeState getState() {\r
152         return mState;\r
153     }\r
154 \r
155     /**\r
156      * This method is used to know if the device is on boarded or not\r
157      *\r
158      * @return True if on-boarded successfully or False\r
159      */\r
160 \r
161     protected boolean onBoarded() {\r
162         return (mState == EnrolleeState.DEVICE_ON_BOARDED_STATE) ? true : false;\r
163     }\r
164 \r
165 \r
166 }\r