rhodes 2.1.0 → 2.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. data/CHANGELOG +7 -0
  2. data/README.textile +4 -5
  3. data/Rakefile +8 -1
  4. data/lib/build/jake.rb +22 -16
  5. data/lib/extensions/rhoxml/rexml/cdata.rb +67 -0
  6. data/lib/extensions/rhoxml/rexml/document.rb +2 -116
  7. data/lib/extensions/rhoxml/rexml/element.rb +1 -1
  8. data/lib/extensions/rhoxml/rexml/text.rb +117 -0
  9. data/lib/framework/rho/render.rb +19 -11
  10. data/lib/framework/rho/rho.rb +17 -10
  11. data/lib/framework/rho/rhobluetooth.rb +103 -0
  12. data/lib/framework/rho/rhocontroller.rb +2 -0
  13. data/lib/framework/rho/rhoevent.rb +43 -0
  14. data/lib/framework/rho/rhoevent_bb.rb +80 -0
  15. data/lib/framework/rho/rhoevent_c.rb +47 -0
  16. data/lib/framework/rhodes.rb +2 -2
  17. data/lib/framework/rhom/rhom_db_adapter.rb +2 -1
  18. data/lib/framework/rhom/rhom_model.rb +9 -3
  19. data/lib/framework/rhom/rhom_object_factory.rb +46 -22
  20. data/lib/framework/rhom/rhom_source.rb +12 -10
  21. data/lib/framework/version.rb +2 -2
  22. data/lib/rhodes.rb +2 -2
  23. data/platform/android/Rhodes/AndroidManifest.xml +23 -2
  24. data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +54 -38
  25. data/platform/android/Rhodes/jni/include/rhodes.h +3 -0
  26. data/platform/android/Rhodes/jni/include/rhodes/JNIRhodes.h +2 -2
  27. data/platform/android/Rhodes/jni/include/rhodes/details/rhojava.inc +4 -0
  28. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_RhodesService.h +16 -0
  29. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_bluetooth_RhoBluetoothManager.h +21 -0
  30. data/platform/android/Rhodes/jni/src/bluetooth.cpp +169 -0
  31. data/platform/android/Rhodes/jni/src/callbacks.cpp +10 -0
  32. data/platform/android/Rhodes/jni/src/event.cpp +429 -0
  33. data/platform/android/Rhodes/jni/src/fileapi.cpp +51 -1
  34. data/platform/android/Rhodes/jni/src/rhodes.cpp +16 -0
  35. data/platform/android/Rhodes/jni/src/sslimpl.cpp +3 -0
  36. data/platform/android/Rhodes/res/layout/bt_device_list.xml +42 -0
  37. data/platform/android/Rhodes/res/layout/bt_device_name.xml +7 -0
  38. data/platform/android/Rhodes/res/values/strings.xml +8 -0
  39. data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +14 -0
  40. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +2 -0
  41. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Push.java +7 -0
  42. data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushReceiver.java +58 -0
  43. data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushService.java +53 -0
  44. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +8 -0
  45. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +144 -3
  46. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/IRhoBluetoothManager.java +66 -0
  47. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothDeviceListActivity.java +201 -0
  48. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManager.java +139 -0
  49. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManagerNew.java +401 -0
  50. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManagerOld.java +136 -0
  51. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothSession.java +457 -0
  52. data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/UUIDHelper.java +71 -0
  53. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +12 -7
  54. data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/Event.java +19 -0
  55. data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/EventStore.java +261 -0
  56. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +4 -2
  57. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +2 -2
  58. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +10 -2
  59. data/platform/android/build/RhodesSRC_build.files +33 -22
  60. data/platform/android/build/android.rake +198 -27
  61. data/platform/android/build/librhodes_build.files +3 -1
  62. data/platform/android/build/libruby_build.files +4 -1
  63. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +2 -2
  64. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBRowResult.java +1 -1
  65. data/platform/bb/Hsqldb/src/org/hsqldb/Expression.java +7 -4
  66. data/platform/bb/Hsqldb/src/org/hsqldb/Like.java +3 -3
  67. data/platform/bb/Hsqldb/src/org/hsqldb/Table.java +3 -1
  68. data/platform/bb/Hsqldb/src/org/hsqldb/Tokenizer.java +1 -1
  69. data/platform/bb/RubyVM/RubyVM.jdp +1 -0
  70. data/platform/bb/RubyVM/src/com/rho/RhoConf.java +108 -1
  71. data/platform/bb/RubyVM/src/com/rho/RhoLogConf.java +7 -1
  72. data/platform/bb/RubyVM/src/com/rho/RhoRuby.java +7 -4
  73. data/platform/bb/RubyVM/src/com/rho/ThreadQueue.java +7 -1
  74. data/platform/bb/RubyVM/src/com/rho/net/AsyncHttp.java +1 -1
  75. data/platform/bb/RubyVM/src/com/rho/net/NetRequest.java +21 -23
  76. data/platform/bb/RubyVM/src/com/rho/net/RhoConnection.java +19 -10
  77. data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +8 -0
  78. data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +3 -0
  79. data/platform/bb/RubyVM/src/com/rho/sync/SyncThread.java +14 -17
  80. data/platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyFile.java +7 -5
  81. data/platform/bb/RubyVM/src/com/xruby/runtime/lang/RhoSupport.java +2 -0
  82. data/platform/bb/RubyVM/src/com/xruby/runtime/lang/RubyRuntime.java +10 -1
  83. data/platform/bb/RubyVM/src/j2me/io/File.java +7 -6
  84. data/platform/bb/build/RubyVM_build.files +412 -412
  85. data/platform/bb/build/bb.rake +42 -18
  86. data/platform/bb/build/hsqldb_build.files +151 -151
  87. data/platform/bb/build/rhodes_build.files +44 -40
  88. data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +2 -0
  89. data/platform/bb/rhodes/platform/5.0/com/rho/RhodesApplicationPlatform.java +237 -0
  90. data/platform/bb/rhodes/platform/common/com/rho/RhodesApplicationPlatform.java +14 -0
  91. data/platform/bb/rhodes/rhodes.jdp +6 -1
  92. data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +7 -1
  93. data/platform/bb/rhodes/src/com/rho/RhodesApplicationPlatform.java +14 -0
  94. data/platform/bb/rhodes/src/com/rho/net/NetworkAccess.java +62 -76
  95. data/platform/bb/rhodes/src/com/rho/rubyext/RhoCalendar.java +660 -0
  96. data/platform/bb/rhodes/src/{rhomobile → com/rho/rubyext}/RhoPhonebook.java +95 -38
  97. data/platform/bb/rhodes/src/com/rho/rubyext/System.java +22 -1
  98. data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +26 -6
  99. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +21 -7
  100. data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothManager.java +528 -0
  101. data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothPort.java +281 -0
  102. data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothScreen.java +119 -0
  103. data/platform/bb/rhodes/src/rhomobile/camera/CameraFilesListener.java +2 -2
  104. data/platform/iphone/Classes/AppManager/AppManager.m +70 -7
  105. data/platform/iphone/Classes/Bluetooth/Bluetooth.h +72 -0
  106. data/platform/iphone/Classes/Bluetooth/Bluetooth.m +414 -0
  107. data/platform/iphone/Classes/Event/Event.h +12 -0
  108. data/platform/iphone/Classes/Event/Event.m +300 -0
  109. data/platform/iphone/Classes/LogOptionsController.h +2 -1
  110. data/platform/iphone/Classes/LogOptionsController.m +1 -1
  111. data/platform/iphone/Classes/LogViewController.h +2 -1
  112. data/platform/iphone/Classes/MapView/MapViewController.h +2 -1
  113. data/platform/iphone/Classes/RhoViewController.h +16 -0
  114. data/platform/iphone/Classes/RhoViewController.m +20 -0
  115. data/platform/iphone/Classes/Rhodes.h +12 -0
  116. data/platform/iphone/Classes/Rhodes.m +34 -6
  117. data/platform/iphone/Classes/Signature/SignatureViewController.h +2 -2
  118. data/platform/iphone/Classes/Signature/SignatureViewController.m +0 -10
  119. data/platform/iphone/Classes/SimpleMainView.h +2 -2
  120. data/platform/iphone/Classes/SimpleMainView.m +5 -14
  121. data/platform/iphone/Classes/SplashViewController.h +2 -2
  122. data/platform/iphone/Classes/TabbedMainView.h +2 -2
  123. data/platform/iphone/Classes/TabbedMainView.m +5 -10
  124. data/platform/iphone/Info.plist +5 -5
  125. data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +39 -0
  126. data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +47 -4
  127. data/platform/osx/Rhodes Debugger/NoodleLineNumberView.m +3 -2
  128. data/platform/shared/common/AutoPointer.h +3 -0
  129. data/platform/shared/common/RhoConf.cpp +2 -1
  130. data/platform/shared/common/RhoThread.h +1 -1
  131. data/platform/shared/common/RhoTime.h +3 -3
  132. data/platform/shared/common/RhodesApp.cpp +75 -23
  133. data/platform/shared/common/RhodesApp.h +4 -0
  134. data/platform/shared/common/RhodesAppBase.h +2 -0
  135. data/platform/shared/common/ThreadQueue.cpp +23 -18
  136. data/platform/shared/common/ThreadQueue.h +2 -0
  137. data/platform/shared/db/res/db/syncdb.schema +39 -39
  138. data/platform/shared/logging/RhoLogConf.cpp +58 -3
  139. data/platform/shared/logging/RhoLogConf.h +3 -1
  140. data/platform/shared/net/CURLNetRequest.cpp +17 -6
  141. data/platform/shared/net/HttpServer.cpp +125 -25
  142. data/platform/shared/net/HttpServer.h +4 -3
  143. data/platform/shared/ruby/ext/bluetooth/bluetooth.i +56 -0
  144. data/platform/shared/ruby/ext/bluetooth/bluetooth_wrap.c +2563 -0
  145. data/platform/shared/ruby/ext/calendar/calendar.i +28 -0
  146. data/platform/shared/ruby/ext/calendar/calendar_wrap.c +2251 -0
  147. data/platform/shared/ruby/ext/calendar/event.h +41 -0
  148. data/platform/shared/ruby/ext/calendar/event.i +28 -0
  149. data/platform/shared/ruby/ext/calendar/event_wrap.c +2151 -0
  150. data/platform/shared/ruby/ext/rho/rhoruby.c +103 -3
  151. data/platform/shared/ruby/ext/rho/rhoruby.h +16 -2
  152. data/platform/shared/ruby/ext/rhoconf/rhoconf.i +12 -0
  153. data/platform/shared/ruby/ext/rhoconf/rhoconf_wrap.c +101 -0
  154. data/platform/shared/ruby/ext/system/system.i +14 -0
  155. data/platform/shared/ruby/ext/system/system_wrap.c +2568 -2208
  156. data/platform/shared/ruby/main.c +8 -0
  157. data/platform/shared/rubyext/GeoLocation.cpp +6 -3
  158. data/platform/shared/rubyext/System.cpp +14 -0
  159. data/platform/shared/sync/SyncEngine.cpp +9 -1
  160. data/platform/shared/sync/SyncNotify.cpp +16 -8
  161. data/platform/shared/sync/SyncNotify.h +1 -0
  162. data/platform/shared/sync/SyncThread.cpp +7 -12
  163. data/platform/shared/sync/SyncThread.h +5 -3
  164. data/platform/wm/build/wm.rake +7 -1
  165. data/platform/wm/rhodes/Alert.cpp +1 -1
  166. data/platform/wm/rhodes/MainWindow.cpp +28 -0
  167. data/platform/wm/rhodes/MainWindow.h +9 -0
  168. data/platform/wm/rhodes/OutlookApp.cpp +72 -0
  169. data/platform/wm/rhodes/OutlookApp.h +22 -0
  170. data/platform/wm/rhodes/Rhodes.cpp +8 -0
  171. data/platform/wm/rhodes/Rhodes.rc +31 -0
  172. data/platform/wm/rhodes/bluetooth/Bluetooth.cpp +1274 -0
  173. data/platform/wm/rhodes/bluetooth/Bluetooth.h +321 -0
  174. data/platform/wm/rhodes/phonebook/NativeAddressBook.cpp +37 -70
  175. data/platform/wm/rhodes/phonebook/NativeAddressBook.h +0 -4
  176. data/platform/wm/rhodes/resource.h +8 -1
  177. data/platform/wm/rhodes/rho/net/NetRequest.cpp +4 -0
  178. data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +6 -4
  179. data/platform/wm/rhodes/rho/rubyext/calendar.cpp +487 -0
  180. data/platform/wm/rhodes/rhodes.vcproj +28 -11
  181. data/platform/wm/rhodes/stdafx.h +1 -0
  182. data/platform/wm/rubylib/rubylib.vcproj +32 -0
  183. data/rakefile.rb +8 -1
  184. data/res/generators/templates/application/Rakefile +1 -1
  185. data/res/generators/templates/application/app/layout.erb +4 -1
  186. data/res/generators/templates/application/build.yml +0 -1
  187. data/res/generators/templates/application/public/css/iphone.css +2 -2
  188. data/res/generators/templates/application/public/jqtouch/jqtouch-iphone.css +9 -0
  189. data/res/generators/templates/application/public/jqtouch/jqtouch.css +1 -5
  190. data/res/generators/templates/application/public/jqtouch/jqtouch.js +3 -2
  191. data/rhodes.gemspec +1 -1
  192. data/spec/perfomance_spec/app/Benchmark/benchmark.rb +4 -0
  193. data/spec/perfomance_spec/app/Benchmark/bulk_results.erb +13 -0
  194. data/spec/perfomance_spec/app/Benchmark/controller.rb +178 -0
  195. data/spec/perfomance_spec/app/Benchmark/create_results.erb +13 -0
  196. data/spec/perfomance_spec/app/Benchmark/customers.erb +35 -0
  197. data/spec/perfomance_spec/app/Benchmark/index.erb +9 -0
  198. data/spec/perfomance_spec/app/Benchmark/products.erb +25 -0
  199. data/spec/perfomance_spec/app/Benchmark/search_results.erb +13 -0
  200. data/spec/perfomance_spec/app/Customer/customer.rb +6 -0
  201. data/spec/perfomance_spec/app/Perftest/index.erb +5 -0
  202. data/spec/perfomance_spec/app/Product/index.erb +25 -0
  203. data/spec/perfomance_spec/app/Product/product.rb +6 -0
  204. data/spec/perfomance_spec/app/helpers/application_helper.rb +126 -0
  205. data/spec/perfomance_spec/app/helpers/browser_helper.rb +18 -0
  206. data/spec/perfomance_spec/rhoconfig.txt +1 -1
  207. data/spec/phone_spec/app/Account_s/account_s.rb +5 -2
  208. data/spec/phone_spec/app/Case/case.rb +1 -0
  209. data/spec/phone_spec/app/Case_s/case_s.rb +2 -0
  210. data/spec/phone_spec/app/Data/perftest.json +35 -0
  211. data/spec/phone_spec/app/Data/testCDATA.xml +11 -0
  212. data/spec/phone_spec/app/Product/product.rb +1 -1
  213. data/spec/phone_spec/app/{Spec → spec}/asynchttp_spec.rb +66 -17
  214. data/spec/phone_spec/app/{Spec → spec}/barcode_spec.rb +0 -0
  215. data/spec/phone_spec/app/{Spec → spec}/blobsync_spec.rb +0 -0
  216. data/spec/phone_spec/app/{Spec → spec}/bsearch_spec.rb +0 -0
  217. data/spec/phone_spec/app/{Spec → spec}/bulksync_spec.rb +0 -0
  218. data/spec/phone_spec/app/{Spec → spec}/contacts_spec.rb +0 -0
  219. data/spec/phone_spec/app/{Spec → spec}/crypt_spec.rb +0 -0
  220. data/spec/phone_spec/app/{Spec → spec}/date_spec.rb +0 -0
  221. data/spec/phone_spec/app/spec/events_spec.rb +199 -0
  222. data/spec/phone_spec/app/{Spec → spec}/fixtures/client_info.txt +0 -0
  223. data/spec/phone_spec/app/{Spec → spec}/fixtures/object_values.txt +0 -0
  224. data/spec/phone_spec/app/{Spec → spec}/json_spec.rb +11 -2
  225. data/spec/phone_spec/app/{Spec → spec}/mapview_spec.rb +0 -0
  226. data/spec/phone_spec/app/{Spec → spec}/nativebar_spec.rb +0 -0
  227. data/spec/phone_spec/app/{Spec → spec}/navbar_spec.rb +0 -0
  228. data/spec/phone_spec/app/{Spec → spec}/pagination/fixtures/object_values.txt +0 -0
  229. data/spec/phone_spec/app/{Spec → spec}/rho_controller_spec.rb +5 -0
  230. data/spec/phone_spec/app/{Spec → spec}/rho_spec.rb +48 -0
  231. data/spec/phone_spec/app/{Spec → spec}/rhofile_spec.rb +9 -6
  232. data/spec/phone_spec/app/{Spec → spec}/rhom_object_spec.rb +188 -9
  233. data/spec/phone_spec/app/{Spec → spec}/syncengine_spec.rb +0 -0
  234. data/spec/phone_spec/app/{Spec → spec}/xml_spec.rb +15 -0
  235. data/spec/phone_spec/app/{Spec → spec}/xruby_spec.rb +0 -0
  236. data/spec/phone_spec/app/spec_runner.rb +4 -1
  237. data/spec/phone_spec/build.yml +2 -1
  238. metadata +95 -31
  239. data/platform/bb/rhodes/platform/5.0/com/rho/RhoMainScreen.java +0 -36
  240. data/platform/bb/rhodes/platform/6.0/com/rho/BrowserAdapter5.java +0 -155
  241. data/platform/bb/rhodes/platform/6.0/com/rho/RhoMainScreen.java +0 -36
