RDK Documentation (Open Sourced RDK Components)
vrexSession.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22 * @defgroup iarmmgrs
23 * @{
24 * @defgroup vrexmgr
25 * @{
26 **/
27 
28 
29 #if !defined(VREX_SESSION_H)
30 #define VREX_SESSION_H
31 
32 #include <map>
33 #include <string>
34 #include <utility>
35 
36 #include <curl/curl.h>
37 
38 #include <sys/socket.h>
39 #include <linux/un.h>
40 #include <unistd.h>
41 
42 #include <pthread.h>
43 
44 #include "jsonParser.h"
45 //#include "gpMgr.h"
46 #include "rf4ceMgr.h"
47 
48 
49 
50 // Time in seconds before curl request times out
51 #define DEFAULT_VREX_TIMEOUT 30
52 
53 using namespace std;
54 
55 typedef struct {
56  string mimeType;
57  string subType;
58  string language;
59 } AudioInfo;
60 
61 typedef struct {
62  double x;
63  double y;
64  double z;
65 } MotionInfo;
66 
67 // Note that these *must* match IARM_Bus_VREXMgr_SpeechEndReason_t enum in vrexMgr.h
68 typedef enum {
69  AudioDone = 0, // Normal EOS
70  AudioAbort, // Audio was normally interrupted/cancelled
71  AudioError, // An abnormal error caused end
72 } AudioStreamEndReason;
73 
74 // The VREX SendEvent types
75 typedef enum {
76  BeginRecording,
77  FinishedRecording,
78  FinishedRecordingWithResults,
79  FinishedRecordingWithErrors
80 } SendState;
81 
83 {
84 public:
85  VREXSession();
86 
87 #ifdef RF4CE_GENMSO_API
88  VREXSession(unsigned char remoteId, string receiverId, int defaultConversationLength, string route, string aspect_ratio, string language,
89  MSOBusAPI_RfStatus_t *rfStatus, int bindRemotesIndex, string stbName, string appId="xr11v2-789ec072-d47e-4eac-9b5d-5f8f7a46e143");
90 #elif defined(RF4CE_API)
91  VREXSession(unsigned char remoteId, string receiverId, int defaultConversationLength, string route, string aspect_ratio, string language,
92  rf4ce_RfStatus_t *rfStatus, int bindRemotesIndex, string stbName, string appId="xr11v2-789ec072-d47e-4eac-9b5d-5f8f7a46e143");
93 #elif defined(RF4CE_GPMSO_API)
94  VREXSession(unsigned char remoteId, string receiverId, int defaultConversationLength, string route, string aspect_ratio, string language,
95  gpMSOBusAPI_RfStatus_t *rfStatus, int bindRemotesIndex, string stbName, string appId="xr11v2-789ec072-d47e-4eac-9b5d-5f8f7a46e143");
96 #else
97 #warning "No RF4CE API defined"
98 #endif
99 
100  virtual ~VREXSession();
101 
102  bool onMotion(MotionInfo);
103  bool onStreamStart(AudioInfo audioInfo);
104  void onStreamData(void *src, size_t size);
105  void onStreamEnd(AudioStreamEndReason);
106  bool sendState(SendState state);
107  void updateExpiration(int expirationWindow);
108 
109  // Internal methods
110  void startTransferServer();
111  size_t serverSocketCallback(void *buffer, size_t size, size_t nmemb);
112  void addKKResponse(string responseData);
113  void addSpeechResponse(string responseData);
114  void addSendStateResponse(string responseData);
115  void changeServerDetails(string route, string aspect_ratio, string language);
116 
117 private:
118  char * getRequestMetrics(CURL *curl,char *);
119  void notifySuccess();
120  void notifyError(long httpErrorCode , long curlErrorCode, long vrexErrorCode ,long rfErrorCode, const char *message, IARM_Bus_VREXMgr_VoiceCallType_t from);
121  void safe_copy(unsigned char *dst, const char *src, size_t len);
122  void getDynamicStbAndRemoteinfo();
123 
124 #ifdef RF4CE_GENMSO_API
125  void getStaticStbAndRemoteinfo(MSOBusAPI_RfStatus_t *rfStatus, int bindRemotesIndex);
126 #elif defined(RF4CE_API)
127  void getStaticStbAndRemoteinfo(rf4ce_RfStatus_t *rfStatus, int bindRemotesIndex);
128 #elif defined(RF4CE_GPMSO_API)
129  void getStaticStbAndRemoteinfo(gpMSOBusAPI_RfStatus_t *rfStatus, int bindRemotesIndex);
130 #else
131 #warning "No RF4CE API defined"
132 #endif
133  string getPostFieldString();
134  string getUserAgentString();
135 
136 
137 private:
138  // These are in the query string
139  string m_userId;
140  string m_appId;
141 
142  // These will be part of the post data
143  string m_receiverId;
144  string m_rf4ceMacAddress;
145  string m_remoteBatteryVoltage;
146  string m_iArmStatusKillCount;
147 
148  // These will be part of the useragent
149  string m_rdkImage;
150  string m_remoteType;
151  string m_remoteSoftwareVersion;
152  string m_remoteHardwareVersion;
153  string m_stbName;
154 
155  // This is data coming back from initial call
156  string m_conversationId;
157 
158  // This is how I make that initial call
159  string m_baseRoute;
160  string m_aspect_ratio;
161  string m_guideLanguage;
162 
163  unsigned char m_remoteId;
164  int m_defaultConversationLength; // In seconds
165  time_t m_conversationExpires;
166  AudioInfo m_audioInfo;
167 
168  bool m_curlInitialized;
169  bool m_logMetrics;
170 
171  string m_kkResponse;
172  string m_sendStateResponse;
173  string m_speechResponse;
174 
175  string m_serverSocketName;
176  int m_serverSocket;
177  int m_clientSocket;
178 
179  pthread_t m_dataReadThread;
180 
181  pthread_cond_t m_cond;
182  pthread_mutex_t m_mutex;
183 
184  // The parameters from kk
185  map<string, JSONParser::varVal *> m_parameters;
186  map<string, JSONParser::varVal *> m_speechResults;
187  map<SendState, string> m_sendStates;
188 };
189 
190 #endif
191 
192 
193 /** @} */
194 /** @} */
VREXSession
Definition: vrexSession.h:82
AudioInfo
Definition: deviceUpdateMgrMain.cpp:849
MotionInfo
Definition: vrexSession.h:61