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.
- data/CHANGELOG +7 -0
- data/README.textile +4 -5
- data/Rakefile +8 -1
- data/lib/build/jake.rb +22 -16
- data/lib/extensions/rhoxml/rexml/cdata.rb +67 -0
- data/lib/extensions/rhoxml/rexml/document.rb +2 -116
- data/lib/extensions/rhoxml/rexml/element.rb +1 -1
- data/lib/extensions/rhoxml/rexml/text.rb +117 -0
- data/lib/framework/rho/render.rb +19 -11
- data/lib/framework/rho/rho.rb +17 -10
- data/lib/framework/rho/rhobluetooth.rb +103 -0
- data/lib/framework/rho/rhocontroller.rb +2 -0
- data/lib/framework/rho/rhoevent.rb +43 -0
- data/lib/framework/rho/rhoevent_bb.rb +80 -0
- data/lib/framework/rho/rhoevent_c.rb +47 -0
- data/lib/framework/rhodes.rb +2 -2
- data/lib/framework/rhom/rhom_db_adapter.rb +2 -1
- data/lib/framework/rhom/rhom_model.rb +9 -3
- data/lib/framework/rhom/rhom_object_factory.rb +46 -22
- data/lib/framework/rhom/rhom_source.rb +12 -10
- data/lib/framework/version.rb +2 -2
- data/lib/rhodes.rb +2 -2
- data/platform/android/Rhodes/AndroidManifest.xml +23 -2
- data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +54 -38
- data/platform/android/Rhodes/jni/include/rhodes.h +3 -0
- data/platform/android/Rhodes/jni/include/rhodes/JNIRhodes.h +2 -2
- data/platform/android/Rhodes/jni/include/rhodes/details/rhojava.inc +4 -0
- data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_RhodesService.h +16 -0
- data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_bluetooth_RhoBluetoothManager.h +21 -0
- data/platform/android/Rhodes/jni/src/bluetooth.cpp +169 -0
- data/platform/android/Rhodes/jni/src/callbacks.cpp +10 -0
- data/platform/android/Rhodes/jni/src/event.cpp +429 -0
- data/platform/android/Rhodes/jni/src/fileapi.cpp +51 -1
- data/platform/android/Rhodes/jni/src/rhodes.cpp +16 -0
- data/platform/android/Rhodes/jni/src/sslimpl.cpp +3 -0
- data/platform/android/Rhodes/res/layout/bt_device_list.xml +42 -0
- data/platform/android/Rhodes/res/layout/bt_device_name.xml +7 -0
- data/platform/android/Rhodes/res/values/strings.xml +8 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +14 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +2 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Push.java +7 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushReceiver.java +58 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushService.java +53 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +8 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +144 -3
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/IRhoBluetoothManager.java +66 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothDeviceListActivity.java +201 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManager.java +139 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManagerNew.java +401 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManagerOld.java +136 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothSession.java +457 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/UUIDHelper.java +71 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +12 -7
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/Event.java +19 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/EventStore.java +261 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +4 -2
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +2 -2
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +10 -2
- data/platform/android/build/RhodesSRC_build.files +33 -22
- data/platform/android/build/android.rake +198 -27
- data/platform/android/build/librhodes_build.files +3 -1
- data/platform/android/build/libruby_build.files +4 -1
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +2 -2
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBRowResult.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/Expression.java +7 -4
- data/platform/bb/Hsqldb/src/org/hsqldb/Like.java +3 -3
- data/platform/bb/Hsqldb/src/org/hsqldb/Table.java +3 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/Tokenizer.java +1 -1
- data/platform/bb/RubyVM/RubyVM.jdp +1 -0
- data/platform/bb/RubyVM/src/com/rho/RhoConf.java +108 -1
- data/platform/bb/RubyVM/src/com/rho/RhoLogConf.java +7 -1
- data/platform/bb/RubyVM/src/com/rho/RhoRuby.java +7 -4
- data/platform/bb/RubyVM/src/com/rho/ThreadQueue.java +7 -1
- data/platform/bb/RubyVM/src/com/rho/net/AsyncHttp.java +1 -1
- data/platform/bb/RubyVM/src/com/rho/net/NetRequest.java +21 -23
- data/platform/bb/RubyVM/src/com/rho/net/RhoConnection.java +19 -10
- data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +8 -0
- data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +3 -0
- data/platform/bb/RubyVM/src/com/rho/sync/SyncThread.java +14 -17
- data/platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyFile.java +7 -5
- data/platform/bb/RubyVM/src/com/xruby/runtime/lang/RhoSupport.java +2 -0
- data/platform/bb/RubyVM/src/com/xruby/runtime/lang/RubyRuntime.java +10 -1
- data/platform/bb/RubyVM/src/j2me/io/File.java +7 -6
- data/platform/bb/build/RubyVM_build.files +412 -412
- data/platform/bb/build/bb.rake +42 -18
- data/platform/bb/build/hsqldb_build.files +151 -151
- data/platform/bb/build/rhodes_build.files +44 -40
- data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +2 -0
- data/platform/bb/rhodes/platform/5.0/com/rho/RhodesApplicationPlatform.java +237 -0
- data/platform/bb/rhodes/platform/common/com/rho/RhodesApplicationPlatform.java +14 -0
- data/platform/bb/rhodes/rhodes.jdp +6 -1
- data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +7 -1
- data/platform/bb/rhodes/src/com/rho/RhodesApplicationPlatform.java +14 -0
- data/platform/bb/rhodes/src/com/rho/net/NetworkAccess.java +62 -76
- data/platform/bb/rhodes/src/com/rho/rubyext/RhoCalendar.java +660 -0
- data/platform/bb/rhodes/src/{rhomobile → com/rho/rubyext}/RhoPhonebook.java +95 -38
- data/platform/bb/rhodes/src/com/rho/rubyext/System.java +22 -1
- data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +26 -6
- data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +21 -7
- data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothManager.java +528 -0
- data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothPort.java +281 -0
- data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothScreen.java +119 -0
- data/platform/bb/rhodes/src/rhomobile/camera/CameraFilesListener.java +2 -2
- data/platform/iphone/Classes/AppManager/AppManager.m +70 -7
- data/platform/iphone/Classes/Bluetooth/Bluetooth.h +72 -0
- data/platform/iphone/Classes/Bluetooth/Bluetooth.m +414 -0
- data/platform/iphone/Classes/Event/Event.h +12 -0
- data/platform/iphone/Classes/Event/Event.m +300 -0
- data/platform/iphone/Classes/LogOptionsController.h +2 -1
- data/platform/iphone/Classes/LogOptionsController.m +1 -1
- data/platform/iphone/Classes/LogViewController.h +2 -1
- data/platform/iphone/Classes/MapView/MapViewController.h +2 -1
- data/platform/iphone/Classes/RhoViewController.h +16 -0
- data/platform/iphone/Classes/RhoViewController.m +20 -0
- data/platform/iphone/Classes/Rhodes.h +12 -0
- data/platform/iphone/Classes/Rhodes.m +34 -6
- data/platform/iphone/Classes/Signature/SignatureViewController.h +2 -2
- data/platform/iphone/Classes/Signature/SignatureViewController.m +0 -10
- data/platform/iphone/Classes/SimpleMainView.h +2 -2
- data/platform/iphone/Classes/SimpleMainView.m +5 -14
- data/platform/iphone/Classes/SplashViewController.h +2 -2
- data/platform/iphone/Classes/TabbedMainView.h +2 -2
- data/platform/iphone/Classes/TabbedMainView.m +5 -10
- data/platform/iphone/Info.plist +5 -5
- data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +39 -0
- data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +47 -4
- data/platform/osx/Rhodes Debugger/NoodleLineNumberView.m +3 -2
- data/platform/shared/common/AutoPointer.h +3 -0
- data/platform/shared/common/RhoConf.cpp +2 -1
- data/platform/shared/common/RhoThread.h +1 -1
- data/platform/shared/common/RhoTime.h +3 -3
- data/platform/shared/common/RhodesApp.cpp +75 -23
- data/platform/shared/common/RhodesApp.h +4 -0
- data/platform/shared/common/RhodesAppBase.h +2 -0
- data/platform/shared/common/ThreadQueue.cpp +23 -18
- data/platform/shared/common/ThreadQueue.h +2 -0
- data/platform/shared/db/res/db/syncdb.schema +39 -39
- data/platform/shared/logging/RhoLogConf.cpp +58 -3
- data/platform/shared/logging/RhoLogConf.h +3 -1
- data/platform/shared/net/CURLNetRequest.cpp +17 -6
- data/platform/shared/net/HttpServer.cpp +125 -25
- data/platform/shared/net/HttpServer.h +4 -3
- data/platform/shared/ruby/ext/bluetooth/bluetooth.i +56 -0
- data/platform/shared/ruby/ext/bluetooth/bluetooth_wrap.c +2563 -0
- data/platform/shared/ruby/ext/calendar/calendar.i +28 -0
- data/platform/shared/ruby/ext/calendar/calendar_wrap.c +2251 -0
- data/platform/shared/ruby/ext/calendar/event.h +41 -0
- data/platform/shared/ruby/ext/calendar/event.i +28 -0
- data/platform/shared/ruby/ext/calendar/event_wrap.c +2151 -0
- data/platform/shared/ruby/ext/rho/rhoruby.c +103 -3
- data/platform/shared/ruby/ext/rho/rhoruby.h +16 -2
- data/platform/shared/ruby/ext/rhoconf/rhoconf.i +12 -0
- data/platform/shared/ruby/ext/rhoconf/rhoconf_wrap.c +101 -0
- data/platform/shared/ruby/ext/system/system.i +14 -0
- data/platform/shared/ruby/ext/system/system_wrap.c +2568 -2208
- data/platform/shared/ruby/main.c +8 -0
- data/platform/shared/rubyext/GeoLocation.cpp +6 -3
- data/platform/shared/rubyext/System.cpp +14 -0
- data/platform/shared/sync/SyncEngine.cpp +9 -1
- data/platform/shared/sync/SyncNotify.cpp +16 -8
- data/platform/shared/sync/SyncNotify.h +1 -0
- data/platform/shared/sync/SyncThread.cpp +7 -12
- data/platform/shared/sync/SyncThread.h +5 -3
- data/platform/wm/build/wm.rake +7 -1
- data/platform/wm/rhodes/Alert.cpp +1 -1
- data/platform/wm/rhodes/MainWindow.cpp +28 -0
- data/platform/wm/rhodes/MainWindow.h +9 -0
- data/platform/wm/rhodes/OutlookApp.cpp +72 -0
- data/platform/wm/rhodes/OutlookApp.h +22 -0
- data/platform/wm/rhodes/Rhodes.cpp +8 -0
- data/platform/wm/rhodes/Rhodes.rc +31 -0
- data/platform/wm/rhodes/bluetooth/Bluetooth.cpp +1274 -0
- data/platform/wm/rhodes/bluetooth/Bluetooth.h +321 -0
- data/platform/wm/rhodes/phonebook/NativeAddressBook.cpp +37 -70
- data/platform/wm/rhodes/phonebook/NativeAddressBook.h +0 -4
- data/platform/wm/rhodes/resource.h +8 -1
- data/platform/wm/rhodes/rho/net/NetRequest.cpp +4 -0
- data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +6 -4
- data/platform/wm/rhodes/rho/rubyext/calendar.cpp +487 -0
- data/platform/wm/rhodes/rhodes.vcproj +28 -11
- data/platform/wm/rhodes/stdafx.h +1 -0
- data/platform/wm/rubylib/rubylib.vcproj +32 -0
- data/rakefile.rb +8 -1
- data/res/generators/templates/application/Rakefile +1 -1
- data/res/generators/templates/application/app/layout.erb +4 -1
- data/res/generators/templates/application/build.yml +0 -1
- data/res/generators/templates/application/public/css/iphone.css +2 -2
- data/res/generators/templates/application/public/jqtouch/jqtouch-iphone.css +9 -0
- data/res/generators/templates/application/public/jqtouch/jqtouch.css +1 -5
- data/res/generators/templates/application/public/jqtouch/jqtouch.js +3 -2
- data/rhodes.gemspec +1 -1
- data/spec/perfomance_spec/app/Benchmark/benchmark.rb +4 -0
- data/spec/perfomance_spec/app/Benchmark/bulk_results.erb +13 -0
- data/spec/perfomance_spec/app/Benchmark/controller.rb +178 -0
- data/spec/perfomance_spec/app/Benchmark/create_results.erb +13 -0
- data/spec/perfomance_spec/app/Benchmark/customers.erb +35 -0
- data/spec/perfomance_spec/app/Benchmark/index.erb +9 -0
- data/spec/perfomance_spec/app/Benchmark/products.erb +25 -0
- data/spec/perfomance_spec/app/Benchmark/search_results.erb +13 -0
- data/spec/perfomance_spec/app/Customer/customer.rb +6 -0
- data/spec/perfomance_spec/app/Perftest/index.erb +5 -0
- data/spec/perfomance_spec/app/Product/index.erb +25 -0
- data/spec/perfomance_spec/app/Product/product.rb +6 -0
- data/spec/perfomance_spec/app/helpers/application_helper.rb +126 -0
- data/spec/perfomance_spec/app/helpers/browser_helper.rb +18 -0
- data/spec/perfomance_spec/rhoconfig.txt +1 -1
- data/spec/phone_spec/app/Account_s/account_s.rb +5 -2
- data/spec/phone_spec/app/Case/case.rb +1 -0
- data/spec/phone_spec/app/Case_s/case_s.rb +2 -0
- data/spec/phone_spec/app/Data/perftest.json +35 -0
- data/spec/phone_spec/app/Data/testCDATA.xml +11 -0
- data/spec/phone_spec/app/Product/product.rb +1 -1
- data/spec/phone_spec/app/{Spec → spec}/asynchttp_spec.rb +66 -17
- data/spec/phone_spec/app/{Spec → spec}/barcode_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/blobsync_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/bsearch_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/bulksync_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/contacts_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/crypt_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/date_spec.rb +0 -0
- data/spec/phone_spec/app/spec/events_spec.rb +199 -0
- data/spec/phone_spec/app/{Spec → spec}/fixtures/client_info.txt +0 -0
- data/spec/phone_spec/app/{Spec → spec}/fixtures/object_values.txt +0 -0
- data/spec/phone_spec/app/{Spec → spec}/json_spec.rb +11 -2
- data/spec/phone_spec/app/{Spec → spec}/mapview_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/nativebar_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/navbar_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/pagination/fixtures/object_values.txt +0 -0
- data/spec/phone_spec/app/{Spec → spec}/rho_controller_spec.rb +5 -0
- data/spec/phone_spec/app/{Spec → spec}/rho_spec.rb +48 -0
- data/spec/phone_spec/app/{Spec → spec}/rhofile_spec.rb +9 -6
- data/spec/phone_spec/app/{Spec → spec}/rhom_object_spec.rb +188 -9
- data/spec/phone_spec/app/{Spec → spec}/syncengine_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/xml_spec.rb +15 -0
- data/spec/phone_spec/app/{Spec → spec}/xruby_spec.rb +0 -0
- data/spec/phone_spec/app/spec_runner.rb +4 -1
- data/spec/phone_spec/build.yml +2 -1
- metadata +95 -31
- data/platform/bb/rhodes/platform/5.0/com/rho/RhoMainScreen.java +0 -36
- data/platform/bb/rhodes/platform/6.0/com/rho/BrowserAdapter5.java +0 -155
- data/platform/bb/rhodes/platform/6.0/com/rho/RhoMainScreen.java +0 -36
@@ -1,5 +1,7 @@
|
|
1
|
-
package
|
1
|
+
package com.rho.rubyext;
|
2
2
|
|
3
|
+
import com.rho.RhoEmptyLogger;
|
4
|
+
import com.rho.RhoLogger;
|
3
5
|
import com.xruby.runtime.builtin.RubyArray;
|
4
6
|
import com.xruby.runtime.builtin.RubyString;
|
5
7
|
import com.xruby.runtime.builtin.RubyHash;
|
@@ -10,6 +12,8 @@ import javax.microedition.pim.*;
|
|
10
12
|
|
11
13
|
//@RubyLevelClass(name="Phonebook")
|
12
14
|
public class RhoPhonebook extends RubyBasic {
|
15
|
+
private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() :
|
16
|
+
new RhoLogger("Phonebook");
|
13
17
|
|
14
18
|
private ContactList m_contactList;
|
15
19
|
|
@@ -339,13 +343,6 @@ public class RhoPhonebook extends RubyBasic {
|
|
339
343
|
return RubyConstant.QTRUE;
|
340
344
|
}
|
341
345
|
|
342
|
-
public static RubyValue getfirstPhonebookRecord(RubyValue arg0) {
|
343
|
-
return RubyConstant.QNIL;
|
344
|
-
}
|
345
|
-
public static RubyValue getnextPhonebookRecord(RubyValue arg0) {
|
346
|
-
return RubyConstant.QNIL;
|
347
|
-
}
|
348
|
-
|
349
346
|
public static void initMethods( RubyClass klass){
|
350
347
|
klass.defineAllocMethod(new RubyNoArgMethod(){
|
351
348
|
protected RubyValue run(RubyValue receiver, RubyBlock block ) {
|
@@ -353,63 +350,123 @@ public class RhoPhonebook extends RubyBasic {
|
|
353
350
|
});
|
354
351
|
|
355
352
|
klass.getSingletonClass().defineMethod("openPhonebook", new RubyNoArgMethod() {
|
356
|
-
protected RubyValue run(RubyValue receiver, RubyBlock block)
|
357
|
-
|
353
|
+
protected RubyValue run(RubyValue receiver, RubyBlock block)
|
354
|
+
{
|
355
|
+
try {
|
356
|
+
return RhoPhonebook.openPhonebook();
|
357
|
+
} catch(Exception e) {
|
358
|
+
LOG.ERROR("openPhonebook failed", e);
|
359
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
360
|
+
}
|
361
|
+
|
358
362
|
}
|
359
363
|
});
|
360
364
|
klass.getSingletonClass().defineMethod("closePhonebook", new RubyOneArgMethod() {
|
361
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block)
|
362
|
-
|
365
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block)
|
366
|
+
{
|
367
|
+
try {
|
368
|
+
return RhoPhonebook.closePhonebook(arg0);
|
369
|
+
} catch(Exception e) {
|
370
|
+
LOG.ERROR("closePhonebook failed", e);
|
371
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
372
|
+
}
|
373
|
+
|
363
374
|
}
|
364
375
|
});
|
365
376
|
klass.getSingletonClass().defineMethod("getallPhonebookRecords", new RubyOneArgMethod() {
|
366
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block)
|
367
|
-
|
377
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block)
|
378
|
+
{
|
379
|
+
try {
|
380
|
+
return RhoPhonebook.getallPhonebookRecords(arg0);
|
381
|
+
} catch(Exception e) {
|
382
|
+
LOG.ERROR("getallPhonebookRecords failed", e);
|
383
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
384
|
+
}
|
385
|
+
|
368
386
|
}
|
369
387
|
});
|
370
388
|
klass.getSingletonClass().defineMethod("openPhonebookRecord", new RubyTwoArgMethod() {
|
371
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
372
|
-
|
389
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
390
|
+
{
|
391
|
+
try {
|
392
|
+
return RhoPhonebook.openPhonebookRecord(arg0, arg1);
|
393
|
+
} catch(Exception e) {
|
394
|
+
LOG.ERROR("openPhonebookRecord failed", e);
|
395
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
396
|
+
}
|
397
|
+
|
373
398
|
}
|
374
399
|
});
|
375
400
|
klass.getSingletonClass().defineMethod("getPhonebookRecord", new RubyTwoArgMethod() {
|
376
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
klass.getSingletonClass().defineMethod("getnextPhonebookRecord", new RubyOneArgMethod() {
|
386
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block) {
|
387
|
-
return RhoPhonebook.getnextPhonebookRecord(arg0);
|
401
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
402
|
+
{
|
403
|
+
try {
|
404
|
+
return RhoPhonebook.getPhonebookRecord(arg0, arg1);
|
405
|
+
} catch(Exception e) {
|
406
|
+
LOG.ERROR("getPhonebookRecord failed", e);
|
407
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
408
|
+
}
|
409
|
+
|
388
410
|
}
|
389
411
|
});
|
390
412
|
klass.getSingletonClass().defineMethod("createRecord", new RubyOneArgMethod() {
|
391
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block)
|
392
|
-
|
413
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block)
|
414
|
+
{
|
415
|
+
try {
|
416
|
+
return RhoPhonebook.createRecord(arg0);
|
417
|
+
} catch(Exception e) {
|
418
|
+
LOG.ERROR("createRecord failed", e);
|
419
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
420
|
+
}
|
421
|
+
|
393
422
|
}
|
394
423
|
});
|
395
424
|
klass.getSingletonClass().defineMethod("setRecordValue", new RubyVarArgMethod() {
|
396
|
-
protected RubyValue run(RubyValue receiver, RubyArray ar, RubyBlock block)
|
397
|
-
|
425
|
+
protected RubyValue run(RubyValue receiver, RubyArray ar, RubyBlock block)
|
426
|
+
{
|
427
|
+
try {
|
428
|
+
return RhoPhonebook.setRecordValue(ar);
|
429
|
+
} catch(Exception e) {
|
430
|
+
LOG.ERROR("setRecordValue failed", e);
|
431
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
432
|
+
}
|
433
|
+
|
398
434
|
}
|
399
435
|
});
|
400
436
|
klass.getSingletonClass().defineMethod("addRecord", new RubyTwoArgMethod() {
|
401
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
402
|
-
|
437
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
438
|
+
{
|
439
|
+
try {
|
440
|
+
return RhoPhonebook.addRecord(arg0, arg1);
|
441
|
+
} catch(Exception e) {
|
442
|
+
LOG.ERROR("addRecord failed", e);
|
443
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
444
|
+
}
|
445
|
+
|
403
446
|
}
|
404
447
|
});
|
405
448
|
klass.getSingletonClass().defineMethod("saveRecord", new RubyTwoArgMethod() {
|
406
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
407
|
-
|
449
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
450
|
+
{
|
451
|
+
try {
|
452
|
+
return RhoPhonebook.saveRecord(arg0, arg1);
|
453
|
+
} catch(Exception e) {
|
454
|
+
LOG.ERROR("saveRecord failed", e);
|
455
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
456
|
+
}
|
457
|
+
|
408
458
|
}
|
409
459
|
});
|
410
460
|
klass.getSingletonClass().defineMethod("deleteRecord", new RubyTwoArgMethod() {
|
411
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
412
|
-
|
461
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block)
|
462
|
+
{
|
463
|
+
try {
|
464
|
+
return RhoPhonebook.deleteRecord(arg0, arg1);
|
465
|
+
} catch(Exception e) {
|
466
|
+
LOG.ERROR("deleteRecord failed", e);
|
467
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
468
|
+
}
|
469
|
+
|
413
470
|
}
|
414
471
|
});
|
415
472
|
|
@@ -13,6 +13,7 @@ import com.xruby.runtime.builtin.ObjectFactory;
|
|
13
13
|
import com.xruby.runtime.lang.*;
|
14
14
|
import com.rho.RhoRubyHelper;
|
15
15
|
import net.rim.device.api.system.DeviceInfo;
|
16
|
+
import net.rim.device.api.system.Backlight;
|
16
17
|
|
17
18
|
public class System {
|
18
19
|
|
@@ -109,12 +110,32 @@ public class System {
|
|
109
110
|
});
|
110
111
|
klass.getSingletonClass().defineMethod("exit", new RubyNoArgMethod() {
|
111
112
|
protected RubyValue run(RubyValue receiver, RubyBlock block) {
|
112
|
-
synchronized(RhodesApplication.getInstance().getEventLock()) {
|
113
|
+
//synchronized(RhodesApplication.getInstance().getEventLock()) {
|
113
114
|
RhodesApplication.getInstance().close();
|
114
115
|
return RubyConstant.QNIL;
|
116
|
+
//}
|
117
|
+
}
|
118
|
+
});
|
119
|
+
|
120
|
+
klass.getSingletonClass().defineMethod( "set_sleeping", new RubyOneArgMethod(){
|
121
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block )
|
122
|
+
{
|
123
|
+
try {
|
124
|
+
RubyValue ret = !Backlight.isEnabled() ? RubyConstant.QTRUE : RubyConstant.QFALSE;
|
125
|
+
|
126
|
+
if ( arg1 != RubyConstant.QTRUE )
|
127
|
+
Backlight.enable(true, 255);
|
128
|
+
else
|
129
|
+
Backlight.enable(false, Backlight.getTimeoutDefault());
|
130
|
+
|
131
|
+
return ret;
|
132
|
+
} catch(Exception e) {
|
133
|
+
LOG.ERROR("set_sleeping failed", e);
|
134
|
+
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
115
135
|
}
|
116
136
|
}
|
117
137
|
});
|
138
|
+
|
118
139
|
}
|
119
140
|
|
120
141
|
//@RubyLevelMethod(name="get_property", module=true)
|
@@ -46,6 +46,26 @@ public class PushListeningThread extends Thread {
|
|
46
46
|
}
|
47
47
|
}
|
48
48
|
|
49
|
+
public static boolean isMDSPushEnabled()
|
50
|
+
{
|
51
|
+
if ( !RhoConf.getInstance().isExist("push_options") )
|
52
|
+
return true;
|
53
|
+
|
54
|
+
String strOptions = RhoConf.getInstance().getString("push_options");
|
55
|
+
|
56
|
+
return strOptions.indexOf("mds") >= 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
public static boolean isPushServiceEnabled()
|
60
|
+
{
|
61
|
+
if ( !RhoConf.getInstance().isExist("push_options") )
|
62
|
+
return true;
|
63
|
+
|
64
|
+
String strOptions = RhoConf.getInstance().getString("push_options");
|
65
|
+
|
66
|
+
return strOptions.indexOf("push_service") >= 0;
|
67
|
+
}
|
68
|
+
|
49
69
|
public void run()
|
50
70
|
{
|
51
71
|
|
@@ -179,7 +199,7 @@ public class PushListeningThread extends Thread {
|
|
179
199
|
}
|
180
200
|
}
|
181
201
|
|
182
|
-
private String[] split(String original, String separator) {
|
202
|
+
private static String[] split(String original, String separator) {
|
183
203
|
Vector nodes = new Vector();
|
184
204
|
// Parse nodes into vector
|
185
205
|
int index = original.indexOf(separator);
|
@@ -202,7 +222,7 @@ public class PushListeningThread extends Thread {
|
|
202
222
|
return result;
|
203
223
|
}
|
204
224
|
|
205
|
-
private String[] splitOnce(String original, String separator) {
|
225
|
+
private static String[] splitOnce(String original, String separator) {
|
206
226
|
String[] result;
|
207
227
|
int index = original.indexOf(separator);
|
208
228
|
if (index>=0) {
|
@@ -216,19 +236,19 @@ public class PushListeningThread extends Thread {
|
|
216
236
|
return result;
|
217
237
|
}
|
218
238
|
|
219
|
-
private void showPopup(String message) {
|
239
|
+
private static void showPopup(String message) {
|
220
240
|
com.rho.rubyext.Alert.showPopup(message);
|
221
241
|
}
|
222
242
|
|
223
|
-
private void vibrate(String duration) {
|
243
|
+
private static void vibrate(String duration) {
|
224
244
|
com.rho.rubyext.Alert.vibrate(duration);
|
225
245
|
}
|
226
246
|
|
227
|
-
private void play_file(String file_name, String media_type) {
|
247
|
+
private static void play_file(String file_name, String media_type) {
|
228
248
|
com.rho.rubyext.Alert.play_file(file_name, media_type);
|
229
249
|
}
|
230
250
|
|
231
|
-
|
251
|
+
public static void processPushMessage(final byte[] data, int nLen)
|
232
252
|
{
|
233
253
|
/* Application.getApplication().invokeLater(new Runnable()
|
234
254
|
{
|
@@ -52,7 +52,7 @@ import com.xruby.runtime.lang.RubyProgram;
|
|
52
52
|
/**
|
53
53
|
*
|
54
54
|
*/
|
55
|
-
final public class RhodesApplication extends
|
55
|
+
final public class RhodesApplication extends RhodesApplicationPlatform implements SystemListener, ISyncStatusListener
|
56
56
|
{
|
57
57
|
// Menu Labels
|
58
58
|
public static final String LABEL_HOME = "Home";
|
@@ -69,6 +69,7 @@ final public class RhodesApplication extends UiApplication implements SystemList
|
|
69
69
|
private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() :
|
70
70
|
new RhoLogger("RhodesApplication");
|
71
71
|
|
72
|
+
|
72
73
|
class CKeyListener implements KeyListener{
|
73
74
|
|
74
75
|
public boolean keyChar(char key, int status, int time) {
|
@@ -402,6 +403,7 @@ final public class RhodesApplication extends UiApplication implements SystemList
|
|
402
403
|
void doClose(){
|
403
404
|
LOG.TRACE("Rhodes DO CLOSE ***--------------------------***");
|
404
405
|
|
406
|
+
onPlatformClose();
|
405
407
|
if ( _pushListeningThread != null )
|
406
408
|
_pushListeningThread.stop();
|
407
409
|
|
@@ -512,6 +514,8 @@ final public class RhodesApplication extends UiApplication implements SystemList
|
|
512
514
|
navigateHome();
|
513
515
|
}
|
514
516
|
|
517
|
+
onPlatformActivate();
|
518
|
+
|
515
519
|
LOG.TRACE("Rhodes end activate ***--------------------------***");
|
516
520
|
}
|
517
521
|
|
@@ -1001,10 +1005,11 @@ final public class RhodesApplication extends UiApplication implements SystemList
|
|
1001
1005
|
|
1002
1006
|
try {
|
1003
1007
|
RhoClassFactory.getNetworkAccess().configure();
|
1008
|
+
|
1004
1009
|
} catch(IOException exc) {
|
1005
1010
|
LOG.ERROR(exc.getMessage());
|
1006
1011
|
}
|
1007
|
-
|
1012
|
+
|
1008
1013
|
PrimaryResourceFetchThread.Create(this);
|
1009
1014
|
LOG.INFO("RHODES STARTUP COMPLETED: ***----------------------------------*** " );
|
1010
1015
|
|
@@ -1154,8 +1159,14 @@ final public class RhodesApplication extends UiApplication implements SystemList
|
|
1154
1159
|
navigateUrl(strStartPage);
|
1155
1160
|
}
|
1156
1161
|
|
1157
|
-
public void close()
|
1158
|
-
|
1162
|
+
public void close()
|
1163
|
+
{
|
1164
|
+
this.invokeLater(new Runnable() {
|
1165
|
+
public void run()
|
1166
|
+
{
|
1167
|
+
_mainScreen.close();
|
1168
|
+
}
|
1169
|
+
});
|
1159
1170
|
}
|
1160
1171
|
|
1161
1172
|
public void processConnection(HttpConnection connection, Object e)
|
@@ -1209,10 +1220,13 @@ final public class RhodesApplication extends UiApplication implements SystemList
|
|
1209
1220
|
return;
|
1210
1221
|
}
|
1211
1222
|
|
1212
|
-
if (com.rho.Capabilities.ENABLE_PUSH)
|
1223
|
+
if ( com.rho.Capabilities.ENABLE_PUSH )
|
1213
1224
|
{
|
1214
|
-
|
1215
|
-
|
1225
|
+
if ( PushListeningThread.isMDSPushEnabled() )
|
1226
|
+
{
|
1227
|
+
_pushListeningThread = new PushListeningThread();
|
1228
|
+
_pushListeningThread.start();
|
1229
|
+
}
|
1216
1230
|
}
|
1217
1231
|
|
1218
1232
|
while( !m_bExit )
|
@@ -0,0 +1,528 @@
|
|
1
|
+
package rhomobile.bluetooth;
|
2
|
+
|
3
|
+
import rhomobile.RhodesApplication;
|
4
|
+
|
5
|
+
import net.rim.device.api.bluetooth.BluetoothSerialPort;
|
6
|
+
import net.rim.device.api.bluetooth.BluetoothSerialPortInfo;
|
7
|
+
import net.rim.device.api.io.http.HttpHeaders;
|
8
|
+
import net.rim.device.api.system.DeviceInfo;
|
9
|
+
import net.rim.device.api.ui.UiApplication;
|
10
|
+
import net.rim.device.api.ui.container.MainScreen;
|
11
|
+
|
12
|
+
import com.rho.RhoEmptyLogger;
|
13
|
+
import com.rho.RhoLogger;
|
14
|
+
import com.xruby.runtime.builtin.ObjectFactory;
|
15
|
+
import com.xruby.runtime.builtin.RubyArray;
|
16
|
+
import com.xruby.runtime.builtin.RubyFixnum;
|
17
|
+
import com.xruby.runtime.builtin.RubyInteger;
|
18
|
+
import com.xruby.runtime.builtin.RubyString;
|
19
|
+
import com.xruby.runtime.lang.*;
|
20
|
+
|
21
|
+
|
22
|
+
public class BluetoothManager /*extends RubyBasic*/ implements BluetoothScreen.BluetoothScreenCallback, BluetoothPort.BluetoothPortListener {
|
23
|
+
|
24
|
+
private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() :
|
25
|
+
new RhoLogger("Bluetooth");
|
26
|
+
|
27
|
+
|
28
|
+
public static String BT_OK = "OK";
|
29
|
+
public static String BT_CANCEL = "CANCEL";
|
30
|
+
public static String BT_ERROR = "ERROR";
|
31
|
+
|
32
|
+
public static String BT_ROLE_SERVER = "ROLE_SERVER";
|
33
|
+
public static String BT_ROLE_CLIENT = "ROLE_CLIENT";
|
34
|
+
|
35
|
+
public static String BT_SESSION_INPUT_DATA_RECEIVED = "SESSION_INPUT_DATA_RECEIVED";
|
36
|
+
public static String BT_SESSION_DISCONNECT = "SESSION_DISCONNECT";
|
37
|
+
|
38
|
+
private static BluetoothManager ourBluetoothManager = null;
|
39
|
+
|
40
|
+
private String mCreateSessionCallback = null;
|
41
|
+
private String mSessionCallback = null;
|
42
|
+
private String mConnectedDeviceName = null;
|
43
|
+
private String mLocalDeviceName = null;
|
44
|
+
private BluetoothScreen mScreen = null;
|
45
|
+
private BluetoothSerialPortInfo[] mDevices = null;
|
46
|
+
private BluetoothPort mPort = null;
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
public static void rhoLogInfo(String msg) {
|
51
|
+
LOG.INFO(msg);
|
52
|
+
//LOG.ERROR(msg);
|
53
|
+
}
|
54
|
+
|
55
|
+
public static void rhoLogError(String msg) {
|
56
|
+
LOG.ERROR(msg);
|
57
|
+
}
|
58
|
+
|
59
|
+
public static BluetoothManager getInstance() {
|
60
|
+
if (ourBluetoothManager == null) {
|
61
|
+
ourBluetoothManager = new BluetoothManager();
|
62
|
+
ourBluetoothManager.init();
|
63
|
+
}
|
64
|
+
return ourBluetoothManager;
|
65
|
+
}
|
66
|
+
|
67
|
+
private void init() {
|
68
|
+
mLocalDeviceName = "Blackberry device";//DeviceInfo.getDeviceName();
|
69
|
+
mScreen = null;
|
70
|
+
mPort = null;
|
71
|
+
}
|
72
|
+
|
73
|
+
private void freeAll() {
|
74
|
+
if (mScreen != null) {
|
75
|
+
rhoPopScreen(mScreen);
|
76
|
+
mScreen = null;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
public static void rhoPushScreen(MainScreen screen) {
|
81
|
+
RhodesApplication app = (RhodesApplication)UiApplication.getUiApplication();
|
82
|
+
final MainScreen scr = screen;
|
83
|
+
app.invokeLater(new Runnable()
|
84
|
+
{
|
85
|
+
public void run()
|
86
|
+
{
|
87
|
+
UiApplication app = UiApplication.getUiApplication();
|
88
|
+
app.pushScreen(scr);
|
89
|
+
app.requestForeground();
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
|
94
|
+
public static void rhoPopScreen(MainScreen screen) {
|
95
|
+
RhodesApplication app = (RhodesApplication)UiApplication.getUiApplication();
|
96
|
+
final MainScreen scr = screen;
|
97
|
+
app.invokeLater(new Runnable()
|
98
|
+
{
|
99
|
+
public void run()
|
100
|
+
{
|
101
|
+
UiApplication app = UiApplication.getUiApplication();
|
102
|
+
app.popScreen(scr);
|
103
|
+
app.requestForeground();
|
104
|
+
}
|
105
|
+
});
|
106
|
+
}
|
107
|
+
|
108
|
+
public void closeBluetoothScreenSilent() {
|
109
|
+
RhodesApplication app = (RhodesApplication)UiApplication.getUiApplication();
|
110
|
+
final BluetoothScreen scr = mScreen;
|
111
|
+
mScreen = null;
|
112
|
+
if (scr != null) {
|
113
|
+
app.invokeLater(new Runnable()
|
114
|
+
{
|
115
|
+
public void run()
|
116
|
+
{
|
117
|
+
if (scr != null) {
|
118
|
+
scr.closeSilent();
|
119
|
+
}
|
120
|
+
}
|
121
|
+
});
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
// BluetoothScreenCallback
|
126
|
+
public void onBluetoothScreenCancel() {
|
127
|
+
rhoLogInfo("onBluetoothScreenCancel()");
|
128
|
+
if (mPort != null) {
|
129
|
+
mPort.disconnect();
|
130
|
+
mPort = null;
|
131
|
+
}
|
132
|
+
fireCreateSessionCallback(BT_CANCEL, "");
|
133
|
+
mScreen = null;
|
134
|
+
}
|
135
|
+
|
136
|
+
// BluetoothScreenCallback
|
137
|
+
public void onBluetoothScreenSelect(int index) {
|
138
|
+
rhoLogInfo("onBluetoothScreenSelect("+String.valueOf(index)+")");
|
139
|
+
UiApplication app = UiApplication.getUiApplication();
|
140
|
+
final int i = index;
|
141
|
+
app.invokeLater(new Runnable()
|
142
|
+
{
|
143
|
+
public void run()
|
144
|
+
{
|
145
|
+
getInstance().mPort = new BluetoothPort(mDevices[i], getInstance());
|
146
|
+
}
|
147
|
+
});
|
148
|
+
mScreen = null;
|
149
|
+
}
|
150
|
+
|
151
|
+
// BluetoothPortListener
|
152
|
+
public void onBluetoothPortDisconnect() {
|
153
|
+
fireSessionCallback(mPort.getConnectedDeviceName(), BT_SESSION_DISCONNECT);
|
154
|
+
}
|
155
|
+
|
156
|
+
// BluetoothPortListener
|
157
|
+
public void onBluetoothPortError() {
|
158
|
+
fireSessionCallback(mPort.getConnectedDeviceName(), BT_ERROR);
|
159
|
+
}
|
160
|
+
|
161
|
+
// BluetoothPortListener
|
162
|
+
public void onBluetoothPortDataReceived() {
|
163
|
+
fireSessionCallback(mPort.getConnectedDeviceName(), BT_SESSION_INPUT_DATA_RECEIVED);
|
164
|
+
}
|
165
|
+
|
166
|
+
// BluetoothPortListener
|
167
|
+
public void onBluetoothPortConnected(boolean success) {
|
168
|
+
if (success) {
|
169
|
+
fireCreateSessionCallback(BT_OK, mPort.getConnectedDeviceName());
|
170
|
+
}
|
171
|
+
else {
|
172
|
+
fireCreateSessionCallback(BT_ERROR, mPort.getConnectedDeviceName());
|
173
|
+
}
|
174
|
+
closeBluetoothScreenSilent();
|
175
|
+
}
|
176
|
+
|
177
|
+
private void fireCreateSessionCallback(String status, String connected_device_name) {
|
178
|
+
String body = "&status=";
|
179
|
+
body += status;
|
180
|
+
body += "&connected_device_name=";
|
181
|
+
body += connected_device_name;
|
182
|
+
if (mCreateSessionCallback != null) {
|
183
|
+
rhoLogInfo("fire Create Session Callback status="+status+", connected_device_name="+connected_device_name);
|
184
|
+
fireRhodeCallback(mCreateSessionCallback, body);
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
rhoLogError("fire Create Session Callback ERROR - Create Session callback not defined");
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
private void fireSessionCallback(String connected_device_name, String event_type) {
|
192
|
+
String body = "&connected_device_name=";
|
193
|
+
body += connected_device_name;
|
194
|
+
body += "&event_type=";
|
195
|
+
body += event_type;
|
196
|
+
if (mSessionCallback != null) {
|
197
|
+
rhoLogInfo("fire Session Callback connected_device_name="+connected_device_name+", event="+event_type);
|
198
|
+
fireRhodeCallback(mSessionCallback, body);
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
rhoLogError("fire Session Callback ERROR - Session callback not defined");
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
private void fireRhodeCallback(String callback_url, String body) {
|
206
|
+
RhodesApplication app = (RhodesApplication)UiApplication.getUiApplication();
|
207
|
+
HttpHeaders headers = new HttpHeaders();
|
208
|
+
headers.addProperty("Content-Type", "application/x-www-form-urlencoded");
|
209
|
+
app.postUrl(callback_url, body, headers);
|
210
|
+
}
|
211
|
+
|
212
|
+
|
213
|
+
public static int is_bluetooth_available() {
|
214
|
+
return BluetoothSerialPort.isSupported()?1:0;
|
215
|
+
}
|
216
|
+
|
217
|
+
public static void off_bluetooth() {
|
218
|
+
rhoLogInfo("off_bluetooth()");
|
219
|
+
getInstance().freeAll();
|
220
|
+
ourBluetoothManager = null;
|
221
|
+
}
|
222
|
+
|
223
|
+
public static void set_device_name(String device_name) {
|
224
|
+
getInstance().mLocalDeviceName = device_name;
|
225
|
+
}
|
226
|
+
|
227
|
+
public static String get_device_name() {
|
228
|
+
return getInstance().mLocalDeviceName;
|
229
|
+
}
|
230
|
+
public static String get_last_error() {
|
231
|
+
return BT_OK;
|
232
|
+
}
|
233
|
+
|
234
|
+
public static String create_session(String role, String callback_url) {
|
235
|
+
rhoLogInfo("create_session("+role+", "+callback_url+")");
|
236
|
+
getInstance().mCreateSessionCallback = callback_url;
|
237
|
+
if (BT_ROLE_CLIENT.equals(role)) {
|
238
|
+
// client
|
239
|
+
if (is_bluetooth_available() != 0) {
|
240
|
+
getInstance().mDevices = BluetoothSerialPort.getSerialPortInfo();
|
241
|
+
int count = getInstance().mDevices.length;
|
242
|
+
String devices[] = new String[count];
|
243
|
+
int i;
|
244
|
+
for (i = 0; i < count; i++) {
|
245
|
+
devices[i] = getInstance().mDevices[i].getDeviceName();
|
246
|
+
}
|
247
|
+
getInstance().mScreen = new BluetoothScreen(BluetoothScreen.BLUETOOTH_SCREEN_TYPE_CLIENT, devices, getInstance());
|
248
|
+
}
|
249
|
+
else {
|
250
|
+
getInstance().mScreen = new BluetoothScreen(BluetoothScreen.BLUETOOTH_SCREEN_TYPE_UNSUPPORTED, null, getInstance());
|
251
|
+
}
|
252
|
+
rhoPushScreen(getInstance().mScreen);
|
253
|
+
}
|
254
|
+
else {
|
255
|
+
// server
|
256
|
+
if (is_bluetooth_available() != 0) {
|
257
|
+
getInstance().mPort = new BluetoothPort(null, getInstance());
|
258
|
+
getInstance().mScreen = new BluetoothScreen(BluetoothScreen.BLUETOOTH_SCREEN_TYPE_SERVER, null, getInstance());
|
259
|
+
rhoPushScreen(getInstance().mScreen);
|
260
|
+
getInstance().mPort.startListenThread();
|
261
|
+
}
|
262
|
+
else {
|
263
|
+
getInstance().mScreen = new BluetoothScreen(BluetoothScreen.BLUETOOTH_SCREEN_TYPE_UNSUPPORTED, null, getInstance());
|
264
|
+
rhoPushScreen(getInstance().mScreen);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
return BT_OK;
|
268
|
+
}
|
269
|
+
|
270
|
+
public static void session_set_callback(String connected_device_name, String callback_url) {
|
271
|
+
rhoLogInfo("session_set_callback("+connected_device_name+", "+callback_url+")");
|
272
|
+
getInstance().mSessionCallback = callback_url;
|
273
|
+
}
|
274
|
+
|
275
|
+
public static void session_disconnect(String connected_device_name) {
|
276
|
+
rhoLogInfo("session_disconnect("+connected_device_name+")");
|
277
|
+
if (getInstance().mPort != null) {
|
278
|
+
getInstance().mPort.disconnect();
|
279
|
+
getInstance().mPort = null;
|
280
|
+
}
|
281
|
+
else {
|
282
|
+
getInstance().fireSessionCallback("", BT_ERROR);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
public static int session_get_status(String connected_device_name) {
|
287
|
+
rhoLogInfo("session_get_status("+connected_device_name+")");
|
288
|
+
if (getInstance().mPort != null) {
|
289
|
+
int status = getInstance().mPort.getStatus();
|
290
|
+
rhoLogInfo("session_get_status() return = "+String.valueOf(status));
|
291
|
+
return status;
|
292
|
+
}
|
293
|
+
else {
|
294
|
+
getInstance().fireSessionCallback("", BT_ERROR);
|
295
|
+
}
|
296
|
+
return 0;
|
297
|
+
}
|
298
|
+
|
299
|
+
public static String session_read_string(String connected_device_name) {
|
300
|
+
rhoLogInfo("session_read_string("+connected_device_name+")");
|
301
|
+
if (getInstance().mPort != null) {
|
302
|
+
byte[] data = getInstance().mPort.readData();
|
303
|
+
String str = new String(data,0,data.length);
|
304
|
+
rhoLogInfo("session_read_string() return = ["+str+"]");
|
305
|
+
return str;
|
306
|
+
}
|
307
|
+
else {
|
308
|
+
getInstance().fireSessionCallback("", BT_ERROR);
|
309
|
+
}
|
310
|
+
return "";
|
311
|
+
}
|
312
|
+
|
313
|
+
public static void session_write_string(String connected_device_name, String str) {
|
314
|
+
rhoLogInfo("session_write_string("+connected_device_name+", "+str+")");
|
315
|
+
if (getInstance().mPort != null) {
|
316
|
+
byte[] data = str.getBytes();
|
317
|
+
getInstance().mPort.writeData(data);
|
318
|
+
}
|
319
|
+
else {
|
320
|
+
getInstance().fireSessionCallback("", BT_ERROR);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
public static byte[] session_read_data(String connected_device_name) {
|
325
|
+
rhoLogInfo("session_read_data()");
|
326
|
+
if (getInstance().mPort != null) {
|
327
|
+
return getInstance().mPort.readData();
|
328
|
+
}
|
329
|
+
else {
|
330
|
+
getInstance().fireSessionCallback("", BT_ERROR);
|
331
|
+
}
|
332
|
+
byte[] m = new byte[0];
|
333
|
+
return m;
|
334
|
+
}
|
335
|
+
|
336
|
+
public static void session_write_data(String connected_device_name, byte[] data) {
|
337
|
+
rhoLogInfo("session_write_data()");
|
338
|
+
if (getInstance().mPort != null) {
|
339
|
+
getInstance().mPort.writeData(data);
|
340
|
+
}
|
341
|
+
else {
|
342
|
+
getInstance().fireSessionCallback("", BT_ERROR);
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
|
347
|
+
public static void initMethods(RubyClass klass) {
|
348
|
+
|
349
|
+
klass.getSingletonClass().defineMethod("is_bluetooth_available", new RubyNoArgMethod() {
|
350
|
+
protected RubyValue run(RubyValue receiver, RubyBlock block) {
|
351
|
+
RubyValue res = RubyConstant.QFALSE;
|
352
|
+
if (is_bluetooth_available() != 0) {
|
353
|
+
res = RubyConstant.QTRUE;
|
354
|
+
}
|
355
|
+
return res;
|
356
|
+
}
|
357
|
+
});
|
358
|
+
klass.getSingletonClass().defineMethod("off_bluetooth", new RubyNoArgMethod() {
|
359
|
+
protected RubyValue run(RubyValue receiver, RubyBlock block) {
|
360
|
+
off_bluetooth();
|
361
|
+
return RubyConstant.QNIL;
|
362
|
+
}
|
363
|
+
});
|
364
|
+
|
365
|
+
klass.getSingletonClass().defineMethod("set_device_name", new RubyOneArgMethod() {
|
366
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block) {
|
367
|
+
if ( arg0 instanceof RubyString )
|
368
|
+
{
|
369
|
+
String device_name = arg0.toString();
|
370
|
+
set_device_name(device_name);
|
371
|
+
}
|
372
|
+
else {
|
373
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.set_device_name: wrong argument type.Should be String");
|
374
|
+
}
|
375
|
+
return RubyConstant.QNIL;
|
376
|
+
}
|
377
|
+
});
|
378
|
+
klass.getSingletonClass().defineMethod("get_device_name", new RubyNoArgMethod() {
|
379
|
+
protected RubyValue run(RubyValue receiver, RubyBlock block) {
|
380
|
+
return ObjectFactory.createString(get_device_name());
|
381
|
+
}
|
382
|
+
});
|
383
|
+
klass.getSingletonClass().defineMethod("get_last_error", new RubyNoArgMethod() {
|
384
|
+
protected RubyValue run(RubyValue receiver, RubyBlock block) {
|
385
|
+
return ObjectFactory.createString(get_last_error());
|
386
|
+
}
|
387
|
+
});
|
388
|
+
klass.getSingletonClass().defineMethod("create_session", new RubyTwoArgMethod() {
|
389
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyValue arg2, RubyBlock block) {
|
390
|
+
if ( (arg1 instanceof RubyString) && (arg2 instanceof RubyString) )
|
391
|
+
{
|
392
|
+
String role = arg1.toString();
|
393
|
+
String callback_url = arg2.toString();
|
394
|
+
return ObjectFactory.createString(create_session(role, callback_url));
|
395
|
+
}
|
396
|
+
else {
|
397
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.create_session: wrong argument type.Should be String");
|
398
|
+
}
|
399
|
+
}
|
400
|
+
});
|
401
|
+
|
402
|
+
klass.getSingletonClass().defineMethod("session_set_callback", new RubyTwoArgMethod() {
|
403
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyValue arg2, RubyBlock block) {
|
404
|
+
if ( (arg1 instanceof RubyString) && (arg2 instanceof RubyString) )
|
405
|
+
{
|
406
|
+
String connected_device_name = arg1.toString();
|
407
|
+
String callback_url = arg2.toString();
|
408
|
+
session_set_callback(connected_device_name, callback_url);
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_set_callback: wrong argument type.Should be String");
|
412
|
+
}
|
413
|
+
return RubyConstant.QNIL;
|
414
|
+
}
|
415
|
+
});
|
416
|
+
klass.getSingletonClass().defineMethod("session_disconnect", new RubyOneArgMethod() {
|
417
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block) {
|
418
|
+
if ( arg0 instanceof RubyString )
|
419
|
+
{
|
420
|
+
String connected_device_name = arg0.toString();
|
421
|
+
session_disconnect(connected_device_name);
|
422
|
+
}
|
423
|
+
else {
|
424
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_disconnect: wrong argument type.Should be String");
|
425
|
+
}
|
426
|
+
return RubyConstant.QNIL;
|
427
|
+
}
|
428
|
+
});
|
429
|
+
klass.getSingletonClass().defineMethod("session_get_status", new RubyOneArgMethod() {
|
430
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block) {
|
431
|
+
if ( arg0 instanceof RubyString )
|
432
|
+
{
|
433
|
+
String connected_device_name = arg0.toString();
|
434
|
+
int status = session_get_status(connected_device_name);
|
435
|
+
return ObjectFactory.createInteger(status);
|
436
|
+
}
|
437
|
+
else {
|
438
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_get_status: wrong argument type.Should be String");
|
439
|
+
}
|
440
|
+
}
|
441
|
+
});
|
442
|
+
klass.getSingletonClass().defineMethod("session_read_string", new RubyOneArgMethod() {
|
443
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block) {
|
444
|
+
if ( arg0 instanceof RubyString )
|
445
|
+
{
|
446
|
+
String connected_device_name = arg0.toString();
|
447
|
+
String str = session_read_string(connected_device_name);
|
448
|
+
return ObjectFactory.createString(str);
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_read_string: wrong argument type.Should be String");
|
452
|
+
}
|
453
|
+
}
|
454
|
+
});
|
455
|
+
klass.getSingletonClass().defineMethod("session_write_string", new RubyTwoArgMethod() {
|
456
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyValue arg2, RubyBlock block) {
|
457
|
+
if ( (arg1 instanceof RubyString) && (arg2 instanceof RubyString) )
|
458
|
+
{
|
459
|
+
String connected_device_name = arg1.toString();
|
460
|
+
String str = arg2.toString();
|
461
|
+
session_write_string(connected_device_name, str);
|
462
|
+
}
|
463
|
+
else {
|
464
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_write_string: wrong argument type.Should be String");
|
465
|
+
}
|
466
|
+
return RubyConstant.QNIL;
|
467
|
+
}
|
468
|
+
});
|
469
|
+
klass.getSingletonClass().defineMethod("session_read_data", new RubyOneArgMethod() {
|
470
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg0, RubyBlock block) {
|
471
|
+
if ( arg0 instanceof RubyString )
|
472
|
+
{
|
473
|
+
String connected_device_name = arg0.toString();
|
474
|
+
byte[] data = session_read_data(connected_device_name);
|
475
|
+
RubyArray ruby_ar = ObjectFactory.createArray(data.length, data.length, false);
|
476
|
+
int i;
|
477
|
+
for (i = 0; i < data.length; i++) {
|
478
|
+
ruby_ar.and(ObjectFactory.createFixnum(data[i]));
|
479
|
+
}
|
480
|
+
return ruby_ar;
|
481
|
+
}
|
482
|
+
else {
|
483
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in session_read_data: wrong argument type.Should be String");
|
484
|
+
}
|
485
|
+
}
|
486
|
+
});
|
487
|
+
klass.getSingletonClass().defineMethod("session_write_data", new RubyTwoArgMethod() {
|
488
|
+
protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyValue arg2, RubyBlock block) {
|
489
|
+
if ( (arg1 instanceof RubyString) && (arg2 instanceof RubyArray) )
|
490
|
+
{
|
491
|
+
String connected_device_name = arg1.toString();
|
492
|
+
RubyArray ruby_ar = (RubyArray)arg2;
|
493
|
+
int i;
|
494
|
+
byte[] data = new byte[ruby_ar.size()];
|
495
|
+
for (i = 0; i < ruby_ar.size(); i++) {
|
496
|
+
RubyValue num = ruby_ar.get(i);
|
497
|
+
int b = 0;
|
498
|
+
if (num instanceof RubyFixnum) {
|
499
|
+
RubyFixnum rv = (RubyFixnum)num;
|
500
|
+
b = rv.toInt();
|
501
|
+
}
|
502
|
+
else {
|
503
|
+
if (num instanceof RubyInteger) {
|
504
|
+
RubyInteger rv = (RubyInteger)num;
|
505
|
+
b = rv.toInt();
|
506
|
+
}
|
507
|
+
else {
|
508
|
+
if (num instanceof RubySymbol) {
|
509
|
+
RubySymbol rv = (RubySymbol)num;
|
510
|
+
b = rv.toInt();
|
511
|
+
}
|
512
|
+
else {
|
513
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_write_data: wrong argument type.Should be Array of Fixnums or Integers");
|
514
|
+
}
|
515
|
+
}
|
516
|
+
}
|
517
|
+
data[i] = (byte)b;
|
518
|
+
}
|
519
|
+
session_write_data(connected_device_name, data);
|
520
|
+
}
|
521
|
+
else {
|
522
|
+
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in RhoBluetooth.session_write_data: wrong argument type.Should be String second should be Array");
|
523
|
+
}
|
524
|
+
return RubyConstant.QNIL;
|
525
|
+
}
|
526
|
+
});
|
527
|
+
}
|
528
|
+
}
|