--- /dev/null
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace CoreApp
+{
+ public class Sniper
+ {
+ private IntPtr nativeWindow;
+ private string storagePath;
+ private int imageWidth;
+ private int imageHeight;
+ public bool SkipUpdateFlag;
+
+ public event EventHandler<Event> UpdatedEvent;
+ public event EventHandler<Event> AddRemoveEvent;
+ public event EventHandler<Event> SkipUpdateEvent;
+
+ public class Event : EventArgs
+ {
+ public string AppId;
+ public string InstanceId;
+ public string Info;
+ }
+
+ private void WriteLog(string message)
+ {
+ }
+
+ private void AddedCallback(string appId, string instanceId)
+ {
+ EventHandler<Event> handler = AddRemoveEvent;
+ Event eventInfo;
+
+ WriteLog("Added " + appId + " " + instanceId);
+
+ if (handler == null)
+ {
+ return;
+ }
+
+ try
+ {
+ eventInfo = new Event();
+ }
+ catch (Exception e)
+ {
+ WriteLog("Updated Exception : " + e.Message);
+ return;
+ }
+
+ eventInfo.AppId = appId;
+ eventInfo.InstanceId = instanceId;
+ eventInfo.Info = "Added";
+
+ handler(this, eventInfo);
+ }
+
+ private void RemovedCallback(string appId, string instanceId)
+ {
+ EventHandler<Event> handler = AddRemoveEvent;
+ Event eventInfo;
+
+ WriteLog("Removed " + appId + " " + instanceId);
+
+ if (handler == null)
+ {
+ return;
+ }
+
+ try
+ {
+ eventInfo = new Event();
+ }
+ catch (Exception e)
+ {
+ WriteLog("Updated Exception : " + e.Message);
+ return;
+ }
+
+ eventInfo.AppId = appId;
+ eventInfo.InstanceId = instanceId;
+ eventInfo.Info = "Removed";
+
+ handler(this, eventInfo);
+ }
+
+ private void UpdatedCallback(string appId, string instanceId, string Filename)
+ {
+ EventHandler<Event> handler = UpdatedEvent;
+ Event eventInfo;
+
+ WriteLog("Updated " + appId + " " + instanceId + " " + Filename);
+
+ if (handler == null)
+ {
+ return;
+ }
+
+ try
+ {
+ eventInfo = new Event();
+ }
+ catch (Exception e)
+ {
+ WriteLog("Updated Exception : " + e.Message);
+ return;
+ }
+
+ eventInfo.Info = Filename;
+ eventInfo.AppId = appId;
+ eventInfo.InstanceId = instanceId;
+
+ handler(this, eventInfo);
+ }
+
+ private int SkipUpdateCallback(string appId, string instanceId, string Filename)
+ {
+ EventHandler<Event> handler = SkipUpdateEvent;
+ Event eventInfo;
+
+ WriteLog("SkipUpdate" + appId + " " + instanceId + " " + Filename);
+
+ if (handler == null)
+ {
+ return 0;
+ }
+
+ try
+ {
+ eventInfo = new Event();
+ }
+ catch (Exception e)
+ {
+ WriteLog("SkipUpdated Exception : " + e.Message);
+ return 0;
+ }
+
+ eventInfo.Info = Filename;
+ eventInfo.AppId = appId;
+ eventInfo.InstanceId = instanceId;
+
+ handler(this, eventInfo);
+
+ if (SkipUpdateFlag)
+ {
+ WriteLog("Update is skipped : " + Filename);
+ SkipUpdateFlag = false;
+ return 1;
+ }
+
+ return 0;
+ }
+
+ public Sniper(IntPtr win, string path, int w, int h)
+ {
+ nativeWindow = win;
+ storagePath = path;
+ imageWidth = w;
+ imageHeight = h;
+ SkipUpdateFlag = false;
+ }
+
+ public void StartMonitor()
+ {
+ InterOp.SniperCallback callbacks;
+
+ try
+ {
+ callbacks = new InterOp.SniperCallback();
+ callbacks.Added = new InterOp.CallbackAddedRemoved(AddedCallback);
+ callbacks.Removed = new InterOp.CallbackAddedRemoved(RemovedCallback);
+ callbacks.Updated = new InterOp.CallbackUpdated(UpdatedCallback);
+ callbacks.SkipUpdate = new InterOp.CallbackSkipUpdate(SkipUpdateCallback);
+ }
+ catch (Exception e)
+ {
+ throw new SniperException(e.Message);
+ }
+
+ try
+ {
+ InterOp.sniper_init(nativeWindow, callbacks, storagePath, imageWidth, imageHeight);
+ }
+ catch (DllNotFoundException e)
+ {
+ WriteLog("Loadable library is not found\n");
+ }
+
+ WriteLog("Sniper starts monitoring : " + storagePath + "ImageSize : " + imageWidth + "x" + imageHeight);
+ }
+
+ public void StopMonitor()
+ {
+ try
+ {
+ InterOp.sniper_fini();
+ }
+ catch (DllNotFoundException e)
+ {
+ WriteLog("Loadable library is not found\n");
+ }
+
+ WriteLog("Sniper stops monitoring : " + storagePath + "ImageSize : " + imageWidth + "x" + imageHeight);
+ }
+
+ public void RequestUpdate(string instanceId)
+ {
+ try
+ {
+ InterOp.sniper_request_update(instanceId);
+ }
+ catch (DllNotFoundException e)
+ {
+ WriteLog("Loadable library is not found\n");
+ }
+
+ WriteLog("Sniper requests update (" + instanceId + ") : " + storagePath + "ImageSize : " + imageWidth + "x" + imageHeight);
+ }
+ }
+}
+
+/* End of a file */
--- /dev/null
+using System;
+using System.Runtime.InteropServices;
+
+namespace CoreApp
+{
+ internal static partial class InterOp
+ {
+ public delegate void CallbackAddedRemoved(string appId, string instanceId);
+ public delegate void CallbackUpdated(string appId, string instanceId, string filename);
+ public delegate int CallbackSkipUpdate(string appid, string instanceId, string filename);
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SniperCallback
+ {
+ public CallbackAddedRemoved Added;
+ public CallbackAddedRemoved Removed;
+ public CallbackUpdated Updated;
+ public CallbackSkipUpdate SkipUpdate;
+ }
+
+ [DllImport("sniper", CharSet = CharSet.Ansi)]
+ internal static extern int sniper_init(IntPtr win, SniperCallback callbacks, string path, int w, int h);
+
+ [DllImport("sniper", CharSet = CharSet.Ansi)]
+ internal static extern int sniper_request_update(string instanceId);
+
+ [DllImport("sniper", CharSet = CharSet.Ansi)]
+ internal static extern int sniper_fini();
+ }
+}
+
+/* End of a file */
using LibTVRefCommonPortable.Utils;
using LibTVRefCommonTizen.Ports;
using Tizen.Xamarin.Forms.Extension.Renderer;
+using CoreApp;
+using System;
namespace TVHome.TizenTV
{
windowPort = new WindowPort();
windowPort.MainWindow = MainWindow;
- // Grab key events
+ /// Grab key events
MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true);
MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
MainWindow.KeyGrab("Up", false);
MainWindow.KeyGrab("Left", false);
MainWindow.KeyGrab("Right", false);
windowPort.SetKeyGrabExclusively(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
+
+ /// Sniper
+ try
+ {
+ Sniper sniper = new Sniper((IntPtr)MainWindow, "/tmp", 960, 540);
+ sniper.UpdatedEvent += OnScreenUpdate;
+ sniper.AddRemoveEvent += SniperAddRemoveEvent;
+ sniper.SkipUpdateEvent += SniperSkipUpdateEvent;
+ sniper.StartMonitor();
+ }
+ catch (SniperException e)
+ {
+ DbgPort.E("Failed to create sniper object : " + e.Message);
+ }
+ }
+
+ private void SniperSkipUpdateEvent(object sender, Sniper.Event e)
+ {
+ DbgPort.D(" [Sniper SkipUpdateEvent] : " + e.Info);
+ (sender as Sniper).SkipUpdateFlag = true;
+ }
+
+ private void SniperAddRemoveEvent(object sender, Sniper.Event e)
+ {
+ DbgPort.D(" [Sniper SniperAddRemoveEvent] : " + e.Info);
+ }
+
+ private void OnScreenUpdate(object sender, Sniper.Event e)
+ {
+ DbgPort.D(" [Sniper OnScreenUpdate] : " + e.Info);
}
/// <summary>