30 #include "vrexMgrInternal.h"
44 #include "vrexSession.h"
50 #define MIN(a,b) (((a)<(b))?(a):(b))
53 #define MAX_IARMSTATUS_COUNT_LENGTH 10
54 #define TEMP_BUFFER_SIZE 20
56 static void* speechServerThread(
void *session)
59 pVREX->startTransferServer();
60 __TIMESTAMP(); LOG(
"Exiting speech thread\n");
64 static size_t voice_writeData(
void *buffer,
size_t size,
size_t nmemb,
void *userData)
68 str.append((
const char *)buffer, size*nmemb);
69 __TIMESTAMP(); LOG(
"voice<%i,%i>: %s", size, nmemb, str.c_str());
71 vrex->addSpeechResponse(str);
76 static size_t kk_writeData(
void *buffer,
size_t size,
size_t nmemb,
void *userData)
80 str.append((
const char *)buffer, size*nmemb);
81 __TIMESTAMP(); LOG(
"kk_writeData<%i,%i>: %s", size, nmemb, str.c_str());
82 vrex->addKKResponse(str);
87 static size_t sendState_writeData(
void *buffer,
size_t size,
size_t nmemb,
void *userData)
91 str.append((
const char *)buffer, size*nmemb);
93 vrex->addSendStateResponse(str);
98 static size_t read_chunked_socket_callback(
void *buffer,
size_t size,
size_t nmemb,
void *userData)
101 return vrex->serverSocketCallback(buffer, size, nmemb);
105 VREXSession::VREXSession() :
106 m_curlInitialized(false),
107 m_baseRoute(
"uninit")
112 #ifdef RF4CE_GENMSO_API
113 VREXSession::VREXSession(
unsigned char remoteId,
string receiverId,
int defaultConversationLength,
string route,
string aspect_ratio,
string language, MSOBusAPI_RfStatus_t *rfStatus,
int bindRemotesIndex,
string stbName,
string appId) :
114 #elif defined(RF4CE_API)
115 VREXSession::
VREXSession(unsigned char remoteId, string receiverId, int defaultConversationLength, string route, string aspect_ratio, string language, rf4ce_RfStatus_t *rfStatus, int bindRemotesIndex, string stbName, string appId) :
116 #elif defined(RF4CE_GPMSO_API)
117 VREXSession::
VREXSession(unsigned char remoteId, string receiverId, int defaultConversationLength, string route, string aspect_ratio, string language, gpMSOBusAPI_RfStatus_t *rfStatus, int bindRemotesIndex, string stbName, string appId) :
119 #error
"No RF4CE API defined"
121 m_remoteId(remoteId),
122 m_receiverId(receiverId),
125 m_defaultConversationLength(defaultConversationLength),
126 m_conversationExpires(std::time(0)-200),
127 m_curlInitialized(false),
131 m_dataReadThread(NULL),
132 m_aspect_ratio(aspect_ratio),
133 m_guideLanguage(language)
136 __TIMESTAMP(); LOG(
"VREXSession constructor for remote %i, %s, %d, %s\n", (
int)m_remoteId, m_receiverId.c_str(), m_defaultConversationLength, m_appId.c_str());
137 res = curl_global_init(CURL_GLOBAL_DEFAULT);
139 if(res != CURLE_OK) {
140 __TIMESTAMP();LOG(
"Error: Can't init cURL: %s\n", curl_easy_strerror(res));
143 m_curlInitialized =
true;
146 pthread_cond_init(&m_cond, NULL);
147 pthread_mutex_init(&m_mutex, NULL);
151 m_sendStates[BeginRecording] =
"BEGIN_RECORDING";
152 m_sendStates[FinishedRecording] =
"FINISHED_RECORDING";
153 m_sendStates[FinishedRecordingWithResults] =
"FINISHED_RECORDING_WITH_RESULTS";
154 m_sendStates[FinishedRecordingWithErrors] =
"FINISHED_RECORDING_WITH_ERRORS";
159 getStaticStbAndRemoteinfo(rfStatus, bindRemotesIndex);
163 VREXSession::~VREXSession()
165 curl_global_cleanup();
168 void VREXSession::changeServerDetails(
string route,
string aspect_ratio,
string language){
172 if(m_baseRoute[m_baseRoute.length()-1] !=
'/')
175 m_aspect_ratio=aspect_ratio;
176 m_guideLanguage=language;
183 if(m_conversationExpires==0)
190 m_conversationExpires=0;
191 __TIMESTAMP(); LOG(
"KnockKnock for remote %i, %s, %s\n", (
int)m_remoteId, m_receiverId.c_str(), m_appId.c_str());
192 if (!m_curlInitialized)
return retval;
197 curl = curl_easy_init();
199 m_kkResponse.clear();
201 __TIMESTAMP(); LOG(
"KnockKnock URL: %s", (m_baseRoute +
"knockknock").c_str());
202 curl_easy_setopt(curl, CURLOPT_URL, (m_baseRoute +
"knockknock").c_str());
205 string postData =
"receiverId=" + m_receiverId +
"&appId=" + m_appId;
207 if (!m_guideLanguage.empty())
209 postData +=
"&language=" + m_guideLanguage;
212 if (!m_aspect_ratio.empty())
214 postData +=
"&aspectRatio=" + m_aspect_ratio;
219 __TIMESTAMP(); LOG(
"KnockKnock POSTFIELDS: %s", postData.c_str());
220 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
222 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, kk_writeData);
223 curl_easy_setopt(curl, CURLOPT_WRITEDATA,
this);
224 curl_easy_setopt(curl, CURLOPT_TIMEOUT, DEFAULT_VREX_TIMEOUT);
225 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
228 string userAgentData = getUserAgentString();
229 __TIMESTAMP(); LOG(
"KnockKnock USERAGENT: %s\n", userAgentData.c_str());
230 curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgentData.c_str());
232 res = curl_easy_perform(curl);
235 if(res != CURLE_OK) {
236 std::stringstream sstm;
237 sstm <<
"cURL call failed KnockKnock:(" << res <<
"): " << curl_easy_strerror(res);
238 string errorMessage = sstm.str();
240 __TIMESTAMP(); LOG(
"onMotion(): %s\n", errorMessage.c_str());
242 notifyError(0, res,0,0, errorMessage.c_str(),KNOCKKNOCK);
248 m_parameters = parser.parse((
const unsigned char *)m_kkResponse.c_str());
250 if (m_parameters[
"code"]->str ==
"0") {
251 time_t currentTime = std::time(0);
252 __TIMESTAMP(); LOG(
"Time now: %s", asctime(localtime(¤tTime)));
253 m_conversationExpires = std::time(0) + m_defaultConversationLength;
254 __TIMESTAMP(); LOG(
"Conversation expires: %s\n", asctime(localtime(&m_conversationExpires)));
256 LOG(
"onMotion CID: <%s>\n", m_parameters[
"cid"]->str.c_str());
262 LOG(
"onMotion response error!\n");
263 LOG(
"onMotion code: <%s>\n", m_parameters[
"code"]->str.c_str());
264 LOG(
"onMotion message: <%s>\n", m_parameters[
"message"]->str.c_str());
265 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
266 returnCode = strtol(m_parameters[
"code"]->str.c_str(), NULL, 10);
268 notifyError(responseCode, 0,returnCode,0, m_parameters[
"message"]->str.c_str(),KNOCKKNOCK);
270 }
catch (
const std::exception err){
271 __TIMESTAMP(); LOG(
"exception in OnMotion response: %s",err.what());
272 __TIMESTAMP(); LOG(
"OnMotion response string for exception: %s",m_kkResponse.c_str());
273 std::stringstream sstm;
274 sstm <<
"Unknown exception:" << err.what() <<
": response:" << m_kkResponse.c_str();
275 string errorMessage = sstm.str();
276 notifyError(0, 0,800,0, errorMessage.c_str(),KNOCKKNOCK);
284 getRequestMetrics(curl,buffer);
288 curl_easy_cleanup(curl);
293 void VREXSession::notifySuccess()
296 memset(&eventData, 0,
sizeof(eventData));
301 if (retval == IARM_RESULT_SUCCESS) {
302 __TIMESTAMP(); LOG(
"Success Event sent successfully");
305 __TIMESTAMP(); LOG(
"Success Event problem, %i", retval);
310 void VREXSession::notifyError(
long httpErrorCode ,
long curlErrorCode,
long vrexErrorCode ,
long rfErrorCode,
const char *message, IARM_Bus_VREXMgr_VoiceCallType_t from)
313 memset(&eventData, 0,
sizeof(eventData));
348 bool needComma=
false;
349 std::stringstream jsonString;
353 jsonString<<
"\"vrexCallType\":\"";
356 jsonString<<
"\"remoteId\":\"";
357 jsonString<<(int)m_remoteId;
358 jsonString<<
"\", \"errors\":{";
361 jsonString<<
"\"httpErrorCode\":\"";
362 jsonString<<(int)httpErrorCode;
372 jsonString<<
"\"curlErrorCode\":\"";
373 jsonString<<(int)curlErrorCode;
381 jsonString<<
"\"vrexErrorCode\":\"";
382 jsonString<<(int)vrexErrorCode;
391 jsonString<<
"\"remoteErrorCode\":\"";
392 jsonString<<(int)rfErrorCode;
399 jsonString<<
"\"message\":\"";
404 string erroStr(jsonString.str());
405 LOG(
"sending event %s",erroStr.c_str());
406 safe_copy(eventData.data.jsonEvent.jsonData, erroStr.c_str(), IARM_BUS_VREXMGR_ERROR_MESSAGE_LENGTH);
408 if (retval == IARM_RESULT_SUCCESS) {
409 __TIMESTAMP(); LOG(
"Error Event sent successfully");
412 __TIMESTAMP(); LOG(
"Error Event problem, %i", retval);
417 void VREXSession::safe_copy(
unsigned char *dst,
const char *src,
size_t len)
421 len = MIN(strlen(src), (len - 1));
424 *((
char *) mempcpy (dst, src, len)) =
'\0';
427 void VREXSession::addKKResponse(
string responseData)
429 m_kkResponse += responseData;
432 void VREXSession::addSpeechResponse(
string responseData)
434 m_speechResponse += responseData;
437 void VREXSession::addSendStateResponse(
string responseData)
439 m_sendStateResponse += responseData;
442 bool VREXSession::onStreamStart(
AudioInfo audioInfo)
445 m_audioInfo = audioInfo;
449 if(m_conversationExpires==0){
451 m_conversationExpires=std::time(0)-200;
454 pthread_mutex_lock(&m_mutex);
456 time_t currentTime = std::time(0);
457 if (currentTime > m_conversationExpires) {
459 __TIMESTAMP(); LOG(
"Conversation id has expired! attempting to acquire another one via knock knock\n");
462 pthread_mutex_unlock(&m_mutex);
463 errorMessage =
"Conversation id expired and could not reacquire. Aborting speech call";
468 m_speechResponse.clear();
470 if (pthread_create(&m_dataReadThread, NULL, speechServerThread, (
void *)
this) != 0)
472 pthread_mutex_unlock(&m_mutex);
473 errorMessage =
"Could not create thread to send speech data";
476 __TIMESTAMP(); LOG(
"Thread blocked waiting for initialization");
477 pthread_cond_wait(&m_cond, &m_mutex);
478 pthread_mutex_unlock(&m_mutex);
481 struct sockaddr_un address;
485 m_clientSocket = socket(PF_UNIX, SOCK_STREAM, 0);
486 if(m_clientSocket < 0) {
487 errorMessage =
"Speech socket call failed";
491 __TIMESTAMP(); LOG(
"Server socket name is <%s>", m_serverSocketName.c_str());
493 memset(&address, 0,
sizeof(
struct sockaddr_un));
494 address.sun_family = AF_UNIX;
495 snprintf(address.sun_path, UNIX_PATH_MAX, m_serverSocketName.c_str());
497 if(connect(m_clientSocket, (
struct sockaddr *) &address,
sizeof(
struct sockaddr_un)) != 0)
499 errorMessage =
"Speech connect call failed";
506 __TIMESTAMP(); LOG(
"Error Message:%s",errorMessage.c_str());
509 notifyError(0, 0,0,0, errorMessage.c_str(),SPEECH);
513 void VREXSession::onStreamData(
void *src,
size_t size)
515 pthread_mutex_lock(&m_mutex);
516 __TIMESTAMP(); LOG(
"onStreamData: numbytes sent: %i", (
int)size);
517 if (m_clientSocket >= 0)
518 write(m_clientSocket, src, size);
519 pthread_mutex_unlock(&m_mutex);
522 void VREXSession::onStreamEnd(AudioStreamEndReason reason)
524 if (m_clientSocket >= 0) {
525 pthread_mutex_lock(&m_mutex);
526 __TIMESTAMP(); LOG(
"Deleting client socket from onStreamEnd\n");
527 close(m_clientSocket);
529 pthread_mutex_unlock(&m_mutex);
531 __TIMESTAMP(); LOG(
"Waiting for server thread to exit\n");
532 pthread_join(m_dataReadThread, NULL);
533 __TIMESTAMP(); LOG(
"Server thread exited!\n");
536 if (reason != AudioDone) {
537 string message =
"Audio stream ";
538 message = message + ((reason == AudioAbort) ?
"canceled" :
"aborted due to error") +
" from remote";
541 notifyError(0, 0,0,(
long)reason, message.c_str(),SPEECH);
546 void VREXSession::updateExpiration(
int expirationWindow)
548 time_t currentTime = std::time(0);
551 if (m_conversationExpires>0 && (currentTime + expirationWindow > m_conversationExpires)) {
553 __TIMESTAMP(); LOG(
"VREXSession: updateExpiration, conversation about to expire. Attempting to extend via knock knock\n");
558 errorMessage =
"Conversation id about to expire and could not reacquire.";
559 __TIMESTAMP(); LOG(
"Error: %s",errorMessage.c_str());
567 bool VREXSession::sendState(SendState state)
571 __TIMESTAMP(); LOG(
"sendState for remote %i, %i\n", (
int)m_remoteId, (
int)state);
573 if (!m_curlInitialized)
return retval;
578 time_t currentTime = std::time(0);
580 curl = curl_easy_init();
582 m_sendStateResponse.clear();
584 if(m_parameters[
"cid"]!=NULL){
586 string url = m_baseRoute +
"xapi/sendstate?cid=" + m_parameters[
"cid"]->str +
"&state=" + m_sendStates[state];
587 __TIMESTAMP(); LOG(
"sendState URL: %s\n", url.c_str());
588 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
591 string postData = getPostFieldString();
592 __TIMESTAMP(); LOG(
"sendState POSTFIELDS: %s\n", postData.c_str());
593 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
595 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, sendState_writeData);
596 curl_easy_setopt(curl, CURLOPT_WRITEDATA,
this);
597 curl_easy_setopt(curl, CURLOPT_TIMEOUT, DEFAULT_VREX_TIMEOUT);
598 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
601 string userAgentData = getUserAgentString();
602 __TIMESTAMP(); LOG(
"sendState USERAGENT: %s\n", userAgentData.c_str());
603 curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgentData.c_str());
606 res = curl_easy_perform(curl);
609 if(res != CURLE_OK) {
610 std::stringstream sstm;
611 sstm <<
"cURL call failed (" << res <<
"): " << curl_easy_strerror(res);
612 string errorMessage = sstm.str();
614 __TIMESTAMP(); LOG(
"sendstate: %s\n", errorMessage.c_str());
619 time_t currentTime = std::time(0);
620 __TIMESTAMP(); LOG(
"Updating expiration time, time now: %s\n", asctime(localtime(¤tTime)));
621 m_conversationExpires = std::time(0) + m_defaultConversationLength;
622 __TIMESTAMP(); LOG(
"Conversation expires: %s\n", asctime(localtime(&m_conversationExpires)));
624 __TIMESTAMP(); LOG(
"Result = %s", m_sendStateResponse.c_str());
626 __TIMESTAMP(); LOG(
"MYRESULT = %s", m_sendStateResponse.c_str());
627 map<string, JSONParser::varVal *> result;
628 result = parser.parse((
const unsigned char *)m_sendStateResponse.c_str());
629 __TIMESTAMP(); LOG(
"AFTER MYRESULT = %s", m_sendStateResponse.c_str());
632 if (result[
"code"]!=NULL && result[
"code"]->str !=
"0") {
633 if (result[
"code"]->str ==
"213") {
635 __TIMESTAMP(); LOG(
"Conversation id has expired! attempting to acquire another one via knock knock\n");
638 __TIMESTAMP(); LOG(
"could not handle the 213 error\n");
644 __TIMESTAMP(); LOG(
"not a 213 error\n");
653 LOG(
"sendstate CODE: <%s>", result[
"code"]->str.c_str());
654 LOG(
"sendstate MESSAGE: <%s>", result[
"message"]->str.c_str());
656 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
657 returnCode = strtol(result[
"code"]->str.c_str(), NULL, 10);
662 }
catch (
const std::exception err){
663 __TIMESTAMP(); LOG(
"exception in SENDSTATE response: %s", err.what());
664 __TIMESTAMP(); LOG(
"SENDSTATE response string for exception: %s",m_kkResponse.c_str());
665 std::stringstream sstm;
666 sstm <<
"Unknown exception:" << err.what() <<
":SENDSTATE response:" << m_sendStateResponse.c_str();
667 string errorMessage = sstm.str();
668 notifyError(0, 0,800,0, errorMessage.c_str(),SENDSTATE);
676 getRequestMetrics(curl,buffer);
681 curl_easy_cleanup(curl);
687 size_t VREXSession::serverSocketCallback(
void *buffer,
size_t size,
size_t nmemb)
696 numBytes = read(m_serverSocket, buffer, size*nmemb);
697 __TIMESTAMP(); LOG(
"serverSocketCallback: got bytes: <%i>:", numBytes);
708 void VREXSession::startTransferServer()
713 struct sockaddr_un address;
714 socklen_t address_length;
716 __TIMESTAMP(); LOG(
"startTransferServer\n");
718 socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
721 __TIMESTAMP(); LOG(
"socket() failed\n");
726 ostringstream stream;
727 int remoteId = (int)m_remoteId;
728 __TIMESTAMP(); LOG(
"remoteId= %i", remoteId);
729 __TIMESTAMP(); LOG(
"receiverId= %s", m_receiverId.c_str());
730 __TIMESTAMP(); LOG(
"appId= %s", m_appId.c_str());
732 stream <<
"/tmp/.vrex" << remoteId <<
"_socket";
733 string socketName(stream.str());
735 m_serverSocketName = socketName;
737 __TIMESTAMP(); LOG(
"sts m_serverSocketName = %s\n", m_serverSocketName.c_str());
738 unlink(socketName.c_str());
740 memset(&address, 0,
sizeof(
struct sockaddr_un));
741 address.sun_family = AF_UNIX;
742 snprintf(address.sun_path, UNIX_PATH_MAX, socketName.c_str());
744 if(bind(socket_fd, (
struct sockaddr *) &address,
745 sizeof(
struct sockaddr_un)) != 0)
748 __TIMESTAMP(); LOG(
"sts bind failed");
752 if(listen(socket_fd, 5) != 0)
755 __TIMESTAMP(); LOG(
"sts listen failed");
760 __TIMESTAMP(); LOG(
"Unblocking waiting thread(s)");
762 pthread_cond_broadcast(&m_cond);
763 __TIMESTAMP(); LOG(
"Thread(s) unblocked(s)");
764 address_length =
sizeof(sockaddr_un);
765 if ((m_serverSocket = accept(socket_fd, (
struct sockaddr *) &address, &address_length)) > -1)
769 struct curl_slist *chunk = NULL;
771 curl = curl_easy_init();
777 url = m_baseRoute +
"speech?cid=" + m_parameters[
"cid"]->str +
"&filters=SR,NLP,X1&codec=" + m_audioInfo.subType +
"&receiverId=" + m_receiverId +
"&appId=" + m_appId;
779 if (!m_guideLanguage.empty())
781 url +=
"&language=" + m_guideLanguage;
784 if (!m_aspect_ratio.empty())
786 url +=
"&aspectRatio=" + m_aspect_ratio;
790 __TIMESTAMP(); LOG(
"Speech connection to: <%s>", url.c_str());
792 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
794 curl_easy_setopt(curl, CURLOPT_POST, 1L);
795 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_chunked_socket_callback);
798 curl_easy_setopt(curl, CURLOPT_READDATA,
this);
800 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, voice_writeData);
801 curl_easy_setopt(curl, CURLOPT_WRITEDATA,
this);
802 curl_easy_setopt(curl, CURLOPT_TIMEOUT, DEFAULT_VREX_TIMEOUT);
803 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
805 chunk = curl_slist_append(chunk,
"Transfer-Encoding: chunked");
806 chunk = curl_slist_append(chunk,
"Content-Type:application/octet-stream");
807 chunk = curl_slist_append(chunk,
"Expect:");
808 res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
811 string userAgentData = getUserAgentString();
812 __TIMESTAMP(); LOG(
"Speech USERAGENT: %s\n", userAgentData.c_str());
813 curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgentData.c_str());
816 res = curl_easy_perform(curl);
818 pthread_mutex_lock(&m_mutex);
819 if (m_clientSocket >= 0) {
820 __TIMESTAMP(); LOG(
"Deleting client socket from after curl_easy_perform\n");
821 close(m_clientSocket);
824 pthread_mutex_unlock(&m_mutex);
826 curl_slist_free_all(chunk);
855 if(res != CURLE_OK) {
856 std::stringstream sstm;
857 sstm <<
"cURL call failed (" << res <<
"): " << curl_easy_strerror(res);
858 string errorMessage = sstm.str();
860 __TIMESTAMP(); LOG(
"speech(): %s\n", errorMessage.c_str());
862 notifyError(0, res,0,0, errorMessage.c_str(),SPEECH);
868 m_speechResults = parser.parse((
const unsigned char *)m_speechResponse.c_str());
870 if (m_speechResults[
"code"] != NULL) {
874 LOG(
"onSpeech response error!\n");
875 LOG(
"onSpeech code: <%s>\n", m_speechResults[
"code"]->str.c_str());
876 if (m_speechResults[
"message"]!=NULL){
877 LOG(
"onSpeech message: <%s>\n", m_speechResults[
"message"]->str.c_str());
879 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
880 returnCode = strtol(m_speechResults[
"code"]->str.c_str(), NULL, 10);
881 if ((responseCode != 200) || (returnCode != 0)) {
882 notifyError(responseCode, 0,returnCode,0, m_speechResults[
"message"]->str.c_str(),SPEECH);
889 }
catch (
const std::exception err){
890 __TIMESTAMP(); LOG(
"exception in Speech response: %s",err.what());
891 __TIMESTAMP(); LOG(
"Speech response string for exception: %s",m_kkResponse.c_str());
892 std::stringstream sstm;
893 sstm <<
"Unknown exception:" << err.what() <<
": speech response:" << m_speechResponse.c_str();
894 string errorMessage = sstm.str();
895 notifyError(0, 0,800,0, errorMessage.c_str(),SPEECH);
901 getRequestMetrics(curl,buffer);
906 curl_easy_cleanup(curl);
908 close(m_serverSocket);
913 unlink(socketName.c_str());
918 char * VREXSession::getRequestMetrics(CURL *curl,
char *buffer)
920 double total, connect, startTransfer, resolve, appConnect, preTransfer, redirect;
921 long responseCode,sslVerify;
923 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
924 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &resolve);
925 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
926 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &appConnect);
927 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &preTransfer);
928 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &startTransfer);
929 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME , &total);
930 curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect);
931 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
933 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, &sslVerify);
935 sprintf(buffer,
"\nHttpRequestEnd %s code=%ld times={total=%g, connect=%g startTransfer=%g resolve=%g, appConnect=%g, preTransfer=%g, redirect=%g, sslVerify=%g}\n", url, responseCode, total, connect, startTransfer, resolve, appConnect, preTransfer, redirect,sslVerify);
939 #ifdef RF4CE_GENMSO_API
940 void VREXSession::getStaticStbAndRemoteinfo(MSOBusAPI_RfStatus_t *rfStatus,
int bindRemotesIndex)
942 MSOBusAPI_BindRemote_t bindRemote;
943 #elif defined(RF4CE_API)
944 void VREXSession::getStaticStbAndRemoteinfo(rf4ce_RfStatus_t *rfStatus,
int bindRemotesIndex)
946 rf4ce_BindRemote_t bindRemote;
947 #elif defined(RF4CE_GPMSO_API)
948 void VREXSession::getStaticStbAndRemoteinfo(gpMSOBusAPI_RfStatus_t *rfStatus,
int bindRemotesIndex)
950 gpMSOBusAPI_BindRemote_t bindRemote;
952 #warning "No RF4CE API defined"
955 char tempBuffer[TEMP_BUFFER_SIZE];
957 if(rfStatus->bindRemotes[bindRemotesIndex].ShortAddress != 0xFFFF)
959 bindRemote = rfStatus->bindRemotes[bindRemotesIndex];
962 m_remoteType = bindRemote.Type;
965 sprintf(tempBuffer,
"%d.%d.%d.%d", bindRemote.VersionInfoSw[0], \
966 bindRemote.VersionInfoSw[1], \
967 bindRemote.VersionInfoSw[2], \
968 bindRemote.VersionInfoSw[3]);
969 m_remoteSoftwareVersion = tempBuffer;
972 sprintf(tempBuffer,
"%d.%d.%d.%d", bindRemote.VersionInfoHw.manufacturer, \
973 bindRemote.VersionInfoHw.model, \
974 bindRemote.VersionInfoHw.hwRevision, \
975 bindRemote.VersionInfoHw.lotCode);
976 m_remoteHardwareVersion = tempBuffer;
979 sprintf(tempBuffer,
"0x%x%x%x%x%x%x%x%x", rfStatus->macAddress[7],rfStatus->macAddress[6],rfStatus->macAddress[5],rfStatus->macAddress[4],rfStatus->macAddress[3],rfStatus->macAddress[2],rfStatus->macAddress[1],rfStatus->macAddress[0]);
980 m_rf4ceMacAddress = tempBuffer;
983 #if 0 // Temporarily remove as STB_VERSION_STRING can't be retrieved in a Yocto build
985 m_rdkImage = STB_VERSION_STRING;
989 #if 0 // Temporarily remove this code as the values had been received from iarmStatus check which has been removed
990 void VREXSession::getDynamicStbAndRemoteinfo()
992 char tempBuffer[TEMP_BUFFER_SIZE];
995 unsigned char batteryLevelLoaded = get_battery_level_loaded(m_remoteId);
996 sprintf(tempBuffer,
"%i.%iV", (UInt16)((batteryLevelLoaded >> 6) & 0x03), (UInt16)(((batteryLevelLoaded & 0x3F)*100) >> 6));
997 m_remoteBatteryVoltage = tempBuffer;
1000 sprintf(tempBuffer,
"%d", get_status_kill_count());
1001 m_iArmStatusKillCount = tempBuffer;
1005 string VREXSession::getPostFieldString()
1007 #if 0 // Temporarily remove this code as the values had been received from iarmStatus check which has been removed
1009 getDynamicStbAndRemoteinfo();
1011 string postData =
"receiverId=" + m_receiverId +
"&appId=" + m_appId +
"&rf4ceMAC=" + m_rf4ceMacAddress +
"&batt=" + m_remoteBatteryVoltage +
"&iarmKill=" + m_iArmStatusKillCount;
1013 string postData =
"receiverId=" + m_receiverId +
"&appId=" + m_appId +
"&rf4ceMAC=" + m_rf4ceMacAddress;
1019 string VREXSession::getUserAgentString()
1021 #if 0 // Temporarily remove as STB_VERSION_STRING can't be retrieved in a Yocto build
1022 string userAgentData =
"rdk=" + m_rdkImage +
"; rmtType=" + m_remoteType +
"; rmtSVer=" + m_remoteSoftwareVersion +
"; rmtHVer=" + m_remoteHardwareVersion;
1024 string userAgentData =
"rmtType=" + m_remoteType +
"; rmtSVer=" + m_remoteSoftwareVersion +
"; rmtHVer=" + m_remoteHardwareVersion +
"; stbName=" + m_stbName;
1027 return userAgentData;