Skip to content
This repository
Browse code

Merge pull request #3313 from t-nelson/winevents_refactor

CWinEvents refactor and allow CWinEvents to observe Peripherals changes
  • Loading branch information...
commit 36e301cc5ff292958dfb848864b81108426a5d97 2 parents e8a8f38 + cb85945
Trent Nelson authored October 03, 2013

Showing 29 changed files with 192 additions and 97 deletions. Show diff stats Hide diff stats

  1. 10  XBMC.xcodeproj/project.pbxproj
  2. 1  project/VS2010Express/XBMC.vcxproj
  3. 3  project/VS2010Express/XBMC.vcxproj.filters
  4. 5  xbmc/android/activity/AndroidMouse.cpp
  5. 1  xbmc/input/linux/LinuxInputDevices.h
  6. 2  xbmc/osx/IOSEAGLView.mm
  7. 14  xbmc/osx/atv2/XBMCController.mm
  8. 6  xbmc/osx/ios/XBMCController.mm
  9. 4  xbmc/peripherals/Peripherals.cpp
  10. 4  xbmc/peripherals/Peripherals.h
  11. 2  xbmc/peripherals/bus/PeripheralBus.cpp
  12. 2  xbmc/utils/Observer.h
  13. 1  xbmc/windowing/Makefile
  14. 84  xbmc/windowing/WinEvents.cpp
  15. 46  xbmc/windowing/WinEvents.h
  16. 5  xbmc/windowing/WinEventsLinux.cpp
  17. 7  xbmc/windowing/WinEventsLinux.h
  18. 11  xbmc/windowing/WinEventsSDL.cpp
  19. 9  xbmc/windowing/WinEventsSDL.h
  20. 1  xbmc/windowing/X11/WinSystemX11.h
  21. 5  xbmc/windowing/android/WinEventsAndroid.cpp
  22. 12  xbmc/windowing/android/WinEventsAndroid.h
  23. 12  xbmc/windowing/osx/WinEventsIOS.h
  24. 12  xbmc/windowing/osx/WinEventsIOS.mm
  25. 6  xbmc/windowing/osx/WinEventsOSX.h
  26. 7  xbmc/windowing/osx/WinEventsOSX.mm
  27. 8  xbmc/windowing/windows/WinEventsWin32.cpp
  28. 7  xbmc/windowing/windows/WinEventsWin32.h
  29. 2  xbmc/windowing/windows/WinSystemWin32.cpp
10  XBMC.xcodeproj/project.pbxproj
@@ -3018,6 +3018,9 @@
3018 3018
 		E4E91BB80E7F7338001F0546 /* NptXbmcFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4E91BB70E7F7338001F0546 /* NptXbmcFile.cpp */; settings = {COMPILER_FLAGS = "-I$SRCROOT/lib/libUPnP/Platinum/Source/Core -I$SRCROOT/lib/libUPnP/Platinum/Source/Platinum -I$SRCROOT/lib/libUPnP/Platinum/Source/Devices/MediaConnect -I$SRCROOT/lib/libUPnP/Platinum/Source/Devices/MediaRenderer -I$SRCROOT/lib/libUPnP/Platinum/Source/Devices/MediaServer -I$SRCROOT/lib/libUPnP/Platinum/Source/Extras -I$SRCROOT/lib/libUPnP/Neptune/Source/System/Posix -I$SRCROOT/lib/libUPnP/Neptune/Source/Core"; }; };
3019 3019
 		EC720A8F155091BB00FFD782 /* ilog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC720A8D155091BB00FFD782 /* ilog.cpp */; };
3020 3020
 		EC720A9D1550927000FFD782 /* XbmcContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC720A9B1550927000FFD782 /* XbmcContext.cpp */; };
  3021
+		F500E35617F3412C004FC217 /* WinEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F500E35517F3412C004FC217 /* WinEvents.cpp */; };
  3022
+		F500E35717F3412C004FC217 /* WinEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F500E35517F3412C004FC217 /* WinEvents.cpp */; };
  3023
+		F500E35817F3412C004FC217 /* WinEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F500E35517F3412C004FC217 /* WinEvents.cpp */; };
3021 3024
 		F506297A0E57B9680066625A /* MultiPathFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F50629780E57B9680066625A /* MultiPathFile.cpp */; };
3022 3025
 		F5071906175A26AD004C87D1 /* VideoDecodeAcceleration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5071905175A26AD004C87D1 /* VideoDecodeAcceleration.framework */; };
3023 3026
 		F50FDC5A119B4B2C00C8B8CD /* GUIDialogTextViewer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F50FDC59119B4B2C00C8B8CD /* GUIDialogTextViewer.cpp */; };
