Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcConnectivityType.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 java.security.InvalidParameterException;
26 import java.util.EnumSet;
27
28 public enum OcConnectivityType {
29     /** use when defaults are ok. */
30     CT_DEFAULT              (0),
31
32     /** IPv4 and IPv6, including 6LoWPAN.*/
33     CT_ADAPTER_IP           (1 << 16),
34
35     /** GATT over Bluetooth LE.*/
36     CT_ADAPTER_GATT_BTLE    (1 << 17),
37
38     /** RFCOMM over Bluetooth EDR.*/
39     CT_ADAPTER_RFCOMM_BTEDR (1 << 18),
40
41     /** Remote Access over XMPP.*/
42     CT_ADAPTER_REMOTE_ACCESS(1 << 19),
43
44     /** Insecure transport is the default (subject to change).*/
45
46     /** secure the transport path.*/
47     CT_FLAG_SECURE          (1 << 4),
48
49     /** IPv4 & IPv6 autoselection is the default.*/
50
51     /** IP adapter only.*/
52     CT_IP_USE_V6            (1 << 5),
53
54     /** IP adapter only.*/
55     CT_IP_USE_V4            (1 << 6),
56
57     /** Link-Local multicast is the default multicast scope for IPv6.
58      * These are placed here to correspond to the IPv6 address bits.*/
59
60     /** IPv6 Interface-Local scope(loopback).*/
61     CT_SCOPE_INTERFACE      (0x1),
62
63     /** IPv6 Link-Local scope (default).*/
64     CT_SCOPE_LINK           (0x2),
65
66     /** IPv6 Realm-Local scope.*/
67     CT_SCOPE_REALM          (0x3),
68
69     /** IPv6 Admin-Local scope.*/
70     CT_SCOPE_ADMIN          (0x4),
71
72     /** IPv6 Site-Local scope.*/
73     CT_SCOPE_SITE           (0x5),
74
75     /** IPv6 Organization-Local scope.*/
76     CT_SCOPE_ORG            (0x8),
77
78     /** IPv6 Global scope.*/
79     CT_SCOPE_GLOBAL         (0xE),
80     ;
81
82     private int value;
83
84     private OcConnectivityType(int value) {
85         this.value = value;
86     }
87
88     public int getValue() {
89         return this.value;
90     }
91
92     public static EnumSet<OcConnectivityType> convertToEnumSet(int value) {
93         EnumSet<OcConnectivityType> typeSet = null;
94
95         for (OcConnectivityType v : values()) {
96             if (0 != (value & v.getValue())) {
97                 if (null == typeSet) {
98                     typeSet = EnumSet.of(v);
99                 } else {
100                     typeSet.add(v);
101                 }
102             }
103         }
104
105         if (null == typeSet || typeSet.isEmpty()) {
106             throw new InvalidParameterException("Unexpected OcConnectivityType value:" + value);
107         }
108
109         return typeSet;
110     }
111 }