rhodes 2.1.0 → 2.2.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,72 @@
|
|
1
|
+
//
|
2
|
+
// Bluetooth.h
|
3
|
+
// rhorunner
|
4
|
+
//
|
5
|
+
// Created by Soldatenkov Dmitry on 27/07/10.
|
6
|
+
// Copyright 2010 Rhomobile. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import <UIKit/UIKit.h>
|
10
|
+
#import <Foundation/Foundation.h>
|
11
|
+
#import <GameKit/GameKit.h>
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
@interface RhoBluetoothManager : NSObject <GKPeerPickerControllerDelegate, GKSessionDelegate> {
|
17
|
+
GKSession *session;
|
18
|
+
|
19
|
+
NSString* connectionCallbackURL;
|
20
|
+
NSString* sessionCallbackURL;
|
21
|
+
|
22
|
+
NSString* deviceName;
|
23
|
+
NSString* connectedDeviceName;
|
24
|
+
NSString* connectedDeviceID;
|
25
|
+
|
26
|
+
NSMutableArray* packets;
|
27
|
+
}
|
28
|
+
|
29
|
+
@property(nonatomic, retain) GKSession *session;
|
30
|
+
@property(nonatomic, copy) NSString *deviceName;
|
31
|
+
@property(nonatomic, copy) NSString *connectedDeviceName;
|
32
|
+
@property(nonatomic, copy) NSString *connectedDeviceID;
|
33
|
+
@property (readwrite, copy) NSString *connectionCallbackURL;
|
34
|
+
@property (readwrite, copy) NSString *sessionCallbackURL;
|
35
|
+
@property(nonatomic, retain) NSMutableArray *packets;
|
36
|
+
|
37
|
+
|
38
|
+
+ (RhoBluetoothManager*)sharedInstance;
|
39
|
+
|
40
|
+
// Peer Picker Related Methods
|
41
|
+
- (void)startPicker:(NSString*)callback;
|
42
|
+
|
43
|
+
// GKPeerPickerControllerDelegate Methods
|
44
|
+
- (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker;
|
45
|
+
- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type;
|
46
|
+
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session;
|
47
|
+
|
48
|
+
// Session Related Methods
|
49
|
+
- (void)invalidateSession:(GKSession *)msession;
|
50
|
+
|
51
|
+
// Data Send/Receive Methods
|
52
|
+
- (void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context;
|
53
|
+
- (void)sendData:(GKSession *)session withData:(void *)data ofLength:(int)length reliable:(BOOL)howtosend;
|
54
|
+
|
55
|
+
// GKSessionDelegate Methods
|
56
|
+
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state;
|
57
|
+
|
58
|
+
|
59
|
+
- (void)fireConnectionCallback:(NSString*)status connected_device_name:(NSString*)connected_device_name;
|
60
|
+
- (void)fireSessionCallback:(NSString*)connected_device_name event_type:(NSString*)event_type;
|
61
|
+
|
62
|
+
- (int)readFromPackets:(void*)buf length:(int)length;
|
63
|
+
- (void)addToPackets:(void*)buf length:(int)length;
|
64
|
+
- (void)clearPackets;
|
65
|
+
- (int)getPacketsSize;
|
66
|
+
|
67
|
+
- (NSString*)readString;
|
68
|
+
- (void)sendString:(NSString*)string;
|
69
|
+
|
70
|
+
- (void)sendData:(void*)buf length:(int)length;
|
71
|
+
|
72
|
+
@end
|
@@ -0,0 +1,414 @@
|
|
1
|
+
//
|
2
|
+
// BluetoothManager.m
|
3
|
+
// rhorunner
|
4
|
+
//
|
5
|
+
// Created by Soldatenkov Dmitry on 27/07/10.
|
6
|
+
// Copyright 2010 Rhomobile. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import "Rhodes.h"
|
10
|
+
#import "Bluetooth.h"
|
11
|
+
#import "AppManager.h"
|
12
|
+
#import "common/RhodesApp.h"
|
13
|
+
#include "ruby/ext/rho/rhoruby.h"
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
#define BTC_OK "OK"
|
18
|
+
#define BTC_CANCEL "CANCEL"
|
19
|
+
#define BTC_ERROR "ERROR"
|
20
|
+
|
21
|
+
#define BT_OK @BTC_OK
|
22
|
+
#define BT_CANCEL @BTC_CANCEL
|
23
|
+
#define BT_ERROR @BTC_ERROR
|
24
|
+
|
25
|
+
#define BT_ROLE_SERVER @"ROLE_SERVER"
|
26
|
+
#define BT_ROLE_CLIENT @"ROLE_CLIENT"
|
27
|
+
|
28
|
+
#define BT_SESSION_INPUT_DATA_RECEIVED @"SESSION_INPUT_DATA_RECEIVED"
|
29
|
+
#define BT_SESSION_DISCONNECT @"SESSION_DISCONNECT"
|
30
|
+
|
31
|
+
// session id must be equal on each device
|
32
|
+
#define BT_RHOMOBILE_SESSION_ID @"RhomobileBluetoothSession"
|
33
|
+
|
34
|
+
|
35
|
+
#define kMaxPacketSize 1024
|
36
|
+
|
37
|
+
|
38
|
+
@implementation RhoBluetoothManager
|
39
|
+
|
40
|
+
|
41
|
+
static RhoBluetoothManager *instance = NULL;
|
42
|
+
|
43
|
+
+ (RhoBluetoothManager*)sharedInstance {
|
44
|
+
if (instance == NULL) {
|
45
|
+
instance = [[RhoBluetoothManager alloc] init];
|
46
|
+
instance.session = nil;
|
47
|
+
instance.deviceName = [[UIDevice currentDevice] name];
|
48
|
+
instance.connectedDeviceName = nil;
|
49
|
+
instance.connectedDeviceID = nil;
|
50
|
+
instance.connectionCallbackURL = nil;
|
51
|
+
instance.sessionCallbackURL = nil;
|
52
|
+
instance.packets = [NSMutableArray arrayWithCapacity:128];
|
53
|
+
}
|
54
|
+
return instance;
|
55
|
+
}
|
56
|
+
|
57
|
+
- (void)dealloc {
|
58
|
+
[self invalidateSession:self.session];
|
59
|
+
self.session = nil;
|
60
|
+
self.deviceName = nil;
|
61
|
+
self.connectedDeviceName = nil;
|
62
|
+
|
63
|
+
[super dealloc];
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
@synthesize session, deviceName, connectedDeviceName, connectedDeviceID, connectionCallbackURL, sessionCallbackURL, packets;
|
68
|
+
|
69
|
+
|
70
|
+
#pragma mark -
|
71
|
+
#pragma mark Peer Picker Related Methods
|
72
|
+
|
73
|
+
-(void)startPicker:(NSString*)role {
|
74
|
+
GKPeerPickerController* picker;
|
75
|
+
picker = [[GKPeerPickerController alloc] init]; // note: picker is released in various picker delegate methods when picker use is done.
|
76
|
+
picker.delegate = self;
|
77
|
+
[picker show]; // show the Peer Picker
|
78
|
+
}
|
79
|
+
|
80
|
+
#pragma mark GKPeerPickerControllerDelegate Methods
|
81
|
+
|
82
|
+
- (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker {
|
83
|
+
// Peer Picker automatically dismisses on user cancel. No need to programmatically dismiss.
|
84
|
+
|
85
|
+
// autorelease the picker.
|
86
|
+
picker.delegate = nil;
|
87
|
+
[picker autorelease];
|
88
|
+
|
89
|
+
// invalidate and release game session if one is around.
|
90
|
+
if(self.session != nil) {
|
91
|
+
[self invalidateSession:self.session];
|
92
|
+
self.session = nil;
|
93
|
+
}
|
94
|
+
[self fireConnectionCallback:BT_CANCEL connected_device_name:@""];
|
95
|
+
}
|
96
|
+
|
97
|
+
- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
|
98
|
+
// session id - identifier for session
|
99
|
+
// display name - name for display on other devices
|
100
|
+
|
101
|
+
GKSession *msession = [[GKSession alloc] initWithSessionID:BT_RHOMOBILE_SESSION_ID displayName:deviceName sessionMode:GKSessionModePeer];
|
102
|
+
return [msession autorelease]; // peer picker retains a reference, so autorelease ours so we don't leak.
|
103
|
+
}
|
104
|
+
|
105
|
+
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)csession {
|
106
|
+
// Remember the current peer.
|
107
|
+
self.connectedDeviceID = peerID;
|
108
|
+
self.connectedDeviceName = [csession displayNameForPeer:peerID]; // copy
|
109
|
+
|
110
|
+
// Make sure we have a reference to the game session and it is set up
|
111
|
+
self.session = csession; // retain
|
112
|
+
self.session.delegate = self;
|
113
|
+
[self.session setDataReceiveHandler:self withContext:NULL];
|
114
|
+
|
115
|
+
// Done with the Peer Picker so dismiss it.
|
116
|
+
[picker dismiss];
|
117
|
+
picker.delegate = nil;
|
118
|
+
[picker autorelease];
|
119
|
+
|
120
|
+
[self fireConnectionCallback:BT_OK connected_device_name:self.connectedDeviceName];
|
121
|
+
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
#pragma mark -
|
126
|
+
#pragma mark Session Related Methods
|
127
|
+
|
128
|
+
- (void)invalidateSession:(GKSession *)msession {
|
129
|
+
if(msession != nil) {
|
130
|
+
[msession disconnectFromAllPeers];
|
131
|
+
msession.available = NO;
|
132
|
+
[msession setDataReceiveHandler: nil withContext: NULL];
|
133
|
+
msession.delegate = nil;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
#pragma mark Data Send/Receive Methods
|
140
|
+
|
141
|
+
- (void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context {
|
142
|
+
static int lastPacketTime = -1;
|
143
|
+
|
144
|
+
unsigned char *incomingPacket = (unsigned char *)[data bytes];
|
145
|
+
int incomingPacketSize= [data length];
|
146
|
+
|
147
|
+
[self addToPackets:incomingPacket length:incomingPacketSize];
|
148
|
+
[self fireSessionCallback:connectedDeviceName event_type:BT_SESSION_INPUT_DATA_RECEIVED];
|
149
|
+
}
|
150
|
+
|
151
|
+
- (void)sendData:(GKSession *)session withData:(void *)data ofLength:(int)length reliable:(BOOL)howtosend {
|
152
|
+
// the packet we'll send is resued
|
153
|
+
static unsigned char networkPacket[kMaxPacketSize];
|
154
|
+
|
155
|
+
unsigned char* indata = (unsigned char*)data;
|
156
|
+
int size = length;
|
157
|
+
while (size > 0) {
|
158
|
+
int send_size = size;
|
159
|
+
if (send_size > kMaxPacketSize) {
|
160
|
+
send_size = kMaxPacketSize;
|
161
|
+
}
|
162
|
+
memcpy( &networkPacket[0], indata, send_size );
|
163
|
+
NSData *packet = [NSData dataWithBytes: networkPacket length: (length)];
|
164
|
+
if(howtosend == YES) {
|
165
|
+
//[self.session sendData:packet toPeers:[NSArray arrayWithObject:self.connectedDeviceID] withDataMode:GKSendDataReliable error:nil];
|
166
|
+
[self.session sendDataToAllPeers:packet withDataMode:GKSendDataReliable error:nil];
|
167
|
+
} else {
|
168
|
+
//[self.session sendData:packet toPeers:[NSArray arrayWithObject:self.connectedDeviceID] withDataMode:GKSendDataUnreliable error:nil];
|
169
|
+
[self.session sendDataToAllPeers:packet withDataMode:GKSendDataUnreliable error:nil];
|
170
|
+
}
|
171
|
+
size -= send_size;
|
172
|
+
indata += send_size;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
- (void)sendNSData:(NSData*)cdata {
|
177
|
+
[self sendData:self.session withData:[cdata bytes] ofLength:[cdata length] reliable:YES];
|
178
|
+
}
|
179
|
+
|
180
|
+
#pragma mark GKSessionDelegate Methods
|
181
|
+
|
182
|
+
// we've gotten a state change in the session
|
183
|
+
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
|
184
|
+
|
185
|
+
if(state == GKPeerStateDisconnected) {
|
186
|
+
// We've been disconnected from the other peer.
|
187
|
+
[self fireSessionCallback:connectedDeviceName event_type:BT_SESSION_DISCONNECT];
|
188
|
+
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
- (void)fireConnectionCallback:(NSString*)status connected_device_name:(NSString*)connected_device_name {
|
193
|
+
if (connectionCallbackURL == nil) {
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
NSString* strBody = @"";
|
197
|
+
strBody = [strBody stringByAppendingString:@"&status="];
|
198
|
+
strBody = [strBody stringByAppendingString:status];
|
199
|
+
strBody = [strBody stringByAppendingString:@"&connected_device_name="];
|
200
|
+
strBody = [strBody stringByAppendingString:connected_device_name];
|
201
|
+
rho_net_request_with_data(rho_http_normalizeurl([connectionCallbackURL UTF8String]), [strBody UTF8String]);
|
202
|
+
}
|
203
|
+
|
204
|
+
- (void)fireSessionCallback:(NSString*)connected_device_name event_type:(NSString*)event_type {
|
205
|
+
if (sessionCallbackURL == nil) {
|
206
|
+
return;
|
207
|
+
}
|
208
|
+
NSString* strBody = @"";
|
209
|
+
strBody = [strBody stringByAppendingString:@"&connected_device_name="];
|
210
|
+
strBody = [strBody stringByAppendingString:connected_device_name];
|
211
|
+
strBody = [strBody stringByAppendingString:@"&event_type="];
|
212
|
+
strBody = [strBody stringByAppendingString:event_type];
|
213
|
+
rho_net_request_with_data(rho_http_normalizeurl([sessionCallbackURL UTF8String]), [strBody UTF8String]);
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
- (void)startConnect:(NSString*)callback {
|
218
|
+
self.session = nil;
|
219
|
+
self.connectedDeviceName = nil;
|
220
|
+
self.connectedDeviceID = nil;
|
221
|
+
|
222
|
+
self.connectionCallbackURL = callback;
|
223
|
+
[self performSelectorOnMainThread:@selector(startPicker:) withObject:BT_ROLE_SERVER waitUntilDone:NO];
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
- (int)readFromPackets:(void*)buf length:(int)length {
|
228
|
+
unsigned char *dst = (unsigned char *)buf;
|
229
|
+
int packets_size = [self getPacketsSize];
|
230
|
+
int readed_size = 0;
|
231
|
+
while ((readed_size < length) && (readed_size < packets_size) && ([self.packets count] > 0)) {
|
232
|
+
NSData* data = [self.packets objectAtIndex:0];
|
233
|
+
if ([data length] <= (length-readed_size)) {
|
234
|
+
int to_read = [data length];
|
235
|
+
// read data and remove packet
|
236
|
+
[data getBytes:dst length:to_read];
|
237
|
+
dst+= to_read;
|
238
|
+
readed_size += to_read;
|
239
|
+
[self.packets removeObjectAtIndex:0];
|
240
|
+
}
|
241
|
+
else {
|
242
|
+
// read part of packet + reduce packet size
|
243
|
+
int to_read = length-readed_size;
|
244
|
+
[data getBytes:dst length:to_read];
|
245
|
+
dst+= to_read;
|
246
|
+
readed_size += to_read;
|
247
|
+
NSData* udata = [data subdataWithRange:NSMakeRange(to_read, [data length]-to_read)];
|
248
|
+
[self.packets removeObjectAtIndex:0];
|
249
|
+
[self.packets insertObject:udata atIndex:0];
|
250
|
+
}
|
251
|
+
}
|
252
|
+
return readed_size;
|
253
|
+
}
|
254
|
+
|
255
|
+
- (void)addToPackets:(void*)buf length:(int)length {
|
256
|
+
NSData* data = [NSData dataWithBytes:buf length:length];
|
257
|
+
[self.packets addObject:data];
|
258
|
+
}
|
259
|
+
|
260
|
+
- (void)clearPackets {
|
261
|
+
[self.packets removeAllObjects];
|
262
|
+
}
|
263
|
+
|
264
|
+
- (int)getPacketsSize {
|
265
|
+
int size =0;
|
266
|
+
int i;
|
267
|
+
for (i = 0; i < self.packets.count; i++) {
|
268
|
+
NSData* data = [self.packets objectAtIndex:i];
|
269
|
+
size += [data length];
|
270
|
+
}
|
271
|
+
return size;
|
272
|
+
}
|
273
|
+
|
274
|
+
- (NSString*)readString {
|
275
|
+
int length = 0;
|
276
|
+
[self readFromPackets:&length length:4];
|
277
|
+
char* buf = (char*)malloc(length+2);
|
278
|
+
[self readFromPackets:buf length:length];
|
279
|
+
buf[length] = 0;
|
280
|
+
buf[length+1] = 0;
|
281
|
+
NSString* s = [NSString stringWithUTF8String:buf];
|
282
|
+
free(buf);
|
283
|
+
return s;
|
284
|
+
}
|
285
|
+
|
286
|
+
- (void)sendString:(NSString*)string {
|
287
|
+
if (self.session == nil) {
|
288
|
+
return;
|
289
|
+
}
|
290
|
+
const char* sbuf = [string UTF8String];
|
291
|
+
int length = strlen(sbuf);
|
292
|
+
|
293
|
+
char* buf = malloc(length+5);
|
294
|
+
char* dst = buf;
|
295
|
+
*((int*)dst) = length;
|
296
|
+
dst += 4;
|
297
|
+
memcpy(dst, sbuf, length);
|
298
|
+
|
299
|
+
//[self sendData:self.session withData:(void*)buf ofLength:(4+length) reliable:YES];
|
300
|
+
NSData* data = [NSData dataWithBytes:buf length:(4+length)];
|
301
|
+
[self performSelectorOnMainThread:@selector(sendNSData:) withObject:data waitUntilDone:NO];
|
302
|
+
free(buf);
|
303
|
+
}
|
304
|
+
|
305
|
+
- (void)sendData:(void*)buf length:(int)length {
|
306
|
+
if (self.session == nil) {
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
//[self sendData:self.session withData:buf ofLength:length reliable:YES];
|
310
|
+
NSData* data = [NSData dataWithBytes:buf length:(length)];
|
311
|
+
[self performSelectorOnMainThread:@selector(sendNSData:) withObject:data waitUntilDone:NO];
|
312
|
+
}
|
313
|
+
|
314
|
+
- (void)doDisconnectCommand:(NSString*)object {
|
315
|
+
if (self.session == nil) {
|
316
|
+
return;
|
317
|
+
}
|
318
|
+
[self invalidateSession:self.session];
|
319
|
+
self.session = nil;
|
320
|
+
[self fireSessionCallback:connectedDeviceName event_type:BT_SESSION_DISCONNECT];
|
321
|
+
self.sessionCallbackURL = nil;
|
322
|
+
}
|
323
|
+
|
324
|
+
- (void)doDisconnect {
|
325
|
+
[self performSelectorOnMainThread:@selector(doDisconnectCommand:) withObject:nil waitUntilDone:NO];
|
326
|
+
}
|
327
|
+
|
328
|
+
- (void)doBluetoothOffCommand:(NSString*)object {
|
329
|
+
[self doDisconnectCommand:nil];
|
330
|
+
instance = NULL;
|
331
|
+
}
|
332
|
+
|
333
|
+
- (void)doBluetoothOff {
|
334
|
+
[self performSelectorOnMainThread:@selector(doBluetoothOffCommand:) withObject:nil waitUntilDone:NO];
|
335
|
+
}
|
336
|
+
|
337
|
+
@end
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
int rho_bluetooth_is_bluetooth_available() {
|
342
|
+
return 1;
|
343
|
+
}
|
344
|
+
|
345
|
+
void rho_bluetooth_off_bluetooth() {
|
346
|
+
[[RhoBluetoothManager sharedInstance] doBluetoothOff];
|
347
|
+
}
|
348
|
+
|
349
|
+
void rho_bluetooth_set_device_name(const char* device_name) {
|
350
|
+
NSString* newname = [NSString stringWithUTF8String:device_name];
|
351
|
+
[RhoBluetoothManager sharedInstance].deviceName = newname;
|
352
|
+
}
|
353
|
+
|
354
|
+
const char* rho_bluetooth_get_device_name() {
|
355
|
+
return [[RhoBluetoothManager sharedInstance].deviceName UTF8String];
|
356
|
+
}
|
357
|
+
|
358
|
+
const char* rho_bluetooth_get_last_error() {
|
359
|
+
return BTC_OK;
|
360
|
+
}
|
361
|
+
|
362
|
+
const char* rho_bluetooth_create_session(const char* role, const char* callback_url) {
|
363
|
+
//NSString* role = [NSString stringWithUTF8String:role];
|
364
|
+
NSString* callback = [NSString stringWithUTF8String:callback_url];
|
365
|
+
[[RhoBluetoothManager sharedInstance] startConnect:callback];
|
366
|
+
return BTC_OK;
|
367
|
+
}
|
368
|
+
|
369
|
+
void rho_bluetooth_session_set_callback(const char* connected_device_name, const char* callback_url) {
|
370
|
+
NSString* callback = [NSString stringWithUTF8String:callback_url];
|
371
|
+
[RhoBluetoothManager sharedInstance].sessionCallbackURL = callback;
|
372
|
+
}
|
373
|
+
|
374
|
+
void rho_bluetooth_session_disconnect(const char* connected_device_name) {
|
375
|
+
[[RhoBluetoothManager sharedInstance] doDisconnect];
|
376
|
+
}
|
377
|
+
|
378
|
+
int rho_bluetooth_session_get_status(const char* connected_device_name) {
|
379
|
+
return [[RhoBluetoothManager sharedInstance] getPacketsSize];
|
380
|
+
}
|
381
|
+
|
382
|
+
const char* rho_bluetooth_session_read_string(const char* connected_device_name) {
|
383
|
+
NSString* s = [[RhoBluetoothManager sharedInstance] readString];
|
384
|
+
return [s UTF8String];
|
385
|
+
}
|
386
|
+
|
387
|
+
void rho_bluetooth_session_write_string(const char* connected_device_name, const char* str) {
|
388
|
+
NSString* s = [NSString stringWithUTF8String:str];
|
389
|
+
[[RhoBluetoothManager sharedInstance] sendString:s];
|
390
|
+
}
|
391
|
+
|
392
|
+
VALUE rho_bluetooth_session_read_data(const char* connected_device_name) {
|
393
|
+
int size = [[RhoBluetoothManager sharedInstance] getPacketsSize];
|
394
|
+
unsigned char* buf = malloc(size);
|
395
|
+
[[RhoBluetoothManager sharedInstance] readFromPackets:buf length:size];
|
396
|
+
VALUE val = rho_ruby_create_byte_array(buf, size);
|
397
|
+
free(buf);
|
398
|
+
return val;
|
399
|
+
}
|
400
|
+
|
401
|
+
void rho_bluetooth_session_write_data(const char* connected_device_name, VALUE data) {
|
402
|
+
int size = rho_ruby_unpack_byte_array(data, 0, 0);
|
403
|
+
if (size <= 0) {
|
404
|
+
return;
|
405
|
+
}
|
406
|
+
unsigned char* buf = malloc(size);
|
407
|
+
size = rho_ruby_unpack_byte_array(data, buf, size);
|
408
|
+
[[RhoBluetoothManager sharedInstance] sendData:buf length:size];
|
409
|
+
free(buf);
|
410
|
+
}
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
|