@@ -5270,6 +5273,8 @@
5270 5273
 		EC720A8E155091BB00FFD782 /* ilog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ilog.h; path = commons/ilog.h; sourceTree = "<group>"; };
5271 5274
 		EC720A9B1550927000FFD782 /* XbmcContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XbmcContext.cpp; sourceTree = "<group>"; };
5272 5275
 		EC720A9C1550927000FFD782 /* XbmcContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XbmcContext.h; sourceTree = "<group>"; };
  5276
+		F500E35517F3412C004FC217 /* WinEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WinEvents.cpp; sourceTree = "<group>"; };
  5277
+		F500E35917F34132004FC217 /* WinEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WinEvents.h; sourceTree = "<group>"; };
5273 5278
 		F502BFDA160F34B900C96C76 /* CallbackHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CallbackHandler.cpp; path = python/CallbackHandler.cpp; sourceTree = "<group>"; };
5274 5279
 		F502BFDB160F34B900C96C76 /* CallbackHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CallbackHandler.h; path = python/CallbackHandler.h; sourceTree = "<group>"; };
5275 5280
 		F502BFE4160F34DC00C96C76 /* LanguageHook.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LanguageHook.cpp; path = python/LanguageHook.cpp; sourceTree = "<group>"; };
@@ -6582,6 +6587,8 @@
6582 6587
 				7C779E26104A57E500F444C4 /* WinEvents.h */,
6583 6588
 				7C779E27104A57E500F444C4 /* WinEventsSDL.cpp */,
6584 6589
 				7C779E28104A57E500F444C4 /* WinEventsSDL.h */,
  6590
+				F500E35517F3412C004FC217 /* WinEvents.cpp */,
  6591
+				F500E35917F34132004FC217 /* WinEvents.h */,
6585 6592
 				7C779E29104A57E500F444C4 /* WinSystem.cpp */,
6586 6593
 				7C779E2A104A57E500F444C4 /* WinSystem.h */,
6587 6594
 				7C779E2F104A57E500F444C4 /* XBMC_events.h */,
@@ -10616,6 +10623,7 @@
10616 10623
 				180F6C8117CE9A5700127892 /* smc.c in Sources */,
10617 10624
 				DFD882F817DD1A5B001516FE /* AddonPythonInvoker.cpp in Sources */,
10618 10625
 				DFD882E917DD189E001516FE /* StringValidation.cpp in Sources */,
  10626
+				F500E35617F3412C004FC217 /* WinEvents.cpp in Sources */,
10619 10627
 			);
10620 10628
 			runOnlyForDeploymentPostprocessing = 0;
10621 10629
 		};
@@ -11645,6 +11653,7 @@
11645 11653
 				DF28DF4F17B8379E0077F41A /* ProfilesOperations.cpp in Sources */,
11646 11654
 				DFD882F617DD1A5B001516FE /* AddonPythonInvoker.cpp in Sources */,
11647 11655
 				DFD882E717DD189E001516FE /* StringValidation.cpp in Sources */,
  11656
+				F500E35817F3412C004FC217 /* WinEvents.cpp in Sources */,
11648 11657
 			);
11649 11658
 			runOnlyForDeploymentPostprocessing = 0;
11650 11659
 		};
@@ -12676,6 +12685,7 @@
12676 12685
 				DF28DF4E17B8379E0077F41A /* ProfilesOperations.cpp in Sources */,
12677 12686
 				DFD882F717DD1A5B001516FE /* AddonPythonInvoker.cpp in Sources */,
12678 12687
 				DFD882E817DD189E001516FE /* StringValidation.cpp in Sources */,
  12688
+				F500E35717F3412C004FC217 /* WinEvents.cpp in Sources */,
12679 12689
 			);
12680 12690
 			runOnlyForDeploymentPostprocessing = 0;
12681 12691
 		};
1  project/VS2010Express/XBMC.vcxproj
@@ -2000,6 +2000,7 @@
2000 2000
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Testsuite|Win32'">true</ExcludedFromBuild>
2001 2001
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release (DirectX)|Win32'">true</ExcludedFromBuild>
2002 2002
     </ClCompile>
  2003
+    <ClCompile Include="..\..\xbmc\windowing\WinEvents.cpp" />
2003 2004
     <ClCompile Include="..\..\xbmc\windowing\WinSystem.cpp" />
2004 2005
     <ClCompile Include="..\..\xbmc\windows\GUIMediaWindow.cpp" />
2005 2006
     <ClCompile Include="..\..\xbmc\windows\GUIWindowDebugInfo.cpp" />
