rhodes 1.5.5 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (529) hide show
  1. data/CHANGELOG +5 -0
  2. data/Manifest.txt +214 -32
  3. data/Rakefile +33 -10
  4. data/bin/upgrade-rhodes-app +0 -1
  5. data/lib/build/compileERB/bb.rb +2 -2
  6. data/lib/build/compileERB/default.rb +7 -5
  7. data/lib/build/jake.rb +1 -1
  8. data/lib/extensions/digest-md5/ext.yml +1 -1
  9. data/lib/extensions/digest-md5/ext/Rakefile +35 -36
  10. data/lib/extensions/digest-md5/ext/build.bat +1 -0
  11. data/lib/extensions/digest-md5/ext/digest-md5.vcproj +203 -0
  12. data/lib/extensions/digest-sha1/ext.yml +1 -1
  13. data/lib/extensions/digest/ext.yml +1 -1
  14. data/lib/extensions/digest/ext/Rakefile +35 -39
  15. data/lib/extensions/digest/ext/build.bat +1 -2
  16. data/lib/extensions/digest/ext/digest.vcproj +203 -0
  17. data/lib/framework/rho/render.rb +79 -22
  18. data/lib/framework/rho/rho.rb +294 -56
  19. data/lib/framework/rho/rhoapplication.rb +10 -0
  20. data/lib/framework/rho/rhofsconnector.rb +2 -6
  21. data/lib/framework/rho/rhoutils.rb +56 -14
  22. data/lib/framework/rho/rhoviewhelpers.rb +2 -0
  23. data/lib/framework/rhodes.rb +2 -2
  24. data/lib/framework/rhom/rhom.rb +42 -15
  25. data/lib/framework/rhom/rhom_db_adapter.rb +165 -159
  26. data/lib/framework/rhom/rhom_object.rb +0 -1
  27. data/lib/framework/rhom/rhom_object_factory.rb +343 -166
  28. data/lib/framework/rhom/rhom_source.rb +28 -15
  29. data/lib/framework/version.rb +2 -2
  30. data/lib/rhodes.rb +2 -2
  31. data/platform/android/Rhodes/AndroidManifest.xml +2 -2
  32. data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +39 -44
  33. data/platform/android/Rhodes/jni/include/JNIRhodes.h +1 -1
  34. data/platform/android/Rhodes/jni/include/details/rhojava.inc +23 -20
  35. data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_RhoMenu.h +61 -0
  36. data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_Rhodes.h +16 -0
  37. data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_alert_Alert.h +21 -0
  38. data/platform/android/Rhodes/jni/include/sslimpl.h +1 -1
  39. data/platform/android/Rhodes/jni/src/alert.cpp +32 -5
  40. data/platform/android/Rhodes/jni/src/callbacks.cpp +51 -21
  41. data/platform/android/Rhodes/jni/src/mapview.cpp +3 -8
  42. data/platform/android/Rhodes/jni/src/menu.cpp +70 -0
  43. data/platform/android/Rhodes/jni/src/navbar.cpp +16 -0
  44. data/platform/android/Rhodes/jni/src/rhodes.cpp +37 -0
  45. data/platform/android/Rhodes/jni/src/sslimpl.cpp +3 -3
  46. data/platform/android/Rhodes/jni/src/webview.cpp +21 -7
  47. data/platform/android/Rhodes/res/drawable/alert_alert.png +0 -0
  48. data/platform/android/Rhodes/res/drawable/alert_info.png +0 -0
  49. data/platform/android/Rhodes/res/drawable/alert_question.png +0 -0
  50. data/platform/android/Rhodes/res/drawable/camera.png +0 -0
  51. data/platform/android/Rhodes/res/layout/camera.xml +18 -3
  52. data/platform/android/Rhodes/res/menu/options.xml +0 -10
  53. data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +5 -10
  54. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +12 -0
  55. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java +105 -0
  56. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +157 -122
  57. data/platform/android/Rhodes/src/com/rhomobile/rhodes/SplashScreen.java +7 -58
  58. data/platform/android/Rhodes/src/com/rhomobile/rhodes/WebView.java +16 -0
  59. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/Alert.java +220 -17
  60. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java +22 -4
  61. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +44 -25
  62. data/platform/android/Rhodes/src/com/rhomobile/rhodes/geolocation/GeoLocation.java +10 -0
  63. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/MainView.java +3 -0
  64. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +10 -21
  65. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +15 -12
  66. data/platform/android/Rhodes/src/com/rhomobile/rhodes/phonebook/Phonebook.java +44 -0
  67. data/platform/android/Rhodes/src/com/rhomobile/rhodes/socket/SSLImpl.java +47 -3
  68. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +13 -6
  69. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/TelUriHandler.java +11 -5
  70. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/UriHandler.java +1 -4
  71. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/VideoUriHandler.java +61 -0
  72. data/platform/android/build/RhodesSRC_build.files +3 -0
  73. data/platform/android/build/android.rake +173 -60
  74. data/platform/android/build/androidcommon.rb +1 -2
  75. data/platform/android/build/librhocommon_build.files +5 -0
  76. data/platform/android/build/librhodes_build.files +2 -0
  77. data/platform/android/build/libruby_build.files +2 -1
  78. data/platform/bb/Hsqldb/Hsqldb.jdp +0 -3
  79. data/platform/bb/Hsqldb/src/com/rho/db/FileUtilBB.java +1 -1
  80. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +16 -1
  81. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBRowResult.java +5 -0
  82. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBStorage.java +25 -4
  83. data/platform/bb/Hsqldb/src/com/rho/db/Journal.java +1 -1
  84. data/platform/bb/Hsqldb/src/com/rho/file/FileAccessBB.java +0 -1
  85. data/platform/bb/Hsqldb/src/j2me/math/Number.java +6 -3
  86. data/platform/bb/Hsqldb/src/org/hsqldb/CompiledStatementExecutor.java +2 -1
  87. data/platform/bb/Hsqldb/src/org/hsqldb/Expression.java +1 -0
  88. data/platform/bb/Hsqldb/src/org/hsqldb/Parser.java +1 -0
  89. data/platform/bb/Hsqldb/src/org/hsqldb/Result.java +2 -0
  90. data/platform/bb/Hsqldb/src/org/hsqldb/Select.java +12 -6
  91. data/platform/bb/Hsqldb/src/org/hsqldb/Session.java +19 -12
  92. data/platform/bb/Hsqldb/src/org/hsqldb/Table.java +10 -4
  93. data/platform/bb/Hsqldb/src/org/hsqldb/Token.java +10 -2
  94. data/platform/bb/Hsqldb/src/org/hsqldb/Tokenizer.java +3 -3
  95. data/platform/bb/Hsqldb/src/org/hsqldb/lib/java/JavaSystem.java +1 -1
  96. data/platform/bb/Hsqldb/src/org/hsqldb/persist/HsqlProperties.java +2 -1
  97. data/platform/bb/Hsqldb/src/org/hsqldb/persist/ScaledRAFile.java +1 -1
  98. data/platform/bb/Hsqldb/src/org/hsqldb/scriptio/ScriptReaderText.java +1 -1
  99. data/platform/bb/Hsqldb/src/org/hsqldb/scriptio/ScriptWriterBase.java +1 -1
  100. data/platform/bb/RubyVM/RubyVM.jdp +9 -10
  101. data/platform/bb/build/RubyVM_build.files +9 -7
  102. data/platform/bb/build/bb.rake +13 -3
  103. data/platform/bb/build/hsqldb_build.files +0 -2
  104. data/platform/bb/build/rhodes_build.files +5 -2
  105. data/platform/bb/rhodes/platform/4.7/com/rho/RhoMainScreen.java +8 -0
  106. data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +154 -0
  107. data/platform/bb/rhodes/platform/5.0/com/rho/RhoMainScreen.java +8 -0
  108. data/platform/bb/rhodes/platform/common/com/rho/BrowserAdapter5.java +28 -0
  109. data/platform/bb/rhodes/rhodes.jdp +12 -7
  110. data/platform/bb/rhodes/src/com/rho/BrowserAdapter.java +331 -0
  111. data/platform/bb/rhodes/src/com/rho/BrowserAdapter5.java +28 -0
  112. data/platform/bb/rhodes/src/com/rho/IBrowserAdapter.java +10 -0
  113. data/platform/bb/rhodes/src/com/rho/RhoMainScreen.java +4 -0
  114. data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +2 -4
  115. data/platform/bb/rhodes/src/com/rho/{Jsr75File.java → file/Jsr75File.java} +83 -36
  116. data/platform/bb/{Hsqldb → rhodes}/src/com/rho/file/Jsr75RAFileImpl.java +0 -1
  117. data/platform/bb/{Hsqldb → rhodes}/src/com/rho/file/PersistRAFileImpl.java +0 -2
  118. data/platform/bb/rhodes/src/com/rho/net/NetworkAccess.java +8 -10
  119. data/platform/bb/rhodes/src/com/rho/rubyext/Alert.java +1 -1
  120. data/platform/bb/rhodes/src/com/rho/rubyext/GeoLocation.java +39 -0
  121. data/platform/bb/rhodes/src/com/rho/rubyext/System.java +63 -2
  122. data/platform/bb/rhodes/src/com/rho/rubyext/WebView.java +100 -0
  123. data/platform/bb/rhodes/src/rhomobile/LogScreen.java +1 -1
  124. data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +13 -1
  125. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +138 -492
  126. data/platform/bb/rhodes/src/rhomobile/SecondaryResourceFetchThread.java +11 -2
  127. data/platform/bb/rhodes/src/rhomobile/Utilities.java +14 -10
  128. data/platform/bb/rhodes/src/rhomobile/camera/CameraScreen.java +5 -14
  129. data/platform/bb/rhodes/src/rhomobile/camera/ImageBrowserScreen.java +1 -1
  130. data/platform/bb/rhodes/src/rhomobile/mapview/GoogleMapField.java +2 -2
  131. data/platform/iphone/Classes/AppManager/AppManager.m +37 -14
  132. data/platform/iphone/Classes/Camera/PickImageDelegate.h +15 -4
  133. data/platform/iphone/Classes/Camera/PickImageDelegate.m +53 -50
  134. data/platform/iphone/Classes/DateTimePicker.h +17 -0
  135. data/platform/iphone/Classes/DateTimePicker.m +35 -0
  136. data/platform/iphone/Classes/GeoLocation/LocationController.m +2 -3
  137. data/platform/iphone/Classes/LogOptionsController.m +3 -2
  138. data/platform/iphone/Classes/LogViewController.m +4 -2
  139. data/platform/iphone/Classes/MapView/GoogleGeocoder.m +12 -20
  140. data/platform/iphone/Classes/MapView/MapAnnotation.h +9 -13
  141. data/platform/iphone/Classes/MapView/MapAnnotation.m +17 -65
  142. data/platform/iphone/Classes/MapView/MapViewController.h +1 -7
  143. data/platform/iphone/Classes/MapView/MapViewController.m +51 -25
  144. data/platform/iphone/Classes/NativeBar.h +0 -12
  145. data/platform/iphone/Classes/NativeBar.m +121 -2
  146. data/platform/iphone/Classes/NavBar.h +16 -0
  147. data/platform/iphone/Classes/NavBar.m +115 -0
  148. data/platform/iphone/Classes/RhoAlert.h +19 -0
  149. data/platform/iphone/Classes/RhoAlert.m +258 -0
  150. data/platform/iphone/Classes/RhoDelegate.m +1 -0
  151. data/platform/iphone/Classes/RhoMainView.h +33 -0
  152. data/platform/iphone/Classes/Rhodes.h +56 -0
  153. data/platform/iphone/Classes/Rhodes.m +533 -0
  154. data/platform/iphone/Classes/RingtoneManager.h +17 -0
  155. data/platform/iphone/Classes/RingtoneManager.m +73 -0
  156. data/platform/iphone/Classes/SimpleMainView.h +30 -0
  157. data/platform/iphone/Classes/SimpleMainView.m +380 -0
  158. data/platform/iphone/Classes/TabbedMainView.h +24 -0
  159. data/platform/iphone/Classes/TabbedMainView.m +202 -0
  160. data/platform/iphone/Classes/WebView.m +123 -0
  161. data/platform/iphone/Classes/rho/net/NetRequestImpl.m +2 -2
  162. data/platform/iphone/Classes/rho/net/sslimpl.cpp +13 -1
  163. data/platform/iphone/Classes/rho/net/sslimpl.h +1 -1
  164. data/platform/iphone/Info.plist +1 -1
  165. data/platform/iphone/RhoLib/RhoLib.xcodeproj/project.pbxproj +44 -0
  166. data/platform/iphone/main.m +1 -2
  167. data/platform/iphone/rbuild/iphone.rake +8 -16
  168. data/platform/iphone/rhoextlib/dosyscall.c +1 -1
  169. data/platform/iphone/rhoextlib/rhoextlib.xcodeproj/project.pbxproj +6 -4
  170. data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +12 -0
  171. data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +97 -62
  172. data/platform/iphone/rhosynclib/rhosynclib.xcodeproj/project.pbxproj +12 -0
  173. data/platform/osx/Rhodes Launcher/launch.rb +14 -21
  174. data/platform/shared/common/AppMenu.cpp +122 -0
  175. data/platform/shared/common/AppMenu.h +46 -0
  176. data/platform/shared/common/PosixThreadImpl.cpp +1 -1
  177. data/platform/shared/common/RhoConf.cpp +27 -2
  178. data/platform/shared/common/RhoConf.h +5 -0
  179. data/platform/shared/common/RhoFilePath.h +21 -0
  180. data/platform/shared/common/RhoStd.h +44 -5
  181. data/platform/shared/common/RhoTime.h +20 -7
  182. data/platform/shared/common/RhodesApp.cpp +236 -177
  183. data/platform/shared/common/RhodesApp.h +36 -13
  184. data/platform/shared/common/SplashScreen.cpp +2 -2
  185. data/platform/shared/common/StringConverter.h +10 -11
  186. data/platform/shared/common/rhoparams.c +0 -6
  187. data/platform/shared/curl/lib/rhossl.c +3 -2
  188. data/platform/shared/curl/lib/url.c +0 -5
  189. data/platform/shared/db/DBAdapter.cpp +304 -81
  190. data/platform/shared/db/DBAdapter.h +24 -7
  191. data/platform/shared/db/DBAttrManager.cpp +83 -30
  192. data/platform/shared/db/DBAttrManager.h +6 -0
  193. data/platform/shared/db/DBResult.h +15 -4
  194. data/platform/shared/json/JSONIterator.cpp +100 -3
  195. data/platform/shared/json/JSONIterator.h +28 -3
  196. data/platform/shared/net/AsyncHttp.cpp +25 -22
  197. data/platform/shared/net/AsyncHttp.h +10 -6
  198. data/platform/shared/net/CURLNetRequest.cpp +115 -36
  199. data/platform/shared/net/CURLNetRequest.h +6 -0
  200. data/platform/shared/net/HttpServer.cpp +6 -4
  201. data/platform/shared/net/HttpServer.h +0 -1
  202. data/platform/shared/net/INetRequest.h +19 -3
  203. data/platform/shared/net/URI.cpp +2 -2
  204. data/platform/shared/net/ssl.cpp +2 -2
  205. data/platform/shared/net/ssl.h +2 -2
  206. data/platform/shared/ruby/ext/alert/alert.i +14 -2
  207. data/platform/shared/ruby/ext/alert/alert_wrap.c +40 -20
  208. data/platform/shared/ruby/ext/asynchttp/asynchttp.i +8 -8
  209. data/platform/shared/ruby/ext/asynchttp/asynchttp_wrap.c +112 -16
  210. data/platform/shared/ruby/ext/geolocation/geolocation.i +16 -12
  211. data/platform/shared/ruby/ext/geolocation/geolocation_wrap.c +481 -125
  212. data/platform/shared/ruby/ext/navbar/navbar.i +20 -0
  213. data/platform/shared/ruby/ext/navbar/navbar_wrap.c +1859 -0
  214. data/platform/shared/ruby/ext/rho/extensions.c +1 -1
  215. data/platform/shared/ruby/ext/rho/rhoruby.c +32 -2
  216. data/platform/shared/ruby/ext/rho/rhoruby.h +7 -2
  217. data/platform/shared/ruby/ext/rhoconf/rhoconf.i +4 -0
  218. data/platform/shared/ruby/ext/rhoconf/rhoconf_wrap.c +31 -0
  219. data/platform/shared/ruby/ext/sqlite3_api/sqlite3_api_wrap.c +188 -3226
  220. data/platform/shared/ruby/ext/syncengine/syncengine.i +14 -25
  221. data/platform/shared/ruby/ext/syncengine/syncengine_wrap.c +96 -104
  222. data/platform/shared/ruby/ext/system/system.i +12 -0
  223. data/platform/shared/ruby/ext/system/system_wrap.c +101 -7
  224. data/platform/shared/ruby/ext/webview/webview.i +20 -15
  225. data/platform/shared/ruby/ext/webview/webview_wrap.c +42 -16
  226. data/platform/shared/ruby/thread_pthread.c +4 -4
  227. data/platform/shared/ruby/thread_win32.c +4 -4
  228. data/platform/shared/ruby/wince/io_wce.c +0 -1
  229. data/platform/shared/rubyJVM/src/com/rho/FilePath.java +18 -2
  230. data/platform/shared/rubyJVM/src/com/rho/IRhoRubyHelper.java +1 -0
  231. data/platform/shared/rubyJVM/src/com/rho/Properties.java +9 -0
  232. data/platform/shared/rubyJVM/src/com/rho/RhoClassFactory.java +2 -3
  233. data/platform/shared/rubyJVM/src/com/rho/RhoConf.java +47 -8
  234. data/platform/shared/rubyJVM/src/com/rho/RhoLogConf.java +1 -0
  235. data/platform/shared/rubyJVM/src/com/rho/RhoLogFileSink.java +1 -0
  236. data/platform/shared/rubyJVM/src/com/rho/RhoRuby.java +43 -5
  237. data/platform/shared/rubyJVM/src/com/rho/RhodesApp.java +98 -3
  238. data/platform/shared/rubyJVM/src/com/rho/db/DBAdapter.java +460 -175
  239. data/platform/shared/rubyJVM/src/com/rho/db/DBAttrManager.java +81 -33
  240. data/platform/shared/rubyJVM/src/com/rho/db/IDBCallback.java +3 -5
  241. data/platform/shared/rubyJVM/src/com/rho/db/IDBResult.java +2 -0
  242. data/platform/shared/rubyJVM/src/com/rho/db/IDBStorage.java +2 -0
  243. data/platform/shared/rubyJVM/src/com/rho/{IFile.java → file/IFile.java} +1 -1
  244. data/platform/shared/rubyJVM/src/com/rho/{IFileAccess.java → file/IFileAccess.java} +1 -1
  245. data/platform/shared/rubyJVM/src/com/rho/{IRAFile.java → file/IRAFile.java} +1 -1
  246. data/platform/{bb/Hsqldb/src/com/rho/db → shared/rubyJVM/src/com/rho/file}/RandomAccessFile.java +1 -2
  247. data/platform/shared/rubyJVM/src/com/rho/{SimpleFile.java → file/SimpleFile.java} +5 -1
  248. data/platform/shared/rubyJVM/src/com/rho/net/AsyncHttp.java +23 -18
  249. data/platform/shared/rubyJVM/src/com/rho/net/NetRequest.java +167 -250
  250. data/platform/shared/rubyJVM/src/com/rho/net/RhoConnection.java +100 -30
  251. data/platform/shared/rubyJVM/src/com/rho/net/URI.java +0 -1
  252. data/platform/shared/rubyJVM/src/com/rho/sync/ClientRegister.java +30 -33
  253. data/platform/shared/rubyJVM/src/com/rho/sync/ISyncProtocol.java +20 -0
  254. data/platform/shared/rubyJVM/src/com/rho/sync/JSONEntry.java +5 -0
  255. data/platform/shared/rubyJVM/src/com/rho/sync/JSONStructIterator.java +74 -0
  256. data/platform/shared/rubyJVM/src/com/rho/sync/SyncEngine.java +486 -257
  257. data/platform/shared/rubyJVM/src/com/rho/sync/SyncNotify.java +89 -58
  258. data/platform/shared/rubyJVM/src/com/rho/sync/SyncProtocol_3.java +79 -0
  259. data/platform/shared/rubyJVM/src/com/rho/sync/SyncSource.java +634 -495
  260. data/platform/shared/rubyJVM/src/com/rho/sync/SyncThread.java +74 -90
  261. data/platform/shared/rubyJVM/src/com/xruby/GeneratedMethods/RubySymbol_Methods.java +1 -0
  262. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyThread.java +6 -0
  263. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyRuntime.java +6 -2
  264. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubySymbol.java +17 -1
  265. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyValue.java +1 -0
  266. data/platform/shared/rubyJVM/src/org/json/me/JSONObject.java +3 -0
  267. data/platform/shared/rubyext/GeoLocation.cpp +23 -0
  268. data/platform/shared/rubyext/GeoLocation.h +2 -0
  269. data/platform/shared/rubyext/RhoRuby.cpp +31 -0
  270. data/platform/shared/rubyext/RhoRuby.h +32 -0
  271. data/platform/shared/rubyext/System.cpp +14 -3
  272. data/platform/shared/rubyext/WebView.h +21 -0
  273. data/platform/shared/sync/ClientRegister.cpp +23 -28
  274. data/platform/shared/sync/ClientRegister.h +6 -2
  275. data/platform/shared/sync/ISyncProtocol.h +29 -0
  276. data/platform/shared/sync/SyncEngine.cpp +450 -190
  277. data/platform/shared/sync/SyncEngine.h +28 -38
  278. data/platform/shared/sync/SyncNotify.cpp +43 -41
  279. data/platform/shared/sync/SyncNotify.h +7 -7
  280. data/platform/shared/sync/SyncProtocol_3.h +86 -0
  281. data/platform/shared/sync/SyncSource.cpp +535 -371
  282. data/platform/shared/sync/SyncSource.h +48 -55
  283. data/platform/shared/sync/SyncThread.cpp +59 -103
  284. data/platform/shared/sync/SyncThread.h +10 -23
  285. data/platform/shared/unzip/unzip.cpp +3 -2
  286. data/platform/shared/unzip/unzip.h +5 -1
  287. data/platform/shared/wtl80/include/atlapp.h +10 -10
  288. data/platform/wm/RhoLib/RhoLib.vcproj +32 -0
  289. data/platform/wm/build/build_inf.js +40 -3
  290. data/platform/wm/build/wm.rake +95 -9
  291. data/platform/wm/rhodes/Alert.cpp +4 -0
  292. data/platform/wm/rhodes/DateTimePicker.cpp +183 -0
  293. data/platform/wm/rhodes/DateTimePicker.h +100 -0
  294. data/platform/wm/rhodes/MainWindow.cpp +222 -209
  295. data/platform/wm/rhodes/MainWindow.h +28 -35
  296. data/platform/wm/rhodes/Rhodes.cpp +20 -60
  297. data/platform/wm/rhodes/Rhodes.rc +41 -7
  298. data/platform/wm/rhodes/Utils.cpp +65 -0
  299. data/platform/wm/rhodes/Utils.h +9 -0
  300. data/platform/wm/rhodes/camera/Camera.cpp +2 -2
  301. data/platform/wm/rhodes/menubar.cpp +2 -33
  302. data/platform/wm/rhodes/menubar.h +0 -14
  303. data/platform/wm/rhodes/resource.h +13 -11
  304. data/platform/wm/rhodes/rho/net/NetRequest.cpp +16 -35
  305. data/platform/wm/rhodes/rho/net/NetRequest.h +8 -2
  306. data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +264 -46
  307. data/platform/wm/rhodes/rho/net/NetRequestImpl.h +14 -4
  308. data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.cpp +1 -1
  309. data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.h +1 -1
  310. data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +77 -4
  311. data/platform/wm/rhodes/rho/rubyext/WebView.cpp +63 -0
  312. data/platform/wm/rhodes/rhodes.vcproj +20 -66
  313. data/platform/wm/rhodes/stdafx.h +22 -0
  314. data/platform/wm/rubylib/rubylib.vcproj +4 -0
  315. data/platform/wm/syncengine/syncengine.vcproj +8 -0
  316. data/platform/wm/tools/detool.sln +66 -0
  317. data/platform/wm/tools/detool/DEMComInterface.tlb +0 -0
  318. data/platform/wm/tools/detool/ReadMe.txt +33 -0
  319. data/platform/wm/tools/detool/detool.cpp +559 -0
  320. data/platform/wm/tools/detool/detool.h +5 -0
  321. data/platform/wm/tools/detool/detool.vcproj +233 -0
  322. data/platform/wm/tools/detool/stdafx.cpp +8 -0
  323. data/platform/wm/tools/detool/stdafx.h +15 -0
  324. data/platform/wm/tools/detool/targetver.h +24 -0
  325. data/platform/wm/tools/rhosetup/ReadMe.txt +41 -0
  326. data/platform/wm/tools/rhosetup/rhosetup.cpp +52 -0
  327. data/platform/wm/tools/rhosetup/rhosetup.vcproj +641 -0
  328. data/platform/wm/tools/rhosetup/stdafx.cpp +8 -0
  329. data/platform/wm/tools/rhosetup/stdafx.h +59 -0
  330. data/rakefile.rb +33 -10
  331. data/res/build-tools/db/syncdb.schema +25 -23
  332. data/res/build-tools/db/syncdb.triggers +1 -1
  333. data/res/build-tools/detool.exe +0 -0
  334. data/res/build-tools/rhosetup.dll +0 -0
  335. data/res/generators/rhogen.rb +27 -22
  336. data/res/generators/templates/application/app/Settings/controller.rb +3 -1
  337. data/res/generators/templates/application/app/Settings/home.bb.erb +17 -0
  338. data/res/generators/templates/application/app/Settings/home.erb +21 -12
  339. data/res/generators/templates/application/app/Settings/index.bb.erb +32 -0
  340. data/res/generators/templates/application/app/Settings/index.erb +44 -15
  341. data/res/generators/templates/application/app/Settings/login.bb.erb +35 -0
  342. data/res/generators/templates/application/app/Settings/login.erb +29 -30
  343. data/res/generators/templates/application/app/Settings/reset.bb.erb +15 -0
  344. data/res/generators/templates/application/app/Settings/reset.erb +16 -13
  345. data/res/generators/templates/application/app/Settings/wait.bb.erb +3 -0
  346. data/res/generators/templates/application/app/Settings/wait.erb +4 -4
  347. data/res/generators/templates/application/app/application.rb +8 -0
  348. data/res/generators/templates/application/app/helpers/browser_helper.rb +13 -0
  349. data/res/generators/templates/application/app/index.bb.erb +26 -0
  350. data/res/generators/templates/application/app/index.erb +21 -12
  351. data/res/generators/templates/application/app/layout.erb +9 -11
  352. data/res/generators/templates/application/public/css/android.css +285 -0
  353. data/res/generators/templates/application/public/css/blackberry.css +85 -78
  354. data/res/generators/templates/application/public/css/iphone.css +286 -296
  355. data/res/generators/templates/application/public/css/webkit.css +34 -0
  356. data/res/generators/templates/application/public/css/windows_mobile.css +208 -0
  357. data/res/generators/templates/application/public/icons/Read me first - license.txt +14 -0
  358. data/res/generators/templates/application/public/icons/about.png +0 -0
  359. data/res/generators/templates/application/public/icons/airplane.png +0 -0
  360. data/res/generators/templates/application/public/icons/baby.png +0 -0
  361. data/res/generators/templates/application/public/icons/badge.png +0 -0
  362. data/res/generators/templates/application/public/icons/bandaid.png +0 -0
  363. data/res/generators/templates/application/public/icons/bar-chart.png +0 -0
  364. data/res/generators/templates/application/public/icons/battery.png +0 -0
  365. data/res/generators/templates/application/public/icons/beaker.png +0 -0
  366. data/res/generators/templates/application/public/icons/beaker2.png +0 -0
  367. data/res/generators/templates/application/public/icons/beermug.png +0 -0
  368. data/res/generators/templates/application/public/icons/bird.png +0 -0
  369. data/res/generators/templates/application/public/icons/book.png +0 -0
  370. data/res/generators/templates/application/public/icons/bookmark.png +0 -0
  371. data/res/generators/templates/application/public/icons/brightness.png +0 -0
  372. data/res/generators/templates/application/public/icons/bug.png +0 -0
  373. data/res/generators/templates/application/public/icons/cabinet.png +0 -0
  374. data/res/generators/templates/application/public/icons/calendar.png +0 -0
  375. data/res/generators/templates/application/public/icons/camera.png +0 -0
  376. data/res/generators/templates/application/public/icons/changeName.rb +22 -0
  377. data/res/generators/templates/application/public/icons/chat2.png +0 -0
  378. data/res/generators/templates/application/public/icons/chicken.png +0 -0
  379. data/res/generators/templates/application/public/icons/clock.png +0 -0
  380. data/res/generators/templates/application/public/icons/cloud.png +0 -0
  381. data/res/generators/templates/application/public/icons/coffee.png +0 -0
  382. data/res/generators/templates/application/public/icons/compass.png +0 -0
  383. data/res/generators/templates/application/public/icons/contrast.png +0 -0
  384. data/res/generators/templates/application/public/icons/dashboard.png +0 -0
  385. data/res/generators/templates/application/public/icons/display.png +0 -0
  386. data/res/generators/templates/application/public/icons/dogpaw.png +0 -0
  387. data/res/generators/templates/application/public/icons/download.png +0 -0
  388. data/res/generators/templates/application/public/icons/dumbbell.png +0 -0
  389. data/res/generators/templates/application/public/icons/ekg.png +0 -0
  390. data/res/generators/templates/application/public/icons/envelope.png +0 -0
  391. data/res/generators/templates/application/public/icons/equalizer.png +0 -0
  392. data/res/generators/templates/application/public/icons/eye.png +0 -0
  393. data/res/generators/templates/application/public/icons/film-roll.png +0 -0
  394. data/res/generators/templates/application/public/icons/flag.png +0 -0
  395. data/res/generators/templates/application/public/icons/fork-and-knife.png +0 -0
  396. data/res/generators/templates/application/public/icons/fuel.png +0 -0
  397. data/res/generators/templates/application/public/icons/gameplan.png +0 -0
  398. data/res/generators/templates/application/public/icons/gear.png +0 -0
  399. data/res/generators/templates/application/public/icons/gear2.png +0 -0
  400. data/res/generators/templates/application/public/icons/gift.png +0 -0
  401. data/res/generators/templates/application/public/icons/heart.png +0 -0
  402. data/res/generators/templates/application/public/icons/house.png +0 -0
  403. data/res/generators/templates/application/public/icons/inbox.png +0 -0
  404. data/res/generators/templates/application/public/icons/index-cards.png +0 -0
  405. data/res/generators/templates/application/public/icons/iphone.png +0 -0
  406. data/res/generators/templates/application/public/icons/ipod.png +0 -0
  407. data/res/generators/templates/application/public/icons/key.png +0 -0
  408. data/res/generators/templates/application/public/icons/lifebuoy.png +0 -0
  409. data/res/generators/templates/application/public/icons/lightbulb.png +0 -0
  410. data/res/generators/templates/application/public/icons/line-chart.png +0 -0
  411. data/res/generators/templates/application/public/icons/location.png +0 -0
  412. data/res/generators/templates/application/public/icons/lock.png +0 -0
  413. data/res/generators/templates/application/public/icons/loopback.png +0 -0
  414. data/res/generators/templates/application/public/icons/magnifying-glass.png +0 -0
  415. data/res/generators/templates/application/public/icons/map-marker.png +0 -0
  416. data/res/generators/templates/application/public/icons/map.png +0 -0
  417. data/res/generators/templates/application/public/icons/medical-bag.png +0 -0
  418. data/res/generators/templates/application/public/icons/medical.png +0 -0
  419. data/res/generators/templates/application/public/icons/microphone.png +0 -0
  420. data/res/generators/templates/application/public/icons/movie1.png +0 -0
  421. data/res/generators/templates/application/public/icons/movie2.png +0 -0
  422. data/res/generators/templates/application/public/icons/network.png +0 -0
  423. data/res/generators/templates/application/public/icons/note.png +0 -0
  424. data/res/generators/templates/application/public/icons/outlet.png +0 -0
  425. data/res/generators/templates/application/public/icons/palette.png +0 -0
  426. data/res/generators/templates/application/public/icons/paperclip.png +0 -0
  427. data/res/generators/templates/application/public/icons/phone.png +0 -0
  428. data/res/generators/templates/application/public/icons/photos.png +0 -0
  429. data/res/generators/templates/application/public/icons/piano.png +0 -0
  430. data/res/generators/templates/application/public/icons/picture-frame.png +0 -0
  431. data/res/generators/templates/application/public/icons/pill.png +0 -0
  432. data/res/generators/templates/application/public/icons/pin.png +0 -0
  433. data/res/generators/templates/application/public/icons/pinetree.png +0 -0
  434. data/res/generators/templates/application/public/icons/planet.png +0 -0
  435. data/res/generators/templates/application/public/icons/puzzle.png +0 -0
  436. data/res/generators/templates/application/public/icons/radar.png +0 -0
  437. data/res/generators/templates/application/public/icons/redo.png +0 -0
  438. data/res/generators/templates/application/public/icons/refresh.png +0 -0
  439. data/res/generators/templates/application/public/icons/runner.png +0 -0
  440. data/res/generators/templates/application/public/icons/shoebox.png +0 -0
  441. data/res/generators/templates/application/public/icons/shopping-bag.png +0 -0
  442. data/res/generators/templates/application/public/icons/shopping-cart.png +0 -0
  443. data/res/generators/templates/application/public/icons/shuffle.png +0 -0
  444. data/res/generators/templates/application/public/icons/signpost.png +0 -0
  445. data/res/generators/templates/application/public/icons/skull-n-crossbones.png +0 -0
  446. data/res/generators/templates/application/public/icons/skull.png +0 -0
  447. data/res/generators/templates/application/public/icons/sliders.png +0 -0
  448. data/res/generators/templates/application/public/icons/spraycan.png +0 -0
  449. data/res/generators/templates/application/public/icons/squiggle.png +0 -0
  450. data/res/generators/templates/application/public/icons/star.png +0 -0
  451. data/res/generators/templates/application/public/icons/stopwatch.png +0 -0
  452. data/res/generators/templates/application/public/icons/suitcase.png +0 -0
  453. data/res/generators/templates/application/public/icons/tag.png +0 -0
  454. data/res/generators/templates/application/public/icons/tags.png +0 -0
  455. data/res/generators/templates/application/public/icons/target.png +0 -0
  456. data/res/generators/templates/application/public/icons/testtube.png +0 -0
  457. data/res/generators/templates/application/public/icons/thermometer.png +0 -0
  458. data/res/generators/templates/application/public/icons/toolbox.png +0 -0
  459. data/res/generators/templates/application/public/icons/trophy.png +0 -0
  460. data/res/generators/templates/application/public/icons/tshirt.png +0 -0
  461. data/res/generators/templates/application/public/icons/tv.png +0 -0
  462. data/res/generators/templates/application/public/icons/umbrella.png +0 -0
  463. data/res/generators/templates/application/public/icons/walk.png +0 -0
  464. data/res/generators/templates/application/public/icons/weather.png +0 -0
  465. data/res/generators/templates/application/public/icons/widescreen.png +0 -0
  466. data/res/generators/templates/application/public/icons/wineglass.png +0 -0
  467. data/res/generators/templates/application/public/icons/zap.png +0 -0
  468. data/res/generators/templates/application/public/images/android/btn_check_off.png +0 -0
  469. data/res/generators/templates/application/public/images/android/btn_check_on.png +0 -0
  470. data/res/generators/templates/application/public/images/android/btn_radio_off.png +0 -0
  471. data/res/generators/templates/application/public/images/android/btn_radio_on.png +0 -0
  472. data/res/generators/templates/application/public/images/android/ic_menu_more.png +0 -0
  473. data/res/generators/templates/application/public/images/iphone/disclosure.png +0 -0
  474. data/res/generators/templates/application/public/images/iphone/disclosure_detail.png +0 -0
  475. data/res/generators/templates/application/public/images/iphone/radiobutton.png +0 -0
  476. data/res/generators/templates/application/public/images/iphone/select.png +0 -0
  477. data/res/generators/templates/application/public/images/iphone/switch.png +0 -0
  478. data/res/generators/templates/application/public/images/listArrow.png +0 -0
  479. data/res/generators/templates/application/public/images/listArrowDown.png +0 -0
  480. data/res/generators/templates/model/controller.rb +2 -0
  481. data/res/generators/templates/model/edit.bb.erb +24 -0
  482. data/res/generators/templates/model/edit.erb +21 -25
  483. data/res/generators/templates/model/index.bb.erb +21 -0
  484. data/res/generators/templates/model/index.erb +28 -14
  485. data/res/generators/templates/model/new.bb.erb +24 -0
  486. data/res/generators/templates/model/new.erb +20 -20
  487. data/res/generators/templates/model/show.bb.erb +21 -0
  488. data/res/generators/templates/model/show.erb +15 -15
  489. data/rhobuild.yml +37 -0
  490. data/rhodes.gemspec +1 -1
  491. data/spec/framework_spec/app/Account/config.rb +57 -1
  492. data/spec/framework_spec/app/Case/config.rb +1 -1
  493. data/spec/framework_spec/app/Customer/config.rb +1 -1
  494. data/spec/framework_spec/app/Product/config.rb +15 -1
  495. data/spec/framework_spec/app/spec/fixtures/object_values.txt +90 -90
  496. data/spec/framework_spec/app/spec/pagination/fixtures/object_values.txt +91 -91
  497. data/spec/framework_spec/app/spec/rho_spec.rb +1 -1
  498. data/spec/framework_spec/app/spec/rhom_object_spec.rb +47 -28
  499. data/spec/framework_spec/app/spec/rhom_spec.rb +8 -8
  500. data/spec/framework_spec/app/spec/spec_helper.rb +13 -5
  501. data/spec/framework_spec/app/spec_runner.rb +5 -4
  502. data/spec/framework_spec/public/css/base.css +0 -1
  503. data/spec/framework_spec/public/css/iphone.css +0 -1
  504. data/spec/framework_spec/rhoconfig.txt +3 -1
  505. metadata +220 -37
  506. data/platform/bb/rhodes/src/rhomobile/WebView.java +0 -90
  507. data/platform/iphone/Classes/BarItem.h +0 -27
  508. data/platform/iphone/Classes/BarItem.m +0 -32
  509. data/platform/iphone/Classes/JSString.h +0 -12
  510. data/platform/iphone/Classes/JSString.m +0 -7
  511. data/platform/iphone/Classes/RhoRunnerAppDelegate.h +0 -48
  512. data/platform/iphone/Classes/RhoRunnerAppDelegate.m +0 -617
  513. data/platform/iphone/Classes/Server/ServerHost.h +0 -81
  514. data/platform/iphone/Classes/Server/ServerHost.m +0 -597
  515. data/platform/iphone/Classes/Server/WebViewUrl.h +0 -13
  516. data/platform/iphone/Classes/Server/WebViewUrl.m +0 -8
  517. data/platform/iphone/Classes/TabBarDelegate.h +0 -39
  518. data/platform/iphone/Classes/TabBarDelegate.m +0 -151
  519. data/platform/iphone/Classes/Utils/unzip.cpp +0 -4328
  520. data/platform/iphone/Classes/Utils/unzip.h +0 -234
  521. data/platform/iphone/Classes/WebViewController.h +0 -59
  522. data/platform/iphone/Classes/WebViewController.m +0 -472
  523. data/platform/wm/rhodes/GetURLDialog.cpp +0 -64
  524. data/platform/wm/rhodes/GetURLDialog.h +0 -39
  525. data/res/generators/templates/application/public/css/base.css +0 -39
  526. data/res/generators/templates/application/public/css/rho.css +0 -3
  527. data/res/generators/templates/application/public/css/xhtml.css +0 -114
  528. data/spec/framework_spec/app/Question/config.rb +0 -3
  529. data/spec/generator_spec/source_generator_spec.rb +0 -27
