2 * ***************************************************************
4 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * ****************************************************************
23 package org.iotivity.service.easysetup.mediator;
26 * This is an abstract class represents the device being provisioned into the network. The
27 * device being enrolled or provisioned into the network is called Enrollee.
28 * Application has to extend this class and provide implementation of abstract methods according
29 * to the ON-BOARDING & PROVISION connectivity i.e. WiFi etc.
32 public abstract class EnrolleeDevice {
34 protected EnrolleeState mState;
35 private EnrolleeSetupError mError;
37 OnBoardingConnection mConnection;
38 final ProvisioningConfig mProvConfig;
39 final OnBoardingConfig mOnBoardingConfig;
41 protected OnBoardingCallback mOnBoardingCallback;
42 protected ProvisioningCallback mProvisioningCallback;
43 protected RemoteEnrollee mRemoteEnrollee;
46 * @param onBoardingConfig Contains details about the connectivity to be established between
47 * the Enrollee device & Mediator device in order to perform
49 * @param provConfig Contains details about the network to which Enrollee device is
52 protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
53 mProvConfig = provConfig;
54 mOnBoardingConfig = onBoardingConfig;
58 * Application has to implement it according to the on boarding connectivity the device is
60 * This method will be called back during the easy setup process.
62 protected abstract void startOnBoardingProcess();
65 * This method is called back during the easy setup process if Application cancels the setup.
66 * Easy setup service checks the state of device and calls this function accordingly.
67 * Application has to provide implementation for this method to cancel the on boarding step.
69 protected abstract void stopOnBoardingProcess();
72 * Application has to implement it according to the type of the network device is going to
73 * connect or provisioned.
74 * This method will be called back once on-boarding of the device is successful.
76 * @param conn Contains detail about the network established between the Enrollee device &
77 * Mediator device. Its implementation vary according to the connectivity type.
79 protected abstract void startProvisioningProcess(OnBoardingConnection conn);
82 * Application has to implement it according to the type of the network device is going to
83 * connect or provisioned.
84 * This method will stop the provisioning process if it is in progress
87 protected abstract void stopProvisioningProcess();
90 * Once on boarding is successful concrete Enrollee class would call this method and set the
93 * @param conn Connectivity between Enrollee device & Mediator device.
95 protected void setConnection(OnBoardingConnection conn) {
100 * This method returns the OnBoardingConnection object depending on the connection type
102 * @return onBoardingConnection object
104 public OnBoardingConnection getConnection() {
110 * This method is called back by Easy setup service if on boarding needs to be done.
112 * @param onBoardingCallback This is called back once the on boarding is completed.
114 void startOnBoarding(OnBoardingCallback onBoardingCallback) {
115 mOnBoardingCallback = onBoardingCallback;
116 startOnBoardingProcess();
120 * This method is called back by Easy setup service once on boarding is successful
122 * @param provisioningCallback This is called back once the provisioning process is completed
124 void startProvisioning(ProvisioningCallback provisioningCallback) {
125 mProvisioningCallback = provisioningCallback;
126 startProvisioningProcess(mConnection);
130 * This method is used to check easy setup status
132 * @return true if successful or false
135 public boolean isSetupSuccessful() {
136 return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;
140 * sets error occured during easy setup process
142 protected void setError(EnrolleeSetupError error) {
147 * Returns error occured during easy setup process
149 * @return True EnrolleeSetupError object
151 public EnrolleeSetupError getError() {
156 * Gives the state of the device being enrolled during the easy setup process.
158 * @return Returns EnrolleeState object
160 public EnrolleeState getState() {
165 * This method is used to know if the device is on boarded or not
167 * @return True if on-boarded successfully or False
170 protected boolean onBoarded() {
171 return (mState == EnrolleeState.DEVICE_ON_BOARDED_STATE) ? true : false;