3  project/VS2010Express/XBMC.vcxproj.filters
@@ -3073,6 +3073,9 @@
3073 3073
     <ClCompile Include="..\..\xbmc\utils\StringValidation.cpp">
3074 3074
       <Filter>utils</Filter>
3075 3075
     </ClCompile>
  3076
+    <ClCompile Include="..\..\xbmc\windowing\WinEvents.cpp">
  3077
+      <Filter>windowing</Filter>
  3078
+    </ClCompile>
3076 3079
   </ItemGroup>
3077 3080
   <ItemGroup>
3078 3081
     <ClInclude Include="..\..\xbmc\win32\pch.h">
5  xbmc/android/activity/AndroidMouse.cpp
@@ -23,6 +23,7 @@
23 23
 #include "Application.h"
24 24
 #include "guilib/GUIWindowManager.h"
25 25
 #include "windowing/WinEvents.h"
  26
+#include "input/MouseStat.h"
26 27
 
27 28
 CAndroidMouse::CAndroidMouse()
28 29
 {
@@ -73,7 +74,7 @@ void CAndroidMouse::MouseMove(float x, float y)
73 74
   newEvent.motion.y = y;
74 75
   newEvent.motion.xrel = 0;
75 76
   newEvent.motion.yrel = 0;
76  
-  CWinEventsAndroid::MessagePush(&newEvent);
  77
+  CWinEvents::MessagePush(&newEvent);
77 78
 }
78 79
 
79 80
 void CAndroidMouse::MouseButton(float x, float y, int32_t action)
@@ -89,5 +90,5 @@ void CAndroidMouse::MouseButton(float x, float y, int32_t action)
89 90
   newEvent.button.x = x;
90 91
   newEvent.button.y = y;
91 92
   newEvent.button.button = XBMC_BUTTON_LEFT;
92  
-  CWinEventsAndroid::MessagePush(&newEvent);
  93
+  CWinEvents::MessagePush(&newEvent);
93 94
 }
1  xbmc/input/linux/LinuxInputDevices.h
@@ -89,6 +89,7 @@ class CLinuxInputDevices
89 89
   XBMC_Event ReadEvent();
90 90
   bool IsRemoteLowBattery();
91 91
   bool IsRemoteNotPaired();
  92
+  size_t Size() { return m_devices.size(); }
92 93
 private:
93 94
   CCriticalSection m_devicesListLock;
94 95
   bool CheckDevice(const char *device);
2  xbmc/osx/IOSEAGLView.mm
@@ -330,7 +330,6 @@ - (void) startAnimation
330 330
 	if (!animating && context)
331 331
 	{
332 332
 		animating = TRUE;
333  
-    CWinEventsIOS::Init();
334 333
 
335 334
     // kick off an animation thread
336 335
     animationThreadLock = [[NSConditionLock alloc] initWithCondition: FALSE];
@@ -358,7 +357,6 @@ - (void) stopAnimation
358 357
     // wait for animation thread to die
359 358
     if ([animationThread isFinished] == NO)
360 359
       [animationThreadLock lockWhenCondition:TRUE];
361  
-    CWinEventsIOS::DeInit();
362 360
 	}
363 361
 }
364 362
 //--------------------------------------------------------------
14  xbmc/osx/atv2/XBMCController.mm
@@ -51,7 +51,7 @@
51 51
 //hack around problem with xbmc's typedef int BOOL
52 52
 // and obj-c's typedef unsigned char BOOL
53 53
 #define BOOL XBMC_BOOL 
54  
-#import "WinEventsIOS.h"
  54
+#import "WinEvents.h"
55 55
 #import "XBMC_events.h"
56 56
 #include "utils/log.h"
57 57
 #include "osx/DarwinUtils.h"
@@ -728,7 +728,7 @@ -(void)flushDiskChanges;
728 728
   newEvent.type = XBMC_USEREVENT;
729 729
   newEvent.jbutton.which = eventId;
730 730
   newEvent.jbutton.holdTime = holdTime;
731  
-  CWinEventsIOS::MessagePush(&newEvent);
  731
+  CWinEvents::MessagePush(&newEvent);
732 732
 }
733 733
 
734 734
 static unsigned int XBMCController$appleModKeyToXbmcModKey(XBMCController* self, SEL _cmd, unsigned int appleModifier)
@@ -845,9 +845,9 @@ -(void)flushDiskChanges;
845 845
         {
846 846
           newEvent.key.keysym.mod = (XBMCMod)[self appleModKeyToXbmcModKey:modifier];
847 847
           newEvent.type = XBMC_KEYDOWN;
848  
-          CWinEventsIOS::MessagePush(&newEvent);
  848
+          CWinEvents::MessagePush(&newEvent);
849 849
           newEvent.type = XBMC_KEYUP;
850  
-          CWinEventsIOS::MessagePush(&newEvent);
  850
+          CWinEvents::MessagePush(&newEvent);
851 851
           is_handled = TRUE;
852 852
         }
