23 #include <fcgi_stdio.h>
25 const char* pSplChar =
"%20";
26 const char *pChangePower =
"ChangePower";
27 const char *pSetPower =
"SetPower=";
28 const char *pSaveName =
"SaveName=";
29 const char *pPairTo =
"PairTo=";
30 const char *pUnPairTo =
"UnpairTo=";
31 const char *pGetName =
"GetName";
32 const char *pStartDiscovery =
"StartDiscovery";
33 const char *pShowDiscovered =
"ShowDiscovered";
34 const char *pShowAllPaired =
"ShowAllPaired";
35 const char *pStartPlaying =
"StartPlaying=";
36 const char *pStopPlaying =
"StopPlaying";
38 const char *pMainPage =
""
40 "<td> Power On/Off Adapter </td> "
41 "<td> <button id=\"power\" class=\"button\" onclick=\"ChangePower()\">....Go....</button> </td> "
45 "<td> Get Name Of the Adapter </td> "
46 "<td> <button class=\"button\" onclick=\"GetName()\">....Go....</button> </td> "
50 "<td> Show Paired Devices </td> "
51 "<td> <button class=\"button\" onclick=\"ShowAllPaired()\">....Go....</button> </td> "
55 "<td> Start Discovery </td> "
56 "<td> <button class=\"button\" onclick=\"StartDiscovery()\">....Go....</button> </td> "
60 "<td> Show Discovered Devices </td> "
61 "<td> <button class=\"button\" onclick=\"ShowDiscovered()\">....Go....</button> </td> "
65 "<td> Stop Playing </td> "
66 "<td> <button class=\"button\" onclick=\"StopPlaying()\">....Go....</button> </td> "
70 "<script type=\"text/javascript\"> "
72 "function ChangePower() { "
73 " location.href = \"ChangePower\" "
76 "function GetName() { "
77 " location.href = \"GetName\" "
80 "function StartDiscovery() { "
81 " location.href = \"StartDiscovery\" "
84 "function ShowDiscovered() { "
85 " location.href = \"ShowDiscovered\" "
88 "function ShowAllPaired() { "
89 " location.href = \"ShowAllPaired\" "
92 "function StopPlaying() { "
93 " location.href = \"StopPlaying\" "
107 const char* pStylePage =
""
111 "<meta http-equiv=\"pragma\" content=\"no-cache\" />"
112 "<meta http-equiv=\"expires\" content=\"0\" />"
116 " padding: 5px 15px; "
117 " text-decoration: none; "
118 " text-align: center; "
119 " display: inline-block; "
126 " background-color: orange; "
130 " background-color: #A0B0C0; "
131 " transform: translateY(4px); "
141 "<body bgcolor=\"#E0F48E\"> "
143 "<table align=\"center\"> "
146 const char* pGoHome =
""
149 "<button onclick=\"location.href='home';\" class=\"button\">Back</button> "
152 const char* pGetNamePage =
""
153 "<script type=\"text/javascript\"> "
155 "function ChangeName() { "
156 " location.href = \"SaveName=\" + document.getElementById(\"name1\").value; "
165 void findAndReplaceSplCharWithSpace (
char* ptr)
176 memset(temp,
'\0',
sizeof(temp));
178 l1 = strlen(pSplChar);
181 p = strstr(ptr, pSplChar);
187 strncat (temp, ptr, (l2 - l3));
201 unsigned long long int gLastPlaying = 0;
203 void startStreaming (
unsigned long long int handle )
209 if (BTRMGR_RESULT_SUCCESS != rc)
210 printf (
"<tr>" "<td> Connection establishment failed\n </td>" "</tr>" "</table> ");
215 if (BTRMGR_RESULT_SUCCESS != rc)
216 printf (
"<tr>" "<td> Failed to Stream out to this device\n </td>" "</tr>" "</table> ");
219 gLastPlaying = handle;
220 printf (
"<tr>" "<td> Enjoy the show...\t\t :-)\n </td>" "</tr>" "</table> ");
225 void stopStreaming ()
230 if (BTRMGR_RESULT_SUCCESS != rc)
231 printf (
"<tr>" "<td> Failed to Stop Streaming... :( </td>" "</tr>" "</table> ");
235 printf (
"<tr>" "<td> Successfully Stopped... </td>" "</tr>" "</table> ");
239 void GetNumberOfAdapters ()
241 unsigned char numOfAdapters = 0;
243 printf (
"<tr>" "<td> Failed to get the count\n\n\n</td>" "</tr>" "</table> ");
245 printf (
"<tr>" "<td> We found %d Bluetooth adapters in this Platform\n\n\n</td>" "</tr>" "</table> ", numOfAdapters);
257 while (FCGI_Accept() >= 0)
259 const char* func = getenv(
"REQUEST_URI");
263 fprintf(stderr,
"No No No.. This is totally not good..! :(\n");
267 fprintf (stderr,
"The func is .. %s\n", func);
268 if (NULL != strstr (func,
"/btmgr/"))
274 if (BTRMGR_RESULT_SUCCESS != rc)
276 fprintf (stderr,
"Failed to init BTMgr.. Quiting.. \n");
286 printf(
"Content-type: text/html\r\n\r\n");
287 printf (
"%s", pStylePage);
289 if (NULL != strstr (func,
"home"))
291 printf (
"%s", pMainPage);
295 if (NULL != (pInput = strstr (func, pChangePower)))
297 unsigned char power_status = 1;
298 char temp1[32] =
"ON";
299 char temp2[32] =
"OFF";
302 if (BTRMGR_RESULT_SUCCESS != rc)
305 if (0 == power_status)
307 strcpy (temp1,
"OFF");
308 strcpy (temp2,
"ON");
313 "<td>The Device is Currently %s; Power %s Adapter </td> "
314 "<td> <button onclick=\"location.href='SetPower=%s';\" class=\"button\"> %s</button> </td>"
317 " ", temp1, temp2, temp2, temp2);
319 else if (NULL != (pInput = strstr (func, pSetPower)))
321 int length = strlen(pSetPower);
322 unsigned char power = 1;
323 if (0 == strcmp(
"OFF", (pInput+length)))
328 if (BTRMGR_RESULT_SUCCESS != rc)
329 printf (
"<tr>" "<td> Failed tp Set the Power... </td>" "</tr>" "</table> ");
331 printf (
"<tr>" "<td> Successfully Set the power... </td>" "</tr>" "</table> ");
333 else if (NULL != (pInput = strstr (func, pSaveName)))
335 int length = strlen(pSaveName);
337 memset (array,
'\0',
sizeof(array));
338 strncpy (array, (pInput+length), 30);
339 findAndReplaceSplCharWithSpace(array);
342 if (BTRMGR_RESULT_SUCCESS != rc)
343 printf (
"<tr>" "<td> Failed to Set the name as %s... </td>" "</tr>" "</table> ", array);
345 printf (
"<tr>" "<td> Successfully Set the name to %s... </td>" "</tr>" "</table> ", array);
347 else if (NULL != (pInput = strstr (func, pPairTo)))
349 int length = strlen(pPairTo);
350 unsigned long long int handle = 0;
352 memset (array,
'\0',
sizeof(array));
353 strncpy (array, (pInput+length), 30);
354 handle = strtoll(array, NULL, 0);
357 if (BTRMGR_RESULT_SUCCESS != rc)
358 printf (
"<tr>" "<td> Failed to Pair to %s </td>" "</tr>" "</table> ", array);
360 printf (
"<tr>" "<td> Successfully Pair to %s </td>" "</tr>" "</table> ", array);
363 else if (NULL != (pInput = strstr (func, pUnPairTo)))
365 int length = strlen(pUnPairTo);
366 unsigned long long int handle = 0;
368 memset (array,
'\0',
sizeof(array));
369 strncpy (array, (pInput+length), 30);
370 handle = strtoll(array, NULL, 0);
374 if (BTRMGR_RESULT_SUCCESS != rc)
375 printf (
"<tr>" "<td> Failed to UnPair to %s </td>" "</tr>" "</table> ", array);
377 printf (
"<tr>" "<td> Successfully UnPair to %s </td>" "</tr>" "</table> ", array);
379 else if (NULL != (pInput = strstr (func, pGetName)))
381 memset (array,
'\0',
sizeof(array));
384 if (BTRMGR_RESULT_SUCCESS != rc)
386 printf (
"<tr>" "<td> Failed to Get the name of this Device </td>" "</tr>" "</table> ");
391 "<td>Name of this Adapter is </td> "
392 "<td><input type=\"text\" id=\"name1\" style=\"background-color:#CBD5E4;color:black\" value=%s></td> "
393 "<td> <button id=\"nameChange\" class=\"button\" onclick=\"ChangeName()\">Change Name</button> </td> "
400 else if (NULL != (pInput = strstr (func, pStartDiscovery)))
403 if (BTRMGR_RESULT_SUCCESS != rc)
404 printf (
"<tr>" "<td> Failed to Start Discovery... </td>" "</tr>" "</table> ");
406 printf (
"<tr>" "<td> Discovery Start Successfully... </td>" "</tr>" "</table> ");
408 else if (NULL != (pInput = strstr (func, pShowDiscovered)))
412 if (BTRMGR_RESULT_SUCCESS != rc)
413 printf (
"<tr>" "<td> Stopping Discovery Failed... </td>" "</tr>" "</table> ");
416 memset (&discoveredDevices, 0,
sizeof(discoveredDevices));
418 if (BTRMGR_RESULT_SUCCESS != rc)
420 printf (
"<tr>" "<td> Failed to Get the Discovered Devices List... </td>" "</tr>" "</table> ");
425 for (; j< discoveredDevices.m_numOfDevices; j++)
427 memset (array,
'\0',
sizeof(array));
429 printf (
"<td> %s </td>", discoveredDevices.m_deviceProperty[j].m_name );
430 printf (
"<td> %s </td>", discoveredDevices.m_deviceProperty[j].m_deviceAddress);
431 sprintf (array,
"%llu", discoveredDevices.m_deviceProperty[j].m_deviceHandle);
432 printf (
"<td> <button onclick=\"location.href='PairTo=%s';\" class=\"button\"> Pair This </button> </td>", array);
435 printf (
"</table>\n");
436 printf (
"<p> We have %d devices discovered </p>\n", discoveredDevices.m_numOfDevices);
440 else if (NULL != (pInput = strstr (func, pShowAllPaired)))
443 memset (&pairedDevices, 0,
sizeof(pairedDevices));
446 if (BTRMGR_RESULT_SUCCESS != rc)
447 printf (
"<tr>" "<td> Failed to Get the Paired Devices List... </td>" "</tr>" "</table> ");
451 for (; j< pairedDevices.m_numOfDevices; j++)
453 memset (array,
'\0',
sizeof(array));
455 printf (
"<td> %s </td>", pairedDevices.m_deviceProperty[j].m_name );
456 sprintf (array,
"%llu" , pairedDevices.m_deviceProperty[j].m_deviceHandle);
457 printf (
"<td> <button onclick=\"location.href='StartPlaying=%s';\" class=\"button\"> StartPlaying </button> </td>", array);
458 printf (
"<td> <button onclick=\"location.href='UnpairTo=%s';\" class=\"button\"> UnPair </button> </td>", array);
461 printf (
"</table>\n");
462 printf (
"<p> We have %d devices paired </p>\n", pairedDevices.m_numOfDevices);
465 else if (NULL != (pInput = strstr (func, pStartPlaying)))
467 int length = strlen(pStartPlaying);
468 unsigned long long int handle = 0;
470 memset (array,
'\0',
sizeof(array));
471 strncpy (array, (pInput+length), 30);
472 handle = strtoll(array, NULL, 0);
474 startStreaming(handle);
476 else if (NULL != (pInput = strstr (func, pStopPlaying)))
481 else if (NULL != strstr (func,
"GetNumberOfAdapters"))
483 GetNumberOfAdapters();
487 printf (
"<tr>" "<td> Seems new to me.. Let me handle this soon.. %s \n</td>" "</tr>" "</table> ", func);
491 printf (
"%s", pGoHome);
492 printf (
"</body> " "</html> ");
497 fprintf (stderr,
"how come it landed here!?!?!\n");