Prevent issue fixes
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / src / prov_adapter.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 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 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <signal.h>
24 #include <unistd.h>
25 #include <stdint.h>
26 #include <sstream>
27
28 #include "prov_adapter.h"
29
30 //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
31 char ipv4addr[IPV4_ADDR_SIZE] = {0};
32
33 static OCProvisioningStatusCB cbData = NULL;
34
35 OCStackResult InitEasySetupManager() {
36
37
38     OCStackResult result = OC_STACK_ERROR;
39
40     if (InitProvisioningHandler() == OC_STACK_OK) {
41         result = OC_STACK_OK;
42         OIC_LOG(DEBUG, TAG, "InitProvisioningHandler returned Success");
43     } else {
44         result = OC_STACK_ERROR;
45         OIC_LOG_V(ERROR, TAG, "InitProvisioningHandler returned error = %s",
46                   result);
47     }
48
49     return result;
50 }
51
52 OCStackResult TerminateEasySetupManager() {
53     return TerminateProvisioningHandler();
54 }
55
56 OCStackResult RegisterProvisioningStausCallback(
57         OCProvisioningStatusCB provisioningStatusCallback) {
58     OCStackResult result = OC_STACK_OK;
59
60     if (provisioningStatusCallback != NULL) {
61         cbData = provisioningStatusCallback;
62     }
63     else {
64         result = OC_STACK_ERROR;
65         OIC_LOG(ERROR, TAG, "provisioningStatusCallback is NULL");
66     }
67
68     return result;
69 }
70
71 void UnRegisterProvisioningStausCallback() {
72     if (cbData) {
73         cbData = NULL;
74     }
75 }
76
77 OCStackResult ProvisionEnrollee(const EnrolleeNWProvInfo_t *netInfo) {
78     return StartProvisioningProcess(netInfo, cbData);
79 }
80
81 OCStackResult StopEnrolleeProvisioning(OCConnectivityType connectivityType) {
82     OCStackResult result = OC_STACK_OK;
83
84     //TODO: Have to handle the transport specific easy setup termination
85     StopProvisioningProcess();
86
87     return result;
88 }
89