Imported Upstream version 1.1.0
[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     /** CoAP over TCP.*/
45     CT_ADAPTER_TCP(1 << 20),
46
47     /** NFC Transport.*/
48     CT_ADAPTER_NFC(1 << 21),
49
50     /** Insecure transport is the default (subject to change).*/
51
52     /** secure the transport path.*/
53     CT_FLAG_SECURE          (1 << 4),
54
55     /** IPv4 & IPv6 autoselection is the default.*/
56
57     /** IP adapter only.*/
58     CT_IP_USE_V6            (1 << 5),
59
60     /** IP adapter only.*/
61     CT_IP_USE_V4            (1 << 6),
62
63     /** Link-Local multicast is the default multicast scope for IPv6.
64      * These are placed here to correspond to the IPv6 address bits.*/
65
66     /** IPv6 Interface-Local scope(loopback).*/
67     CT_SCOPE_INTERFACE      (0x1),
68
69     /** IPv6 Link-Local scope (default).*/
70     CT_SCOPE_LINK           (0x2),
71
72     /** IPv6 Realm-Local scope.*/
73     CT_SCOPE_REALM          (0x3),
74
75     /** IPv6 Admin-Local scope.*/
76     CT_SCOPE_ADMIN          (0x4),
77
78     /** IPv6 Site-Local scope.*/
79     CT_SCOPE_SITE           (0x5),
80
81     /** IPv6 Organization-Local scope.*/
82     CT_SCOPE_ORG            (0x8),
83
84     /** IPv6 Global scope.*/
85     CT_SCOPE_GLOBAL         (0xE),
86     ;
87
88     private int value;
89
90     private OcConnectivityType(int value) {
91         this.value = value;
92     }
93
94     public int getValue() {
95         return this.value;
96     }
97
98     public static EnumSet<OcConnectivityType> convertToEnumSet(int value) {
99         EnumSet<OcConnectivityType> typeSet = null;
100
101         for (OcConnectivityType v : values()) {
102             if (0 != (value & v.getValue())) {
103                 if (null == typeSet) {
104                     typeSet = EnumSet.of(v);
105                 } else {
106                     typeSet.add(v);
107                 }
108             }
109         }
110
111         if (null == typeSet || typeSet.isEmpty()) {
112             throw new InvalidParameterException("Unexpected OcConnectivityType value:" + value);
113         }
114
115         return typeSet;
116     }
117
118     public static OcConnectivityType getInstance(int caTransportAdapter) {
119         switch (caTransportAdapter) {
120             case (1 << 0):
121                 return CT_ADAPTER_IP;
122             case (1 << 1):
123                 return CT_ADAPTER_GATT_BTLE;
124             case (1 << 2):
125                 return CT_ADAPTER_RFCOMM_BTEDR;
126             case (1 << 3):
127                 return CT_ADAPTER_REMOTE_ACCESS;
128             case (1 << 4):
129                 return CT_ADAPTER_TCP;
130             default:
131                 return CT_DEFAULT;
132         }
133     }
134 }