diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /tools/EventClients/examples/c++ | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/EventClients/examples/c++')
-rw-r--r-- | tools/EventClients/examples/c++/example_button1.cpp | 65 | ||||
-rw-r--r-- | tools/EventClients/examples/c++/example_button2.cpp | 75 | ||||
-rw-r--r-- | tools/EventClients/examples/c++/example_log.cpp | 39 | ||||
-rw-r--r-- | tools/EventClients/examples/c++/example_mouse.cpp | 63 | ||||
-rw-r--r-- | tools/EventClients/examples/c++/example_notification.cpp | 64 |
5 files changed, 306 insertions, 0 deletions
diff --git a/tools/EventClients/examples/c++/example_button1.cpp b/tools/EventClients/examples/c++/example_button1.cpp new file mode 100644 index 0000000..d96f268 --- /dev/null +++ b/tools/EventClients/examples/c++/example_button1.cpp @@ -0,0 +1,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); +} diff --git a/tools/EventClients/examples/c++/example_button2.cpp b/tools/EventClients/examples/c++/example_button2.cpp new file mode 100644 index 0000000..ddb55be --- /dev/null +++ b/tools/EventClients/examples/c++/example_button2.cpp @@ -0,0 +1,75 @@ +#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); + // Note that we have foo(BUTTON, DEVICEMAP); + CPacketBUTTON btn1("dpadup", "XG", 0); + btn1.Send(sockfd, my_addr); + + sleep(5); + + CPacketBUTTON btn2(0x28, 0); + btn2.Send(sockfd, my_addr); + + sleep(5); + + CPacketBUTTON btn3("right", "KB", 0); + btn3.Send(sockfd, my_addr); + + sleep(5); + // Release button + CPacketBUTTON btn4; + btn4.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); +} diff --git a/tools/EventClients/examples/c++/example_log.cpp b/tools/EventClients/examples/c++/example_log.cpp new file mode 100644 index 0000000..ca61cb0 --- /dev/null +++ b/tools/EventClients/examples/c++/example_log.cpp @@ -0,0 +1,39 @@ +#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); + //Normally this is already done by the client + CPacketHELO HeloPackage("LOG Test", ICON_NONE); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + //This works as XBMC internal CLog::LOG(LOGTYPE, STRING); + CPacketLOG packet(LOGERROR, "The Log Message"); + packet.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); +} diff --git a/tools/EventClients/examples/c++/example_mouse.cpp b/tools/EventClients/examples/c++/example_mouse.cpp new file mode 100644 index 0000000..a0c5832 --- /dev/null +++ b/tools/EventClients/examples/c++/example_mouse.cpp @@ -0,0 +1,63 @@ +#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/mouse.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/mouse.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 Mouse", usIconType, sIconFile.c_str()); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + + for(int i = 0; i < 65536; i++) + { + CPacketMOUSE mouse(i,i); + mouse.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); +} diff --git a/tools/EventClients/examples/c++/example_notification.cpp b/tools/EventClients/examples/c++/example_notification.cpp new file mode 100644 index 0000000..5cd0657 --- /dev/null +++ b/tools/EventClients/examples/c++/example_notification.cpp @@ -0,0 +1,64 @@ +#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/mail.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/mail.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("Email Notifier", ICON_NONE); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + + CPacketNOTIFICATION packet("New Mail!", // caption + "RE: Check this out", // message + usIconType, // optional icon type + sIconFile.c_str()); // icon file (local) + packet.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); +} |