853 853
       }
@@ -921,7 +921,7 @@ -(void)flushDiskChanges;
921 921
 { 
922 922
   //if queue is empty - skip this timer event
923 923
   //for letting it process
924  
-  if(CWinEventsIOS::GetQueueSize())
  924
+  if(CWinEvents::GetQueueSize())
925 925
     return;
926 926
 
927 927
   NSDate *startDate = [[theTimer userInfo] objectForKey:@"StartDate"];
@@ -1294,7 +1294,7 @@ - (XBMC_Event) translateCocoaToXBMCEvent: (unichar) c
1294 1294
  
1295 1295
   newEvent.appcommand.type = XBMC_APPCOMMAND;
1296 1296
   newEvent.appcommand.action = ACTION_PLAYER_PLAYPAUSE;
1297  
-  CWinEventsIOS::MessagePush(&newEvent);
  1297
+  CWinEvents::MessagePush(&newEvent);
1298 1298
   
1299 1299
   Sleep(2000); 
1300 1300
   [[self glView] pauseAnimation];
@@ -1309,7 +1309,7 @@ - (XBMC_Event) translateCocoaToXBMCEvent: (unichar) c
1309 1309
 
1310 1310
   newEvent.appcommand.type = XBMC_APPCOMMAND;
1311 1311
   newEvent.appcommand.action = ACTION_PLAYER_PLAY;
1312  
-  CWinEventsIOS::MessagePush(&newEvent);
  1312
+  CWinEvents::MessagePush(&newEvent);
1313 1313
  
1314 1314
   [[self glView] resumeAnimation];
1315 1315
 }
6  xbmc/osx/ios/XBMCController.mm
@@ -255,10 +255,10 @@ @implementation XBMCController
255 255
 - (void) sendKeypressEvent: (XBMC_Event) event
256 256
 {
257 257
   event.type = XBMC_KEYDOWN;
258  
-  CWinEventsIOS::MessagePush(&event);
  258
+  CWinEvents::MessagePush(&event);
259 259
 
260 260
   event.type = XBMC_KEYUP;
261  
-  CWinEventsIOS::MessagePush(&event);
  261
+  CWinEvents::MessagePush(&event);
262 262
 }
263 263
 
264 264
 // START OF UIKeyInput protocol
@@ -666,7 +666,7 @@ - (void)postMouseMotionEvent:(CGPoint)point
666 666
   newEvent.motion.y = point.y;
667 667
   newEvent.motion.xrel = 0;
668 668
   newEvent.motion.yrel = 0;
669  
-  CWinEventsIOS::MessagePush(&newEvent);
  669
+  CWinEvents::MessagePush(&newEvent);
670 670
 }
671 671
 //--------------------------------------------------------------
672 672
 - (IBAction)handleSingleFingerSingleTap:(UIGestureRecognizer *)sender 
4  xbmc/peripherals/Peripherals.cpp
@@ -320,6 +320,8 @@ void CPeripherals::OnDeviceAdded(const CPeripheralBus &bus, const CPeripheral &p
320 320
   CGUIMessage msg(GUI_MSG_UPDATE, WINDOW_SETTINGS_SYSTEM, 0);
321 321
   g_windowManager.SendThreadMessage(msg, WINDOW_SETTINGS_SYSTEM);
322 322
 
  323
+  SetChanged();
  324
+
323 325
   CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35005), peripheral.DeviceName());
324 326
 }
325 327
 
@@ -333,6 +335,8 @@ void CPeripherals::OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral
333 335
   CGUIMessage msg(GUI_MSG_UPDATE, WINDOW_SETTINGS_SYSTEM, 0);
334 336
   g_windowManager.SendThreadMessage(msg, WINDOW_SETTINGS_SYSTEM);
335 337
 
  338
+  SetChanged();
  339
+
336 340
   CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35006), peripheral.DeviceName());
337 341
 }
338 342
 
4  xbmc/peripherals/Peripherals.h
@@ -25,6 +25,7 @@
25 25
 #include "settings/ISettingCallback.h"
26 26
 #include "threads/CriticalSection.h"
27 27
 #include "threads/Thread.h"
  28
+#include "utils/Observer.h"
28 29
 
29 30
 class CFileItemList;
30 31
 class CSetting;