@@ -68,6 +68,8 @@ void rho_geo_callcallback();
68
68
  void rho_geo_callcallback_error();
69
69
  int rho_geo_gettimeout_sec();
70
70
 
71
+ double rho_geo_haversine_distance(double lat1, double lon1, double lat2, double lon2);
72
+
71
73
  #ifdef __cplusplus
72
74
  };
73
75
  #endif //__cplusplus
@@ -0,0 +1,31 @@
1
+ #include "RhoRuby.h"
2
+ #include "ruby/ext/rho/rhoruby.h"
3
+
4
+ namespace rho {
5
+ const _CRhoRuby& RhoRuby = _CRhoRuby();
6
+
7
+ /*static*/ String _CRhoRuby::getMessageText(const char* szName)
8
+ {
9
+ return rho_ruby_getMessageText(szName);
10
+ }
11
+
12
+ /*static*/ String _CRhoRuby::getErrorText(int nError)
13
+ {
14
+ return rho_ruby_getErrorText(nError);
15
+ }
16
+
17
+ /*static*/ int _CRhoRuby::getErrorFromResponse(net::INetResponse& resp)
18
+ {
19
+ if ( !resp.isResponseRecieved())
20
+ return RhoRuby.ERR_NETWORK;
21
+
22
+ if ( resp.isUnathorized() )
23
+ return RhoRuby.ERR_UNATHORIZED;
24
+
25
+ if ( !resp.isOK() )
26
+ return RhoRuby.ERR_REMOTESERVER;
27
+
28
+ return RhoRuby.ERR_NONE;
29
+ }
30
+
31
+ }
@@ -0,0 +1,32 @@
1
+ #ifndef _RHORUBY_H_
2
+ #define _RHORUBY_H_
3
+
4
+ #include "common/RhoStd.h"
5
+ #include "net/INetRequest.h"
6
+ #include "ruby/ext/rho/rhoruby.h"
7
+
8
+ namespace rho {
9
+ struct _CRhoRuby {
10
+ static const int ERR_NONE = 0;
11
+ static const int ERR_NETWORK = 1;
12
+ static const int ERR_REMOTESERVER = 2;
13
+ static const int ERR_RUNTIME = 3;
14
+ static const int ERR_UNEXPECTEDSERVERRESPONSE = 4;
15
+ static const int ERR_DIFFDOMAINSINSYNCSRC = 5;
16
+ static const int ERR_NOSERVERRESPONSE = 6;
17
+ static const int ERR_CLIENTISNOTLOGGEDIN = 7;
18
+ static const int ERR_CUSTOMSYNCSERVER = 8;
19
+ static const int ERR_UNATHORIZED = 9;
20
+ static const int ERR_CANCELBYUSER = 10;
21
+ static const int ERR_SYNCVERSION = 11;
22
+ static const int ERR_GEOLOCATION = 12;
23
+
24
+ static String getMessageText(const char* szName);
25
+ static String getErrorText(int nError);
26
+ static int getErrorFromResponse(net::INetResponse& resp);
27
+
28
+ };
29
+ extern const _CRhoRuby& RhoRuby;
30
+ }
31
+
32
+ #endif //_RHORUBY_H_
@@ -1,13 +1,14 @@
1
1
  #include "common/RhoPort.h"
