1package eu.siacs.conversations.xmpp.jingle.stanzas;
2
3import android.support.annotation.NonNull;
4
5import com.google.common.base.CaseFormat;
6
7import eu.siacs.conversations.xmpp.jingle.RtpContentMap;
8
9public enum Reason {
10 ALTERNATIVE_SESSION,
11 BUSY,
12 CANCEL,
13 CONNECTIVITY_ERROR,
14 DECLINE,
15 EXPIRED,
16 FAILED_APPLICATION,
17 FAILED_TRANSPORT,
18 GENERAL_ERROR,
19 GONE,
20 INCOMPATIBLE_PARAMETERS,
21 MEDIA_ERROR,
22 SECURITY_ERROR,
23 SUCCESS,
24 TIMEOUT,
25 UNSUPPORTED_APPLICATIONS,
26 UNSUPPORTED_TRANSPORTS,
27 UNKNOWN;
28
29 public static Reason of(final String value) {
30 try {
31 return Reason.valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, value));
32 } catch (Exception e) {
33 return UNKNOWN;
34 }
35 }
36
37 @Override
38 @NonNull
39 public String toString() {
40 return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, super.toString());
41 }
42
43 public static Reason of(final RuntimeException e) {
44 if (e instanceof SecurityException) {
45 return SECURITY_ERROR;
46 } else if (e instanceof RtpContentMap.UnsupportedTransportException) {
47 return UNSUPPORTED_TRANSPORTS;
48 } else if (e instanceof RtpContentMap.UnsupportedApplicationException) {
49 return UNSUPPORTED_APPLICATIONS;
50 } else {
51 return FAILED_APPLICATION;
52 }
53 }
54}