replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / PlatformConfig.java
1 /*
2  *******************************************************************
3  *
4  * Copyright 2015 Intel Corporation.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base;
24
25 import android.content.Context;
26 import android.app.Activity;
27 import java.util.EnumSet;
28 /**
29  * Data structure to provide the configuration.
30  */
31 public class PlatformConfig {
32     private Activity mActivity;
33     private Context mContext;
34     private ServiceType mServiceType;
35     private ModeType mModeType;
36     private String mIpAddress;
37     private int mPort;
38     private QualityOfService mQualityOfService;
39     private String mSvrDbPath; //TODO: Instead of SVRDB file, it should be Persistent Storage.
40                               //this is only for 0.9.2
41     private String mSvrDbPathDefault;
42     private String mSvrDbPathRescue;
43     private int mKeySize;
44     private byte[] mKey;
45     private int mTransportType;
46     /**
47      * @param activity         app activity
48      * @param context          app context
49      * @param serviceType      indicate IN_PROC or OUT_OF_PROC
50      * @param modeType         indicate whether we want to do server, client or both
51      * @param ipAddress        ip address of server
52      *                         if you specify 0.0.0.0 : it listens on any interface
53      * @param port             port of server
54      *                         if you specifiy 0 : next available random port is used
55      *                         if you specify 5683 : client discovery can work even if they don't
56      *                         specify port
57      * @param qualityOfService quality of service
58      * @param dbPath           Persistant storage file for SVR Database.
59      */
60     public PlatformConfig(Activity activity,
61                           Context context,
62                           ServiceType serviceType,
63                           ModeType modeType,
64                           String ipAddress,
65                           int port,
66                           QualityOfService qualityOfService,
67                           String dbPath) {
68         this.mActivity=activity;
69         this.mContext = context;
70         this.mServiceType = serviceType;
71         this.mModeType = modeType;
72         this.mIpAddress = ipAddress;
73         this.mPort = port;
74         this.mQualityOfService = qualityOfService;
75         this.mSvrDbPath = dbPath;
76         this.mTransportType = 0;
77     }
78
79     public PlatformConfig(Context context,
80                           ServiceType serviceType,
81                           ModeType modeType,
82                           String ipAddress,
83                           int port,
84                           QualityOfService qualityOfService,
85                           String dbPath,
86                           String dbPathDefault,
87                           String dbPathRescue,
88                           int keySize,
89                           byte[] key) {
90         this.mContext = context;
91         this.mServiceType = serviceType;
92         this.mModeType = modeType;
93         this.mIpAddress = ipAddress;
94         this.mPort = port;
95         this.mQualityOfService = qualityOfService;
96         this.mSvrDbPath = dbPath;
97         this.mSvrDbPathDefault = dbPathDefault;
98         this.mSvrDbPathRescue = dbPathRescue;
99         this.mKeySize = keySize;
100         this.mKey = key;
101         this.mTransportType = 0;
102     }
103     /**
104      * @param context          app context
105      * @param serviceType      indicate IN_PROC or OUT_OF_PROC
106      * @param modeType         indicate whether we want to do server, client or both
107      * @param ipAddress        ip address of server
108      *                         if you specify 0.0.0.0 : it listens on any interface
109      * @param port             port of server
110      *                         if you specifiy 0 : next available random port is used
111      *                         if you specify 5683 : client discovery can work even if they don't
112      *                         specify port
113      * @param qualityOfService quality of service
114      * @param dbPath           Persistant storage file for SVR Database.
115      */
116     public PlatformConfig(Context context,
117                           ServiceType serviceType,
118                           ModeType modeType,
119                           String ipAddress,
120                           int port,
121                           QualityOfService qualityOfService,
122                           String dbPath) {
123         this(null,context,serviceType,modeType,ipAddress,port,qualityOfService, dbPath);
124     }
125
126     /**
127      * @param context          app context
128      * @param serviceType      indicate IN_PROC or OUT_OF_PROC
129      * @param modeType         indicate whether we want to do server, client or both
130      * @param ipAddress        ip address of server
131      *                         if you specify 0.0.0.0 : it listens on any interface
132      * @param port             port of server
133      *                         if you specifiy 0 : next available random port is used
134      *                         if you specify 5683 : client discovery can work even if they don't
135      *                         specify port
136      * @param qualityOfService quality of service
137      */
138     // Avoid breaking building java samples due to persistent storage SVR DB changes.
139     public PlatformConfig(Context context,
140                           ServiceType serviceType,
141                           ModeType modeType,
142                           String ipAddress,
143                           int port,
144                           QualityOfService qualityOfService) {
145         this(null,context,serviceType,modeType,ipAddress,port,qualityOfService, "");
146     }
147
148     /**
149      * @param activity         app activity
150      * @param context          app context
151      * @param serviceType      indicate IN_PROC or OUT_OF_PROC
152      * @param modeType         indicate whether we want to do server, client or both
153      * @param ipAddress        ip address of server
154      *                         if you specify 0.0.0.0 : it listens on any interface
155      * @param port             port of server
156      *                         if you specifiy 0 : next available random port is used
157      *                         if you specify 5683 : client discovery can work even if they don't
158      *                         specify port
159      * @param qualityOfService quality of service
160      */
161     // Avoid breaking building java samples due to persistent storage SVR DB changes.
162     public PlatformConfig(Activity activity,
163                           Context context,
164                           ServiceType serviceType,
165                           ModeType modeType,
166                           String ipAddress,
167                           int port,
168                           QualityOfService qualityOfService) {
169         this(activity,context,serviceType,modeType,ipAddress,port,qualityOfService, "");
170     }
171     public Context getContext() {
172         return mContext;
173     }
174
175     public ServiceType getServiceType() {
176         return mServiceType;
177     }
178
179     public ModeType getModeType() {
180         return mModeType;
181     }
182
183     public String getIpAddress() {
184         return mIpAddress;
185     }
186
187     public int getPort() {
188         return mPort;
189     }
190
191     public QualityOfService getQualityOfService() {
192         return mQualityOfService;
193     }
194
195     public String getSvrDbPath() {
196         return mSvrDbPath;
197     }
198
199     public Activity getActivity() {
200         return mActivity;
201     }
202
203     public String getDBDefaultPath() {
204         return mSvrDbPathDefault;
205     }
206
207     public String getDBRescuePath() {
208         return mSvrDbPathRescue;
209     }
210
211     public int getKeySize()
212     {
213         return mKeySize;
214     }
215
216     public byte[] getKey()
217     {
218         return mKey;
219     }
220
221     public void setAvailableTransportType(EnumSet<OcConnectivityType> type) {
222         for (OcConnectivityType connType : OcConnectivityType.values()) {
223             if (type.contains(connType))
224                 mTransportType |= connType.getValue();
225         }
226     }
227
228     public int getAvailableTransportType() {
229         return mTransportType;
230     }
231 }