@@ -37,7 +38,8 @@ namespace PERIPHERALS
37 38
 {
38 39
   #define g_peripherals CPeripherals::Get()
39 40
 
40  
-  class CPeripherals : public ISettingCallback
  41
+  class CPeripherals :  public ISettingCallback,
  42
+                        public Observable
41 43
   {
42 44
   public:
43 45
     static CPeripherals &Get(void);
2  xbmc/peripherals/bus/PeripheralBus.cpp
@@ -127,6 +127,8 @@ bool CPeripheralBus::ScanForDevices(void)
127 127
     UnregisterRemovedDevices(results);
128 128
     RegisterNewDevices(results);
129 129
 
  130
+    CPeripherals::Get().NotifyObservers(ObservableMessagePeripheralsChanged);
  131
+
130 132
     bReturn = true;
131 133
   }
132 134
 
2  xbmc/utils/Observer.h
@@ -21,6 +21,7 @@
21 21
  */
22 22
 
23 23
 #include "threads/CriticalSection.h"
  24
+#include <vector>
24 25
 
25 26
 class Observable;
26 27
 class ObservableMessageJob;
@@ -38,6 +39,7 @@ typedef enum
38 39
   ObservableMessageTimers,
39 40
   ObservableMessageTimersReset,
40 41
   ObservableMessageRecordings,
  42
+  ObservableMessagePeripheralsChanged,
41 43
 } ObservableMessage;
42 44
 
43 45
 class Observer
1  xbmc/windowing/Makefile
... ...
@@ -1,6 +1,7 @@
1 1
 SRCS=WinEventsSDL.cpp \
2 2
      WinEventsLinux.cpp \
3 3
      WinSystem.cpp \
  4
+     WinEvents.cpp
4 5
      
5 6
 LIB=windowing.a
6 7
 
84  xbmc/windowing/WinEvents.cpp
... ...
@@ -0,0 +1,84 @@
  1
+/*
  2
+ *      Copyright (C) 2013 Team XBMC
  3
+ *      http://xbmc.org
  4
+ *
  5
+ *  This Program is free software; you can redistribute it and/or modify
  6
+ *  it under the terms of the GNU General Public License as published by
  7
+ *  the Free Software Foundation; either version 2, or (at your option)
  8
+ *  any later version.
  9
+ *
  10
+ *  This Program is distributed in the hope that it will be useful,
  11
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13
+ *  GNU General Public License for more details.
  14
+ *
  15
+ *  You should have received a copy of the GNU General Public License
  16
+ *  along with XBMC; see the file COPYING.  If not, see
  17
+ *  <http://www.gnu.org/licenses/>.
  18
+ *
  19
+ */
  20
+
  21
+#include "WinEvents.h"
  22
+#include "peripherals/Peripherals.h"
  23
+#include "threads/SingleLock.h"
  24
+
  25
+#if   defined(TARGET_WINDOWS)
  26
+#include "windows/WinEventsWin32.h"
  27
+#define WinEventsType CWinEventsWin32
  28
+
  29
+#elif defined(TARGET_DARWIN_OSX)
  30
+#include "osx/WinEventsOSX.h"
  31
+#define WinEventsType CWinEventsOSX
  32
+
  33
+#elif defined(TARGET_DARWIN_IOS)
  34
+#include "osx/WinEventsIOS.h"
  35
+#define WinEventsType CWinEventsIOS
  36
+
  37
+#elif defined(TARGET_ANDROID)
  38
+#include "android/WinEventsAndroid.h"
  39
+#define WinEventsType CWinEventsAndroid
  40
+
  41
+#elif (defined(TARGET_FREEBSD) || defined(TARGET_LINUX)) && defined(HAS_SDL_WIN_EVENTS)
  42
+#include "WinEventsSDL.h"
  43
+#define WinEventsType CWinEventsSDL
  44
+
  45
+#elif defined(TARGET_LINUX) && defined(HAS_LINUX_EVENTS)
  46
+#include "WinEventsLinux.h"
  47
+#define WinEventsType CWinEventsLinux
  48
+#endif
  49
+
  50
+static WinEventsType    g_imp;
  51
+static CCriticalSection g_lock;
  52
+static bool             g_init  = false;
  53
+
  54
+void Init()
  55
+{
  56
+  CSingleLock lock(g_lock);
  57
+  if (!g_init)
  58
+  {
  59
+    PERIPHERALS::CPeripherals::Get().RegisterObserver(&g_imp);
  60
+    g_init = true;
  61
+  }
  62
+}
  63
+
  64
+void CWinEvents::MessagePush(XBMC_Event* ev)
  65
+{
  66
+  if (!g_init)
  67
+    Init();
  68
+  g_imp.MessagePush(ev);
  69
+}
  70
+
  71
+bool CWinEvents::MessagePump()
  72
