Thanks
Well I believe I have made some steps, got basic function under c++, as I was able to get a one off command to work, move right, have not handled getting the response as suggested, working on.
Have not done an LNMCE specific stuff yet, just trying to understand the process, that is coding in c++ and how all works, attempt shown below
/**********************************
Testing the use of libcurl to send JSON
to XBMC
Put together from findings on google
************************************/
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <curl/curl.h>
int main()
{
CURL *curl;
CURLcode res;
struct curl_slist *headers=NULL;
char jsonObj[80];
int a=1;
float b=2.0;
if (0 != curl_global_init(CURL_GLOBAL_ALL))
{
fprintf(stderr, "Global Call Failed: %s\n", "Some error");
return false;
}
else
{
curl = curl_easy_init();
if (curl)
{
sprintf(jsonObj, "\"jsonrpc\": \"%.1f\", \"method\": \"%s\", \"id\": \"%d\"", b, "Input.Right", a);
/*Ok curl initialized, let first set the URL for XBMC */
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.80.150:80/jsonrpc");
/*Set header here as CURLOPT_HTTPHEADER requires this variable type*/
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* Now specify the POST data */
/*fprintf(stderr, jsonObj); to check what the object was doing, realized it converts everything to string, which fails for the ID
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObj);*/
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Left\", \"id\": 1}");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)-1);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
res = curl_easy_perform(curl); /*So I segment faulting here */
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
/* always cleanup */
curl_easy_cleanup(curl);
}
fprintf(stderr, "Clean global: %s\n", " ");
curl_global_cleanup();
return 0;
}
}
What was helpful also, was curl at the command prompt, has an option to build the code, though it did not work when compiled, was nice
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Right\", \"id\": 1}" http://192.168.80.150:80/jsonrpc --libcurl mytest.txt
Yes not nice, but seeing the light, currently testing options, as pass right, left, etc, then realized c++ does not support case statement with strings, so did with an if and else if, using compare.
Now its time to start properly working on what can be the base, a xbmc_control.h and xbmc_control.cpp.
Any advice is welcomed, as c++ is totally new to me, google is truly a friend, wish I had more time, LOL.