2 * ***************************************************************
\r
4 * Copyright 2015 Samsung Electronics All Rights Reserved.
\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
12 * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * ****************************************************************
\r
23 package org.iotivity.service.easysetup.mediator;
\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
32 public abstract class EnrolleeDevice {
\r
34 protected EnrolleeState mState;
\r
35 private EnrolleeSetupError mError;
\r
37 protected OnBoardingConnection mConnection;
\r
38 protected final ProvisioningConfig mProvConfig;
\r
39 protected final OnBoardingConfig mOnBoardingConfig;
\r
41 protected OnBoardingCallback mOnBoardingCallback;
\r
42 protected ProvisioningCallback mProvisioningCallback;
\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
48 * @param provConfig Contains details about the network to which Enrollee device is
\r
51 protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
\r
52 mProvConfig = provConfig;
\r
53 mOnBoardingConfig = onBoardingConfig;
\r
57 * Application has to implement it according to the on boarding connectivity the device is
\r
59 * This method will be called back during the easy setup process.
\r
61 protected abstract void startOnBoardingProcess();
\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
68 protected abstract void stopOnBoardingProcess();
\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
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
78 protected abstract void startProvisioningProcess(OnBoardingConnection conn);
\r
81 * Once on boarding is successful concrete Enrollee class would call this method and set the
\r
84 * @param conn Connectivity between Enrollee device & Mediator device.
\r
86 protected void setConnection(OnBoardingConnection conn) {
\r
91 * This method returns the OnBoardingConnection object depending on the connection type
\r
93 * @return onBoardingConnection object
\r
95 public OnBoardingConnection getConnection() {
\r
101 * This method is called back by Easy setup service if on boarding needs to be done.
\r
103 * @param onBoardingCallback This is called back once the on boarding is completed.
\r
105 void startOnBoarding(OnBoardingCallback onBoardingCallback) {
\r
106 mOnBoardingCallback = onBoardingCallback;
\r
107 startOnBoardingProcess();
\r
111 * This method is called back by Easy setup service once on boarding is successful
\r
113 * @param provisioningCallback This is called back once the provisioning process is completed
\r
115 void startProvisioning(ProvisioningCallback provisioningCallback) {
\r
116 mProvisioningCallback = provisioningCallback;
\r
117 startProvisioningProcess(mConnection);
\r
121 * This method is used to check easy setup status
\r
123 * @return true if successful or false
\r
126 public boolean isSetupSuccessful() {
\r
127 return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;
\r
131 * sets error occured during easy setup process
\r
133 protected void setError(EnrolleeSetupError error) {
\r
138 * Returns error occured during easy setup process
\r
140 * @return True EnrolleeSetupError object
\r
142 public EnrolleeSetupError getError() {
\r
147 * Gives the state of the device being enrolled during the easy setup process.
\r
149 * @return Returns EnrolleeState object
\r
151 public EnrolleeState getState() {
\r
156 * This method is used to know if the device is on boarded or not
\r
158 * @return True if on-boarded successfully or False
\r
161 protected boolean onBoarded() {
\r
162 return (mState == EnrolleeState.DEVICE_ON_BOARDED_STATE) ? true : false;
\r