aboutsummaryrefslogtreecommitdiff
path: root/tools/EventClients
diff options
context:
space:
mode:
authorVasyl Gello <vasek.gello@gmail.com>2020-11-16 13:58:31 +0200
committerVasyl Gello <vasek.gello@gmail.com>2020-11-16 13:58:31 +0200
commit2d4618cb53871b41ec3911563bac27a3a5710003 (patch)
tree88279221fbfab4c45f38dc439cc7e6eff6ab6efd /tools/EventClients
parentde0329a45682d86f6ada399f01289d03098f7c55 (diff)
[EventClients] Fix examples and libs
* Provide correct icon paths and types depending on file existence * Fix C++ and Java EventClient examples
Diffstat (limited to 'tools/EventClients')
-rw-r--r--tools/EventClients/examples/c#/XBMCDemoClient1.cs20
-rw-r--r--tools/EventClients/examples/c++/example_button1.cpp29
-rw-r--r--tools/EventClients/examples/c++/example_button2.cpp35
-rw-r--r--tools/EventClients/examples/c++/example_log.cpp5
-rw-r--r--tools/EventClients/examples/c++/example_mouse.cpp29
-rw-r--r--tools/EventClients/examples/c++/example_notification.cpp31
-rw-r--r--tools/EventClients/examples/java/XBMCDemoClient1.java22
-rwxr-xr-xtools/EventClients/examples/python/example_action.py19
-rwxr-xr-xtools/EventClients/examples/python/example_button1.py19
-rwxr-xr-xtools/EventClients/examples/python/example_button2.py19
-rwxr-xr-xtools/EventClients/examples/python/example_mouse.py19
-rwxr-xr-xtools/EventClients/examples/python/example_notification.py25
-rwxr-xr-xtools/EventClients/examples/python/example_simple.py20
13 files changed, 251 insertions, 41 deletions
diff --git a/tools/EventClients/examples/c#/XBMCDemoClient1.cs b/tools/EventClients/examples/c#/XBMCDemoClient1.cs
index c837ab1a83..df74dea41f 100644
--- a/tools/EventClients/examples/c#/XBMCDemoClient1.cs
+++ b/tools/EventClients/examples/c#/XBMCDemoClient1.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Windows.Forms;
using XBMC;
@@ -13,11 +14,22 @@ namespace XBMCEventClientDemo
[STAThread]
static void Main()
{
- EventClient eventClient = new EventClient();
- eventClient.Connect("127.0.0.1", 9777);
- eventClient.SendHelo("XBMC Client Demo", IconType.ICON_PNG, "icon.png");
+ EventClient eventClient = new EventClient();
+ eventClient.Connect("127.0.0.1", 9777);
+
+ string iconFile = @"../../icons/icon.png";
+ IconType iconType = IconType.ICON_PNG;
+
+ if !File.Exists(iconFile) {
+ iconFile = @"/usr/share/xbmc/media/icon.png";
+ if !File.Exists(iconFile) {
+ iconType = IconType.ICON_NONE;
+ }
+ }
+
+ eventClient.SendHelo("XBMC Client Demo", iconType, iconFile);
System.Threading.Thread.Sleep(1000);
- eventClient.SendNotification("XBMC Client Demo", "Notification Message", IconType.ICON_PNG, "/usr/share/xbmc/media/icon.png");
+ eventClient.SendNotification("XBMC Client Demo", "Notification Message", iconType, iconFile);
System.Threading.Thread.Sleep(1000);
eventClient.SendButton("dpadup", "XG", ButtonFlagsType.BTN_DOWN | ButtonFlagsType.BTN_NO_REPEAT, 0);
System.Threading.Thread.Sleep(1000);
diff --git a/tools/EventClients/examples/c++/example_button1.cpp b/tools/EventClients/examples/c++/example_button1.cpp
index a980e3da24..d96f2681f3 100644
--- a/tools/EventClients/examples/c++/example_button1.cpp
+++ b/tools/EventClients/examples/c++/example_button1.cpp
@@ -2,6 +2,11 @@
#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)
{
@@ -19,7 +24,29 @@ int main(int argc, char **argv)
my_addr.Bind(sockfd);
- CPacketHELO HeloPackage("Example Remote", ICON_PNG, "../../icons/bluetooth.png");
+ 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);
diff --git a/tools/EventClients/examples/c++/example_button2.cpp b/tools/EventClients/examples/c++/example_button2.cpp
index 852e49f9a2..ddb55be644 100644
--- a/tools/EventClients/examples/c++/example_button2.cpp
+++ b/tools/EventClients/examples/c++/example_button2.cpp
@@ -2,6 +2,11 @@
#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)
{
@@ -19,22 +24,44 @@ int main(int argc, char **argv)
my_addr.Bind(sockfd);
- CPacketHELO HeloPackage("Example Remote", ICON_PNG, "../../icons/bluetooth.png");
+ 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");
+ CPacketBUTTON btn1("dpadup", "XG", 0);
btn1.Send(sockfd, my_addr);
sleep(5);
- CPacketBUTTON btn2(0x28);
+ CPacketBUTTON btn2(0x28, 0);
btn2.Send(sockfd, my_addr);
sleep(5);
- CPacketBUTTON btn3("right", "KB");
+ CPacketBUTTON btn3("right", "KB", 0);
btn3.Send(sockfd, my_addr);
sleep(5);
diff --git a/tools/EventClients/examples/c++/example_log.cpp b/tools/EventClients/examples/c++/example_log.cpp
index 6194ed9c51..ca61cb04fd 100644
--- a/tools/EventClients/examples/c++/example_log.cpp
+++ b/tools/EventClients/examples/c++/example_log.cpp
@@ -2,6 +2,11 @@
#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)
{
diff --git a/tools/EventClients/examples/c++/example_mouse.cpp b/tools/EventClients/examples/c++/example_mouse.cpp
index 23f40d3de8..a0c583285c 100644
--- a/tools/EventClients/examples/c++/example_mouse.cpp
+++ b/tools/EventClients/examples/c++/example_mouse.cpp
@@ -2,6 +2,11 @@
#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)
{
@@ -19,7 +24,29 @@ int main(int argc, char **argv)
my_addr.Bind(sockfd);
- CPacketHELO HeloPackage("Example Mouse", ICON_PNG, "../../icons/mouse.png");
+ 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);
diff --git a/tools/EventClients/examples/c++/example_notification.cpp b/tools/EventClients/examples/c++/example_notification.cpp
index dc51075b85..5cd0657444 100644
--- a/tools/EventClients/examples/c++/example_notification.cpp
+++ b/tools/EventClients/examples/c++/example_notification.cpp
@@ -2,6 +2,11 @@
#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)
{
@@ -20,6 +25,28 @@ int main(int argc, char **argv)
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);
@@ -27,8 +54,8 @@ int main(int argc, char **argv)
CPacketNOTIFICATION packet("New Mail!", // caption
"RE: Check this out", // message
- ICON_PNG, // optional icon type
- "../../icons/mail.png"); // icon file (local)
+ 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
diff --git a/tools/EventClients/examples/java/XBMCDemoClient1.java b/tools/EventClients/examples/java/XBMCDemoClient1.java
index 922d4d64ed..5bb2821eb4 100644
--- a/tools/EventClients/examples/java/XBMCDemoClient1.java
+++ b/tools/EventClients/examples/java/XBMCDemoClient1.java
@@ -1,5 +1,6 @@
package org.xbmc.eventclient.demo;
+import java.io.File;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
@@ -18,10 +19,27 @@ public class XBMCDemoClient1 {
* @param args
*/
public static void main(String[] args) throws IOException, InterruptedException {
- InetAddress host = Inet4Address.getByAddress(new byte[] { (byte)192, (byte)168, 0, 20 } );
+ InetAddress host = Inet4Address.getByAddress(new byte[] { (byte)127, 0, 0, 1 } );
Thread.sleep(20000);
- XBMCClient oXBMCClient = new XBMCClient(host, 9777, "My Client", "/usr/share/xbmc/media/icon.png");
+
+ String iconFile = "/usr/share/xbmc/media/icon.png";
+
+ if (! new File(iconFile).exists()) {
+ iconFile = "../../icons/icon.png";
+
+ if (! new File(iconFile).exists()) {
+ iconFile = "";
+ }
+ }
+
+ XBMCClient oXBMCClient = null;
+
+ if (iconFile != "") {
+ oXBMCClient = new XBMCClient(host, 9777, "My Client", iconFile);
+ } else {
+ oXBMCClient = new XBMCClient(host, 9777, "My Client");
+ }
Thread.sleep(7000);
diff --git a/tools/EventClients/examples/python/example_action.py b/tools/EventClients/examples/python/example_action.py
index 224072c300..b87fc297bb 100755
--- a/tools/EventClients/examples/python/example_action.py
+++ b/tools/EventClients/examples/python/example_action.py
@@ -3,11 +3,22 @@
# This is a simple example showing how you can send a key press event
# to XBMC using the XBMCClient class
+import os
+from socket import *
import sys
-sys.path.append("../../lib/python")
-import time
-from xbmcclient import XBMCClient,ACTION_EXECBUILTIN,ACTION_BUTTON
+if os.path.exists("../../lib/python"):
+ # try loading modules from source directory
+ sys.path.append("../../lib/python")
+
+ from xbmcclient import *
+
+ ICON_PATH = "../../icons/"
+else:
+ # fallback to system wide modules
+
+ from kodi.xbmcclient import *
+ from kodi.defs import *
def main():
@@ -15,7 +26,7 @@ def main():
port = 9777
# Create an XBMCClient object and connect
- xbmc = XBMCClient("Example Remote", "../../icons/bluetooth.png")
+ xbmc = XBMCClient("Example Remote", ICON_PATH + "/bluetooth.png")
xbmc.connect()
# send a up key press using the xbox gamepad map "XG" and button
diff --git a/tools/EventClients/examples/python/example_button1.py b/tools/EventClients/examples/python/example_button1.py
index a356d72573..abdfe49342 100755
--- a/tools/EventClients/examples/python/example_button1.py
+++ b/tools/EventClients/examples/python/example_button1.py
@@ -20,11 +20,22 @@
# import the XBMC client library
# NOTE: The library is not complete yet but is usable at this stage.
+import os
+from socket import *
import sys
-sys.path.append("../../lib/python")
-from xbmcclient import *
-from socket import *
+if os.path.exists("../../lib/python"):
+ # try loading modules from source directory
+ sys.path.append("../../lib/python")
+
+ from xbmcclient import *
+
+ ICON_PATH = "../../icons/"
+else:
+ # fallback to system wide modules
+
+ from kodi.xbmcclient import *
+ from kodi.defs import *
def main():
import time
@@ -43,7 +54,7 @@ def main():
# 'icon_type' can be one of ICON_NONE, ICON_PNG, ICON_JPG or ICON_GIF
packet = PacketHELO(devicename="Example Remote",
icon_type=ICON_PNG,
- icon_file="../../icons/bluetooth.png")
+ icon_file=ICON_PATH + "/bluetooth.png")
packet.send(sock, addr)
# IMPORTANT: After a HELO packet is sent, the client needs to "ping" XBMC
diff --git a/tools/EventClients/examples/python/example_button2.py b/tools/EventClients/examples/python/example_button2.py
index 39b8fb74f4..bb91704d06 100755
--- a/tools/EventClients/examples/python/example_button2.py
+++ b/tools/EventClients/examples/python/example_button2.py
@@ -10,11 +10,22 @@
# NOTE: Read the comments in 'example_button1.py' for a more detailed
# explanation.
+import os
+from socket import *
import sys
-sys.path.append("../../lib/python")
-from xbmcclient import *
-from socket import *
+if os.path.exists("../../lib/python"):
+ # try loading modules from source directory
+ sys.path.append("../../lib/python")
+
+ from xbmcclient import *
+
+ ICON_PATH = "../../icons/"
+else:
+ # fallback to system wide modules
+
+ from kodi.xbmcclient import *
+ from kodi.defs import *
def main():
import time
@@ -28,7 +39,7 @@ def main():
# First packet must be HELO and can contain an icon
packet = PacketHELO("Example Remote", ICON_PNG,
- "../../icons/bluetooth.png")
+ ICON_PATH + "/bluetooth.png")
packet.send(sock, addr)
# wait for notification window to close (in XBMC)
diff --git a/tools/EventClients/examples/python/example_mouse.py b/tools/EventClients/examples/python/example_mouse.py
index 88e90f5b8b..7c43782428 100755
--- a/tools/EventClients/examples/python/example_mouse.py
+++ b/tools/EventClients/examples/python/example_mouse.py
@@ -6,11 +6,22 @@
# NOTE: Read the comments in 'example_button1.py' for a more detailed
# explanation.
+import os
+from socket import *
import sys
-sys.path.append("../../lib/python")
-from xbmcclient import *
-from socket import *
+if os.path.exists("../../lib/python"):
+ # try loading modules from source directory
+ sys.path.append("../../lib/python")
+
+ from xbmcclient import *
+
+ ICON_PATH = "../../icons/"
+else:
+ # fallback to system wide modules
+
+ from kodi.xbmcclient import *
+ from kodi.defs import *
def main():
import time
@@ -24,7 +35,7 @@ def main():
# First packet must be HELO and can contain an icon
packet = PacketHELO("Example Mouse", ICON_PNG,
- "../../icons/mouse.png")
+ ICON_PATH + "/mouse.png")
packet.send(sock, addr)
# wait for notification window to close (in XBMC)
diff --git a/tools/EventClients/examples/python/example_notification.py b/tools/EventClients/examples/python/example_notification.py
index 55e0771ab3..fd1a82e319 100755
--- a/tools/EventClients/examples/python/example_notification.py
+++ b/tools/EventClients/examples/python/example_notification.py
@@ -4,11 +4,22 @@
# window with a custom icon inside XBMC. It could be used by mail
# monitoring apps, calendar apps, etc.
+import os
+from socket import *
import sys
-sys.path.append("../../lib/python")
-from xbmcclient import *
-from socket import *
+if os.path.exists("../../lib/python"):
+ # try loading modules from source directory
+ sys.path.append("../../lib/python")
+
+ from xbmcclient import *
+
+ ICON_PATH = "../../icons/"
+else:
+ # fallback to system wide modules
+
+ from kodi.xbmcclient import *
+ from kodi.defs import *
def main():
import time
@@ -25,10 +36,10 @@ def main():
# wait for 5 seconds
time.sleep (5)
- packet = PacketNOTIFICATION("New Mail!", # caption
- "RE: Check this out", # message
- ICON_PNG, # optional icon type
- "../../icons/mail.png") # icon file (local)
+ packet = PacketNOTIFICATION("New Mail!", # caption
+ "RE: Check this out", # message
+ ICON_PNG, # optional icon type
+ ICON_PATH + "/mail.png") # icon file (local)
packet.send(sock, addr)
packet = PacketBYE()
diff --git a/tools/EventClients/examples/python/example_simple.py b/tools/EventClients/examples/python/example_simple.py
index 6beca8540d..2d807e884e 100755
--- a/tools/EventClients/examples/python/example_simple.py
+++ b/tools/EventClients/examples/python/example_simple.py
@@ -3,11 +3,23 @@
# This is a simple example showing how you can send a key press event
# to XBMC using the XBMCClient class
+import os
+from socket import *
import sys
-sys.path.append("../../lib/python")
-
import time
-from xbmcclient import XBMCClient
+
+if os.path.exists("../../lib/python"):
+ # try loading modules from source directory
+ sys.path.append("../../lib/python")
+
+ from xbmcclient import *
+
+ ICON_PATH = "../../icons/"
+else:
+ # fallback to system wide modules
+
+ from kodi.xbmcclient import *
+ from kodi.defs import *
def main():
@@ -15,7 +27,7 @@ def main():
port = 9777
# Create an XBMCClient object and connect
- xbmc = XBMCClient("Example Remote", "../../icons/bluetooth.png")
+ xbmc = XBMCClient("Example Remote", ICON_PATH + "/bluetooth.png")
xbmc.connect()
# wait for notification window to close (in XBMC) (optional)