2
2
  #include "ruby/ext/rho/rhoruby.h"
3
3
  #include "sync/ClientRegister.h"
4
+ #include "common/RhodesApp.h"
4
5
  #include "logging/RhoLog.h"
5
6
  #undef DEFAULT_LOGCATEGORY
6
7
  #define DEFAULT_LOGCATEGORY "RhoSystem"
7
8
 
8
9
  extern "C"
9
10
  {
10
- extern VALUE rho_sysimpl_get_property(char* szPropName);
11
+ extern int rho_sysimpl_get_property(char* szPropName, VALUE* resValue);
11
12
  extern VALUE rho_sys_has_network();
12
13
  extern VALUE rho_sys_get_locale();
13
14
  extern int rho_sys_get_screen_width();
@@ -35,8 +36,8 @@ VALUE rho_sys_get_property(char* szPropName)
35
36
  if (!szPropName || !*szPropName)
36
37
  return rho_ruby_get_NIL();
37
38
 
38
- VALUE res = rho_sysimpl_get_property(szPropName);
39
- if (res)
39
+ VALUE res;
40
+ if (rho_sysimpl_get_property(szPropName, &res))
40
41
  return res;
41
42
 
42
43
  if (strcasecmp("platform",szPropName) == 0)
@@ -71,4 +72,14 @@ VALUE rho_sys_get_property(char* szPropName)
71
72
  return rho_ruby_get_NIL();
72
73
  }