+{
  73
+  if (!g_init)
  74
+    Init();
  75
+  return g_imp.MessagePump();
  76
+}
  77
+
  78
+size_t CWinEvents::GetQueueSize()
  79
+{
  80
+  if (!g_init)
  81
+    Init();
  82
+  return g_imp.GetQueueSize();
  83
+}
  84
+
46  xbmc/windowing/WinEvents.h
@@ -23,43 +23,27 @@
23 23
 
24 24
 #pragma once
25 25
 
26  
-#include "utils/StdString.h"
  26
+#include "utils/Observer.h"
27 27
 #include "XBMC_events.h"
28 28
 
29 29
 typedef bool (* PHANDLE_EVENT_FUNC)(XBMC_Event& newEvent);
30 30
 
31  
-class CWinEventsBase
  31
+class IWinEvents : public Observer
32 32
 {
  33
+  public:
  34
+    virtual       ~IWinEvents() {};
  35
+    virtual bool  MessagePump()   = 0;
  36
+    virtual size_t GetQueueSize()  = 0;
  37
+    virtual void  MessagePush(XBMC_Event* ev) {};
  38
+    virtual void  Notify(const Observable &obs, const ObservableMessage msg) {};
  39
+};
  40
+class CWinEvents
  41
+{
  42
+  public:
  43
+    static void MessagePush(XBMC_Event* ev);
  44
+    static bool MessagePump();
  45
+    static size_t GetQueueSize();
33 46
 };
34 47
 
35  
-#if   defined(TARGET_WINDOWS)
36  
-#include "windows/WinEventsWin32.h"
37  
-#define CWinEvents CWinEventsWin32
38  
-
39  
-#elif defined(TARGET_DARWIN_OSX)
40  
-#include "osx/WinEventsOSX.h"
41  
-#define CWinEvents CWinEventsOSX
42  
-
43  
-#elif defined(TARGET_DARWIN_IOS)
44  
-#include "osx/WinEventsIOS.h"
45  
-#define CWinEvents CWinEventsIOS
46  
-
47  
-#elif defined(TARGET_ANDROID)
48  
-#include "android/WinEventsAndroid.h"
49  
-#define CWinEvents CWinEventsAndroid
50  
-
51  
-#elif defined(TARGET_FREEBSD) && defined(HAS_SDL_WIN_EVENTS)
52  
-#include "WinEventsSDL.h"
53  
-#define CWinEvents CWinEventsSDL
54  
-
55  
-#elif defined(TARGET_LINUX) && defined(HAS_SDL_WIN_EVENTS)
56  
-#include "WinEventsSDL.h"
57  
-#define CWinEvents CWinEventsSDL
58  
-
59  
-#elif defined(TARGET_LINUX) && defined(HAS_LINUX_EVENTS)
60  
-#include "WinEventsLinux.h"
61  
-#define CWinEvents CWinEventsLinux
62  
-
63  
-#endif
64 48
 
65 49
 #endif // WINDOW_EVENTS_H
5  xbmc/windowing/WinEventsLinux.cpp
@@ -74,4 +74,9 @@ bool CWinEventsLinux::MessagePump()
74 74
   return ret;
75 75
 }
76 76
 
  77
+size_t CWinEventsLinux::GetQueueSize()
  78
+{
  79
+  return m_devices.Size();
  80
+}
  81
+
77 82
 #endif
7  xbmc/windowing/WinEventsLinux.h
@@ -25,12 +25,13 @@
25 25
 #include "windowing/WinEvents.h"
26 26
 #include "input/linux/LinuxInputDevices.h"
27 27
 
28  
-class CWinEventsLinux : public CWinEventsBase
  28
+class CWinEventsLinux : public IWinEvents
29 29
 {
30 30
 public:
31 31
   CWinEventsLinux();
32  
-  static bool MessagePump();
33  
-  static void RefreshDevices();
  32
+  bool MessagePump();
  33
+  size_t GetQueueSize();
  34
+  void RefreshDevices();
34 35
   static bool IsRemoteLowBattery();
35 36
 
36 37
 private:
11  xbmc/windowing/WinEventsSDL.cpp
@@ -400,6 +400,17 @@ bool CWinEventsSDL::MessagePump()
400 400
   return ret;
401 401
 }
402 402
 
  403
+size_t CWinEventsSDL::GetQueueSize()
  404
+{
  405
+  int ret;
  406
+  SDL_Event event;
  407
+
  408
+  if (-1 == (ret = SDL_PeepEvents(&event, 0, SDL_PEEKEVENT, ~0)))
  409
+    ret = 0;
  410
+
  411
+  return ret;
  412
+}
  413
+
403 414
 #ifdef TARGET_DARWIN_OSX