@@ -0,0 +1,1274 @@
1
+ #include "stdafx.h"
2
+
3
+
4
+
5
+
6
+ #if defined(_WIN32_WCE)
7
+ #include <aygshell.h>
8
+ #endif
9
+ #include <atltime.h>
10
+ #include "ext/rho/rhoruby.h"
11
+ #include "../MainWindow.h"
12
+ #include "Bluetooth.h"
13
+ #include "common/RhodesApp.h"
14
+
15
+ #include "../logging/RhoLog.h"
16
+
17
+ #include "../Utils.h"
18
+
19
+ #ifndef OS_WINDOWS
20
+
21
+ #ifdef _MSC_VER
22
+ // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
23
+ #pragma warning ( disable : 4800 )
24
+ #endif
25
+
26
+ extern "C" HWND getMainWnd();
27
+
28
+ #if defined(_WIN32_WCE)
29
+ // strdup is implemented as part of ruby CE port
30
+ extern "C" char *strdup(const char * str);
31
+ extern "C" wchar_t* wce_mbtowc(const char* a);
32
+ extern "C" char* wce_wctomb(const wchar_t*);
33
+
34
+ #endif
35
+
36
+
37
+ extern "C" int rho_sys_get_screen_height();
38
+ extern "C" int rho_sys_get_screen_width();
39
+
40
+
41
+ BYTE rgbSdpRecord[] = {
42
+ 0x35, 0x4d, 0x09, 0x00, 0x01, 0x35, 0x11, 0x1c,
43
+ 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
44
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
45
+ 0x09, 0x00, 0x04, 0x35, 0x0c, 0x35, 0x03, 0x19,
46
+ 0x01, 0x00, 0x35, 0x05, 0x19, 0x00, 0x03, 0x08,
47
+ 0x1a, 0x09, 0x00, 0x06, 0x35, 0x09, 0x09, 0x65,
48
+ 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, 0x09,
49
+ 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11,
50
+ 0x05, 0x09, 0x01, 0x00, 0x09, 0x01, 0x00, 0x25,
51
+ 0x06, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c
52
+ };
53
+
54
+ //SDP record size constant returned by bthnscreate.exe
55
+ #define SDP_RECORD_SIZE 0x0000004f
56
+ #define SDP_CHANNEL_OFFSET 40
57
+
58
+ //server GUID
59
+ //WCHAR strGUID[]=L"29 F9 C0 FD-BB 6E-47 97-9F A9-3E C9 A8 54 29 0C";
60
+ //WCHAR strGUID[]=L"00 00 11 01-00 00-10 00-80 00-00 80 5F 9B 34 FB";
61
+ WCHAR strGUID[]=L"00001101-0000-1000-8000-00805F9B34FB";
62
+
63
+
64
+
65
+ DWORD WINAPI runThreadOpenDiscoverDlg(LPVOID data) {
66
+ return 0;
67
+ }
68
+
69
+ DWORD WINAPI runThreadOpenDiscoveredDlg(LPVOID data) {
70
+ return 0;
71
+ }
72
+
73
+ DWORD WINAPI runThreadDiscoverDevices(LPVOID data) {
74
+ RhoBluetoothManager::getInstance()->DiscoverDevices();
75
+ int iNumDevices=0, iRetVal=0;
76
+ iRetVal=RhoBluetoothManager::getInstance()->DiscoverDevices();
77
+ RhoBluetoothManager::getInstance()->mDiscoverDlg.updateDeviceListFromManager();
78
+ RhoBluetoothManager::getInstance()->terminateDiscoverThread();
79
+ return 0;
80
+ }
81
+
82
+ /*
83
+ iRetVal=objBthUtils.OpenServerConnection(rgbSdpRecord, SDP_RECORD_SIZE, SDP_CHANNEL_OFFSET, DisplayMessage);
84
+ if(iRetVal!=0)
85
+ {
86
+ StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"%d: Server socket failed.", iRetVal);
87
+ SendMessage(GetDlgItem(hDlg, IDC_MESSAGES), LB_ADDSTRING,0,(LPARAM)szMessage);
88
+ }
89
+ else
90
+ {
91
+ StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"You are now ready to receive messages.");
92
+ SendMessage(GetDlgItem(hDlg, IDC_MESSAGES), LB_ADDSTRING,0,(LPARAM)szMessage);
93
+ }
94
+
95
+ OpenServerConnection(BYTE *rgbSdpRecord, int cSdpRecord, int iChannelOffset, void (*funcPtr)(WCHAR *))
96
+ */
97
+
98
+ DWORD WINAPI RhoBluetoothManager::runThreadDiscovered(LPVOID data) {
99
+ int iNameLen=0;
100
+ RhoBluetoothManager* mManager = RhoBluetoothManager::getInstance();
101
+ if(mManager->m_socketServer!=INVALID_SOCKET) {
102
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
103
+ return 0;
104
+ }
105
+ mManager->m_socketServer = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM);
106
+ if (mManager->m_socketServer == INVALID_SOCKET)
107
+ {
108
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
109
+ return WSAGetLastError ();
110
+ }
111
+
112
+ SOCKADDR_BTH sa;
113
+ memset (&sa, 0, sizeof(sa));
114
+ sa.addressFamily = AF_BT;
115
+ sa.port = 0;
116
+ if (bind (mManager->m_socketServer, (SOCKADDR *)&sa, sizeof(sa)))
117
+ {
118
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
119
+ return WSAGetLastError ();
120
+ }
121
+ iNameLen = sizeof(sa);
122
+ if (getsockname(mManager->m_socketServer, (SOCKADDR *)&sa, &iNameLen))
123
+ {
124
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
125
+ return WSAGetLastError ();
126
+ }
127
+
128
+ if(mManager->RegisterService(rgbSdpRecord, SDP_RECORD_SIZE, SDP_CHANNEL_OFFSET, (UCHAR)sa.port)!=0)
129
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
130
+ return WSAGetLastError();
131
+
132
+ if (listen (mManager->m_socketServer, SOMAXCONN))
133
+ {
134
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
135
+ return WSAGetLastError ();
136
+ }
137
+ int iSize=0, cbBytesRecd=0 ;
138
+ WCHAR szMessage[MAX_MESSAGE_SIZE];
139
+ char pbuf[MAX_MESSAGE_SIZE];
140
+ iSize = sizeof(mManager->m_saClient);
141
+ BTH_REMOTE_NAME remotename;
142
+ memset(&remotename, sizeof(remotename), 0);
143
+
144
+ SOCKET s = accept (mManager->m_socketServer, (SOCKADDR*)&(mManager->m_saClient), &iSize);
145
+ remotename.bt = mManager->m_saClient.btAddr;
146
+
147
+ setsockopt(mManager->m_socketServer,SOL_RFCOMM, SO_BTH_SET_READ_REMOTE_NAME, (char*)&remotename, sizeof(remotename));
148
+
149
+ sockaddr peer;
150
+ int size = sizeof(peer);
151
+ if (getpeername( mManager->m_socketServer, &peer, &size)) {
152
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
153
+ return WSAGetLastError ();
154
+ }
155
+ memcpy(mManager->mConnectedDeviceName, peer.sa_data, size);
156
+ mManager->mConnectedDeviceName[size] = 0;
157
+
158
+
159
+
160
+ if (s != INVALID_SOCKET)
161
+ {
162
+ for ( ; ; )
163
+ {
164
+ //receive data in pbuf
165
+ cbBytesRecd = recv (s, pbuf, MAX_MESSAGE_SIZE, 0);
166
+ //if error occured in receiving, return error code
167
+ if (cbBytesRecd == SOCKET_ERROR)
168
+ {
169
+ mManager->fireSessionCallBack(mManager->mConnectedDeviceName, RHO_BT_ERROR);
170
+ return WSAGetLastError();
171
+ }
172
+ else
173
+ {
174
+ // something was received, then copy the contents in szMessage
175
+ if(cbBytesRecd>0)
176
+ {
177
+ RhoDataBlock* block = new RhoDataBlock;
178
+ block->buf = new unsigned char[cbBytesRecd];
179
+ memcpy(block->buf, pbuf, cbBytesRecd);
180
+ block->size = cbBytesRecd;
181
+ mManager->addDataBlock(block);
182
+ LOG(INFO) + "RhoBluetoothManager::runThreadReadData() read data from Server Socket";
183
+ mManager->fireSessionCallBack(mManager->mConnectedDeviceName, RHO_BT_SESSION_INPUT_DATA_RECEIVED);
184
+ }
185
+ }
186
+ }
187
+ }
188
+ else {
189
+ mManager->fireCreateSessionCallBack(RHO_BT_ERROR, "");
190
+ mManager->terminateDiscoveredThread();
191
+ }
192
+ return 0;
193
+ }
194
+
195
+ void RhoBluetoothManager::onServerConnectionCreated() {
196
+ getDiscoveredDlg()->closeDialog();
197
+ fireCreateSessionCallBack(RHO_BT_OK, mConnectedDeviceName);
198
+ }
199
+
200
+
201
+ int RhoBluetoothManager::RegisterService(BYTE *rgbSdpRecord, int cSdpRecord, int iChannelOffset, UCHAR channel)
202
+ {
203
+ ULONG recordHandle = 0;
204
+
205
+ struct bigBlob
206
+ {
207
+ BTHNS_SETBLOB b;
208
+
209
+ }*pBigBlob;
210
+
211
+ pBigBlob = (bigBlob *)malloc(sizeof(struct bigBlob)+cSdpRecord);
212
+ ULONG ulSdpVersion = BTH_SDP_VERSION;
213
+ pBigBlob->b.pRecordHandle = &recordHandle;
214
+ pBigBlob->b.pSdpVersion = &ulSdpVersion;
215
+ pBigBlob->b.fSecurity = 0;
216
+ pBigBlob->b.fOptions = 0;
217
+ pBigBlob->b.ulRecordLength = cSdpRecord;
218
+
219
+ memcpy (pBigBlob->b.pRecord, rgbSdpRecord, cSdpRecord);
220
+ pBigBlob->b.pRecord[iChannelOffset] = (unsigned char)channel;
221
+ BLOB blob;
222
+ blob.cbSize = sizeof(BTHNS_SETBLOB) + cSdpRecord - 1;
223
+ blob.pBlobData = (PBYTE) pBigBlob;
224
+
225
+ WSAQUERYSET Service;
226
+ memset (&Service, 0, sizeof(Service));
227
+ Service.dwSize = sizeof(Service);
228
+ Service.lpBlob = &blob;
229
+ Service.dwNameSpace = NS_BTH;
230
+ if (WSASetService(&Service,RNRSERVICE_REGISTER,0) == SOCKET_ERROR)
231
+ {
232
+ free(pBigBlob);
233
+ return WSAGetLastError();
234
+ }
235
+ else
236
+ {
237
+ free(pBigBlob);
238
+ return 0;
239
+ }
240
+ }
241
+
242
+
243
+
244
+ static RhoBluetoothManager* ourRhoBluetoothManager = NULL;
245
+
246
+ RhoBluetoothManager::RhoBluetoothManager() {
247
+ init();
248
+ }
249
+
250
+ RhoBluetoothManager::~RhoBluetoothManager() {
251
+ freeAll();
252
+ }
253
+
254
+
255
+
256
+ RhoBluetoothManager* RhoBluetoothManager::getInstance() {
257
+ if (ourRhoBluetoothManager == NULL) {
258
+ ourRhoBluetoothManager = new RhoBluetoothManager();
259
+ }
260
+ return ourRhoBluetoothManager;
261
+ }
262
+
263
+ void RhoBluetoothManager::releaseAll() {
264
+ if (ourRhoBluetoothManager != NULL) {
265
+ delete ourRhoBluetoothManager;
266
+ ourRhoBluetoothManager = NULL;
267
+ }
268
+ }
269
+
270
+ int RhoBluetoothManager::rho_bluetooth_is_bluetooth_available() {
271
+ return mIsBluetoothEnabled;
272
+ }
273
+
274
+ void RhoBluetoothManager::rho_bluetooth_off_bluetooth() {
275
+ releaseAll();
276
+ }
277
+
278
+ void RhoBluetoothManager::rho_bluetooth_set_device_name(const char* device_name) {
279
+
280
+ }
281
+
282
+ const char* RhoBluetoothManager::rho_bluetooth_get_device_name() {
283
+ return mLocalDeviceName;
284
+ }
285
+
286
+ const char* RhoBluetoothManager::rho_bluetooth_get_last_error() {
287
+ return RHO_BT_OK;
288
+ }
289
+
290
+ const char* RhoBluetoothManager::rho_bluetooth_create_session(const char* role, const char* callback_url) {
291
+ LOG(INFO) + "RhoBluetoothManager::rho_bluetooth_create_session( "+role+", "+callback_url+")";
292
+ strcpy(mCreateSessionCallback,callback_url);
293
+ if (strcmp(role, RHO_BT_ROLE_CLIENT) == 0)
294
+ {
295
+ DWORD data = 0;
296
+ CreateThread(NULL, 0, runThreadDiscoverDevices, (LPVOID)data, 0, NULL);
297
+ //mDiscoverDlg.openDialog(this);
298
+ HWND main_wnd = getMainWnd();
299
+ ::PostMessage(main_wnd, WM_BLUETOOTH_DISCOVER, 0, 0);
300
+ }
301
+ else
302
+ {
303
+ DWORD data = 0;
304
+ //mDiscoveredDlg.openDialog(this);
305
+ HWND main_wnd = getMainWnd();
306
+ ::PostMessage(main_wnd, WM_BLUETOOTH_DISCOVERED, 0, 0);
307
+ CreateThread(NULL, 0, runThreadDiscovered, (LPVOID)data, 0, NULL);
308
+ }
309
+ return RHO_BT_OK;
310
+ }
311
+
312
+ void RhoBluetoothManager::rho_bluetooth_session_set_callback(const char* connected_device_name, const char* callback_url) {
313
+ LOG(INFO) + "RhoBluetoothManager::rho_bluetooth_session_set_callback( "+connected_device_name+", "+callback_url+")";
314
+ strcpy(mSessionCallback,callback_url);
315
+ }
316
+
317
+ void RhoBluetoothManager::rho_bluetooth_session_disconnect(const char* connected_device_name) {
318
+ LOG(INFO) + "RhoBluetoothManager::rho_bluetooth_session_disconnect("+connected_device_name+")";
319
+ if (strcmp(connected_device_name, mConnectedDeviceName) != 0) {
320
+ return;
321
+ }
322
+ freeAll();
323
+ init();
324
+ fireSessionCallBack(connected_device_name, RHO_BT_SESSION_DISCONNECT);
325
+ }
326
+
327
+ int RhoBluetoothManager::rho_bluetooth_session_get_status(const char* connected_device_name) {
328
+ return getBlocksSummarySize();
329
+ }
330
+
331
+ const char* RhoBluetoothManager::rho_bluetooth_session_read_string(const char* connected_device_name) {
332
+ LOG(INFO) + "RhoBluetoothManager::rho_bluetooth_session_read_string("+connected_device_name+")";
333
+ if (mReadedString) {
334
+ delete mReadedString;
335
+ mReadedString = NULL;
336
+ }
337
+ int size = 0;
338
+ mReadedString = (char*)readAllBlocks(&size, 1);
339
+ mReadedString[size] = 0;
340
+ LOG(INFO) + "RhoBluetoothManager::rho_bluetooth_session_read_string() readed:"+mReadedString;
341
+ return mReadedString;
342
+ }
343
+
344
+ void RhoBluetoothManager::rho_bluetooth_session_write_data(const char* connected_device_name, void* buf, int datasize) {
345
+ LOG(INFO) + "RhoBluetoothManager::rho_bluetooth_session_write_data()";
346
+ int iBytesSent = send (m_socketClient, (char *)buf, datasize, 0);
347
+ if (iBytesSent != datasize)
348
+ {
349
+ fireSessionCallBack(mConnectedDeviceName, RHO_BT_ERROR);
350
+ return;
351
+ //return WSAGetLastError ();
352
+ }
353
+ }
354
+
355
+ void RhoBluetoothManager::fireCreateSessionCallBack(const char* status, const char* connected_device_name) {
356
+ if (strlen(mCreateSessionCallback) <= 0) {
357
+ return;
358
+ }
359
+ char body[2048];
360
+ strcpy(body, "&status=");
361
+ strcat(body, status);
362
+ strcat(body, "&connected_device_name=");
363
+ strcat(body, connected_device_name);
364
+ fireRhodeCallback(mCreateSessionCallback, body);
365
+ }
366
+
367
+ void RhoBluetoothManager::fireSessionCallBack(const char* connected_device_name, const char* event_type) {
368
+ if (strlen(mSessionCallback) <= 0) {
369
+ return;
370
+ }
371
+ char body[2048];
372
+ strcpy(body, "&connected_device_name=");
373
+ strcat(body, connected_device_name);
374
+ strcat(body, "&event_type=");
375
+ strcat(body, event_type);
376
+ fireRhodeCallback(mSessionCallback, body);
377
+ }
378
+
379
+ void RhoBluetoothManager::fireRhodeCallback(const char* callback_url, const char* body) {
380
+ LOG(INFO) + "RhoBluetoothManager::fireRhodeCallback( "+callback_url+", "+body+")";
381
+ rho_net_request_with_data(rho_http_normalizeurl(callback_url), body);
382
+ //rho_rhodesapp_callBluetoothCallback(callback_url, body);
383
+ /*
384
+ HWND main_wnd = getMainWnd();
385
+ char* mcallback = new char[strlen(callback_url)+1];
386
+ strcpy(mcallback, callback_url);
387
+ char* mbody = new char[strlen(body)+1];
388
+ strcpy(mbody, body);
389
+ ::PostMessage(main_wnd, WM_BLUETOOTH_CALLBACK, (WPARAM)mcallback, (LPARAM)mbody);
390
+ */
391
+ }
392
+
393
+
394
+ void RhoBluetoothManager::init() {
395
+ LOG(INFO) + "RhoBluetoothManager::init()";
396
+ WORD wVersionRequested;
397
+ WSADATA wsaData;
398
+ wVersionRequested = MAKEWORD( 2, 2 );
399
+ WSAStartup( wVersionRequested, &wsaData );
400
+
401
+ m_pDeviceList = NULL;
402
+ m_pStart = NULL;
403
+ m_pEnd = NULL;
404
+ m_pCurrentDevice = NULL;
405
+ m_iNumDevices = 0;
406
+ //pCallBackFunction = NULL;
407
+ m_hReadThread = NULL;
408
+ m_socketServer = INVALID_SOCKET;
409
+ m_socketClient = INVALID_SOCKET;
410
+ BthGetMode(&m_dwBluetoothMode);
411
+ if(m_dwBluetoothMode==BTH_POWER_OFF)
412
+ {
413
+ BthSetMode(BTH_DISCOVERABLE);
414
+ }
415
+ RhoDeviceInfo devInfo;
416
+ GetLocalDeviceName(&devInfo);
417
+
418
+ m_hDiscoverThred = NULL;
419
+ m_hDiscoveredThread = NULL;
420
+ mReadedString = NULL;
421
+
422
+ WideCharToMultiByte(CP_UTF8, 0, devInfo.szDeviceNameAddr, -1, mLocalDeviceName, MAX_NAME_SIZE, 0, 0);
423
+
424
+ mIsBluetoothEnabled = true;
425
+ strcpy(mConnectedDeviceName,"");
426
+ strcpy(mCreateSessionCallback,"");
427
+ strcpy(mSessionCallback,"");
428
+ }
429
+
430
+
431
+ void RhoBluetoothManager::terminateDiscoverThread() {
432
+ if (m_hDiscoverThred) {
433
+ DWORD dwExitCode = 0;
434
+ TerminateThread(m_hDiscoverThred, dwExitCode);
435
+ m_hDiscoverThred = NULL;
436
+ }
437
+ }
438
+
439
+ void RhoBluetoothManager::terminateDiscoveredThread() {
440
+ if (m_hDiscoveredThread) {
441
+ DWORD dwExitCode = 0;
442
+ TerminateThread(m_hDiscoveredThread, dwExitCode);
443
+ m_hDiscoveredThread = NULL;
444
+ }
445
+ }
446
+
447
+
448
+ void RhoBluetoothManager::freeAll() {
449
+ LOG(INFO) + "RhoBluetoothManager::freeAll()";
450
+ //Set radio mode back to original state
451
+ BthSetMode(m_dwBluetoothMode);
452
+ if(m_pStart)
453
+ {
454
+ for(m_pCurrentDevice = m_pStart;m_pCurrentDevice;)
455
+ {
456
+ RhoDeviceList *temp = m_pCurrentDevice;
457
+ m_pCurrentDevice = m_pCurrentDevice->NextDevice;
458
+ free(temp);
459
+ }
460
+ m_pStart=NULL;
461
+ }
462
+
463
+ if(m_socketClient) {
464
+ closesocket (m_socketClient);
465
+ }
466
+ if(m_socketServer) {
467
+ closesocket (m_socketServer);
468
+ }
469
+
470
+ //Terminate the read thread that receives chat messages from the client
471
+ if(m_hReadThread)
472
+ {
473
+ DWORD dwExitCode = 0;
474
+ TerminateThread(m_hReadThread, dwExitCode);
475
+ }
476
+ if (m_hDiscoverThred) {
477
+ DWORD dwExitCode = 0;
478
+ TerminateThread(m_hDiscoverThred, dwExitCode);
479
+ }
480
+ if (m_hDiscoveredThread) {
481
+ DWORD dwExitCode = 0;
482
+ TerminateThread(m_hDiscoveredThread, dwExitCode);
483
+ }
484
+ if (mReadedString) {
485
+ delete mReadedString;
486
+ mReadedString = NULL;
487
+ }
488
+
489
+ WSACleanup();
490
+
491
+ freeAllBlocks();
492
+ }
493
+
494
+
495
+ void RhoBluetoothManager::addDataBlock(RhoDataBlock* block) {
496
+ if (mFirstDataBlock == NULL) {
497
+ mFirstDataBlock = block;
498
+ mLastDataBlock = block;
499
+ block->next = NULL;
500
+ return;
501
+ }
502
+ if (mLastDataBlock != NULL) {
503
+ mLastDataBlock->next = block;
504
+ mLastDataBlock = block;
505
+ block->next = NULL;
506
+ return;
507
+ }
508
+ }
509
+
510
+ void* RhoBluetoothManager::readAllBlocks(int* size, int additional_space) {
511
+ RhoDataBlock* first = mFirstDataBlock;
512
+ mFirstDataBlock = NULL;
513
+ mLastDataBlock = NULL;
514
+ int summsize = getBlocksSummarySizeFromBlock(first);
515
+ if (summsize <= 0) {
516
+ *size = 0;
517
+ return NULL;
518
+ }
519
+ unsigned char* buf = new unsigned char[summsize+additional_space];
520
+ unsigned char* p = buf;
521
+ RhoDataBlock* b = first;
522
+ while (b != NULL) {
523
+ memcpy(p, b->buf, b->size);
524
+ p+= b->size;
525
+ b = b->next;
526
+ }
527
+ *size = summsize;
528
+ return buf;
529
+ }
530
+
531
+ void RhoBluetoothManager::freeAllBlocks() {
532
+ RhoDataBlock* b = mFirstDataBlock;
533
+ mFirstDataBlock = NULL;
534
+ mLastDataBlock = NULL;
535
+ while (b != NULL) {
536
+ RhoDataBlock* d = b;
537
+ b = b->next;
538
+ delete d;
539
+ }
540
+ }
541
+
542
+ int RhoBluetoothManager::getBlocksSummarySize() {
543
+ LOG(INFO) + "RhoBluetoothManager::getBlocksSummarySize()";
544
+ int size = getBlocksSummarySizeFromBlock(mFirstDataBlock);
545
+ return size;
546
+ }
547
+
548
+ int RhoBluetoothManager::getBlocksSummarySizeFromBlock(RhoDataBlock* block) {
549
+ int summsize = 0;
550
+ RhoDataBlock* b = block;
551
+ while (b != NULL) {
552
+ summsize += b->size;
553
+ b = b->next;
554
+ }
555
+ return summsize;
556
+ }
557
+
558
+
559
+
560
+
561
+ int RhoBluetoothManager::DiscoverDevices() {
562
+ LOG(INFO) + "RhoBluetoothManager::DiscoverDevices() START";
563
+ WSAQUERYSET wsaq;
564
+ HANDLE hLookup;
565
+ RhoDeviceList * tempDevice;
566
+
567
+ union {
568
+ CHAR buf[5000];
569
+ double __unused; // ensure proper alignment
570
+ };
571
+
572
+ LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET) buf;
573
+ DWORD dwSize = sizeof(buf);
574
+ BOOL bHaveName;
575
+
576
+ ZeroMemory(&wsaq, sizeof(wsaq));
577
+ wsaq.dwSize = sizeof(wsaq);
578
+ wsaq.dwNameSpace = NS_BTH;
579
+ wsaq.lpcsaBuffer = NULL;
580
+
581
+ if (ERROR_SUCCESS != WSALookupServiceBegin (&wsaq, LUP_CONTAINERS, &hLookup))
582
+ {
583
+ LOG(INFO) + "RhoBluetoothManager::DiscoverDevices() return ERROR";
584
+ return WSAGetLastError();
585
+ }
586
+
587
+ ZeroMemory(pwsaResults, sizeof(WSAQUERYSET));
588
+ pwsaResults->dwSize = sizeof(WSAQUERYSET);
589
+ pwsaResults->dwNameSpace = NS_BTH;
590
+ pwsaResults->lpBlob = NULL;
591
+
592
+ if(m_pStart)
593
+ {
594
+ for(m_pCurrentDevice=m_pStart;m_pCurrentDevice;)
595
+ {
596
+ RhoDeviceList *temp=m_pCurrentDevice;
597
+ m_pCurrentDevice=m_pCurrentDevice->NextDevice;
598
+ free(temp);
599
+ }
600
+ }
601
+ m_pEnd=m_pStart=NULL;
602
+ m_iNumDevices=0;
603
+ while (true)
604
+ {
605
+ if(WSALookupServiceNext (hLookup, LUP_RETURN_NAME | LUP_RETURN_ADDR, &dwSize, pwsaResults)!=ERROR_SUCCESS)
606
+ break;
607
+ ASSERT (pwsaResults->dwNumberOfCsAddrs == 1);
608
+ //Populate the link list
609
+ tempDevice=(RhoDeviceList*)malloc(sizeof(RhoDeviceList));
610
+ tempDevice->NextDevice=NULL;
611
+ if(m_pStart==NULL)
612
+ {
613
+ m_pStart = tempDevice;
614
+ m_pEnd=m_pStart;
615
+ }
616
+ else
617
+ {
618
+ m_pEnd->NextDevice =tempDevice;
619
+ m_pEnd=tempDevice;
620
+ }
621
+ m_iNumDevices++;
622
+ m_pEnd->bthAddress = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;
623
+ bHaveName = pwsaResults->lpszServiceInstanceName && *(pwsaResults->lpszServiceInstanceName);
624
+ //If device name is available, add to node
625
+ StringCchPrintf(m_pEnd->bthName, ARRAYSIZE(m_pEnd->bthName),L"%s",bHaveName ? pwsaResults->lpszServiceInstanceName : L"");
626
+ {
627
+ char name[1024];
628
+ WideCharToMultiByte(CP_UTF8, 0, m_pEnd->bthName, -1, name, 1024, 0, 0);
629
+ LOG(INFO) + "RhoBluetoothManager::DiscoverDevices() FOUND = "+name;
630
+ }
631
+ }
632
+
633
+ WSALookupServiceEnd(hLookup);
634
+ LOG(INFO) + "RhoBluetoothManager::DiscoverDevices() FINISH";
635
+ // LeaveCriticalSection(&criticalSection);
636
+ return 0;
637
+ }
638
+
639
+
640
+ DWORD WINAPI RhoBluetoothManager::runThreadReadData(LPVOID voidArg) {
641
+ LOG(INFO) + "RhoBluetoothManager::runThreadReadData() START";
642
+ int iSize=0, cbBytesRecd=0 ;
643
+ //WCHAR szMessage[MAX_MESSAGE_SIZE];
644
+ char pbuf[MAX_MESSAGE_SIZE];
645
+ RhoBluetoothManager* functionInfo = (RhoBluetoothManager*) voidArg;
646
+ iSize = sizeof(functionInfo->m_saClient);
647
+ //BTH_REMOTE_NAME remotename;
648
+ //memset(&remotename, sizeof(remotename), 0);
649
+
650
+ SOCKET s = functionInfo->m_socketClient;//accept (functionInfo->m_socketServer, (SOCKADDR*)&(functionInfo->m_saClient), &iSize);
651
+ //remotename.bt = functionInfo->m_saClient.btAddr;
652
+
653
+ //setsockopt(functionInfo->m_socketServer,SOL_RFCOMM, SO_BTH_SET_READ_REMOTE_NAME, (char*)&remotename, sizeof(remotename));
654
+
655
+ if (s != INVALID_SOCKET)
656
+ {
657
+ for ( ; ; )
658
+ {
659
+ //receive data in pbuf
660
+ cbBytesRecd = recv (s, pbuf, MAX_MESSAGE_SIZE, 0);
661
+ //if error occured in receiving, return error code
662
+ if (cbBytesRecd == SOCKET_ERROR)
663
+ {
664
+ LOG(INFO) + "RhoBluetoothManager::runThreadReadData() exit with error";
665
+ functionInfo->fireSessionCallBack(functionInfo->mConnectedDeviceName, RHO_BT_ERROR);
666
+ return WSAGetLastError();
667
+ }
668
+ else
669
+ {
670
+ // something was received, then copy the contents in szMessage
671
+ if(cbBytesRecd>0)
672
+ {
673
+ RhoDataBlock* block = new RhoDataBlock;
674
+ block->buf = new unsigned char[cbBytesRecd];
675
+ memcpy(block->buf, pbuf, cbBytesRecd);
676
+ block->size = cbBytesRecd;
677
+ functionInfo->addDataBlock(block);
678
+ LOG(INFO) + "RhoBluetoothManager::runThreadReadData() read data from Socket";
679
+ functionInfo->fireSessionCallBack(functionInfo->mConnectedDeviceName, RHO_BT_SESSION_INPUT_DATA_RECEIVED);
680
+ //StringCchPrintf (szMessage, ARRAYSIZE(szMessage), L"%s", pbuf);
681
+ //int o;
682
+ //o = 9;
683
+ //(*functionInfo->pCallBackFunction)(szMessage);
684
+ }
685
+ }
686
+ }
687
+ }
688
+ return 0;
689
+ }
690
+
691
+ int RhoBluetoothManager::makeConnection(BT_ADDR bt_addr) {
692
+ LOG(INFO) + "RhoBluetoothManager::makeConnection() START";
693
+ // client part
694
+ if (m_socketClient==INVALID_SOCKET)
695
+ {
696
+ GUID ServerGuid;
697
+
698
+ if(GetGUID(SerialPortConnectGUID, &ServerGuid))
699
+ return -1;
700
+ m_socketClient = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM);
701
+
702
+ if (m_socketClient == INVALID_SOCKET)
703
+ {
704
+ LOG(INFO) + "RhoBluetoothManager::makeConnection() return with invalid socket opened";
705
+ return WSAGetLastError();
706
+ }
707
+
708
+ SOCKADDR_BTH sa;
709
+
710
+ memset (&sa, 0, sizeof(sa));
711
+ sa.addressFamily = AF_BT;
712
+ //Search for the selected device in the list box in the link list
713
+ //m_pCurrentDevice=m_pStart;
714
+ sa.serviceClassId=ServerGuid;
715
+
716
+ //if(iSelectedDeviceIndex==-1)
717
+ //{
718
+ // sa.btAddr=m_saClient.btAddr;
719
+ //}
720
+ //else
721
+ //{
722
+ //for (int iCount = 0 ;(m_pCurrentDevice)&&iCount!=iSelectedDeviceIndex;m_pCurrentDevice=m_pCurrentDevice->NextDevice,iCount++);
723
+ //sa.btAddr = m_pCurrentDevice->bthAddress;
724
+ //}
725
+ sa.btAddr = bt_addr;
726
+
727
+ if (connect (m_socketClient, (SOCKADDR *)&sa, sizeof(sa)) == SOCKET_ERROR)
728
+ {
729
+ LOG(INFO) + "RhoBluetoothManager::makeConnection() return with error during socket connection";
730
+ m_socketClient=INVALID_SOCKET;
731
+ return WSAGetLastError();
732
+ }
733
+ // start read thred
734
+ m_hReadThread= CreateThread(NULL, 0, runThreadReadData, (LPVOID)this, 0, NULL);
735
+ }
736
+ LOG(INFO) + "RhoBluetoothManager::makeConnection() FINISH";
737
+ return 0;
738
+ }
739
+
740
+
741
+ void RhoBluetoothManager::onDiscoverDlgSelectDevice(int index) {
742
+ LOG(INFO) + "RhoBluetoothManager::onDiscoverDlgSelectDevice() START";
743
+ if (index < 0) {
744
+ fireCreateSessionCallBack(RHO_BT_CANCEL, "");
745
+ LOG(INFO) + "RhoBluetoothManager::onDiscoverDlgSelectDevice() invalid index";
746
+ return;
747
+ }
748
+
749
+ // make client connection
750
+ m_pCurrentDevice=m_pStart;
751
+ if (m_pStart == NULL) {
752
+ LOG(INFO) + "RhoBluetoothManager::onDiscoverDlgSelectDevice() empty device list";
753
+ fireCreateSessionCallBack(RHO_BT_ERROR, "");
754
+ return;
755
+ }
756
+ for (int iCount = 0 ;(m_pCurrentDevice)&&iCount!=index;m_pCurrentDevice=m_pCurrentDevice->NextDevice,iCount++);
757
+ BT_ADDR bt_addr = m_pCurrentDevice->bthAddress;
758
+
759
+ if (makeConnection(bt_addr) == 0) {
760
+ // get connected_device_name
761
+ RhoDeviceInfo devInfo;
762
+ GetDeviceInfo(&devInfo, index);
763
+ WideCharToMultiByte(CP_UTF8, 0, devInfo.szDeviceNameAddr, -1, mConnectedDeviceName, MAX_NAME_SIZE, 0, 0);
764
+ // fire callback
765
+ LOG(INFO) + "RhoBluetoothManager::onDiscoverDlgSelectDevice() FINISH OK";
766
+ fireCreateSessionCallBack(RHO_BT_OK, mConnectedDeviceName);
767
+ return;
768
+ }
769
+ LOG(INFO) + "RhoBluetoothManager::onDiscoverDlgSelectDevice() cannot make connection !";
770
+
771
+ // fire callback
772
+ fireCreateSessionCallBack(RHO_BT_ERROR, "");
773
+
774
+ }
775
+
776
+ void RhoBluetoothManager::onDiscoverDlgCancel() {
777
+ fireCreateSessionCallBack(RHO_BT_CANCEL, "");
778
+ }
779
+
780
+ void RhoBluetoothManager::onDiscoveredDlgCancel() {
781
+ terminateDiscoveredThread();
782
+ fireCreateSessionCallBack(RHO_BT_CANCEL, "");
783
+ }
784
+
785
+
786
+
787
+ //Function: GetDeviceInfo
788
+ //Purpose: Returns name and address of all the devices in the link list in DeviceInfo. This is used by the UI to display the names and addresses of the devices found
789
+ //Output: DeviceInfo: name and address
790
+ //Return: Success returns zero.
791
+ int RhoBluetoothManager::GetDeviceInfo(RhoDeviceInfo *pPeerDevicesInfo)
792
+ {
793
+ int iCtr=0;
794
+ for (m_pCurrentDevice = m_pStart;(m_pCurrentDevice);m_pCurrentDevice=m_pCurrentDevice->NextDevice,iCtr++)
795
+ {
796
+ StringCchPrintf(pPeerDevicesInfo[iCtr].szDeviceNameAddr, ARRAYSIZE(pPeerDevicesInfo[iCtr].szDeviceNameAddr), L"%s:(%04x%08x)", m_pCurrentDevice->bthName, GET_NAP(m_pCurrentDevice->bthAddress), GET_SAP(m_pCurrentDevice->bthAddress));
797
+ }
798
+ return 0;
799
+ }
800
+
801
+ //Function: GetDeviceInfo
802
+ //Purpose: Searches the link list for the specified device and returns address and name in DeviceInfo
803
+ //Input: The current device index selected in the UI
804
+ //Output: DeviceInfo: name and address
805
+ //Return: Returns -1 in case of an error, otherwise returns zero.
806
+ int RhoBluetoothManager::GetDeviceInfo(RhoDeviceInfo *pPeerDeviceInfo, int iSelectedItem)
807
+ {
808
+ int iCtr=0;
809
+
810
+ for (m_pCurrentDevice = m_pStart;(m_pCurrentDevice);m_pCurrentDevice=m_pCurrentDevice->NextDevice,iCtr++)
811
+ {
812
+ if(iCtr==iSelectedItem)
813
+ {
814
+ StringCchPrintf(pPeerDeviceInfo[0].szDeviceNameAddr, ARRAYSIZE(pPeerDeviceInfo[0].szDeviceNameAddr), L"%s:(%04x%08x)", m_pCurrentDevice->bthName, GET_NAP(m_pCurrentDevice->bthAddress), GET_SAP(m_pCurrentDevice->bthAddress));
815
+ return 0;
816
+ }
817
+ }
818
+ return -1;
819
+ }
820
+
821
+
822
+
823
+ //Function: GetGUID
824
+ //Purpose: Conversts a string containing the GUID into a GUID datatype.
825
+ //Input: string cotaining the GUID
826
+ //Output: GUID type
827
+ //Return: Returns -1 in case of an error, otherwise returns zero.
828
+ int RhoBluetoothManager::GetGUID(WCHAR *psz, GUID *pGUID)
829
+ {
830
+ int data1, data2, data3;
831
+ int data4[8];
832
+
833
+ if (11 == swscanf(psz, L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
834
+ &data1, &data2, &data3,
835
+ &data4[0], &data4[1], &data4[2], &data4[3],
836
+ &data4[4], &data4[5], &data4[6], &data4[7])) {
837
+ pGUID->Data1 = data1;
838
+ pGUID->Data2 = data2 & 0xffff;
839
+ pGUID->Data3 = data3 & 0xffff;
840
+
841
+ for (int i = 0 ; i < 8 ; ++i)
842
+ pGUID->Data4[i] = data4[i] & 0xff;
843
+
844
+ return 0;
845
+ }
846
+ return -1;
847
+ }
848
+
849
+ //Function: GetLocalDeviceName
850
+ //Purpose: Returns the name of the owner set in the registry
851
+ //Output: DeviceInfo: (only)name
852
+ //Return: Returns -1 in case of an error, otherwise returns zero.
853
+
854
+ int RhoBluetoothManager::GetLocalDeviceName(RhoDeviceInfo *pLocalDeviceInfo)
855
+
856
+ {
857
+ HKEY hKey;
858
+ DWORD dwRegType, dwRegSize;
859
+ if(RegOpenKeyEx(HKEY_CURRENT_USER,L"ControlPanel\\Owner",0,0,&hKey)==ERROR_SUCCESS)
860
+ {
861
+ if(RegQueryValueEx(hKey,L"Name",0,&dwRegType,(LPBYTE)pLocalDeviceInfo->szDeviceNameAddr,&dwRegSize)==ERROR_SUCCESS)
862
+ {
863
+ if (dwRegSize>MAX_NAME_SIZE)
864
+ {
865
+ RegCloseKey(hKey);
866
+ return -1;
867
+ }
868
+ RegCloseKey(hKey);
869
+ }
870
+ RegCloseKey(hKey);
871
+ }
872
+ return 0;
873
+ }
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+ RhoDiscoverDlg::RhoDiscoverDlg() {
890
+
891
+ }
892
+
893
+ RhoDiscoverDlg::~RhoDiscoverDlg() {
894
+
895
+ }
896
+ void RhoDiscoverDlg::openDialog(RhoBluetoothManager* btManager) {
897
+ LOG(INFO) + "RhoDiscoverDlg::openDialog()";
898
+ mBtManager = btManager;
899
+ hCurs = GetCursor();
900
+ //mShowCursor = ShowCursor(false);
901
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
902
+
903
+ dlg.mSelectedDevice = -1;
904
+ int retVal = dlg.DoModal(getMainWnd());
905
+ //dlg.ShowWindow();
906
+ SetCursor(hCurs);
907
+ ShowCursor(false);
908
+ if (retVal != IDOK) {
909
+ LOG(INFO) + "RhoDiscoverDlg::openDialog() dialog closed with not OK";
910
+ mBtManager->onDiscoverDlgSelectDevice(-1);
911
+ }
912
+ LOG(INFO) + "RhoDiscoverDlg::openDialog() dialog closed with OK";
913
+ mBtManager->onDiscoverDlgSelectDevice(dlg.mSelectedDevice);
914
+ }
915
+
916
+ void RhoDiscoverDlg::updateDeviceListFromManager() {
917
+ LOG(INFO) + "RhoDiscoverDlg::updateDeviceListFromManager() START";
918
+ //mBtManager->onDiscoverDlgSelectDevice(0);
919
+
920
+ int count = mBtManager->GetNumDevices();
921
+
922
+ if (count <= 0) {
923
+ LOG(INFO) + "RhoDiscoverDlg::updateDeviceListFromManager() Device list is Empty !!!";
924
+ ::MessageBox(getMainWnd(), L"Not found any Bluetooth devices !", L"Warning", MB_OK | MB_ICONINFORMATION);
925
+ dlg.EndDialog(IDCANCEL);
926
+ //mBtManager->onDiscoverDlgSelectDevice(-1);
927
+ return;
928
+ }
929
+
930
+ int i;
931
+ for (i = 0; i < count; ++i) {
932
+ RhoDeviceInfo devInfo;
933
+ mBtManager->GetDeviceInfo(&devInfo, i);
934
+ int index = SendMessage(dlg.GetDlgItem(IDC_BT_LIST).m_hWnd, LB_ADDSTRING,0,(LPARAM) devInfo.szDeviceNameAddr);
935
+ SendMessage(dlg.GetDlgItem(IDC_BT_LIST).m_hWnd, LB_SETITEMDATA, (WPARAM)index, (LPARAM) i);
936
+ }
937
+
938
+ SendMessage(dlg.GetDlgItem(IDC_BT_LIST).m_hWnd, LB_SETCURSEL, 0,0);
939
+ SetCursor(hCurs);
940
+ ShowCursor(false);
941
+ SetWindowText(dlg.GetDlgItem(IDC_BT_STATIC).m_hWnd, L"Please select Bluetooth device to connect :");
942
+ LOG(INFO) + "RhoDiscoverDlg::updateDeviceListFromManager() FINISH";
943
+ //dlg.RedrawWindow();
944
+ //mBtManager->onDiscoverDlgSelectDevice(0);
945
+ }
946
+
947
+
948
+ RhoDiscoveredDlg::RhoDiscoveredDlg() {
949
+
950
+ }
951
+
952
+ RhoDiscoveredDlg::~RhoDiscoveredDlg() {
953
+
954
+ }
955
+
956
+ void RhoDiscoveredDlg::openDialog(RhoBluetoothManager* btManager) {
957
+ LOG(INFO) + "RhoDiscoveredDlg::openDialog()";
958
+ mBtManager = btManager;
959
+ hCurs = GetCursor();
960
+ //mShowCursor = ShowCursor(false);
961
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
962
+
963
+ int retVal = dlg.DoModal(getMainWnd());
964
+ //dlg.ShowWindow();
965
+ SetCursor(hCurs);
966
+ ShowCursor(false);
967
+ if (retVal != 555) {
968
+ LOG(INFO) + "RhoDiscoveredDlg::openDialog() dialog closed with not OK";
969
+ mBtManager->onDiscoveredDlgCancel();
970
+ }
971
+ LOG(INFO) + "RhoDiscoveredDlg::openDialog() dialog closed with OK";
972
+ }
973
+
974
+ void RhoDiscoveredDlg::closeDialog() {
975
+ dlg.EndDialog(555);
976
+ }
977
+
978
+
979
+
980
+
981
+
982
+
983
+
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+ int rho_bluetooth_is_bluetooth_available() {
1023
+ return RhoBluetoothManager::getInstance()->rho_bluetooth_is_bluetooth_available();
1024
+ }
1025
+
1026
+ void rho_bluetooth_off_bluetooth() {
1027
+ RhoBluetoothManager::getInstance()->rho_bluetooth_off_bluetooth();
1028
+ }
1029
+
1030
+ void rho_bluetooth_set_device_name(const char* device_name) {
1031
+ RhoBluetoothManager::getInstance()->rho_bluetooth_set_device_name(device_name);
1032
+ }
1033
+
1034
+ const char* rho_bluetooth_get_device_name() {
1035
+ return RhoBluetoothManager::getInstance()->rho_bluetooth_get_device_name();
1036
+ }
1037
+
1038
+ const char* rho_bluetooth_get_last_error() {
1039
+ return RhoBluetoothManager::getInstance()->rho_bluetooth_get_last_error();
1040
+ }
1041
+
1042
+ const char* rho_bluetooth_create_session(const char* role, const char* callback_url) {
1043
+ return RhoBluetoothManager::getInstance()->rho_bluetooth_create_session(role, callback_url);
1044
+ }
1045
+
1046
+ void rho_bluetooth_session_set_callback(const char* connected_device_name, const char* callback_url) {
1047
+ RhoBluetoothManager::getInstance()->rho_bluetooth_session_set_callback(connected_device_name, callback_url);
1048
+ }
1049
+
1050
+ void rho_bluetooth_session_disconnect(const char* connected_device_name) {
1051
+ RhoBluetoothManager::getInstance()->rho_bluetooth_session_disconnect(connected_device_name);
1052
+ }
1053
+
1054
+ int rho_bluetooth_session_get_status(const char* connected_device_name) {
1055
+ return RhoBluetoothManager::getInstance()->rho_bluetooth_session_get_status(connected_device_name);
1056
+ }
1057
+
1058
+ const char* rho_bluetooth_session_read_string(const char* connected_device_name) {
1059
+ return RhoBluetoothManager::getInstance()->rho_bluetooth_session_read_string(connected_device_name);
1060
+ }
1061
+
1062
+ void rho_bluetooth_session_write_string(const char* connected_device_name, const char* str) {
1063
+ int length = strlen(str);
1064
+ if (length <= 0) {
1065
+ return;
1066
+ }
1067
+ RhoBluetoothManager::getInstance()->rho_bluetooth_session_write_data(connected_device_name, (void*)str, length);
1068
+ }
1069
+
1070
+ VALUE rho_bluetooth_session_read_data(const char* connected_device_name) {
1071
+ int size = 0;
1072
+ void* buf = RhoBluetoothManager::getInstance()->readAllBlocks(&size, 0);
1073
+ VALUE val = rho_ruby_create_byte_array((unsigned char*)buf, size);
1074
+ free(buf);
1075
+ return val;
1076
+ }
1077
+
1078
+ void rho_bluetooth_session_write_data(const char* connected_device_name, VALUE data) {
1079
+ int size = rho_ruby_unpack_byte_array(data, 0, 0);
1080
+ if (size <= 0) {
1081
+ return;
1082
+ }
1083
+ unsigned char* buf = (unsigned char*)malloc(size);
1084
+ size = rho_ruby_unpack_byte_array(data, buf, size);
1085
+ RhoBluetoothManager::getInstance()->rho_bluetooth_session_write_data(connected_device_name, buf, size);
1086
+ free(buf);
1087
+ }
1088
+
1089
+
1090
+
1091
+ // CRhoBluetoothDiscoverDlg dialog
1092
+
1093
+ CRhoBluetoothDiscoverDlg::CRhoBluetoothDiscoverDlg ()
1094
+ {
1095
+ }
1096
+
1097
+ CRhoBluetoothDiscoverDlg::~CRhoBluetoothDiscoverDlg ()
1098
+ {
1099
+ }
1100
+
1101
+ LRESULT CRhoBluetoothDiscoverDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
1102
+ {
1103
+ SetWindowText(_T("Discover Bluetooth devices"));
1104
+
1105
+ #if defined(_WIN32_WCE)
1106
+
1107
+ SHINITDLGINFO shidi = { SHIDIM_FLAGS, m_hWnd, SHIDIF_SIZEDLGFULLSCREEN };
1108
+ RHO_ASSERT(SHInitDialog(&shidi));
1109
+
1110
+
1111
+ SHMENUBARINFO mbi = { sizeof(mbi), 0 };
1112
+ mbi.hwndParent = m_hWnd;
1113
+ mbi.nToolBarId = IDR_GETURL_MENUBAR;
1114
+ mbi.hInstRes = _AtlBaseModule.GetResourceInstance();
1115
+ RHO_ASSERT(SHCreateMenuBar(&mbi));
1116
+ //GotoDlgCtrl(GetDlgItem(IDC_DATE_CTRL));
1117
+
1118
+ #else
1119
+
1120
+ CreateButtons();
1121
+ GotoDlgCtrl(m_btnOk);
1122
+
1123
+ #endif
1124
+
1125
+ //DLG_ITEM_SET_FONT_BOLD (IDC_DATE_STATIC);
1126
+ //DLG_ITEM_SET_FONT_BOLD (IDC_TIME_STATIC);
1127
+
1128
+ //if (m_format == CDateTimeMessage::FORMAT_DATE) {
1129
+ // GetDlgItem(IDC_TIME_CTRL).ShowWindow(SW_HIDE);
1130
+ // GetDlgItem(IDC_TIME_STATIC).ShowWindow(SW_HIDE);
1131
+ //}
1132
+ mSelectedDevice = -1;
1133
+ return FALSE;
1134
+ }
1135
+
1136
+ LRESULT CRhoBluetoothDiscoverDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND hwnd, BOOL& /*bHandled*/)
1137
+ {
1138
+ // set selected device
1139
+
1140
+ int sel_item = SendMessage(GetDlgItem(IDC_BT_LIST).m_hWnd, LB_GETCURSEL, 0, 0);
1141
+ mSelectedDevice = SendMessage(GetDlgItem(IDC_BT_LIST).m_hWnd, LB_GETITEMDATA, (WPARAM)sel_item, 0);
1142
+ EndDialog(wID);
1143
+ return 0;
1144
+ }
1145
+
1146
+
1147
+ LRESULT CRhoBluetoothDiscoverDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1148
+ {
1149
+ EndDialog(wID);
1150
+ return 0;
1151
+ }
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+ // CRhoBluetoothDiscoveredDlg dialog
1159
+
1160
+ CRhoBluetoothDiscoveredDlg::CRhoBluetoothDiscoveredDlg ()
1161
+ {
1162
+ }
1163
+
1164
+ CRhoBluetoothDiscoveredDlg::~CRhoBluetoothDiscoveredDlg ()
1165
+ {
1166
+ }
1167
+
1168
+ LRESULT CRhoBluetoothDiscoveredDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
1169
+ {
1170
+ SetWindowText(_T("Discoverable"));
1171
+
1172
+ #if defined(_WIN32_WCE)
1173
+
1174
+ SHINITDLGINFO shidi = { SHIDIM_FLAGS, m_hWnd, SHIDIF_SIZEDLGFULLSCREEN };
1175
+ RHO_ASSERT(SHInitDialog(&shidi));
1176
+
1177
+
1178
+ SHMENUBARINFO mbi = { sizeof(mbi), 0 };
1179
+ mbi.hwndParent = m_hWnd;
1180
+ mbi.nToolBarId = IDR_GETURL_MENUBAR;
1181
+ mbi.hInstRes = _AtlBaseModule.GetResourceInstance();
1182
+ RHO_ASSERT(SHCreateMenuBar(&mbi));
1183
+ //GotoDlgCtrl(GetDlgItem(IDC_DATE_CTRL));
1184
+
1185
+ #else
1186
+
1187
+ CreateButtons();
1188
+ GotoDlgCtrl(m_btnOk);
1189
+
1190
+ #endif
1191
+
1192
+ //DLG_ITEM_SET_FONT_BOLD (IDC_DATE_STATIC);
1193
+ //DLG_ITEM_SET_FONT_BOLD (IDC_TIME_STATIC);
1194
+
1195
+ //if (m_format == CDateTimeMessage::FORMAT_DATE) {
1196
+ // GetDlgItem(IDC_TIME_CTRL).ShowWindow(SW_HIDE);
1197
+ // GetDlgItem(IDC_TIME_STATIC).ShowWindow(SW_HIDE);
1198
+ //}
1199
+ return FALSE;
1200
+ }
1201
+
1202
+ LRESULT CRhoBluetoothDiscoveredDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND hwnd, BOOL& /*bHandled*/)
1203
+ {
1204
+ EndDialog(wID);
1205
+ return 0;
1206
+ }
1207
+
1208
+
1209
+ LRESULT CRhoBluetoothDiscoveredDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1210
+ {
1211
+ EndDialog(wID);
1212
+ return 0;
1213
+ }
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+ #else // OS_WINDOWS
1225
+
1226
+ int rho_bluetooth_is_bluetooth_available() {
1227
+ return 0;
1228
+ }
1229
+
1230
+ void rho_bluetooth_off_bluetooth() {
1231
+ }
1232
+
1233
+ void rho_bluetooth_set_device_name(const char* device_name) {
1234
+ }
1235
+
1236
+ const char* rho_bluetooth_get_device_name() {
1237
+ return "ERROR";
1238
+ }
1239
+
1240
+ const char* rho_bluetooth_get_last_error() {
1241
+ return "ERROR";
1242
+ }
1243
+
1244
+ const char* rho_bluetooth_create_session(const char* role, const char* callback_url) {
1245
+ return "ERROR";
1246
+ }
1247
+
1248
+ void rho_bluetooth_session_set_callback(const char* connected_device_name, const char* callback_url) {
1249
+ }
1250
+
1251
+ void rho_bluetooth_session_disconnect(const char* connected_device_name) {
1252
+ }
1253
+
1254
+ int rho_bluetooth_session_get_status(const char* connected_device_name) {
1255
+ return -1;
1256
+ }
1257
+
1258
+ const char* rho_bluetooth_session_read_string(const char* connected_device_name) {
1259
+ return "ERROR";
1260
+ }
1261
+
1262
+ void rho_bluetooth_session_write_string(const char* connected_device_name, const char* str) {
1263
+ }
1264
+
1265
+ VALUE rho_bluetooth_session_read_data(const char* connected_device_name) {
1266
+ return 0;
1267
+ }
1268
+
1269
+ void rho_bluetooth_session_write_data(const char* connected_device_name, VALUE data) {
1270
+ }
1271
+
1272
+
1273
+ #endif // OS_WINDOWS
1274
+