Skip to content

Commit

Permalink
add has_camera to wm
Browse files Browse the repository at this point in the history
refactor system ruby ext
  • Loading branch information
genywind committed Mar 4, 2010
1 parent ec95f63 commit 061f2c3
Show file tree
Hide file tree
Showing 26 changed files with 231 additions and 257 deletions.
30 changes: 20 additions & 10 deletions platform/android/Rhodes/jni/src/callbacks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "JNIRhodes.h"

#include "RhoClassFactory.h"
#include "ruby/ext/rho/rhoruby.h"

#undef DEFAULT_LOGCATEGORY
#define DEFAULT_LOGCATEGORY "Callbacks"
Expand Down Expand Up @@ -36,13 +37,13 @@ RHO_GLOBAL void rho_appmanager_load( void* /*httpContext*/, const char* /*szQuer
// Nothing
}

RHO_GLOBAL int rho_net_has_network()
RHO_GLOBAL VALUE rho_sys_has_network()
{
jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES);
if (!cls) return 0;
if (!cls) return rho_ruby_create_boolean(0);
jmethodID mid = getJNIClassStaticMethod(cls, "hasNetwork", "()Z");
if (!mid) return 0;
return jnienv()->CallStaticBooleanMethod(cls, mid);
if (!mid) return rho_ruby_create_boolean(0);
return rho_ruby_create_boolean(jnienv()->CallStaticBooleanMethod(cls, mid));
}

RHO_GLOBAL void delete_files_in_folder(const char *szFolderPath)
Expand All @@ -57,7 +58,7 @@ RHO_GLOBAL void delete_files_in_folder(const char *szFolderPath)
env->DeleteLocalRef(objFolderPath);
}

RHO_GLOBAL VALUE rho_syscall(const char* callname, int nparams, char** param_names, char** param_values)
RHO_GLOBAL VALUE rho_sys_makephonecall(const char* callname, int nparams, char** param_names, char** param_values)
{
// TODO:
RHO_NOT_IMPLEMENTED;
Expand Down Expand Up @@ -86,22 +87,22 @@ RHO_GLOBAL void rho_nativethread_end(void *)
jvm()->DetachCurrentThread();
}

RHO_GLOBAL const char *rho_sys_get_locale()
RHO_GLOBAL VALUE rho_sys_get_locale()
{
if (g_currentLocale.empty())
{
jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES);
if (!cls) return NULL;
if (!cls) return rho_ruby_create_string("");
jmethodID mid = getJNIClassStaticMethod(cls, "getCurrentLocale", "()Ljava/lang/String;");
if (!mid) return NULL;
if (!mid) return rho_ruby_create_string("");
JNIEnv *env = jnienv();
jstring objLocale = (jstring)env->CallStaticObjectMethod(cls, mid);
if (!objLocale) return NULL;
if (!objLocale) return rho_ruby_create_string("");
const char *s = env->GetStringUTFChars(objLocale, JNI_FALSE);
g_currentLocale = s;
env->ReleaseStringUTFChars(objLocale, s);
}
return g_currentLocale.c_str();
return rho_ruby_create_string(g_currentLocale.c_str());
}

RHO_GLOBAL int rho_sys_get_screen_width()
Expand Down Expand Up @@ -129,3 +130,12 @@ RHO_GLOBAL int rho_sys_get_screen_height()
}
return g_screenHeight;
}

RHO_GLOBAL VALUE rho_sysimpl_get_property(char* szPropName)
{
//TODO: has_camera
if (strcasecmp("has_camera",szPropName) == 0)
return rho_ruby_create_boolean(1);

return rho_ruby_get_NIL();
}
1 change: 1 addition & 0 deletions platform/android/build/librhocommon_build.files
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ platform/shared/net/URI.cpp
platform/shared/net/ssl.cpp
platform/shared/statistic/RhoProfiler.cpp
platform/shared/rubyext/GeoLocation.cpp
platform/shared/rubyext/System.cpp
2 changes: 0 additions & 2 deletions platform/android/build/libruby_build.files
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ platform/shared/ruby/ext/sqlite3_api/sqlite3_api_wrap.c
platform/shared/ruby/ext/stringio/stringio.c
platform/shared/ruby/ext/strscan/strscan.c
platform/shared/ruby/ext/syncengine/syncengine_wrap.c
platform/shared/ruby/ext/system/network.c
platform/shared/ruby/ext/system/system_properties.c
platform/shared/ruby/ext/system/system_wrap.c
platform/shared/ruby/ext/webview/webview_wrap.c
platform/shared/ruby/file.c
Expand Down
10 changes: 5 additions & 5 deletions platform/iphone/Classes/Phonebook/phonebook.m
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static VALUE _getRecordByIndex(CFArrayRef people, CFIndex index, ABRecordID* pre
if (ref!=NULL) {
return _getRecord(ref,precordId);
}
return getnil();
return rho_ruby_get_NIL();
}

VALUE getallPhonebookRecords(void* pb) {
Expand All @@ -327,7 +327,7 @@ VALUE getallPhonebookRecords(void* pb) {

return hash;
}
return getnil();
return rho_ruby_get_NIL();
}

VALUE getPhonebookRecord(void* pb, char* id) {
Expand All @@ -341,7 +341,7 @@ VALUE getPhonebookRecord(void* pb, char* id) {
return _getRecord(ref,NULL);
}
}
return getnil();
return rho_ruby_get_NIL();
}

//==================================================================================
Expand All @@ -352,7 +352,7 @@ VALUE getfirstPhonebookRecord(void* pb) {
_getAllPeople(phonebook);
return _getRecordByIndex(phonebook->_people, phonebook->_index, NULL);
}
return getnil();
return rho_ruby_get_NIL();
}

VALUE getnextPhonebookRecord(void* pb) {
Expand All @@ -363,7 +363,7 @@ VALUE getnextPhonebookRecord(void* pb) {
return _getRecordByIndex(phonebook->_people, phonebook->_index, NULL);
}
}
return getnil();
return rho_ruby_get_NIL();
}

//==================================================================================
Expand Down
2 changes: 1 addition & 1 deletion platform/iphone/rhoextlib/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

extern void _rho_ext_syscall(PARAMS_WRAPPER* params);

VALUE rho_syscall(const char* callname, int nparams, char** param_names, char** param_values) {
VALUE rho_sys_makephonecall(const char* callname, int nparams, char** param_names, char** param_values) {
PARAMS_WRAPPER params = {nparams,param_names,param_values,callname,0};
PARAMS_WRAPPER* ret;
VALUE ret_value = Qnil;
Expand Down
4 changes: 2 additions & 2 deletions platform/shared/json/RJSONTokener.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ struct json_object* rjson_tokener_parse_ex(struct json_tokener *tok,
if(strncasecmp(json_null_str, tok->pb->buf,
min(tok->st_pos+1, strlen(json_null_str))) == 0) {
if(tok->st_pos == strlen(json_null_str)) {
current = (struct json_object*)getnil();
current = (struct json_object*)rho_ruby_get_NIL();
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
goto redo_char;
Expand Down Expand Up @@ -579,5 +579,5 @@ VALUE rho_json_parse(VALUE v,VALUE str)
if ( szError )
free(szError);

return getnil();
return rho_ruby_get_NIL();
}
4 changes: 0 additions & 4 deletions platform/shared/ruby/ext/rho/rhoruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ void RhoRubyStop()

char* makeControllerCall(char* classname, char* methodname);

VALUE getnil() {
return Qnil;
}

//typedef void rho_eachstr_func(const char*, const char*, void*);
struct CHashEnumData
{
Expand Down
1 change: 0 additions & 1 deletion platform/shared/ruby/ext/rho/rhoruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void RhoRubyInitApp();
//void RhoRubyThreadStop();
void rho_ruby_activateApp();

VALUE getnil();
VALUE createHash();
VALUE addTimeToHash(VALUE hash, const char* key, time_t val);
VALUE addIntToHash(VALUE hash, const char* key, int val);
Expand Down
28 changes: 0 additions & 28 deletions platform/shared/ruby/ext/system/network.c

This file was deleted.

23 changes: 0 additions & 23 deletions platform/shared/ruby/ext/system/network.h

This file was deleted.

18 changes: 11 additions & 7 deletions platform/shared/ruby/ext/system/system.i
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* system.i */
%module System
%{
extern VALUE rho_syscall(const char* callname, int nparams, char** param_names, char** param_values);
#define syscall rho_syscall
extern char* get_property(char* property);
extern VALUE has_network();
extern VALUE rho_sys_makephonecall(const char* callname, int nparams, char** param_names, char** param_values);
#define syscall rho_sys_makephonecall

extern VALUE rho_sys_get_property(char* property);
#define get_property rho_sys_get_property

extern VALUE rho_sys_has_network();
#define has_network rho_sys_has_network

extern char* rho_sys_get_locale();
extern VALUE rho_sys_get_locale();
#define get_locale rho_sys_get_locale

extern int rho_sys_get_screen_width();
Expand Down Expand Up @@ -41,8 +45,8 @@ extern int rho_sys_get_screen_height();
free((void *) $3);
}
extern VALUE syscall(const char* callname, int nparams, char** param_names, char** param_values);
extern char* get_property(char* property);
extern VALUE get_property(char* property);
extern VALUE has_network();
extern char* get_locale();
extern VALUE get_locale();
extern int get_screen_width();
extern int get_screen_height();
41 changes: 0 additions & 41 deletions platform/shared/ruby/ext/system/system_properties.c

This file was deleted.

10 changes: 0 additions & 10 deletions platform/shared/ruby/ext/system/system_properties.h

This file was deleted.

Loading

0 comments on commit 061f2c3

Please sign in to comment.