404 415
 bool CWinEventsSDL::ProcessOSXShortcuts(SDL_Event& event)
405 416
 {
9  xbmc/windowing/WinEventsSDL.h
@@ -22,17 +22,20 @@
22 22
 #ifndef WINDOW_EVENTS_SDL_H
23 23
 #define WINDOW_EVENTS_SDL_H
24 24
 
  25
+#include "system.h"
  26
+
25 27
 #ifdef HAS_SDL
26 28
 #include <SDL/SDL_events.h>
27 29
 
28 30
 #include "WinEvents.h"
29 31
 
30  
-class CWinEventsSDL : public CWinEventsBase
  32
+class CWinEventsSDL : public IWinEvents
31 33
 {
32 34
 public:
33  
-  static bool MessagePump();
  35
+  virtual bool MessagePump();
  36
+  virtual size_t GetQueueSize();
34 37
 
35  
-protected:
  38
+private:
36 39
 #ifdef TARGET_DARWIN
37 40
   static bool ProcessOSXShortcuts(SDL_Event& event);
38 41
 #elif defined(TARGET_POSIX)
1  xbmc/windowing/X11/WinSystemX11.h
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include "system_gl.h"
27 27
 #include <GL/glx.h>
  28
+#include <SDL/SDL.h>
28 29
 
29 30
 #include "windowing/WinSystem.h"
30 31
 #include "utils/Stopwatch.h"
5  xbmc/windowing/android/WinEventsAndroid.cpp
@@ -20,7 +20,6 @@
20 20
 
21 21
 #include "system.h"
22 22
 #include <list>
23  
-#include "windowing/WinEvents.h"
24 23
 #include "WinEventsAndroid.h"
25 24
 #include "Application.h"
26 25
 #include "threads/CriticalSection.h"
@@ -49,7 +48,7 @@ bool CWinEventsAndroid::MessagePump()
49 48
 
50 49
   // Do not always loop, only pump the initial queued count events. else if ui keep pushing 
51 50
   // events the loop won't finish then it will block xbmc main message loop. 
52  
-  for (int pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) 
  51
+  for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) 
53 52
   {
54 53
   
55 54
     // Pop up only one event per time since in App::OnEvent it may init modal dialog which init 
@@ -69,7 +68,7 @@ bool CWinEventsAndroid::MessagePump()
69 68
   return ret;
70 69
 }
71 70
 
72  
-int CWinEventsAndroid::GetQueueSize()
  71
+size_t CWinEventsAndroid::GetQueueSize()
73 72
 {
74 73
   CSingleLock lock(g_inputCond);
75 74
   return events.size();
12  xbmc/windowing/android/WinEventsAndroid.h
@@ -24,19 +24,15 @@
24 24
 #define WINDOW_EVENTS_ANDROID_H
25 25
 
26 26
 #include "windowing/WinEvents.h"
27  
-#include "input/MouseStat.h"
28 27
 
29  
-class CWinEventsAndroid : public CWinEventsBase
  28
+class CWinEventsAndroid : public IWinEvents
30 29
 {
31 30
 public:
32 31
   static void Init();
33 32
   static void DeInit();
34  
-  static void MessagePush(XBMC_Event *newEvent);
35  
-  static bool MessagePump();
36  
-
37  
-protected:
38  
-  static int  GetQueueSize();
39  
-
  33
+  void MessagePush(XBMC_Event *newEvent);
  34
+  bool MessagePump();
  35
+  virtual size_t  GetQueueSize();
40 36
 };
41 37
 
42 38
 #endif // WINDOW_EVENTS_ANDROID_H
12  xbmc/windowing/osx/WinEventsIOS.h
@@ -25,16 +25,12 @@
25 25
 
26 26
 #include "windowing/WinEvents.h"
27 27
 
28  
-class CWinEventsIOS : public CWinEventsBase
  28
+class CWinEventsIOS : public IWinEvents
29 29
 {
30 30
 public:
31  
-  static void Init();
32  
-  static void DeInit();
33  
-  static void MessagePush(XBMC_Event *newEvent);
34  
-  static bool MessagePump();
35  
-  static int  GetQueueSize();
36  
-
37  
-protected:
  31
+  void MessagePush(XBMC_Event *newEvent);
  32
+  bool MessagePump();
  33
+  virtual size_t  GetQueueSize();
38 34
 };
39 35
 
40 36
 #endif // WINDOW_EVENTS_IOS_H
12  xbmc/windowing/osx/WinEventsIOS.mm
@@ -32,14 +32,6 @@
32 32
 
33 33
 static std::list<XBMC_Event> events;
34 34
 
35  
-void CWinEventsIOS::DeInit()
36  
-{
37  
-}
38  
-
39  
-void CWinEventsIOS::Init()
40  
-{
41  
-}
42  
-
43 35
 void CWinEventsIOS::MessagePush(XBMC_Event *newEvent)
44 36
 {
45 37
   CSingleLock lock(g_inputCond);
@@ -53,7 +45,7 @@
53 45
   
54 46
   // Do not always loop, only pump the initial queued count events. else if ui keep pushing
55 47
   // events the loop won't finish then it will block xbmc main message loop.
56  
-  for (int pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount)
  48
+  for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount)
57 49
   {
58 50
     // Pop up only one event per time since in App::OnEvent it may init modal dialog which init
59 51
     // deeper message loop and call the deeper MessagePump from there.
@@ -86,7 +78,7 @@
86 78
   return ret;
87 79
 }
88 80
 
89  
-int CWinEventsIOS::GetQueueSize()
  81
+size_t CWinEventsIOS::GetQueueSize()
90 82
 {
91 83
   CSingleLock lock(g_inputCond);
92 84
   return events.size();
6  xbmc/windowing/osx/WinEventsOSX.h
@@ -20,13 +20,11 @@
20 20
  *
21 21
  */
22 22
 
23  
-#include "windowing/WinEvents.h"
  23
+#include "windowing/WinEventsSDL.h"
24 24
 
25  
-class CWinEventsOSX : public CWinEventsBase
  25
+class CWinEventsOSX : public CWinEventsSDL
26 26
 {
27 27
 public:
28 28
   CWinEventsOSX();
29 29
   ~CWinEventsOSX();
30  
-
31  
-  static bool MessagePump();
32 30
 };
7  xbmc/windowing/osx/WinEventsOSX.mm
@@ -19,9 +19,6 @@
19 19
  */
20 20
 
21 21
 #define BOOL XBMC_BOOL
22  
-#include "system.h"
23  
-#include "utils/log.h"
24  
-#include "windowing/WinEventsSDL.h"
25 22
 #include "windowing/osx/WinEventsOSX.h"
26 23
 #undef BOOL
27 24
 
@@ -35,7 +32,3 @@
35 32
 {
36 33
 }
37 34
 
38  
-bool CWinEventsOSX::MessagePump()
39  
-{
40  
-  return CWinEventsSDL::MessagePump();
41  
-}
8  xbmc/windowing/windows/WinEventsWin32.cpp
@@ -25,7 +25,7 @@
25 25
 
26 26
 #include "utils/log.h"
27 27
 #include "Windowsx.h"
28  
-#include "windowing/WinEvents.h"
  28
+#include "WinEventsWin32.h"
29 29
 #include "WIN32Util.h"
30 30
 #include "storage/windows/Win32StorageProvider.h"
31 31
 #include "Application.h"
@@ -392,6 +392,12 @@ bool CWinEventsWin32::MessagePump()
392 392
   return true;
393 393
 }
394 394
 
  395
+size_t CWinEventsWin32::GetQueueSize()
  396
+{
  397
+  MSG  msg;
  398
+  return PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
  399
+}
  400
+
395 401
 LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
396 402
 {
397 403
   XBMC_Event newEvent;
7  xbmc/windowing/windows/WinEventsWin32.h
@@ -29,11 +29,12 @@
29 29
 
30 30
 class CGenericTouchSwipeDetector;
31 31
 
32  
-class CWinEventsWin32 : public CWinEventsBase
  32
+class CWinEventsWin32 : public IWinEvents
33 33
 {
34 34
 public:
35  
-  static void MessagePush(XBMC_Event *newEvent);
36  
-  static bool MessagePump();
  35
+  void MessagePush(XBMC_Event *newEvent);
  36
+  bool MessagePump();
  37
+  virtual size_t GetQueueSize();
37 38
   static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
38 39
 
39 40
 private:
2  xbmc/windowing/windows/WinSystemWin32.cpp
@@ -89,7 +89,7 @@ bool CWinSystemWin32::CreateNewWindow(const CStdString& name, bool fullScreen, R
89 89
   // Register the windows class
90 90
   WNDCLASS wndClass;
91 91
   wndClass.style = CS_OWNDC; // For OpenGL
92  
-  wndClass.lpfnWndProc = CWinEvents::WndProc;
  92
+  wndClass.lpfnWndProc = CWinEventsWin32::WndProc;
93 93
   wndClass.cbClsExtra = 0;
94 94
   wndClass.cbWndExtra = 0;
95 95
   wndClass.hInstance = m_hInstance;

0 notes on commit 36e301c

Please sign in to comment.
Something went wrong with that request. Please try again.