summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java
blob: 112e26bb4113ea724c6f767fac1d839c110ba144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided with the
 * distribution.
 *
 * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from this 
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package com.smartdevicelink.protocol.enums;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

public enum FunctionID{
    // DEPRECATED FUNCTIONS
    SYNC_P_DATA(65537, "SyncPData"),
    ON_SYNC_P_DATA(98305, "OnSyncPData"),
    ENCODED_SYNC_P_DATA(65536, "EncodedSyncPData"),
    ON_ENCODED_SYNC_P_DATA(98304, "OnEncodedSyncPData"),

    // REQUESTS & RESPONSES
    REGISTER_APP_INTERFACE(1, "RegisterAppInterface"),
    UNREGISTER_APP_INTERFACE(2, "UnregisterAppInterface"),
    SET_GLOBAL_PROPERTIES(3, "SetGlobalProperties"),
    RESET_GLOBAL_PROPERTIES(4, "ResetGlobalProperties"),
    ADD_COMMAND(5, "AddCommand"),
    DELETE_COMMAND(6, "DeleteCommand"),
    ADD_SUB_MENU(7, "AddSubMenu"),
    DELETE_SUB_MENU(8, "DeleteSubMenu"),
    CREATE_INTERACTION_CHOICE_SET(9, "CreateInteractionChoiceSet"),
    PERFORM_INTERACTION(10, "PerformInteraction"),
    DELETE_INTERACTION_CHOICE_SET(11, "DeleteInteractionChoiceSet"),
    ALERT(12, "Alert"),
    SHOW(13, "Show"),
    SPEAK(14, "Speak"),
    SET_MEDIA_CLOCK_TIMER(15, "SetMediaClockTimer"),
    PERFORM_AUDIO_PASS_THRU(16, "PerformAudioPassThru"),
    END_AUDIO_PASS_THRU(17, "EndAudioPassThru"),
    SUBSCRIBE_BUTTON(18, "SubscribeButton"),
    UNSUBSCRIBE_BUTTON(19, "UnsubscribeButton"),
    SUBSCRIBE_VEHICLE_DATA(20, "SubscribeVehicleData"),
    UNSUBSCRIBE_VEHICLE_DATA(21, "UnsubscribeVehicleData"),
    GET_VEHICLE_DATA(22, "GetVehicleData"),
    READ_DID(23, "ReadDID"),
    GET_DTCS(24, "GetDTCs"),
    SCROLLABLE_MESSAGE(25, "ScrollableMessage"),
    SLIDER(26, "Slider"),
    SHOW_CONSTANT_TBT(27, "ShowConstantTBT"),
    ALERT_MANEUVER(28, "AlertManeuver"),
    UPDATE_TURN_LIST(29, "UpdateTurnList"),
    CHANGE_REGISTRATION(30, "ChangeRegistration"),
    GENERIC_RESPONSE(31, "GenericResponse"),
    PUT_FILE(32, "PutFile"),
    DELETE_FILE(33, "DeleteFile"),
    LIST_FILES(34, "ListFiles"),
    SET_APP_ICON(35, "SetAppIcon"),
    SET_DISPLAY_LAYOUT(36, "SetDisplayLayout"),
    DIAGNOSTIC_MESSAGE(37, "DiagnosticMessage"),
    SYSTEM_REQUEST(38, "SystemRequest"),
    SEND_LOCATION(39, "SendLocation"),
    DIAL_NUMBER(40, "DialNumber"),

    BUTTON_PRESS(41, "ButtonPress"),
    GET_INTERIOR_VEHICLE_DATA(43, "GetInteriorVehicleData"),
    SET_INTERIOR_VEHICLE_DATA(44, "SetInteriorVehicleData"),

    GET_WAY_POINTS(45, "GetWayPoints"),
    SUBSCRIBE_WAY_POINTS(46, "SubscribeWayPoints"),
    UNSUBSCRIBE_WAY_POINTS(47, "UnsubscribeWayPoints"),
    GET_SYSTEM_CAPABILITY(48, "GetSystemCapability"),
	SEND_HAPTIC_DATA(49, "SendHapticData"),
    SET_CLOUD_APP_PROPERTIES(50, "SetCloudAppProperties"),
	GET_CLOUD_APP_PROPERTIES(51, "GetCloudAppProperties"),
    PUBLISH_APP_SERVICE(52, "PublishAppService"),
    GET_APP_SERVICE_DATA(53, "GetAppServiceData"),
    GET_FILE(54, "GetFile"),
    PERFORM_APP_SERVICES_INTERACTION(55, "PerformAppServiceInteraction"),
    UNPUBLISH_APP_SERVICE(56, "UnpublishAppService"),
    CLOSE_APPLICATION(58, "CloseApplication"),
    SHOW_APP_MENU(59, "ShowAppMenu"),
    GET_INTERIOR_VEHICLE_DATA_CONSENT(60, "GetInteriorVehicleDataConsent"),
    RELEASE_INTERIOR_VEHICLE_MODULE(61, "ReleaseInteriorVehicleDataModule"),

