aboutsummaryrefslogtreecommitdiff
path: root/tools/EventClients/examples/c++/example_button1.cpp
blob: d96f2681f39e07f599dc29490032709e04f5fb87 (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
#include "../../lib/c++/xbmcclient.h"
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#ifdef _WIN32
#include <Windows.h> // for sleep
#else
#include <unistd.h>
#endif

int main(int argc, char **argv)
{
  /* connect to localhost, port 9777 using a UDP socket
     this only needs to be done once.
     by default this is where XBMC will be listening for incoming
     connections. */
  CAddress my_addr; // Address => localhost on 9777
  int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0)
  {
    printf("Error creating socket\n");
    return -1;
  }

  my_addr.Bind(sockfd);

  std::string sIconFile = "../../icons/bluetooth.png";
  unsigned short usIconType = ICON_PNG;

  std::ifstream file (sIconFile, std::ios::in|std::ios::binary|std::ios::ate);
  if (!file.is_open())
  {
    sIconFile = "/usr/share/pixmaps/kodi/bluetooth.png";
    file.open(sIconFile, std::ios::in|std::ios::binary|std::ios::ate);

    if (!file.is_open()) {
      usIconType = ICON_NONE;
    }
    else
    {
      file.close();
    }
  }
  else
  {
    file.close();
  }

  CPacketHELO HeloPackage("Example Remote", usIconType, sIconFile.c_str());
  HeloPackage.Send(sockfd, my_addr);

  sleep(5);
  // press 'S'
  CPacketBUTTON btn1('S', true);
  btn1.Send(sockfd, my_addr);

  sleep(2);
  // press the enter key (13 = enter)
  CPacketBUTTON btn2(13, true);
  btn2.Send(sockfd, my_addr);

  // BYE is not required since XBMC would have shut down
  CPacketBYE bye; // CPacketPing if you want to ping
  bye.Send(sockfd, my_addr);
}