rhodes 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -1
- data/Manifest.txt +5197 -0
- data/lib/framework/rho/rho.rb +20 -4
- data/lib/framework/rho/rhocontroller.rb +13 -9
- data/lib/framework/rhodes.rb +2 -2
- data/lib/framework/version.rb +2 -2
- data/lib/rhodes.rb +2 -2
- data/platform/android/Rhodes/AndroidManifest.xml +2 -2
- data/platform/android/build/android.rake +4 -2
- data/platform/android/build/androidcommon.rb +2 -1
- data/platform/bb/rhodes/src/com/rho/rubyext/System.java +9 -1
- data/platform/iphone/Classes/RhoRunnerAppDelegate.m +9 -0
- data/platform/iphone/Classes/Server/ServerHost.h +2 -0
- data/platform/iphone/Classes/Server/ServerHost.m +29 -6
- data/platform/iphone/Info.plist +1 -1
- data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +12 -0
- data/platform/shared/common/RhodesApp.cpp +2 -12
- data/platform/shared/common/RhodesApp.h +0 -1
- data/platform/shared/net/AsyncHttp.cpp +38 -49
- data/platform/shared/net/AsyncHttp.h +6 -7
- data/platform/shared/ruby/ext/asynchttp/asynchttp.i +8 -12
- data/platform/shared/ruby/ext/asynchttp/asynchttp_wrap.c +24 -101
- data/platform/shared/rubyJVM/src/com/rho/RhoRuby.java +5 -0
- data/platform/shared/rubyJVM/src/com/rho/RhodesApp.java +3 -10
- data/platform/shared/rubyJVM/src/com/rho/net/AsyncHttp.java +45 -63
- metadata +3 -2
@@ -26,6 +26,7 @@ class CAsyncHttp : public common::CRhoThread, rho::ICallbackObject
|
|
26
26
|
Hashtable<String,String> m_mapHeaders;
|
27
27
|
|
28
28
|
String m_strUrl, m_strBody, m_strCallback, m_strCallbackParams;
|
29
|
+
String m_strResBody;
|
29
30
|
boolean m_bFinished;
|
30
31
|
public:
|
31
32
|
enum EHttpCommands{ hcGet = 0, hcPost, hcDownload, hcUpload };
|
@@ -33,8 +34,6 @@ private:
|
|
33
34
|
EHttpCommands m_eCmd;
|
34
35
|
public:
|
35
36
|
|
36
|
-
static boolean m_bNoThreaded;
|
37
|
-
|
38
37
|
CAsyncHttp(common::IRhoClassFactory* factory, EHttpCommands eCmd,
|
39
38
|
const char* url, unsigned long headers, const char* body, const char* callback, const char* callback_params);
|
40
39
|
|
@@ -45,6 +44,7 @@ public:
|
|
45
44
|
//rho::ICallbackObject
|
46
45
|
virtual unsigned long getObjectValue();
|
47
46
|
|
47
|
+
unsigned long getRetValue();
|
48
48
|
private:
|
49
49
|
virtual void run();
|
50
50
|
|
@@ -63,13 +63,12 @@ private:
|
|
63
63
|
extern "C" {
|
64
64
|
#endif //__cplusplus
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
unsigned long rho_asynchttp_get(const char* url, unsigned long headers, const char* callback, const char* callback_params);
|
67
|
+
unsigned long rho_asynchttp_post(const char* url, unsigned long headers, const char* body, const char* callback, const char* callback_params);
|
68
|
+
unsigned long rho_asynchttp_downloadfile(const char* url, unsigned long headers, const char* filename, const char* callback, const char* callback_params);
|
69
|
+
unsigned long rho_asynchttp_uploadfile(const char* url, unsigned long headers, const char* filename, const char* callback, const char* callback_params);
|
70
70
|
void rho_asynchttp_cancel(const char* cancel_callback);
|
71
71
|
void rho_asynchttp_destroy();
|
72
|
-
void rho_asynchttp_set_threaded_mode(int b);
|
73
72
|
|
74
73
|
#ifdef __cplusplus
|
75
74
|
};
|
@@ -2,33 +2,29 @@
|
|
2
2
|
%module "Rho::AsyncHttp"
|
3
3
|
%{
|
4
4
|
/* Put header files here or function declarations like below */
|
5
|
-
extern
|
5
|
+
extern VALUE rho_asynchttp_get(const char* url, VALUE headers, const char* callback, const char* callback_params);
|
6
6
|
#define do_get rho_asynchttp_get
|
7
7
|
|
8
|
-
extern
|
8
|
+
extern VALUE rho_asynchttp_post(const char* url, VALUE headers, const char* body, const char* callback, const char* callback_params);
|
9
9
|
#define do_post rho_asynchttp_post
|
10
10
|
|
11
|
-
extern
|
11
|
+
extern VALUE rho_asynchttp_downloadfile(const char* url, VALUE headers, const char* filename, const char* callback, const char* callback_params);
|
12
12
|
#define do_downloadfile rho_asynchttp_downloadfile
|
13
13
|
|
14
|
-
extern
|
14
|
+
extern VALUE rho_asynchttp_uploadfile(const char* url, VALUE headers, const char* filename, const char* callback, const char* callback_params);
|
15
15
|
#define do_uploadfile rho_asynchttp_uploadfile
|
16
16
|
|
17
17
|
extern void rho_asynchttp_cancel(const char* cancel_callback);
|
18
18
|
#define cancel rho_asynchttp_cancel
|
19
19
|
|
20
|
-
extern void rho_asynchttp_set_threaded_mode(int b);
|
21
|
-
#define set_threaded_mode rho_asynchttp_set_threaded_mode
|
22
|
-
|
23
20
|
%}
|
24
21
|
|
25
22
|
%typemap(default) const char* cancel_callback {
|
26
23
|
$1 = "*";
|
27
24
|
}
|
28
25
|
|
29
|
-
extern
|
30
|
-
extern
|
31
|
-
extern
|
32
|
-
extern
|
26
|
+
extern VALUE do_get(const char* url, VALUE headers, const char* callback, const char* callback_params);
|
27
|
+
extern VALUE do_post(const char* url, VALUE headers, const char* body, const char* callback, const char* callback_params);
|
28
|
+
extern VALUE do_downloadfile(const char* url, VALUE headers, const char* filename, const char* callback, const char* callback_params);
|
29
|
+
extern VALUE do_uploadfile(const char* url, VALUE headers, const char* filename, const char* callback, const char* callback_params);
|
33
30
|
extern void cancel(const char* cancel_callback);
|
34
|
-
extern void set_threaded_mode(int b);
|
@@ -1546,24 +1546,21 @@ static VALUE mAsyncHttp;
|
|
1546
1546
|
|
1547
1547
|
|
1548
1548
|
/* Put header files here or function declarations like below */
|
1549
|
-
extern
|
1549
|
+
extern VALUE rho_asynchttp_get(const char* url, VALUE headers, const char* callback, const char* callback_params);
|
1550
1550
|
#define do_get rho_asynchttp_get
|
1551
1551
|
|
1552
|
-
extern
|
1552
|
+
extern VALUE rho_asynchttp_post(const char* url, VALUE headers, const char* body, const char* callback, const char* callback_params);
|
1553
1553
|
#define do_post rho_asynchttp_post
|
1554
1554
|
|
1555
|
-
extern
|
1555
|
+
extern VALUE rho_asynchttp_downloadfile(const char* url, VALUE headers, const char* filename, const char* callback, const char* callback_params);
|
1556
1556
|
#define do_downloadfile rho_asynchttp_downloadfile
|
1557
1557
|
|
1558
|
-
extern
|
1558
|
+
extern VALUE rho_asynchttp_uploadfile(const char* url, VALUE headers, const char* filename, const char* callback, const char* callback_params);
|
1559
1559
|
#define do_uploadfile rho_asynchttp_uploadfile
|
1560
1560
|
|
1561
1561
|
extern void rho_asynchttp_cancel(const char* cancel_callback);
|
1562
1562
|
#define cancel rho_asynchttp_cancel
|
1563
1563
|
|
1564
|
-
extern void rho_asynchttp_set_threaded_mode(int b);
|
1565
|
-
#define set_threaded_mode rho_asynchttp_set_threaded_mode
|
1566
|
-
|
1567
1564
|
|
1568
1565
|
|
1569
1566
|
SWIGINTERN swig_type_info*
|
@@ -1619,76 +1616,13 @@ SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
|
|
1619
1616
|
|
1620
1617
|
|
1621
1618
|
|
1622
|
-
|
1623
|
-
#include <limits.h>
|
1624
|
-
#ifndef LLONG_MIN
|
1625
|
-
# define LLONG_MIN LONG_LONG_MIN
|
1626
|
-
#endif
|
1627
|
-
#ifndef LLONG_MAX
|
1628
|
-
# define LLONG_MAX LONG_LONG_MAX
|
1629
|
-
#endif
|
1630
|
-
#ifndef ULLONG_MAX
|
1631
|
-
# define ULLONG_MAX ULONG_LONG_MAX
|
1632
|
-
#endif
|
1633
|
-
|
1634
|
-
|
1635
|
-
SWIGINTERN VALUE
|
1636
|
-
SWIG_ruby_failed(void)
|
1637
|
-
{
|
1638
|
-
return Qnil;
|
1639
|
-
}
|
1640
|
-
|
1641
|
-
|
1642
|
-
/*@SWIG:%ruby_aux_method@*/
|
1643
|
-
SWIGINTERN VALUE SWIG_AUX_NUM2LONG(VALUE *args)
|
1644
|
-
{
|
1645
|
-
VALUE obj = args[0];
|
1646
|
-
VALUE type = TYPE(obj);
|
1647
|
-
long *res = (long *)(args[1]);
|
1648
|
-
*res = type == T_FIXNUM ? NUM2LONG(obj) : rb_big2long(obj);
|
1649
|
-
return obj;
|
1650
|
-
}
|
1651
|
-
/*@SWIG@*/
|
1652
|
-
|
1653
|
-
SWIGINTERN int
|
1654
|
-
SWIG_AsVal_long (VALUE obj, long* val)
|
1655
|
-
{
|
1656
|
-
VALUE type = TYPE(obj);
|
1657
|
-
if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
|
1658
|
-
long v;
|
1659
|
-
VALUE a[2];
|
1660
|
-
a[0] = obj;
|
1661
|
-
a[1] = (VALUE)(&v);
|
1662
|
-
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
1663
|
-
if (val) *val = v;
|
1664
|
-
return SWIG_OK;
|
1665
|
-
}
|
1666
|
-
}
|
1667
|
-
return SWIG_TypeError;
|
1668
|
-
}
|
1669
|
-
|
1670
|
-
|
1671
|
-
SWIGINTERN int
|
1672
|
-
SWIG_AsVal_int (VALUE obj, int *val)
|
1673
|
-
{
|
1674
|
-
long v;
|
1675
|
-
int res = SWIG_AsVal_long (obj, &v);
|
1676
|
-
if (SWIG_IsOK(res)) {
|
1677
|
-
if ((v < INT_MIN || v > INT_MAX)) {
|
1678
|
-
return SWIG_OverflowError;
|
1679
|
-
} else {
|
1680
|
-
if (val) *val = (int)(v);
|
1681
|
-
}
|
1682
|
-
}
|
1683
|
-
return res;
|
1684
|
-
}
|
1685
|
-
|
1686
1619
|
SWIGINTERN VALUE
|
1687
1620
|
_wrap_do_get(int argc, VALUE *argv, VALUE self) {
|
1688
1621
|
char *arg1 = (char *) 0 ;
|
1689
1622
|
VALUE arg2 = (VALUE) 0 ;
|
1690
1623
|
char *arg3 = (char *) 0 ;
|
1691
1624
|
char *arg4 = (char *) 0 ;
|
1625
|
+
VALUE result;
|
1692
1626
|
int res1 ;
|
1693
1627
|
char *buf1 = 0 ;
|
1694
1628
|
int alloc1 = 0 ;
|
@@ -1698,6 +1632,7 @@ _wrap_do_get(int argc, VALUE *argv, VALUE self) {
|
|
1698
1632
|
int res4 ;
|
1699
1633
|
char *buf4 = 0 ;
|
1700
1634
|
int alloc4 = 0 ;
|
1635
|
+
VALUE vresult = Qnil;
|
1701
1636
|
|
1702
1637
|
if ((argc < 4) || (argc > 4)) {
|
1703
1638
|
rb_raise(rb_eArgError, "wrong # of arguments(%d for 4)",argc); SWIG_fail;
|
@@ -1718,11 +1653,12 @@ _wrap_do_get(int argc, VALUE *argv, VALUE self) {
|
|
1718
1653
|
SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "do_get" "', argument " "4"" of type '" "char const *""'");
|
1719
1654
|
}
|
1720
1655
|
arg4 = (char *)(buf4);
|
1721
|
-
do_get((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4);
|
1656
|
+
result = (VALUE)do_get((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4);
|
1657
|
+
vresult = result;
|
1722
1658
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1723
1659
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
1724
1660
|
if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
|
1725
|
-
return
|
1661
|
+
return vresult;
|
1726
1662
|
fail:
|
1727
1663
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1728
1664
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
@@ -1738,6 +1674,7 @@ _wrap_do_post(int argc, VALUE *argv, VALUE self) {
|
|
1738
1674
|
char *arg3 = (char *) 0 ;
|
1739
1675
|
char *arg4 = (char *) 0 ;
|
1740
1676
|
char *arg5 = (char *) 0 ;
|
1677
|
+
VALUE result;
|
1741
1678
|
int res1 ;
|
1742
1679
|
char *buf1 = 0 ;
|
1743
1680
|
int alloc1 = 0 ;
|
@@ -1750,6 +1687,7 @@ _wrap_do_post(int argc, VALUE *argv, VALUE self) {
|
|
1750
1687
|
int res5 ;
|
1751
1688
|
char *buf5 = 0 ;
|
1752
1689
|
int alloc5 = 0 ;
|
1690
|
+
VALUE vresult = Qnil;
|
1753
1691
|
|
1754
1692
|
if ((argc < 5) || (argc > 5)) {
|
1755
1693
|
rb_raise(rb_eArgError, "wrong # of arguments(%d for 5)",argc); SWIG_fail;
|
@@ -1775,12 +1713,13 @@ _wrap_do_post(int argc, VALUE *argv, VALUE self) {
|
|
1775
1713
|
SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "do_post" "', argument " "5"" of type '" "char const *""'");
|
1776
1714
|
}
|
1777
1715
|
arg5 = (char *)(buf5);
|
1778
|
-
do_post((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5);
|
1716
|
+
result = (VALUE)do_post((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5);
|
1717
|
+
vresult = result;
|
1779
1718
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1780
1719
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
1781
1720
|
if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
|
1782
1721
|
if (alloc5 == SWIG_NEWOBJ) free((char*)buf5);
|
1783
|
-
return
|
1722
|
+
return vresult;
|
1784
1723
|
fail:
|
1785
1724
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1786
1725
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
@@ -1797,6 +1736,7 @@ _wrap_do_downloadfile(int argc, VALUE *argv, VALUE self) {
|
|
1797
1736
|
char *arg3 = (char *) 0 ;
|
1798
1737
|
char *arg4 = (char *) 0 ;
|
1799
1738
|
char *arg5 = (char *) 0 ;
|
1739
|
+
VALUE result;
|
1800
1740
|
int res1 ;
|
1801
1741
|
char *buf1 = 0 ;
|
1802
1742
|
int alloc1 = 0 ;
|
@@ -1809,6 +1749,7 @@ _wrap_do_downloadfile(int argc, VALUE *argv, VALUE self) {
|
|
1809
1749
|
int res5 ;
|
1810
1750
|
char *buf5 = 0 ;
|
1811
1751
|
int alloc5 = 0 ;
|
1752
|
+
VALUE vresult = Qnil;
|
1812
1753
|
|
1813
1754
|
if ((argc < 5) || (argc > 5)) {
|
1814
1755
|
rb_raise(rb_eArgError, "wrong # of arguments(%d for 5)",argc); SWIG_fail;
|
@@ -1834,12 +1775,13 @@ _wrap_do_downloadfile(int argc, VALUE *argv, VALUE self) {
|
|
1834
1775
|
SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "do_downloadfile" "', argument " "5"" of type '" "char const *""'");
|
1835
1776
|
}
|
1836
1777
|
arg5 = (char *)(buf5);
|
1837
|
-
do_downloadfile((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5);
|
1778
|
+
result = (VALUE)do_downloadfile((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5);
|
1779
|
+
vresult = result;
|
1838
1780
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1839
1781
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
1840
1782
|
if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
|
1841
1783
|
if (alloc5 == SWIG_NEWOBJ) free((char*)buf5);
|
1842
|
-
return
|
1784
|
+
return vresult;
|
1843
1785
|
fail:
|
1844
1786
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1845
1787
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
@@ -1856,6 +1798,7 @@ _wrap_do_uploadfile(int argc, VALUE *argv, VALUE self) {
|
|
1856
1798
|
char *arg3 = (char *) 0 ;
|
1857
1799
|
char *arg4 = (char *) 0 ;
|
1858
1800
|
char *arg5 = (char *) 0 ;
|
1801
|
+
VALUE result;
|
1859
1802
|
int res1 ;
|
1860
1803
|
char *buf1 = 0 ;
|
1861
1804
|
int alloc1 = 0 ;
|
@@ -1868,6 +1811,7 @@ _wrap_do_uploadfile(int argc, VALUE *argv, VALUE self) {
|
|
1868
1811
|
int res5 ;
|
1869
1812
|
char *buf5 = 0 ;
|
1870
1813
|
int alloc5 = 0 ;
|
1814
|
+
VALUE vresult = Qnil;
|
1871
1815
|
|
1872
1816
|
if ((argc < 5) || (argc > 5)) {
|
1873
1817
|
rb_raise(rb_eArgError, "wrong # of arguments(%d for 5)",argc); SWIG_fail;
|
@@ -1893,12 +1837,13 @@ _wrap_do_uploadfile(int argc, VALUE *argv, VALUE self) {
|
|
1893
1837
|
SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "do_uploadfile" "', argument " "5"" of type '" "char const *""'");
|
1894
1838
|
}
|
1895
1839
|
arg5 = (char *)(buf5);
|
1896
|
-
do_uploadfile((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5);
|
1840
|
+
result = (VALUE)do_uploadfile((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5);
|
1841
|
+
vresult = result;
|
1897
1842
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1898
1843
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
1899
1844
|
if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
|
1900
1845
|
if (alloc5 == SWIG_NEWOBJ) free((char*)buf5);
|
1901
|
-
return
|
1846
|
+
return vresult;
|
1902
1847
|
fail:
|
1903
1848
|
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
|
1904
1849
|
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
@@ -1937,27 +1882,6 @@ fail:
|
|
1937
1882
|
}
|
1938
1883
|
|
1939
1884
|
|
1940
|
-
SWIGINTERN VALUE
|
1941
|
-
_wrap_set_threaded_mode(int argc, VALUE *argv, VALUE self) {
|
1942
|
-
int arg1 ;
|
1943
|
-
int val1 ;
|
1944
|
-
int ecode1 = 0 ;
|
1945
|
-
|
1946
|
-
if ((argc < 1) || (argc > 1)) {
|
1947
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
|
1948
|
-
}
|
1949
|
-
ecode1 = SWIG_AsVal_int(argv[0], &val1);
|
1950
|
-
if (!SWIG_IsOK(ecode1)) {
|
1951
|
-
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "set_threaded_mode" "', argument " "1"" of type '" "int""'");
|
1952
|
-
}
|
1953
|
-
arg1 = (int)(val1);
|
1954
|
-
set_threaded_mode(arg1);
|
1955
|
-
return Qnil;
|
1956
|
-
fail:
|
1957
|
-
return Qnil;
|
1958
|
-
}
|
1959
|
-
|
1960
|
-
|
1961
1885
|
|
1962
1886
|
/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
|
1963
1887
|
|
@@ -2226,6 +2150,5 @@ SWIGEXPORT void Init_AsyncHttp(void) {
|
|
2226
2150
|
rb_define_module_function(mAsyncHttp, "do_downloadfile", _wrap_do_downloadfile, -1);
|
2227
2151
|
rb_define_module_function(mAsyncHttp, "do_uploadfile", _wrap_do_uploadfile, -1);
|
2228
2152
|
rb_define_module_function(mAsyncHttp, "cancel", _wrap_cancel, -1);
|
2229
|
-
rb_define_module_function(mAsyncHttp, "set_threaded_mode", _wrap_set_threaded_mode, -1);
|
2230
2153
|
}
|
2231
2154
|
|
@@ -102,6 +102,11 @@ public class RhoRuby {
|
|
102
102
|
return res.toStr();
|
103
103
|
}
|
104
104
|
|
105
|
+
public static void set_const(String name, String value)
|
106
|
+
{
|
107
|
+
RubyRuntime.ObjectClass.setConstant(name, ObjectFactory.createString(value) );
|
108
|
+
}
|
109
|
+
|
105
110
|
public static void RhoRubyStart(String szAppPath)throws Exception
|
106
111
|
{
|
107
112
|
String[] args = new String[0];
|
@@ -59,21 +59,14 @@ public class RhodesApp
|
|
59
59
|
return strRes;
|
60
60
|
}
|
61
61
|
|
62
|
-
public void delCallbackObject(RubyValue valObject)
|
63
|
-
{
|
64
|
-
for (int i = 0; i < (int)m_arCallbackObjects.size(); i++)
|
65
|
-
{
|
66
|
-
if ( m_arCallbackObjects.elementAt(i) == valObject )
|
67
|
-
m_arCallbackObjects.setElementAt(null,i);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
62
|
public RubyValue getCallbackObject(int nIndex)
|
72
63
|
{
|
73
64
|
if ( nIndex < 0 || nIndex > m_arCallbackObjects.size() )
|
74
65
|
return null;
|
75
66
|
|
76
|
-
|
67
|
+
RubyValue res = (RubyValue)m_arCallbackObjects.elementAt(nIndex);
|
68
|
+
m_arCallbackObjects.setElementAt(null,nIndex);
|
69
|
+
return res;
|
77
70
|
}
|
78
71
|
|
79
72
|
}
|
@@ -27,12 +27,12 @@ public class AsyncHttp extends RhoThread
|
|
27
27
|
private Hashtable/*<String,String>*/ m_mapHeaders = new Hashtable();
|
28
28
|
|
29
29
|
private String m_strUrl, m_strBody, m_strCallback, m_strCallbackParams;
|
30
|
+
private String m_strResBody = "";
|
30
31
|
boolean m_bFinished = false;
|
31
32
|
|
32
33
|
private RubyValue m_valBody;
|
33
34
|
public final static int hcGet = 0, hcPost=1, hcDownload=2, hcUpload =3;
|
34
35
|
private int m_eCmd;
|
35
|
-
public static boolean m_bNoThreaded;
|
36
36
|
|
37
37
|
private RhodesApp RHODESAPP(){ return RhodesApp.getInstance(); }
|
38
38
|
|
@@ -52,7 +52,7 @@ public class AsyncHttp extends RhoThread
|
|
52
52
|
|
53
53
|
addNewObject(this);
|
54
54
|
|
55
|
-
if (
|
55
|
+
if (m_strCallback.length()==0)
|
56
56
|
run();
|
57
57
|
else
|
58
58
|
start(epLow);
|
@@ -152,7 +152,7 @@ public class AsyncHttp extends RhoThread
|
|
152
152
|
break;
|
153
153
|
}
|
154
154
|
|
155
|
-
if ( !m_pNetRequest.isCancelled()
|
155
|
+
if ( !m_pNetRequest.isCancelled() )
|
156
156
|
{
|
157
157
|
processResponse(m_pNetResponse);
|
158
158
|
callNotify(m_pNetResponse, 0);
|
@@ -215,69 +215,65 @@ public class AsyncHttp extends RhoThread
|
|
215
215
|
m_valBody = RhoRuby.create_string(resp.getCharData());
|
216
216
|
}
|
217
217
|
|
218
|
+
RubyValue getRetValue()
|
219
|
+
{
|
220
|
+
if ( m_strCallback.length() == 0 )
|
221
|
+
return RhoRuby.create_string(m_strResBody);
|
222
|
+
|
223
|
+
return RubyConstant.QNIL;
|
224
|
+
}
|
225
|
+
|
218
226
|
void callNotify(NetResponse resp, int nError )
|
219
227
|
{
|
220
|
-
|
221
|
-
|
228
|
+
m_strResBody = "rho_callback=1";
|
229
|
+
m_strResBody += "&status=";
|
222
230
|
if ( nError > 0 )
|
223
231
|
{
|
224
|
-
|
232
|
+
m_strResBody += "error&error_code=" + nError;
|
225
233
|
}else
|
226
234
|
{
|
227
235
|
if ( resp.isOK() )
|
228
|
-
|
236
|
+
m_strResBody += "ok";
|
229
237
|
else
|
230
238
|
{
|
231
|
-
|
239
|
+
m_strResBody += "error&error_code=";
|
232
240
|
/*if ( !resp.isResponseRecieved())
|
233
241
|
strBody += RhoRuby.ERR_NETWORK;
|
234
242
|
else */if ( resp.isUnathorized() )
|
235
|
-
|
243
|
+
m_strResBody += RhoRuby.ERR_UNATHORIZED;
|
236
244
|
else
|
237
|
-
|
245
|
+
m_strResBody += RhoRuby.ERR_REMOTESERVER;
|
238
246
|
|
239
247
|
//if ( resp.isResponseRecieved())
|
240
|
-
|
248
|
+
m_strResBody += "&http_error=" + resp.getRespCode();
|
241
249
|
}
|
242
250
|
|
243
251
|
String cookies = resp.getCookies();
|
244
252
|
if (cookies.length()>0)
|
245
|
-
|
253
|
+
m_strResBody += "&cookies=" + URI.urlEncode(cookies);
|
246
254
|
|
247
|
-
|
248
|
-
|
255
|
+
m_strResBody += "&" + makeHeadersString();
|
256
|
+
m_strResBody += "&" + RHODESAPP().addCallbackObject(m_valBody, "body");
|
249
257
|
}
|
250
258
|
|
251
259
|
if ( m_strCallbackParams.length() > 0 )
|
252
|
-
|
260
|
+
m_strResBody += "&" + m_strCallbackParams;
|
253
261
|
|
254
|
-
/*
|
255
|
-
if ( m_bNoThreaded )
|
256
|
-
{
|
257
|
-
const char* szName = strrchr(m_strCallback.c_str(), '/');
|
258
|
-
if (!szName)
|
259
|
-
szName = m_strCallback.c_str();
|
260
|
-
else
|
261
|
-
szName++;
|
262
|
-
|
263
|
-
String strName = "C_";
|
264
|
-
strName += szName;
|
265
|
-
rho_ruby_set_const( strName.c_str(), strBody.c_str());
|
266
|
-
}else
|
267
|
-
{*/
|
268
|
-
try{
|
269
|
-
NetRequest pNetRequest = m_ptrFactory.createNetRequest();
|
270
|
-
|
271
|
-
String strFullUrl = pNetRequest.resolveUrl(m_strCallback);
|
272
|
-
NetResponse resp1 = pNetRequest.pushData( strFullUrl, strBody, null );
|
273
|
-
if ( !resp1.isOK() )
|
274
|
-
LOG.ERROR("AsyncHttp notification failed. Code: " + resp1.getRespCode() + "; Error body: " + resp1.getCharData() );
|
275
|
-
}catch(Exception exc)
|
276
|
-
{
|
277
|
-
LOG.ERROR("Async http callback failed.", exc);
|
278
|
-
}
|
279
262
|
|
280
|
-
|
263
|
+
if ( m_strCallback.length() > 0 )
|
264
|
+
{
|
265
|
+
try{
|
266
|
+
NetRequest pNetRequest = m_ptrFactory.createNetRequest();
|
267
|
+
|
268
|
+
String strFullUrl = pNetRequest.resolveUrl(m_strCallback);
|
269
|
+
NetResponse resp1 = pNetRequest.pushData( strFullUrl, m_strResBody, null );
|
270
|
+
if ( !resp1.isOK() )
|
271
|
+
LOG.ERROR("AsyncHttp notification failed. Code: " + resp1.getRespCode() + "; Error body: " + resp1.getCharData() );
|
272
|
+
}catch(Exception exc)
|
273
|
+
{
|
274
|
+
LOG.ERROR("Async http callback failed.", exc);
|
275
|
+
}
|
276
|
+
}
|
281
277
|
}
|
282
278
|
|
283
279
|
public static void initMethods(RubyModule klass) {
|
@@ -292,12 +288,12 @@ public class AsyncHttp extends RhoThread
|
|
292
288
|
String url = args.get(0).toStr();
|
293
289
|
String callback = args.get(2).toStr();
|
294
290
|
String callback_params = args.get(3).toStr();
|
295
|
-
new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcGet, url, args.get(1), null, callback, callback_params );
|
291
|
+
AsyncHttp pHttp = new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcGet, url, args.get(1), null, callback, callback_params );
|
292
|
+
return pHttp.getRetValue();
|
296
293
|
} catch(Exception e) {
|
297
294
|
LOG.ERROR("do_get failed", e);
|
298
295
|
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
299
296
|
}
|
300
|
-
return RubyConstant.QNIL;
|
301
297
|
}
|
302
298
|
});
|
303
299
|
|
@@ -313,12 +309,12 @@ public class AsyncHttp extends RhoThread
|
|
313
309
|
String body = args.get(2).toStr();
|
314
310
|
String callback = args.get(3).toStr();
|
315
311
|
String callback_params = args.get(4).toStr();
|
316
|
-
new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcPost, url, args.get(1), body, callback, callback_params );
|
312
|
+
AsyncHttp pHttp = new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcPost, url, args.get(1), body, callback, callback_params );
|
313
|
+
return pHttp.getRetValue();
|
317
314
|
} catch(Exception e) {
|
318
315
|
LOG.ERROR("do_post failed", e);
|
319
316
|
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
320
317
|
}
|
321
|
-
return RubyConstant.QNIL;
|
322
318
|
}
|
323
319
|
});
|
324
320
|
|
@@ -334,12 +330,12 @@ public class AsyncHttp extends RhoThread
|
|
334
330
|
String filepath = args.get(2).toStr();
|
335
331
|
String callback = args.get(3).toStr();
|
336
332
|
String callback_params = args.get(4).toStr();
|
337
|
-
new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcDownload, url, args.get(1), filepath, callback, callback_params );
|
333
|
+
AsyncHttp pHttp = new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcDownload, url, args.get(1), filepath, callback, callback_params );
|
334
|
+
return pHttp.getRetValue();
|
338
335
|
} catch(Exception e) {
|
339
336
|
LOG.ERROR("do_downloadfile failed", e);
|
340
337
|
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
341
338
|
}
|
342
|
-
return RubyConstant.QNIL;
|
343
339
|
}
|
344
340
|
});
|
345
341
|
|
@@ -355,12 +351,12 @@ public class AsyncHttp extends RhoThread
|
|
355
351
|
String filepath = args.get(2).toStr();
|
356
352
|
String callback = args.get(3).toStr();
|
357
353
|
String callback_params = args.get(4).toStr();
|
358
|
-
new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcUpload, url, args.get(1), filepath, callback, callback_params );
|
354
|
+
AsyncHttp pHttp = new AsyncHttp(new RhoClassFactory(), AsyncHttp.hcUpload, url, args.get(1), filepath, callback, callback_params );
|
355
|
+
return pHttp.getRetValue();
|
359
356
|
} catch(Exception e) {
|
360
357
|
LOG.ERROR("do_uploadfile failed", e);
|
361
358
|
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
362
359
|
}
|
363
|
-
return RubyConstant.QNIL;
|
364
360
|
}
|
365
361
|
});
|
366
362
|
|
@@ -378,20 +374,6 @@ public class AsyncHttp extends RhoThread
|
|
378
374
|
}
|
379
375
|
});
|
380
376
|
|
381
|
-
klass.getSingletonClass().defineMethod("set_threaded_mode", new RubyOneArgMethod(){
|
382
|
-
protected RubyValue run(RubyValue receiver, RubyValue arg, RubyBlock block )
|
383
|
-
{
|
384
|
-
try {
|
385
|
-
int b = arg.toInt();
|
386
|
-
AsyncHttp.m_bNoThreaded = (b==0);
|
387
|
-
} catch(Exception e) {
|
388
|
-
LOG.ERROR("set_threaded_mode failed", e);
|
389
|
-
throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
|
390
|
-
}
|
391
|
-
return RubyConstant.QNIL;
|
392
|
-
}
|
393
|
-
});
|
394
|
-
|
395
377
|
}
|
396
378
|
|
397
379
|
}
|