73
74
 
75
+ void rho_sys_set_push_notification(const char *url, const char* params)
76
+ {
77
+ RHODESAPP().setPushNotification(url, params);
74
78
  }
79
+
80
+ void rho_sys_set_screen_rotation_notification(const char *url, const char* params)
81
+ {
82
+ RHODESAPP().setScreenRotationNotification(url, params);
83
+ }
84
+
85
+ } //extern "C"
@@ -0,0 +1,21 @@
1
+ #ifndef _RHOWEBVIEW_H_
2
+ #define _RHOWEBVIEW_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif //__cplusplus
7
+
8
+ void rho_webview_refresh(int index);
9
+ void rho_webview_navigate(const char* url, int index);
10
+ void rho_webview_navigate_back();
11
+ const char* rho_webview_execute_js(const char* js, int index);
12
+ const char* rho_webview_current_location(int index);
13
+ int rho_webview_active_tab();
14
+ void rho_webview_set_menu_items(VALUE valMenu);
15
+ void rho_webview_full_screen_mode(int enable);
16
+
17
+ #ifdef __cplusplus
18
+ };
19
+ #endif //__cplusplus
20
+
21
+ #endif //_RHOWEBVIEW_H_
@@ -1,12 +1,12 @@
1
1
  #include "ClientRegister.h"
