2 *******************************************************************
4 * Copyright 2015 Intel Corporation.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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.base;
25 import android.content.Context;
26 import android.app.Activity;
27 import java.util.EnumSet;
29 * Data structure to provide the configuration.
31 public class PlatformConfig {
32 private Activity mActivity;
33 private Context mContext;
34 private ServiceType mServiceType;
35 private ModeType mModeType;
36 private String mIpAddress;
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;
45 private int mTransportType;
46 private byte[] mUuidSeed;
47 private int mUuidSeedSize;
50 * @param activity app activity
51 * @param context app context
52 * @param serviceType indicate IN_PROC or OUT_OF_PROC
53 * @param modeType indicate whether we want to do server, client or both
54 * @param ipAddress ip address of server
55 * if you specify 0.0.0.0 : it listens on any interface
56 * @param port port of server
57 * if you specifiy 0 : next available random port is used
58 * if you specify 5683 : client discovery can work even if they don't
60 * @param qualityOfService quality of service
61 * @param dbPath Persistant storage file for SVR Database.
62 * @param uuidSeed byte array of seed value for gernerating UUID.
63 * @param uuidSeedSize length of seed
65 public PlatformConfig(Activity activity,
67 ServiceType serviceType,
71 QualityOfService qualityOfService,
75 this.mActivity=activity;
76 this.mContext = context;
77 this.mServiceType = serviceType;
78 this.mModeType = modeType;
79 this.mIpAddress = ipAddress;
81 this.mQualityOfService = qualityOfService;
82 this.mSvrDbPath = dbPath;
83 this.mTransportType = 0;
84 this.mUuidSeed = seed;
85 this.mUuidSeedSize = seedSize;
88 public PlatformConfig(Context context,
89 ServiceType serviceType,
93 QualityOfService qualityOfService,
99 this.mContext = context;
100 this.mServiceType = serviceType;
101 this.mModeType = modeType;
102 this.mIpAddress = ipAddress;
104 this.mQualityOfService = qualityOfService;
105 this.mSvrDbPath = dbPath;
106 this.mSvrDbPathDefault = dbPathDefault;
107 this.mSvrDbPathRescue = dbPathRescue;
108 this.mKeySize = keySize;
110 this.mTransportType = 0;
114 * @param context app context
115 * @param serviceType indicate IN_PROC or OUT_OF_PROC
116 * @param modeType indicate whether we want to do server, client or both
117 * @param ipAddress ip address of server
118 * if you specify 0.0.0.0 : it listens on any interface
119 * @param port port of server
120 * if you specifiy 0 : next available random port is used
121 * if you specify 5683 : client discovery can work even if they don't
123 * @param qualityOfService quality of service
124 * @param dbPath Persistant storage file for SVR Database.
126 public PlatformConfig(Context context,
127 ServiceType serviceType,
131 QualityOfService qualityOfService,
133 this(null,context,serviceType,modeType,ipAddress,port,qualityOfService, dbPath, null, 0);
137 * @param context app context
138 * @param serviceType indicate IN_PROC or OUT_OF_PROC
139 * @param modeType indicate whether we want to do server, client or both
140 * @param ipAddress ip address of server
141 * if you specify 0.0.0.0 : it listens on any interface
142 * @param port port of server
143 * if you specifiy 0 : next available random port is used
144 * if you specify 5683 : client discovery can work even if they don't
146 * @param qualityOfService quality of service
147 * @param dbPath Persistant storage file for SVR Database.
148 * @param uuidSeed byte array of seed value for gernerating UUID.
149 * @param uuidSeedSize length of seed
151 public PlatformConfig(Context context,
152 ServiceType serviceType,
156 QualityOfService qualityOfService,
160 this(null,context,serviceType,modeType,ipAddress,port,qualityOfService, dbPath, uuidSeed, uuidSeedSize);
164 * @param context app context
165 * @param serviceType indicate IN_PROC or OUT_OF_PROC
166 * @param modeType indicate whether we want to do server, client or both
167 * @param ipAddress ip address of server
168 * if you specify 0.0.0.0 : it listens on any interface
169 * @param port port of server
170 * if you specifiy 0 : next available random port is used
171 * if you specify 5683 : client discovery can work even if they don't
173 * @param qualityOfService quality of service
175 // Avoid breaking building java samples due to persistent storage SVR DB changes.
176 public PlatformConfig(Context context,
177 ServiceType serviceType,
181 QualityOfService qualityOfService) {
182 this(null,context,serviceType,modeType,ipAddress,port,qualityOfService, "", null, 0);
186 * @param activity app activity
187 * @param context app context
188 * @param serviceType indicate IN_PROC or OUT_OF_PROC
189 * @param modeType indicate whether we want to do server, client or both
190 * @param ipAddress ip address of server
191 * if you specify 0.0.0.0 : it listens on any interface
192 * @param port port of server
193 * if you specifiy 0 : next available random port is used
194 * if you specify 5683 : client discovery can work even if they don't
196 * @param qualityOfService quality of service
198 // Avoid breaking building java samples due to persistent storage SVR DB changes.
199 public PlatformConfig(Activity activity,
201 ServiceType serviceType,
205 QualityOfService qualityOfService) {
206 this(activity,context,serviceType,modeType,ipAddress,port,qualityOfService, "", null, 0);
208 public Context getContext() {
212 public ServiceType getServiceType() {
216 public ModeType getModeType() {
220 public String getIpAddress() {
224 public int getPort() {
228 public QualityOfService getQualityOfService() {
229 return mQualityOfService;
232 public String getSvrDbPath() {
236 public Activity getActivity() {
240 public String getDBDefaultPath() {
241 return mSvrDbPathDefault;
244 public String getDBRescuePath() {
245 return mSvrDbPathRescue;
248 public int getKeySize()
253 public byte[] getKey()
258 public void setAvailableTransportType(EnumSet<OcConnectivityType> type) {
259 for (OcConnectivityType connType : OcConnectivityType.values()) {
260 if (type.contains(connType))
261 mTransportType |= connType.getValue();
265 public int getAvailableTransportType() {
266 return mTransportType;
269 public byte[] getUuidSeed()
274 public int getUuidSeedSize()
276 return mUuidSeedSize;