    // NOTIFICATIONS
    ON_HMI_STATUS(32768, "OnHMIStatus"),
    ON_APP_INTERFACE_UNREGISTERED(32769, "OnAppInterfaceUnregistered"),
    ON_BUTTON_EVENT(32770, "OnButtonEvent"),
    ON_BUTTON_PRESS(32771, "OnButtonPress"),
    ON_VEHICLE_DATA(32772, "OnVehicleData"),
    ON_COMMAND(32773, "OnCommand"),
    ON_TBT_CLIENT_STATE(32774, "OnTBTClientState"),
    ON_DRIVER_DISTRACTION(32775, "OnDriverDistraction"),
    ON_PERMISSIONS_CHANGE(32776, "OnPermissionsChange"),
    ON_AUDIO_PASS_THRU(32777, "OnAudioPassThru"),
    ON_LANGUAGE_CHANGE(32778, "OnLanguageChange"),
    ON_KEYBOARD_INPUT(32779, "OnKeyboardInput"),
    ON_TOUCH_EVENT(32780, "OnTouchEvent"),
    ON_SYSTEM_REQUEST(32781, "OnSystemRequest"),
    ON_HASH_CHANGE(32782, "OnHashChange"),
    ON_INTERIOR_VEHICLE_DATA(32783, "OnInteriorVehicleData"),
    ON_WAY_POINT_CHANGE(32784, "OnWayPointChange"),
    ON_RC_STATUS(32785, "OnRCStatus"),
    ON_APP_SERVICE_DATA(32786, "OnAppServiceData"),
    ON_SYSTEM_CAPABILITY_UPDATED(32787, "OnSystemCapabilityUpdated"),

    // MOCKED FUNCTIONS (NOT SENT FROM HEAD-UNIT)
    ON_LOCK_SCREEN_STATUS(-1, "OnLockScreenStatus"),
    ON_SDL_CHOICE_CHOSEN(-1, "OnSdlChoiceChosen"),
    ON_STREAM_RPC(-1, "OnStreamRPC"),
    STREAM_RPC(-1, "StreamRPC"),

    ;

    public static final int                 INVALID_ID = -1;

    private static HashMap<String, Integer> functionMap;

    private final int                       ID;
    private final String                    JSON_NAME;

    private FunctionID(int id, String jsonName){
        this.ID = id;
        this.JSON_NAME = jsonName;
    }

    public int getId(){
        return this.ID;
    }

    @Override
    public String toString(){
        return this.JSON_NAME;
    }

    private static void initFunctionMap(){
        functionMap = new HashMap<String, Integer>(values().length);

        for(FunctionID value : EnumSet.allOf(FunctionID.class)){
            functionMap.put(value.toString(), value.getId());
        }
    }

    public static String getFunctionName(int i){
        if(functionMap == null){
            initFunctionMap();
        }

        Iterator<Entry<String, Integer>> iterator = functionMap.entrySet().iterator();
        while(iterator.hasNext()){
            Entry<String, Integer> thisEntry = iterator.next();
            if(Integer.valueOf(i).equals(thisEntry.getValue())){
                return thisEntry.getKey();
            }
        }

        return null;
    }

    public static int getFunctionId(String functionName){
        if(functionMap == null){
            initFunctionMap();
        }

        Integer result = functionMap.get(functionName);
        return ( result == null ) ? INVALID_ID : result;
    }

    /**
     * This method gives the corresponding FunctionID enum value for a string RPC 
     * @param name String value represents the name of the RPC
     * @return FunctionID represents the equivalent enum value for the provided string
     */
    public static FunctionID getEnumForString(String name){
        for(FunctionID value : EnumSet.allOf(FunctionID.class)) {
            if(value.JSON_NAME.equals(name)){
                return value;
            }
        }
        return null;
    }
}