summaryrefslogtreecommitdiff
path: root/SDL_Core/src/components/AppMgr/include/AppMgr/AppMgrCore.h
blob: 909e6d77b12d428f093835070f0cd977c9bf664d (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
//
// Copyright (c) 2013, Ford Motor Company
// 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 Ford Motor Company 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.
//

#ifndef APPMGR_H_
#define APPMGR_H_

#include <string>
#include "AppMgr/Application.h"
#include "AppMgr/ButtonMapping.h"
#include "AppMgr/VehicleDataMapping.h"
#include "AppMgr/CapabilitesContainer.h"
#include "AppMgr/SyncPManager.h"
#include "AppMgr/DeviceList.h"
#include "AppMgr/DeviceHandler.h"
#include "JSONHandler/SDLRPCObjects/V2/DisplayCapabilities.h"
#include "JSONHandler/SDLRPCObjects/V2/OnDriverDistraction.h"
#include "JSONHandler/RPC2Objects/NsRPC2Communication/Buttons/OnButtonEvent.h"
#include "JSONHandler/RPC2Objects/NsRPC2Communication/Buttons/OnButtonPress.h"
#include "JSONHandler/SDLRPCObjects/V2/VehicleType.h"
#include "JSONHandler/SDLRPCObjects/V1/Language.h"
#include "JSONHandler/SDLRPCObjects/V2/Language.h"
#include "AppMgr/MessageChaining.hpp"
#include "AppMgr/DeviceStorage.hpp"

namespace NsSmartDeviceLinkRPC
{
    class SDLRPCMessage;
}
class JSONHandler;
class JSONRPC2Handler;

namespace NsSmartDeviceLinkRPC
{
    class RegisterAppInterface_request;
    class OnDriverDistraction;
    class SDLRPCRequest;
}

namespace NsRPC2Communication
{
    class RPC2Command;
}

namespace log4cplus
{
    class Logger;
}

namespace NsConnectionHandler
{
    class IDevicesDiscoveryStarter;
}

namespace NsAppManager
{
    class RegistryItem;
    template< class QueueType >
    class AppMgrCoreQueue;

    /**
     * \brief a connection between a mobile RPC message and a session
     */
    typedef std::pair<NsSmartDeviceLinkRPC::SDLRPCMessage*, int> Message;

    /**
     * \brief a list of device names
     */
    typedef std::vector<std::string> DeviceNamesList;

    /**
      *\brief Map of messages between mobile app and hmi
    */
    typedef std::map<int, MessageChaining*> MessageChains;

    /**
     * \brief Core app manager class which acts as a core for application manager
     */
    class AppMgrCore
    {
        friend class SubscribeButtonCmd;
    public:

        /**
         * \brief Default class destructor
         */
        virtual ~AppMgrCore();

        /**
         * \brief Returning class instance
         * \return class instance
         */
        static AppMgrCore& getInstance();

        /**
         * \brief push mobile RPC message to a queue
         * \param message a message to be pushed
         */
        void pushMobileRPCMessage(NsSmartDeviceLinkRPC::SDLRPCMessage * message , int appId);

        /**
         * \brief push HMI RPC2 message to a queue
         * \param message a message to be pushed
         */
        void pushRPC2CommunicationMessage( NsRPC2Communication::RPC2Command * message );

        /**
         * \brief method to execute threads.
         */
        void executeThreads();

        /**
         * \brief set Json mobile handler
         * \param handler a handler instance
         */
        void setJsonHandler(JSONHandler* handler);

        /**
         * \brief get Json mobile handler
         * \return JSONHandler instance
         */
        JSONHandler* getJsonHandler( ) const;

        /**
         * \brief set Json RPC2 handler
         * \param handler a handler instance
         */
        void setJsonRPC2Handler(JSONRPC2Handler* handler);

        /**
         * \brief get Json RPC2 handler
         * \return JSONRPC2Handler instance
         */
        JSONRPC2Handler* getJsonRPC2Handler( ) const;

        /**
         * \brief Sets connection handler instance
         * \param handler connection handler
         */
        void setConnectionHandler(NsConnectionHandler::IDevicesDiscoveryStarter* handler);

        /**
         * \brief Gets connection handler instance
         * \return connection handler
         */
        NsConnectionHandler::IDevicesDiscoveryStarter* getConnectionHandler( ) const;

        /**
         * \brief set device list
         * \param deviceList device list
         */
        void setDeviceList( const NsConnectionHandler::tDeviceList& deviceList );

        /**
         * \brief get device list
         * \return device list
         */
        const NsConnectionHandler::tDeviceList& getDeviceList() const;

        /**
         * \brief add a device to a mapping
         * \param sessionKey session/connection key
         * \param device device handler
         */
        void addDevice( const NsConnectionHandler::tDeviceHandle &device,
            const int &sessionKey, int firstSessionKey );

        /**
         * \brief remove a device from a mapping
         * \param sessionKey session/connection key
         */
        void removeDevice(const int &sessionKey, int firstSessionKey);

        bool getAudioPassThruFlag() const;
        void setAudioPassThruFlag(bool flag);

        //const MessageMapping& getMessageMapping() const;

        /**
         * \brief retrieve an application instance from the RegistryItrem instance checking for non-null values
         * \param item a RegistryItem from which to retrieve an app pointer
         * \return Application instance retrieved from item
         */
        Application* getApplicationFromItemCheckNotNull( const RegistryItem* item ) const;

        /**
         * \brief Sends notification to Mobile Application about changes in its HMI status
         * ie in system context/hmi level/audio streaming state.
         * \param application Mobile app to be notified about changes
         */
        void sendHMINotificationToMobile( Application * application );

        /**
         * \brief Activates app and deactivates others.
         * \param app Application to be activated.
         * \return bool Success of operation
         */
        bool performActivitiesForActivatingApp( Application * app );

        Application * getItem( int applicationId );

    private:

        /**
         * \brief Default class constructor
         */
        AppMgrCore();

        /**
         * \brief Copy constructor
         */
        AppMgrCore(const AppMgrCore&);

        /**
         * \brief mobile RPC message handler
         * \param mesage a message to be handled
         * \param pThis a pointer to AppMgrCore class instance
         */
        static void handleMobileRPCMessage(Message message, void* pThis);

        /**
         * \brief push HMI RPC2 message to a queue
         * \param msg a message to be pushed
         * \param pThis a pointer to AppMgrCore class instance
         */
        static void handleBusRPCMessageIncoming( NsRPC2Communication::RPC2Command* msg, void* pThis );

        /**
         * \brief Register an application
         * \param request a RegisterAppInterface request which is the source for application fields initial values
         * \param connectionID id of the connection which will be associated with the application
         * \param sessionID an id of the session which will be associated with the application
         * \return A instance of RegistryItem created for application
         */
        const Application* registerApplication(NsSmartDeviceLinkRPC::SDLRPCMessage *request , int sessionKey);

        /**
         * \brief unregister an application associated with the given session
         * \param connectionID an id of the connection asociated with the application to be unregistered
         * \param sessionID an id of the session asociated with the application to be unregistered
         */
        void unregisterApplication(int appId);

        /**
         * \brief Remove all app components from HMI
         * \param currentApp app which components to be removed
         * \param connectionID connection id
         * \param sessionID session id
         */
        void removeAppFromHmi(Application* currentApp, int appId);

        /**
         * \brief serialize a string value to the text file
         * \param fileName name of the file to serialize to
         * \param value a value to serialize
         * \return bool success of an operation - true or false
         */
        bool serializeToFile(const std::string& fileName, const std::string &value) const;

        /**
         * \brief Sends notification to mobile app about button event.
         * \param app Application to receive notification
         * \param object Notification received from HMI.
         */
        void sendButtonEvent( Application * app, NsRPC2Communication::Buttons::OnButtonEvent * object );

        /**
         * \brief Send notification to mobile app about button press event
         * \param app Application to receive notification
         * \param object Notification received from HMI.
         */
        void sendButtonPress( Application * app, NsRPC2Communication::Buttons::OnButtonPress * object );

        /**
         * \brief Remove message from message chain between mobile app and hmi.
         * If counter == 0 then remove message completely.
         * \param chain Iterator in message map
         * \return bool True if chain was deleted otherwise false
         */
        bool decreaseMessageChain(const MessageChains::iterator & chain);

        /**
         * \brief Inserts message chain
         * \param chain Pointer to @MessageChain
         * \param connectionKey Id of connection for Mobile side
         * \param correlationID Correlation id for response for Mobile side
         * \return @MessageChaining* pointer to result chain
         */
        MessageChaining * addChain(MessageChaining * chain, int connectionKey, unsigned int correlationID);

        void differenceBetweenLists( const NsConnectionHandler::tDeviceList &deviceList );

        Application * getActiveItem();

        Application * getApplicationByCommand(const unsigned int &cmdId, int appId);

        bool activateApp( Application * appToBeActivated );

        AppMgrCoreQueue<Message>* mQueueRPCSmartDeviceLinkObjectsIncoming;
        AppMgrCoreQueue<NsRPC2Communication::RPC2Command*>* mQueueRPCBusObjectsIncoming;

        //CapabilitiesContainer<NsSmartDeviceLinkRPC::ButtonCapabilities> mButtonCapabilitiesV1;
        CapabilitiesContainer<NsSmartDeviceLinkRPCV2::ButtonCapabilities> mButtonCapabilitiesV2;
        NsSmartDeviceLinkRPC::DisplayCapabilities mDisplayCapabilitiesV1;
        NsSmartDeviceLinkRPCV2::DisplayCapabilities mDisplayCapabilitiesV2;
        NsSmartDeviceLinkRPCV2::PresetBankCapabilities mPresetBankCapabilities;
        //CapabilitiesContainer<NsSmartDeviceLinkRPC::HmiZoneCapabilities> mHmiZoneCapabilitiesV1;
        CapabilitiesContainer<NsSmartDeviceLinkRPCV2::HmiZoneCapabilities> mHmiZoneCapabilitiesV2;
        //CapabilitiesContainer<NsSmartDeviceLinkRPC::VrCapabilities> mVrCapabilitiesV1;
        //CapabilitiesContainer<NsSmartDeviceLinkRPC::SpeechCapabilities> mSpeechCapabilitiesV1;
        CapabilitiesContainer<NsSmartDeviceLinkRPCV2::VrCapabilities> mVrCapabilitiesV2;
        CapabilitiesContainer<NsSmartDeviceLinkRPCV2::SpeechCapabilities> mSpeechCapabilitiesV2;
        CapabilitiesContainer<NsSmartDeviceLinkRPCV2::SoftButtonCapabilities> mSoftButtonCapabilities;
        ButtonMapping       mButtonsMapping;
        VehicleDataMapping  mVehicleDataMapping;
        //MessageMapping      mMessageMapping;
        //RequestMapping      mRequestMapping;
        //DeviceList          mDeviceList;
        DeviceHandler       mDeviceHandler;

        MessageChains mMessageChaining;

        NsSmartDeviceLinkRPC::OnDriverDistraction* mDriverDistractionV1;
        NsSmartDeviceLinkRPCV2::OnDriverDistraction* mDriverDistractionV2;

        NsSmartDeviceLinkRPC::Language mUiLanguageV1;
        NsSmartDeviceLinkRPC::Language mVrLanguageV1;
        NsSmartDeviceLinkRPC::Language mTtsLanguageV1;
        NsSmartDeviceLinkRPCV2::Language mUiLanguageV2;
        NsSmartDeviceLinkRPCV2::Language mVrLanguageV2;
        NsSmartDeviceLinkRPCV2::Language mTtsLanguageV2;
        std::vector<NsSmartDeviceLinkRPCV2::Language> mUISupportedLanguages;
        std::vector<NsSmartDeviceLinkRPCV2::Language> mVRSupportedLanguages;
        std::vector<NsSmartDeviceLinkRPCV2::Language> mTTSSupportedLanguages;

        NsSmartDeviceLinkRPCV2::VehicleType mVehicleType;
        bool mAudioPassThruFlag;
        int mPerformInteractionFlag;
        int mHMIStartupFlag;

        std::map<int, int> menuMapping;  // map<request_id, menu_id>

        SyncPManager     mSyncPManager;

        static log4cplus::Logger mLogger;

        std::map<int, Application*> mApplications;
        std::map<int, DeviceStorage> mDevices;
        //NsConnectionHandler::tDeviceList mDevices;
    };

} // namespace NsAppManager

#endif /* APPMGR_H_ */