Added Multi PHY EasySetup Service
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / core / 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.core;\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     public void setConnection(OnBoardingConnection conn) {\r
87         mConnection = conn;\r
88     }\r
89 \r
90     public OnBoardingConnection getConnection() {\r
91         return mConnection;\r
92     }\r
93 \r
94 \r
95     /**\r
96      * This method is called back by Easy setup service if on boarding needs to be done.\r
97      *\r
98      * @param onBoardingCallback This is called back once the on boarding is completed.\r
99      */\r
100     void startOnBoarding(OnBoardingCallback onBoardingCallback) {\r
101         mOnBoardingCallback = onBoardingCallback;\r
102         startOnBoardingProcess();\r
103     }\r
104 \r
105     /**\r
106      * This method is called back by Easy setup service once on boarding is successful\r
107      *\r
108      * @param provisioningCallback This is called back once the provisioning process is completed\r
109      */\r
110     void startProvisioning(ProvisioningCallback provisioningCallback) {\r
111         mProvisioningCallback = provisioningCallback;\r
112         startProvisioningProcess(mConnection);\r
113     }\r
114 \r
115     /**\r
116      * This method is used to check easy setup status\r
117      *\r
118      * @return true if successful or false\r
119      */\r
120 \r
121     public boolean isSetupSuccessful() {\r
122         return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;\r
123     }\r
124 \r
125     /**\r
126      * sets error occured during easy setup process\r
127      */\r
128     public void setError(EnrolleeSetupError error) {\r
129         mError = error;\r
130     }\r
131 \r
132     /**\r
133      * Returns error occured during easy setup process\r
134      *\r
135      * @return True EnrolleeSetupError object\r
136      */\r
137     public EnrolleeSetupError getError() {\r
138         return mError;\r
139     }\r
140 \r
141     /**\r
142      * Gives the state of the device being enrolled during the easy setup process.\r
143      *\r
144      * @return Returns EnrolleeState object\r
145      */\r
146     public EnrolleeState getState() {\r
147         return mState;\r
148     }\r
149 \r
150     /**\r
151      * This method is used to know if the device is on boarded or not\r
152      *\r
153      * @return True if on-boarded successfully or False\r
154      */\r
155 \r
156     public boolean onBoarded() {\r
157         return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;\r
158     }\r
159 \r
160 \r
161 }\r