2
2
  #include "sync/SyncThread.h"
3
3
  #include "common/RhoConf.h"
4
- #include "common/StringConverter.h"
5
4
 
6
5
  namespace rho{
7
6
  namespace sync{
8
7
 
9
8
  using namespace rho::common;
9
+ using namespace rho::db;
10
10
 
11
11
  #define THREAD_WAIT_TIMEOUT 10
12
12
 
@@ -37,9 +37,12 @@ CClientRegister::CClientRegister(common::IRhoClassFactory* factory,const char* d
37
37
 
38
38
  m_strDevicePin = device_pin;
39
39
  m_NetRequest = factory->createNetRequest();
40
+ m_nPollInterval = POLL_INTERVAL_SECONDS;
40
41
 
41
42
  delete factory;
42
- start(epLow);
43
+
44
+ if ( RHOCONF().getString("syncserver").length() > 0 )
45
+ start(epLow);
43
46
  }
44
47
 
45
48
  CClientRegister::~CClientRegister()
@@ -61,34 +64,35 @@ void CClientRegister::run()
61
64
  break;
62
65
  }
63
66
 
64
- LOG(INFO)+"Waiting for "+ POLL_INTERVAL_SECONDS+ " sec to try again to register client";
65
- wait(POLL_INTERVAL_SECONDS);
67
+ LOG(INFO)+"Waiting for "+ m_nPollInterval+ " sec to try again to register client";
68
+ wait(m_nPollInterval);
66
69
  }
67
70
  LOG(INFO)+"ClientRegister thread shutdown";
68
71
  }
69
72
 
70
- String CClientRegister::getRegisterBody()
73
+ String CClientRegister::getRegisterBody(const String& strClientID)
71
74
  {
72
75
  int port = RHOCONF().getInt("push_port");
73
76
 
74
- String strBody = "device_pin=" + m_strDevicePin +
75
- "&device_port=" + convertToStringA(port > 0 ? port : DEFAULT_PUSH_PORT) +
76
- "&device_type=" + m_sysInfo->getPlatform();
77
-
78
- return strBody;
77
+ return CSyncThread::getSyncEngine().getProtocol().getClientRegisterBody( strClientID, m_strDevicePin,
78
+ port > 0 ? port : DEFAULT_PUSH_PORT, m_sysInfo->getPlatform());
79
79
  }
80
80
 
81
81
  boolean CClientRegister::doRegister(CSyncEngine& oSync)
82
82
  {
83
83
  String session = oSync.loadSession();
84
84
  if ( session.length() == 0 )
85
+ {
86
+ m_nPollInterval = POLL_INTERVAL_INFINITE;
85
87
  return false;
86
-
88
+ }
89
+ m_nPollInterval = POLL_INTERVAL_SECONDS;
90
+
87
91
  String client_id = oSync.loadClientID();
88
92
  if ( client_id.length() == 0 )
89
93
  return false;
90
94
 
91
- DBResult( res, oSync.getDB().executeSQL("SELECT token,token_sent from client_info") );
95
+ DBResult( res, CDBAdapter::getUserDB().executeSQL("SELECT token,token_sent from client_info") );
92
96
  if ( !res.isEnd() ) {
93
97
  String token = res.getStringByIdx(0);
94
98
  int token_sent = res.getIntByIdx(1);
@@ -99,28 +103,19 @@ boolean CClientRegister::doRegister(CSyncEngine& oSync)
99
103
  return true;
100
104
  }
101
105
  }
102
-
103
- String serverUrl = RHOCONF().getPath("syncserver");
104
- if (serverUrl.length()>0)
106
+ String strBody = getRegisterBody(client_id);
107
+ NetResponse(resp, getNet().pushData( oSync.getProtocol().getClientRegisterUrl(), strBody, &oSync ));
108
+ if( resp.isOK() )
105
109
  {
106
- String strBody = getRegisterBody();
107
- strBody += "&client_id=" + client_id;
108
-
109
- NetResponse(resp, getNet().pushData(serverUrl+"clientregister", strBody, &oSync ));
110
- if( resp.isOK() )
111
- {
112
110
  // try {
113
- oSync.getDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", 1, m_strDevicePin );
111
+ CDBAdapter::getUserDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", 1, m_strDevicePin );
114
112
  // } catch(Exception ex) {
115
113
  // LOG.ERROR("Error saving token_sent to the DB...");
116
114
  // }
117
- LOG(INFO)+"Registered client sucessfully...";
118
- return true;
119
- } else {
120
- LOG(INFO)+"Network error POST-ing device pin to the server...";
121
- }
115
+ LOG(INFO)+"Registered client sucessfully...";
116
+ return true;
122
117
  } else {
123
- LOG(INFO)+"Can't register client because syncserver url is not configured...";
118
+ LOG(INFO)+"Network error POST-ing device pin to the server...";
124
119
  }
125
120
 
126
121
  return false;
@@ -14,6 +14,7 @@ class CSyncEngine;
14
14
 
15
15
  #define WAIT_BEFOREKILL_SECONDS 3
16
16
  #define POLL_INTERVAL_SECONDS 60
17
+ #define POLL_INTERVAL_INFINITE (unsigned int)(-1)
17
18
  #define DEFAULT_PUSH_PORT 100
18
19
 
19
20
  class CClientRegister : public common::CRhoThread
@@ -24,6 +25,7 @@ class CClientRegister : public common::CRhoThread
24
25
  common::CAutoPtr<common::ISystemInfo> m_sysInfo;
25
26
  common::CAutoPtr<net::INetRequest> m_NetRequest;
26
27
  String m_strDevicePin;
28
+ unsigned int m_nPollInterval;
27
29
  public:
28
30
  static CClientRegister* Create(common::IRhoClassFactory* factory,const char* device_pin);
29
31
  //static void Destroy();
@@ -32,12 +34,14 @@ public:
32
34
  virtual void run();
33
35
 
34
36
  const String& getDevicePin(){return m_strDevicePin;}
35
- boolean doRegister(CSyncEngine& oSync);
36
- String getRegisterBody();
37
+
38
+ String getRegisterBody(const String& strClientID);
39
+
37
40
  private:
38
41
  CClientRegister(common::IRhoClassFactory* factory,const char* device_pin);
39
42
  ~CClientRegister();
40
43
 
44
+ boolean doRegister(CSyncEngine& oSync);
41
45
  net::INetRequest& getNet(){ return *m_NetRequest; }
42
46
 
43
47
  };
@@ -0,0 +1,29 @@
1
+ #pragma once
2
+
3
+ #include "common/RhoStd.h"
4
+
5
+ namespace rho {
6
+ namespace sync {
7
+
8
+ struct ISyncProtocol
9
+ {
10
+ virtual const String& getContentType() = 0;
11
+ virtual int getVersion() = 0;
12
+
13
+ virtual String getLoginUrl() = 0;
14
+ virtual String getLoginBody( const String& name, const String& password)=0;
15
+ virtual String getClientCreateUrl() = 0;
16
+
17
+ virtual String getClientRegisterUrl() = 0;
18
+ virtual String getClientRegisterBody(const String& strClientID, const String& strPin, int nPort, const String& strType ) = 0;
19
+
20
+ virtual String getClientResetUrl(const String& strClientID) = 0;
21
+ virtual String getClientChangesUrl() = 0;
22
+
23
+ virtual String getServerQueryUrl(const String& strAction) = 0;
24
+ virtual String getServerQueryBody(const String& strSrcName, const String& strClientID, int nPageSize )=0;
25
+
26
+ };
27
+
28
+ }
29
+ }
@@ -1,29 +1,21 @@
1
1
  #include "SyncEngine.h"
2
2
  #include "SyncSource.h"
3
+ #include "SyncThread.h"
3
4
 
4
5
  #include "json/JSONIterator.h"
5
6
  #include "common/RhoConf.h"
6
- #include "common/RhoFilePath.h"
7
7
  #include "common/StringConverter.h"
8
8
  #include "sync/ClientRegister.h"
9
9
  #include "net/URI.h"
10
10
  #include "statistic/RhoProfiler.h"
11
- #include "ruby/ext/rho/rhoruby.h"
11
+ #include "rubyext/RhoRuby.h"
12
+ #include "common/RhoTime.h"
13
+ #include "common/RhoFilePath.h"
14
+ #include "common/RhoFile.h"
15
+ #include "SyncProtocol_3.h"
12
16
  #include "net/URI.h"
13
17
 
14
18
  namespace rho {
15
- const _CRhoRuby& RhoRuby = _CRhoRuby();
16
-
17
- /*static*/ String _CRhoRuby::getMessageText(const char* szName)
18
- {
19
- return rho_ruby_getMessageText(szName);
20
- }
21
-
22
- /*static*/ String _CRhoRuby::getErrorText(int nError)
23
- {
24
- return rho_ruby_getErrorText(nError);
25
- }
26
-
27
19
  namespace sync {
28
20
  IMPLEMENT_LOGCLASS(CSyncEngine,"Sync");
29
21
 
@@ -31,27 +23,59 @@ using namespace rho::net;
31
23
  using namespace rho::common;
32
24
  using namespace rho::json;
33
25
 
34
- CSyncEngine::CSyncEngine(db::CDBAdapter& db): m_dbAdapter(db), m_NetRequest(0), m_syncState(esNone), m_oSyncNotify(*this)
26
+ CSyncEngine::CSyncEngine():m_NetRequest(0), m_syncState(esNone), m_oSyncNotify(*this)
35
27
  {
28
+ m_bNoThreaded = false;
36
29
  m_bStopByUser = false;
37
30
  m_nSyncPageSize = 2000;
38
- m_bNoThreaded = false;
31
+
32
+ initProtocol();
39
33
  }
40
34
 
41
- String CSyncEngine::SYNC_PAGE_SIZE() { return convertToStringA(m_nSyncPageSize); }
35
+ void CSyncEngine::initProtocol()
36
+ {
37
+ m_SyncProtocol = new CSyncProtocol_3();
38
+ }
42
39
 
43
- void CSyncEngine::doSyncAllSources()
40
+ void CSyncEngine::prepareSync(ESyncState eState)
44
41
  {
45
- setState(esSyncAllSources);
42
+ setState(eState);
46
43
  m_bStopByUser = false;
44
+ m_nErrCode = RhoRuby.ERR_NONE;
45
+
47
46
  loadAllSources();
48
47
 
49
48
  m_strSession = loadSession();
50
49
  if ( isSessionExist() )
51
50
  {
52
51
  m_clientID = loadClientID();
53
- getNotify().cleanLastSyncObjectCount();
52
+ if ( m_nErrCode == RhoRuby.ERR_NONE )
53
+ {
54
+ getNotify().cleanLastSyncObjectCount();
55
+ doBulkSync();
56
+
57
+ return;
58
+ }
59
+ }else
60
+ m_nErrCode = RhoRuby.ERR_CLIENTISNOTLOGGEDIN;
61
+
62
+ if ( m_sources.size() > 0 )
63
+ {
64
+ CSyncSource& src = *m_sources.elementAt(getStartSource());
65
+ src.m_nErrCode = m_nErrCode;
66
+ getNotify().fireSyncNotification(&src, true, src.m_nErrCode, "");
67
+ }else
68
+ getNotify().fireSyncNotification(null, true, m_nErrCode, "");
69
+
70
+ stopSync();
71
+ }
72
+
73
+ void CSyncEngine::doSyncAllSources()
74
+ {
75
+ prepareSync(esSyncAllSources);
54
76
 
77
+ if ( isContinueSync() )
78
+ {
55
79
  PROF_CREATE_COUNTER("Net");
56
80
  PROF_CREATE_COUNTER("Parse");
57
81
  PROF_CREATE_COUNTER("DB");
@@ -71,74 +95,181 @@ void CSyncEngine::doSyncAllSources()
71
95
  PROF_STOP("Sync");
72
96
 
73
97
  }
74
- else
75
- {
76
- if ( m_sources.size() > 0 )
77
- {
78
- CSyncSource& src = *m_sources.elementAt(getStartSource());
79
- //src.m_strError = "Client is not logged in. No sync will be performed.";
80
- src.m_nErrCode = RhoRuby.ERR_CLIENTISNOTLOGGEDIN;
81
98
 
82
- getNotify().fireSyncNotification(&src, true, src.m_nErrCode, "");
83
- }else
84
- getNotify().fireSyncNotification(null, true, RhoRuby.ERR_CLIENTISNOTLOGGEDIN, "");
85
- }
99
+ getNotify().cleanCreateObjectErrors();
86
100
 
87
101
  if ( getState() != esExit )
88
102
  setState(esNone);
89
103
  }
90
104
 
91
- void CSyncEngine::doSyncSource(const CSourceID& oSrcID, String strParams, String strAction, boolean bSearchSyncChanges, int nProgressStep)
105
+ void CSyncEngine::doSearch(rho::Vector<rho::String>& arSources, String strParams, String strAction, boolean bSearchSyncChanges, int nProgressStep)
92
106
  {
93
- setState(esSyncSource);
94
- m_bStopByUser = false;
95
- loadAllSources();
107
+ prepareSync(esSearch);
108
+ if ( !isContinueSync() )
109
+ {
110
+ if ( getState() != esExit )
111
+ setState(esNone);
112
+
113
+ return;
114
+ }
96
115
 
97
- CSyncSource* pSrc = findSource(oSrcID);
98
- if ( pSrc != null )
116
+ CTimeInterval startTime = CTimeInterval::getCurrentTime();
117
+
118
+ if ( bSearchSyncChanges )
99
119
  {
100
- CSyncSource& src = *pSrc;
101
-
102
- LOG(INFO) +"Started synchronization of the data source: " + src.getName();
103
-
104
- src.m_strParams = strParams;
105
- src.m_strAction = strAction;
106
- src.m_bSearchSyncChanges = bSearchSyncChanges;
107
- src.m_nProgressStep = nProgressStep;
108
- if ( oSrcID.m_strUrl.length() != 0 )
109
- {
110
- net::URI uri(oSrcID.m_strUrl);
111
- src.setUrlParams(uri.getQueryString());
112
-
113
- if (uri.getScheme().length()>0)
114
- src.setUrl(uri.getPathSpecificPart());
115
- }
116
-
117
- m_strSession = loadSession();
118
- if ( isSessionExist() ) {
119
- m_clientID = loadClientID();
120
- if ( getState() != esStop )
120
+ for ( int i = 0; i < (int)arSources.size(); i++ )
121
+ {
122
+ CSyncSource* pSrc = findSourceByName(arSources.elementAt(i));
123
+ if ( pSrc != null )
124
+ pSrc->syncClientChanges();
125
+ }
126
+ }
127
+
128
+ int nErrCode = 0;
129
+ while( isContinueSync() )
130
+ {
131
+ int nSearchCount = 0;
132
+ String strUrl = getProtocol().getServerQueryUrl(strAction);
133
+ String strQuery = getProtocol().getServerQueryBody("", getClientID(), getSyncPageSize());
134
+
135
+ if ( strParams.length() > 0 )
136
+ strQuery += strParams;
137
+
138
+ for ( int i = 0; i < (int)arSources.size(); i++ )
139
+ {
140
+ CSyncSource* pSrc = findSourceByName(arSources.elementAt(i));
141
+ if ( pSrc != null )
121
142
  {
122
- getNotify().cleanLastSyncObjectCount();
123
- src.sync();
143
+ strQuery += "&sources[][name]=" + pSrc->getName();
144
+
145
+ if ( !pSrc->isTokenFromDB() && pSrc->getToken() > 1 )
146
+ strQuery += "&sources[][token]=" + convertToStringA(pSrc->getToken());
124
147
  }
125
- } else {
126
- //src.m_strError = "Client is not logged in. No sync will be performed.";
127
- src.m_nErrCode = RhoRuby.ERR_CLIENTISNOTLOGGEDIN;
128
- }
148
+ }
129
149
 
130
- getNotify().fireSyncNotification(&src, true, src.m_nErrCode, src.m_nErrCode == RhoRuby.ERR_NONE ? RhoRuby.getMessageText("sync_completed") : "");
131
- }else
132
- {
133
- LOG(ERROR) + "Sync one source : Unknown Source " + oSrcID.toString();
150
+ LOG(INFO) + "Call search on server. Url: " + (strUrl+strQuery);
151
+ NetResponse(resp,getNet().pullData(strUrl+strQuery, this));
134
152
 
135
- CSyncSource src(*this);
136
- //src.m_strError = "Unknown sync source.";
137
- src.m_nErrCode = RhoRuby.ERR_RUNTIME;
153
+ if ( !resp.isOK() )
154
+ {
155
+ stopSync();
156
+ nErrCode = RhoRuby.getErrorFromResponse(resp);
157
+ continue;
158
+ }
159
+
160
+ const char* szData = resp.getCharData();
161
+
162
+ CJSONArrayIterator oJsonArr(szData);
163
+
164
+ for( ; !oJsonArr.isEnd() && isContinueSync(); oJsonArr.next() )
165
+ {
166
+ CJSONArrayIterator oSrcArr(oJsonArr.getCurItem());
167
+
168
+ int nVersion = 0;
169
+ if ( !oSrcArr.isEnd() && oSrcArr.getCurItem().hasName("version") )
170
+ {
171
+ nVersion = oSrcArr.getCurItem().getInt("version");
172
+ oJsonArr.next();
173
+ }
174
+
175
+ if ( nVersion != getProtocol().getVersion() )
176
+ {
177
+ LOG(ERROR) + "Sync server send search data with incompatible version. Client version: " + convertToStringA(getProtocol().getVersion()) +
178
+ "; Server response version: " + convertToStringA(nVersion);
179
+ stopSync();
180
+ nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
181
+ continue;
182
+ }
183
+
184
+ if ( !oSrcArr.getCurItem().hasName("source") )
185
+ {
186
+ LOG(ERROR) + "Sync server send search data without source name.";
187
+ stopSync();
188
+ nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
189
+ continue;
190
+ }
191
+
192
+ String strSrcName = oSrcArr.getCurItem().getString("source");
193
+ CSyncSource* pSrc = findSourceByName(strSrcName);
194
+ if ( pSrc == null )
195
+ {
196
+ LOG(ERROR) + "Sync server send search data for unknown source name:" + strSrcName;
197
+ stopSync();
198
+ nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
199
+ continue;
200
+ }
201
+
202
+ oSrcArr.reset(0);
203
+ pSrc->m_bIsSearch = true;
204
+ pSrc->setProgressStep(nProgressStep);
205
+ pSrc->processServerResponse_ver3(oSrcArr);
206
+
207
+ nSearchCount += pSrc->getCurPageCount();
208
+ }
209
+
210
+ if ( nSearchCount == 0 )
211
+ break;
212
+ }
138
213
 
214
+ if ( isContinueSync() )
215
+ getNotify().fireSyncNotification(null, true, RhoRuby.ERR_NONE, RhoRuby.getMessageText("sync_completed"));
216
+ else if ( nErrCode != 0 )
217
+ {
218
+ CSyncSource& src = *m_sources.elementAt(getStartSource());
219
+ src.m_nErrCode = nErrCode;
220
+ src.m_bIsSearch = true;
139
221
  getNotify().fireSyncNotification(&src, true, src.m_nErrCode, "");
140
222
  }
141
223
 
224
+ //update db info
225
+ CTimeInterval endTime = CTimeInterval::getCurrentTime();
226
+ unsigned long timeUpdated = CLocalTime().toULong();
227
+ for ( int i = 0; i < (int)arSources.size(); i++ )
228
+ {
229
+ CSyncSource* pSrc = findSourceByName(arSources.elementAt(i));
230
+ if ( pSrc == null )
231
+ continue;
232
+ CSyncSource& oSrc = *pSrc;
233
+ oSrc.getDB().executeSQL("UPDATE sources set last_updated=?,last_inserted_size=?,last_deleted_size=?, \
234
+ last_sync_duration=?,last_sync_success=?, backend_refresh_time=? WHERE source_id=?",
235
+ timeUpdated, oSrc.getInsertedCount(), oSrc.getDeletedCount(),
236
+ (endTime-startTime).toULong(), oSrc.getGetAtLeastOnePage(), oSrc.getRefreshTime(),
237
+ oSrc.getID() );
238
+ }
239
+ //
240
+
241
+ getNotify().cleanCreateObjectErrors();
242
+ if ( getState() != esExit )
243
+ setState(esNone);
244
+ }
245
+
246
+ void CSyncEngine::doSyncSource(const CSourceID& oSrcID)
247
+ {
248
+ prepareSync(esSyncSource);
249
+
250
+ if ( isContinueSync() )
251
+ {
252
+ CSyncSource* pSrc = findSource(oSrcID);
253
+ if ( pSrc != null )
254
+ {
255
+ CSyncSource& src = *pSrc;
256
+ LOG(INFO) +"Started synchronization of the data source: " + src.getName();
257
+
258
+ src.sync();
259
+
260
+ getNotify().fireSyncNotification(&src, true, src.m_nErrCode, src.m_nErrCode == RhoRuby.ERR_NONE ? RhoRuby.getMessageText("sync_completed") : "");
261
+ }else
262
+ {
263
+ LOG(ERROR) + "Sync one source : Unknown Source " + oSrcID.toString();
264
+
265
+ CSyncSource src(*this, getUserDB() );
266
+ //src.m_strError = "Unknown sync source.";
267
+ src.m_nErrCode = RhoRuby.ERR_RUNTIME;
268
+
269
+ getNotify().fireSyncNotification(&src, true, src.m_nErrCode, "");
270
+ }
271
+ }
272
+
142
273
  getNotify().cleanCreateObjectErrors();
143
274
 
144
275
  if ( getState() != esExit )
@@ -159,29 +290,28 @@ CSyncSource* CSyncEngine::findSource(const CSourceID& oSrcID)
159
290
 
160
291
  CSyncSource* CSyncEngine::findSourceByName(const String& strSrcName)
161
292
  {
162
- CSourceID oSrcID;
163
- oSrcID.m_strName = strSrcName;
164
- return findSource(oSrcID);
293
+ return findSource(CSourceID(strSrcName));
165
294
  }
166
295
 
167
296
  void CSyncEngine::loadAllSources()
168
297
  {
169
298
  m_sources.clear();
299
+ m_arPartitions.clear();
170
300
 
171
- DBResult( res, getDB().executeSQL("SELECT source_id,source_url,token,name from sources ORDER BY priority") );
301
+ DBResult( res, getUserDB().executeSQL("SELECT source_id,sync_type,name, partition from sources ORDER BY priority") );
172
302
  for ( ; !res.isEnd(); res.next() )
173
303
  {
174
- String strDbUrl = res.getStringByIdx(1);
175
- if ( strDbUrl.length() == 0 )
304
+ String strShouldSync = res.getStringByIdx(1);
305
+ if ( strShouldSync.compare("none") == 0 )
176
306
  continue;
177
307
 
178
- String strUrl = strDbUrl.find("http") == 0 ? strDbUrl : CFilePath::join(RHOCONF().getPath("syncserver") , strDbUrl);
179
- if ( strUrl.at(strUrl.length()-1) == '/' || strUrl.at(strUrl.length()-1) == '\\' )
180
- strUrl.erase(strUrl.end()-1);
308
+ String strName = res.getStringByIdx(2);
309
+ String strPartition = res.getStringByIdx(3);
181
310
 
182
- String strName = res.getStringByIdx(3);
183
- if ( strUrl.length() > 0 )
184
- m_sources.addElement( new CSyncSource( res.getIntByIdx(0), strUrl, strName, res.getUInt64ByIdx(2), *this) );
311
+ if ( m_arPartitions.indexOf(strPartition) < 0 )
312
+ m_arPartitions.addElement(strPartition);
313
+
314
+ m_sources.addElement( new CSyncSource( res.getIntByIdx(0), strName, strShouldSync, getDB(strPartition), *this) );
185
315
  }
186
316
  }
187
317
 
@@ -191,9 +321,8 @@ String CSyncEngine::loadClientID()
191
321
  synchronized(m_mxLoadClientID)
192
322
  {
193
323
  boolean bResetClient = false;
194
-
195
324
  {
196
- DBResult( res, getDB().executeSQL("SELECT client_id,reset from client_info limit 1") );
325
+ DBResult( res, getUserDB().executeSQL("SELECT client_id,reset from client_info limit 1") );
197
326
  if ( !res.isEnd() )
198
327
  {
199
328
  clientID = res.getStringByIdx(0);
@@ -205,73 +334,248 @@ String CSyncEngine::loadClientID()
205
334
  {
206
335
  clientID = requestClientIDByNet();
207
336
 
208
- getDB().executeSQL("DELETE FROM client_info");
209
- getDB().executeSQL("INSERT INTO client_info (client_id) values (?)", clientID);
337
+ DBResult( res , getUserDB().executeSQL("SELECT * FROM client_info") );
338
+ if ( !res.isEnd() )
339
+ getUserDB().executeSQL("UPDATE client_info SET client_id=?", clientID);
340
+ else
341
+ getUserDB().executeSQL("INSERT INTO client_info (client_id) values (?)", clientID);
342
+
210
343
  }else if ( bResetClient )
211
344
  {
212
345
  if ( !resetClientIDByNet(clientID) )
213
- {
214
- if ( m_sources.size() > 0 )
215
- {
216
- CSyncSource& src = *m_sources.elementAt(getStartSource());
217
- src.m_nErrCode = RhoRuby.ERR_REMOTESERVER;
218
-
219
- getNotify().fireSyncNotification(&src, true, src.m_nErrCode, "");
220
- }else
221
- getNotify().fireSyncNotification(null, true, RhoRuby.ERR_REMOTESERVER, "");
222
-
223
346
  stopSync();
224
- }
225
347
  else
226
- getDB().executeSQL("UPDATE client_info SET reset=? where client_id=?", 0, clientID );
348
+ getUserDB().executeSQL("UPDATE client_info SET reset=? where client_id=?", 0, clientID );
227
349
  }
228
350
  }
351
+
229
352
  return clientID;
230
353
  }
231
354
 
232
- boolean CSyncEngine::resetClientIDByNet(const String& strClientID)//throws Exception
355
+ void CSyncEngine::processServerSources(String strSources)
233
356
  {
234
- String serverUrl = RHOCONF().getPath("syncserver");
235
- String strUrl = serverUrl + "clientreset";
236
- String strQuery = "?client_id=" + strClientID;
237
- if ( CClientRegister::getInstance() != null )
238
- strQuery += "&" + CClientRegister::getInstance()->getRegisterBody();
239
-
240
- NetResponse( resp, getNet().pullData(strUrl+strQuery, this) );
241
- return resp.isOK();
242
- /* if ( resp.isOK() )
357
+ if ( strSources.length() > 0 )
243
358
  {
244
- if ( CClientRegister::getInstance() != null )
245
- return CClientRegister::getInstance()->doRegister(*this);
359
+ NetResponse(resp,getNet().pushData( getNet().resolveUrl("/system/loadserversources"), strSources, null ));
360
+ loadAllSources();
246
361
 
247
- return true;
362
+ rho_db_init_attr_manager();
248
363
  }
364
+ }
249
365
 
250
- return false;*/
366
+ boolean CSyncEngine::resetClientIDByNet(const String& strClientID)//throws Exception
367
+ {
368
+ //TODO: send client register info in client reset
369
+ //String strBody = "";
370
+ //if ( CClientRegister::getInstance() != null )
371
+ // strBody += CClientRegister::getInstance()->getRegisterBody();
372
+
373
+ NetResponse( resp, getNet().pullData(getProtocol().getClientResetUrl(strClientID), this) );
374
+
375
+ /* processServerSources("{\"server_sources\":[{\"name\":\"Product\",\"partition\":\"application\",\"source_id\":\"2\",\"priority\":\"0\","
376
+ "\"schema_version\":\"7.0\",\"schema\":{"
377
+ "\"columns\":[\'brand\',\'created_at\',\'name\',\'price\',\'quantity\',\'sku\',\'updated_at\']"*/
378
+ /* "\"sql\":\"CREATE TABLE Product ( "
379
+ "brand varchar default NULL,"
380
+ "created_at varchar default NULL,"
381
+ "name varchar default NULL,"
382
+ "price varchar default NULL,"
383
+ "quantity int default NULL,"
384
+ "sku varchar default NULL,"
385
+ "updated_at varchar default NULL,"
386
+ "test varchar default NULL,"
387
+ "object varchar(255) PRIMARY KEY )\"*/
388
+ //"}}]}");
389
+
390
+ if ( !resp.isOK() )
391
+ m_nErrCode = RhoRuby.getErrorFromResponse(resp);
392
+ else
393
+ {
394
+ processServerSources(resp.getCharData());
395
+ }
396
+
397
+ return resp.isOK();
251
398
  }
252
399
 
253
400
  String CSyncEngine::requestClientIDByNet()
254
401
  {
255
- String serverUrl = RHOCONF().getPath("syncserver");
256
- String strUrl = serverUrl + "clientcreate";
257
- String strQuery = SYNC_SOURCE_FORMAT();
258
- if ( CClientRegister::getInstance() != null )
259
- strQuery += "&" + CClientRegister::getInstance()->getRegisterBody();
402
+ //TODO: send client register info in client create
403
+ //String strBody = "";
404
+ //if ( CClientRegister::getInstance() != null )
405
+ // strBody += CClientRegister::getInstance()->getRegisterBody();
260
406
 
261
- NetResponse(resp,getNet().pullData(strUrl+strQuery, this));
407
+ NetResponse(resp,getNet().pullData(getProtocol().getClientCreateUrl(), this));
262
408
  if ( resp.isOK() && resp.getCharData() != null )
263
409
  {
264
410
  const char* szData = resp.getCharData();
411
+ /*
412
+ "{\"client\":{\"client_id\":\"vasy\"},\"server_sources\":[{\"name\":\"Product\",\"partition\":\"application\",\"source_id\":\"2\",\"priority\":\"0\","
413
+ "\"schema\":{\"version\":\"1.0\","
414
+ "\"sql\":\"CREATE TABLE Product ( "
415
+ "brand varchar default NULL,"
416
+ "created_at varchar default NULL,"
417
+ "name varchar default NULL,"
418
+ "price varchar default NULL,"
419
+ "quantity int default NULL,"
420
+ "sku varchar default NULL,"
421
+ "updated_at varchar default NULL,"
422
+ "object varchar(255) PRIMARY KEY )\"}}]}";*/
423
+
265
424
  CJSONEntry oJsonEntry(szData);
266
425
 
426
+ if (oJsonEntry.hasName("server_sources") )
427
+ processServerSources(szData);
428
+
267
429
  CJSONEntry oJsonObject = oJsonEntry.getEntry("client");
268
430
  if ( !oJsonObject.isEmpty() )
269
431
  return oJsonObject.getString("client_id");
432
+ }else
433
+ {
434
+ m_nErrCode = RhoRuby.getErrorFromResponse(resp);
435
+ if ( m_nErrCode == RhoRuby.ERR_NONE )
436
+ m_nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
270
437
  }
271
438
 
272
439
  return "";
273
440
  }
274
441
 
442
+ void CSyncEngine::doBulkSync()//throws Exception
443
+ {
444
+ if ( !RHOCONF().isExist("bulksync_state") )
445
+ return;
446
+
447
+ int nBulkSyncState = RHOCONF().getInt("bulksync_state");
448
+ if ( nBulkSyncState >= 1 || !isContinueSync() )
449
+ return;
450
+
451
+ LOG(INFO) + "Bulk sync: start";
452
+ getNotify().fireBulkSyncNotification(false, "start", "", RhoRuby.ERR_NONE);
453
+
454
+ for (int i = 0; i < (int)m_arPartitions.size() && isContinueSync(); i++)
455
+ loadBulkPartition(m_arPartitions.elementAt(i));
456
+
457
+ if (isContinueSync())
458
+ {
459
+ RHOCONF().setInt("bulksync_state", 1, true);
460
+ getNotify().fireBulkSyncNotification(true, "", "", RhoRuby.ERR_NONE);
461
+ }
462
+ }
463
+
464
+ extern "C" int rho_unzip_file(const char* szZipPath);
465
+
466
+ static String getHostFromUrl( const String& strUrl );
467
+ void CSyncEngine::loadBulkPartition(const String& strPartition )
468
+ {
469
+ db::CDBAdapter& dbPartition = getDB(strPartition);
470
+ String serverUrl = RHOCONF().getPath("syncserver");
471
+ String strUrl = serverUrl + "bulk_data";
472
+ String strQuery = "?client_id=" + m_clientID + "&partition=" + strPartition;
473
+ String strDataUrl = "", strCmd = "";
474
+
475
+ getNotify().fireBulkSyncNotification(false, "start", strPartition, RhoRuby.ERR_NONE);
476
+
477
+ while(strCmd.length() == 0&&isContinueSync())
478
+ {
479
+ NetResponse( resp, getNet().pullData(strUrl+strQuery, this) );
480
+ const char* szData = resp.getCharData();
481
+ if ( !resp.isOK() || szData == null || *szData == 0)
482
+ {
483
+ LOG(ERROR) + "Bulk sync failed: server return an error.";
484
+ stopSync();
485
+ getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_REMOTESERVER);
486
+ return;
487
+ }
488
+
489
+ LOG(INFO) + "Bulk sync: got response from server: " + szData;
490
+
491
+ CJSONEntry oJsonEntry(szData);
492
+ strCmd = oJsonEntry.getString("result");
493
+ if ( oJsonEntry.hasName("url") )
494
+ strDataUrl = oJsonEntry.getString("url");
495
+
496
+ if ( strCmd.compare("wait") == 0)
497
+ {
498
+ int nTimeout = RHOCONF().getInt("bulksync_timeout_sec");
499
+ if ( nTimeout == 0 )
500
+ nTimeout = 5;
501
+
502
+ CSyncThread::getInstance()->wait(nTimeout);
503
+ strCmd = "";
504
+ }
505
+ }
506
+
507
+ if ( strCmd.compare("nop") == 0)
508
+ {
509
+ LOG(INFO) + "Bulk sync return no data.";
510
+ getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_NONE);
511
+
512
+ return;
513
+ }
514
+
515
+ if ( !isContinueSync() )
516
+ return;
517
+
518
+ getNotify().fireBulkSyncNotification(false, "download", strPartition, RhoRuby.ERR_NONE);
519
+
520
+ String fDataName = makeBulkDataFileName(/*"data/bbook/bbook_1264475432.data"*/strDataUrl, dbPartition.getDBPath(), "");//, "_bulk");
521
+ String strZip = ".rzip";
522
+ String strSqlDataUrl = /*"http://204.236.220.203/data/bbook/bbook_1264475432.data" + strZip;*/getHostFromUrl(serverUrl) + strDataUrl+strZip;
523
+ LOG(INFO) + "Bulk sync: download data from server: " + strSqlDataUrl;
524
+ {
525
+ NetResponse( resp1, getNet().pullFile(strSqlDataUrl, fDataName+strZip, this, null) );
526
+ if ( !resp1.isOK() )
527
+ {
528
+ LOG(ERROR) + "Bulk sync failed: cannot download database file.";
529
+ stopSync();
530
+ getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_REMOTESERVER);
531
+ return;
532
+ }
533
+ }
534
+
535
+ if ( !isContinueSync() )
536
+ return;
537
+
538
+ LOG(INFO) + "Bulk sync: unzip db";
539
+
540
+ if ( !rho_unzip_file((fDataName+strZip).c_str()) )
541
+ {
542
+ CRhoFile::deleteFile((fDataName+strZip).c_str());
543
+ LOG(ERROR) + "Bulk sync failed: cannot unzip database file.";
544
+ stopSync();
545
+ getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE);
546
+ return;
547
+ }
548
+ CRhoFile::deleteFile((fDataName+strZip).c_str());
549
+
550
+ LOG(INFO) + "Bulk sync: start change db";
551
+ getNotify().fireBulkSyncNotification(false, "change_db", strPartition, RhoRuby.ERR_NONE);
552
+
553
+ dbPartition.setBulkSyncDB(fDataName);
554
+
555
+ LOG(INFO) + "Bulk sync: end change db";
556
+ getNotify().fireBulkSyncNotification(false, "", strPartition, RhoRuby.ERR_NONE);
557
+ }
558
+
559
+ String CSyncEngine::makeBulkDataFileName(String strDataUrl, String strDbPath, String strExt)
560
+ {
561
+ CFilePath oUrlPath(strDataUrl);
562
+ String strNewName = oUrlPath.getBaseName();
563
+ String strOldName = RHOCONF().getString("bulksync_filename");
564
+ if ( strOldName.length() > 0 && strNewName.compare(strOldName) != 0 )
565
+ {
566
+ CFilePath oFilePath(strDbPath);
567
+ String strFToDelete = oFilePath.changeBaseName(strOldName+strExt);
568
+ LOG(INFO) + "Bulk sync: remove old bulk file '" + strFToDelete + "'";
569
+
570
+ CRhoFile::deleteFile( strFToDelete.c_str() );
571
+ }
572
+
573
+ RHOCONF().setString("bulksync_filename", strNewName, true);
574
+
575
+ CFilePath oFilePath(strDbPath);
576
+ return oFilePath.changeBaseName(strNewName+strExt);
577
+ }
578
+
275
579
  int CSyncEngine::getStartSource()
276
580
  {
277
581
  for( int i = 0; i < (int)m_sources.size(); i++ )
@@ -286,10 +590,14 @@ int CSyncEngine::getStartSource()
286
590
 
287
591
  void CSyncEngine::syncAllSources()
288
592
  {
593
+ //TODO: do not stop on error source
289
594
  boolean bError = false;
290
595
  for( int i = getStartSource(); i < (int)m_sources.size() && isContinueSync(); i++ )
291
596
  {
292
597
  CSyncSource& src = *m_sources.elementAt(i);
598
+ if ( src.getSyncType().compare("bulk_sync_only")==0 )
599
+ continue;
600
+
293
601
  if ( isSessionExist() && getState() != esStop )
294
602
  src.sync();
295
603
 
@@ -301,61 +609,19 @@ void CSyncEngine::syncAllSources()
301
609
  getNotify().fireSyncNotification(null, true, RhoRuby.ERR_NONE, RhoRuby.getMessageText("sync_completed"));
302
610
  }
303
611
 
304
- static String getServerFromUrl( const String& strUrl );
305
- boolean CSyncEngine::checkAllSourcesFromOneDomain()//throws Exception
306
- {
307
- loadAllSources();
308
-
309
- if ( m_sources.size() == 0 )
310
- return true;
311
-
312
- //All sources should be from one domain
313
- CSyncSource& src0 = *m_sources.elementAt(0);
314
- String srv0 = getServerFromUrl(src0.getUrl());
315
- for( int i = 1; i < (int)m_sources.size(); i++ )
316
- {
317
- CSyncSource& src = *m_sources.elementAt(i);
318
- String srv = getServerFromUrl(src.getUrl());
319
- if ( srv.compare( srv0 ) != 0 )
320
- return false;
321
- }
322
-
323
- return true;
324
- }
325
-
326
612
  void CSyncEngine::login(String name, String password, String callback)
327
613
  {
328
614
  PROF_START("Login");
329
615
  //try {
330
- if ( !checkAllSourcesFromOneDomain() )
331
- {
332
- getNotify().callLoginCallback(callback, RhoRuby.ERR_DIFFDOMAINSINSYNCSRC, "");
333
- return;
334
- }
335
616
 
336
- String serverUrl = RHOCONF().getPath("syncserver");
337
- String strBody = "login=" + name + "&password=" + password + "&remember_me=1";
338
-
339
- NetResponse( resp, getNet().pullCookies( serverUrl+"client_login", strBody, this ) );
340
-
341
- if ( !resp.isResponseRecieved())
617
+ NetResponse( resp, getNet().pullCookies( getProtocol().getLoginUrl(), getProtocol().getLoginBody(name, password), this ) );
618
+ int nErrCode = RhoRuby.getErrorFromResponse(resp);
619
+ if ( nErrCode != RhoRuby.ERR_NONE )
342
620
  {
343
- getNotify().callLoginCallback(callback, RhoRuby.ERR_NETWORK, resp.getCharData());
621
+ getNotify().callLoginCallback(callback, nErrCode, resp.getCharData());
344
622
  return;
345
623
  }
346
624
 
347
- if ( resp.isUnathorized() )
348
- {
349
- getNotify().callLoginCallback(callback, RhoRuby.ERR_UNATHORIZED, resp.getCharData());
350
- return;
351
- }
352
-
353
- if ( !resp.isOK() )
354
- {
355
- getNotify().callLoginCallback(callback, RhoRuby.ERR_REMOTESERVER, resp.getCharData());
356
- return;
357
- }
358
-
359
625
  String strSession = resp.getCharData();
360
626
  if ( strSession.length() == 0 )
361
627
  {
@@ -364,12 +630,16 @@ void CSyncEngine::login(String name, String password, String callback)
364
630
  return;
365
631
  }
366
632
 
367
- //TODO: move session to client_info table
368
- getDB().executeSQL( "UPDATE sources SET session=?", strSession );
633
+ DBResult( res , getUserDB().executeSQL("SELECT * FROM client_info") );
634
+ if ( !res.isEnd() )
635
+ getUserDB().executeSQL( "UPDATE client_info SET session=?", strSession );
636
+ else
637
+ getUserDB().executeSQL("INSERT INTO client_info (session) values (?)", strSession);
638
+
369
639
 
370
640
  if ( CClientRegister::getInstance() != null )
371
641
  CClientRegister::getInstance()->stopWait();
372
-
642
+
373
643
  getNotify().callLoginCallback(callback, RhoRuby.ERR_NONE, "" );
374
644
 
375
645
  PROF_STOP("Login");
@@ -382,18 +652,18 @@ void CSyncEngine::login(String name, String password, String callback)
382
652
 
383
653
  boolean CSyncEngine::isLoggedIn()
384
654
  {
385
- int nCount = 0;
386
- DBResult( res , getDB().executeSQL("SELECT count(session) FROM sources") );
387
- if ( !res.isEnd() )
388
- nCount = res.getIntByIdx(0);
389
-
390
- return nCount > 0;
655
+ String strRes = "";
656
+ DBResult( res , getUserDB().executeSQL("SELECT session FROM client_info") );
657
+ if ( !res.isEnd() )
658
+ strRes = res.getStringByIdx(0);
659
+
660
+ return strRes.length() > 0;
391
661
  }
392
662
 
393
663
  String CSyncEngine::loadSession()
394
664
  {
395
665
  m_strSession = "";
396
- DBResult( res , getDB().executeSQL("SELECT session FROM sources WHERE session IS NOT NULL") );
666
+ DBResult( res , getUserDB().executeSQL("SELECT session FROM client_info") );
397
667
 
398
668
  if ( !res.isEnd() )
399
669
  m_strSession = res.getStringByIdx(0);
@@ -403,7 +673,7 @@ String CSyncEngine::loadSession()
403
673
 
404
674
  void CSyncEngine::logout()
405
675
  {
406
- getDB().executeSQL( "UPDATE sources SET session=NULL" );
676
+ getUserDB().executeSQL( "UPDATE client_info SET session=NULL" );
407
677
  m_strSession = "";
408
678
 
409
679
  loadAllSources();
@@ -414,12 +684,12 @@ void CSyncEngine::setSyncServer(char* syncserver)
414
684
  rho_conf_setString("syncserver", syncserver);
415
685
  rho_conf_save();
416
686
 
417
- getDB().executeSQL("DELETE FROM client_info");
687
+ getUserDB().executeSQL("DELETE FROM client_info");
418
688
 
419
689
  logout();
420
690
  }
421
691
 
422
- static String getServerFromUrl( const String& strUrl )
692
+ static String getHostFromUrl( const String& strUrl )
423
693
  {
424
694
  const char* url = strUrl.c_str();
425
695
  const char* pStartSrv, *pEndSrv;
@@ -437,16 +707,14 @@ static String getServerFromUrl( const String& strUrl )
437
707
  if ( !pEndSrv )
438
708
  pEndSrv = strchr( pStartSrv, '\\');
439
709
 
440
- nSrvLen = pEndSrv ? (pEndSrv - pStartSrv) : strlen(pStartSrv);
441
- return String(pStartSrv, nSrvLen);
710
+ nSrvLen = pEndSrv ? (pEndSrv+1 - url) : strlen(url);
711
+ return String(url, nSrvLen);
442
712
  }
443
713
 
444
714
  String CSyncEngine::CSourceID::toString()const
445
715
  {
446
716
  if ( m_strName.length() > 0 )
447
717
  return "name : " + m_strName;
448
- else if ( m_strUrl.length() > 0 )
449
- return "url : " + m_strUrl;
450
718
 
451
719
  return "# : " + convertToStringA(m_nID);
452
720
  }
@@ -455,14 +723,6 @@ boolean CSyncEngine::CSourceID::isEqual(CSyncSource& src)const
455
723
  {
456
724
  if ( m_strName.length() > 0 )
457
725
  return src.getName().compare(m_strName)==0;
458
- else if ( m_strUrl.length() > 0 )
459
- {
460
- net::URI uri1(m_strUrl);
461
- net::URI uri2(src.getUrl());
462
-
463
- return uri1.getPath().compare(uri2.getPath()) == 0;
464
- //return src.getUrl().compare(m_strUrl)==0;
465
- }
466
726
 
467
727
  return m_nID == src.getID();
468
728
  }