int SettingsScreen::getSystemProperty(const char* key, MAUtil::String& dst) { int size = maGetSystemProperty(key, NULL, 0); printf("received size: %i", size); if (size < 0) return size; dst.resize(size-1); maGetSystemProperty(key, dst.pointer(), size); return size; }
int XML::getSystemProperty(const char* key, MAUtil::String& dst) { int size = maGetSystemProperty(key, NULL, 0); if(size < 0) return size; dst.resize(size-1); maGetSystemProperty(key, dst.pointer(), size); return size; }
/** * Constructor. */ AppController::AppController() : mTabScreen(NULL), mTestScreen(NULL), mPathPropertyScreen(NULL), mFileUtil(NULL) { mTabScreen = new NativeUI::TabScreen(); mTestScreen = new TestScreen(); mPathPropertyScreen = new PathPropertyScreen(*this); mTabScreen->addTab(mTestScreen); mTabScreen->addTab(mPathPropertyScreen); mTabScreen->show(); mFileUtil = new Wormhole::FileUtil(); // Extract bundled files to the local file system. mFileUtil->extractLocalFiles(); char buf[BUFFER_SIZE]; maGetSystemProperty("mosync.path.local", buf, BUFFER_SIZE); sprintf(buf, "%sImagePath.png", buf); MAUtil::String path = buf; mPathPropertyScreen->setDisplayedImagePath(path); }
/** * Init platform type global variable. */ void initPlatformType() { char platform[NativeUI::BUF_SIZE]; maGetSystemProperty("mosync.device.OS", platform, NativeUI::BUF_SIZE); for (unsigned int i = 0; i < strlen(platform); i++) { platform[i] = tolower(platform[i]); } if (strcmp(platform,"android") == 0) { gPlatformType = PlatformTypeAndroid; } else if (strstr(platform,"iphone") != NULL) { gPlatformType = PlatformTypeiOS; } else { gPlatformType = PlatformTypeWP7; } // Set background color variables. gLayoutBackgroundColor = "00000000"; gTitleBackgroundColor = "50000000"; }
/** * \brief Constructor * * \note This also creates the settings file if it doesn't exist, otherwise * it opens it and calls the LoadSettings() function */ SettingsManager::SettingsManager() : _coin("EUR"), _showAll(true), _showFromDate(false), _showMonthly(false), _debtValue(0.0) { GUI::DeterminePlatform(); char path[Model::BUFF_SIZE]; maGetSystemProperty("mosync.path.local", path, Model::BUFF_SIZE); _settingsFileCompletePath = new MAUtil::String(path); if(false == GUI::_IPhoneOS)(*_settingsFileCompletePath) += "/"; (*_settingsFileCompletePath) += SETTINGS_FILE; _settingsFile = maFileOpen(_settingsFileCompletePath->c_str(), MA_ACCESS_READ_WRITE); if(1 == maFileExists(_settingsFile)) { LoadSettings(); maFileClose(_settingsFile); } else { maFileCreate(_settingsFile); maFileClose(_settingsFile); _date._day = 1; _date._mounth = 1; _date._year = 1601; ApplySettings(); } }
/** * Detects if the current platform is Android. * @return true if the platform is Android, false otherwise. */ bool isAndroid() { char platform[BUF_MAX]; maGetSystemProperty("mosync.device.OS", platform, BUF_MAX); if ( strcmp(platform,"Android") == 0 ) { return true; } return false; }
/** * Detects if the current platform is iOS. * @return true if the platform is iOS, false otherwise. */ bool isIOS() { char platform[BUF_MAX]; maGetSystemProperty("mosync.device.OS", platform, BUF_MAX); for (unsigned int i = 0; i < strlen(platform); i++) { platform[i] = tolower(platform[i]); } if (strstr(platform,"iphone") != NULL) { return true; } return false; }
BenchDBConnector::BenchDBConnector(BenchResult & br) : mHttp(this) //constructor, taking the complete url of the publish_script as an arg , mIsConnected(false) { mDone = false; char devProperties[200]; char devPropertiesUrlEnc[200]; char completeUrl[1000]; int ret = maGetSystemProperty("mosync.device", devProperties, 200); //store the properties of the device in the buffer devProperty printf("Device properties: %s, retval: %d\n", devProperties, ret); //remove whitespaces, and use a placeholder device name if maGetSystemProperty fails if(ret < 0){ br.phone = "unknownDevice"; }else{ for(unsigned int i = 0, j = 0; i < strlen(devProperties) && i < 20; ++i){ if(devProperties[i] == ' '){ //do nothing }else{ devPropertiesUrlEnc[j] = devProperties[i]; ++j; } } br.phone = devPropertiesUrlEnc; } br.runtime = "MoSync"; //this is of course always going to be the MoSync revision printf("publishing benchmark: %s", br.benchmark); printf("Publishing result via url:"); //build url according to benchmark if(strcmp(br.benchmark, "linpack") == 0){ mBenchmark = LINPACK; sprintf(completeUrl, "%s%s%s%s%s%s%s%s%s%s%s%s%.3f", M_URL, "?benchmark=linpack&revision=", br.revision, "&runtime=", br.runtime, "&git_hash=", br.git_hash, "&phone=", br.phone, "&native_sdk_ver=", br.nativeSdkVer, "&mflops=", br.mflops); }else if(strcmp(br.benchmark, "opengl") == 0){ mBenchmark = OPENGL; sprintf(completeUrl, "%s%s%s%s%s%s%s%s%s%s%s%s%d%s%d%s%d%s%d", M_URL, "?benchmark=opengl&revision=", br.revision, "&runtime=", br.runtime, "&git_hash=", br.git_hash, "&phone=", br.phone, "&native_sdk_ver=", br.nativeSdkVer, "&test1=", br.test1, "&test2=", br.test2, "&test3=", br.test3, "&test4=", br.test4); }else if(strcmp(br.benchmark, "membench") == 0){ mBenchmark = MEMBENCH; sprintf(completeUrl, "%s%s%s%s%s%s%s%s%s%s%s%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f", M_URL, "?benchmark=membench&revision=", br.revision, "&runtime=", br.runtime, "&git_hash=", br.git_hash, "&phone=", br.phone, "&native_sdk_ver=", "0", "&alloc_str_10=", br.str_alloc_10, "&alloc_str_100=", br.str_alloc_100, "&alloc_void_1=", br.alloc_void_1, "&alloc_void_100=", br.alloc_void_100, "&alloc_void_1000=", br.alloc_void_1000, "&alloc_dummy=", br.alloc_dummy, "&alloc_dummy_struct=", br.alloc_dummy_struct, "&alloc_dummy_mix=", br.alloc_dummy_mix, "&access_array=", br.access_array, "&access_vector=", br.access_vector, "&add_vector=", br.add_vector, "&access_dummy=", br.access_dummy, "&access_dummy_struct=", br.access_dummy_struct, "&access_dummy_mix=", br.access_dummy_mix); } printf(completeUrl); initiateConnection(completeUrl); //connect to the url, publishing the results via HTTP GET OR POST }
/** * Detects if the current platform is Windows Phone. * @return true if the platform is Windows Phone, false otherwise. */ bool isWindowsPhone() { char platform[BUF_MAX]; maGetSystemProperty("mosync.device.OS", platform, BUF_MAX); for (unsigned int i = 0; i < strlen(platform); i++) { platform[i] = tolower(platform[i]); } if (strstr(platform,"microsoft") != NULL && strstr(platform,"windows") != NULL) { return true; } return false; }
/** * Detects the current platform * @return platform_code specific for Android, iPhone OS or WindowsPhone */ int getPlatform() { char platform[BUF_MAX]; maGetSystemProperty("mosync.device.OS", platform, BUF_MAX); if(strcmp(platform, "Android") == 0) { return ANDROID; } else { if(strcmp(platform, "iPhone OS") == 0) return IOS; } return WINDOWSPHONE7; }
/** * Get the path to the local file system. * @return Path that ends with a slash. */ MAUtil::String FileUtil::getLocalPath() { int bufferSize = 2048; char buffer[bufferSize]; int size = maGetSystemProperty( "mosync.path.local", buffer, bufferSize); // If there was an error, return default root path. if (size < 0 || size > bufferSize) { return "/"; } return buffer; }
/** * Add a new menu item to the Options Menu associated to this screen. * Platform: Android and WP7. * Option Menus are Android specific concept. The Options Menu is launched by * pressing the Menu key. The options menu is where you should include * actions and other options that are relevant to the current activity * context, such as "Search," "Compose email," or "Settings". * When opened, the first visible portion is the icon menu, which holds * up to six menu items. If your menu includes more than six items, Android * places the sixth item and the rest into the overflow menu, which the user * can open by selecting More. Those items do not display icons. On Windows * Phone 7 the control used is the application bar. * * @param title The title associated for the new item. Can be left null. * @param icon The id of an icon from the Android and WP7 predefined icon set, * these can be found under the OptionsMenuIconConstants group, or the name of * the icon file (works only for WP7). * @param isPath If true, indicates that the icon is based on the path, otherwise * it is one of the predefined icon constants. * * Note: For Windows phone 7 the option menu icons must be added under the following folder * structure "/ApplicationBarIcons/". By using this function you will obtain an * application bar icon button (text + icon). Note that only 4 buttons are * visible on an application bar. If you exceed this limit the option menu * items will be added as application bar menu items on WP7. * * @return The index on which the menu item was added in the options menu, * an error code otherwise. */ int Screen::addOptionsMenuItem( const MAUtil::String title, const MAUtil::String icon, bool isPath) { if(isPath) { char platform[BUF_MAX]; maGetSystemProperty("mosync.device.OS", platform, BUF_MAX); if(strcmp(platform, "Android") == 0) return MAW_RES_ERROR; else { return maWidgetScreenAddOptionsMenuItem( getWidgetHandle(), title.c_str(), icon.c_str(), 0 ); } } else return maWidgetScreenAddOptionsMenuItem( getWidgetHandle(), title.c_str(), icon.c_str(), 1 ); }
void MenuScreen::xcConnError(int code) { feed->remHttp(); if (feed->getHttps() <= 0) { label = (Label*) mainLayout->getChildren()[0]->getChildren()[1]; label->setCaption(""); } if (code == -6) { if(versionChecked ==0) { char buf[128] = ""; memset(buf, 0, 128); int imsi = maGetSystemProperty("mosync.imsi", buf, sizeof(buf)); memset(buf, 0, 128); int imei = maGetSystemProperty("mosync.imei", buf, sizeof(buf)); memset(buf, 0, 128); char *os = new char[strlen(MA_PROF_STRING_PLATFORM)+1]; memset(os, 0, strlen(MA_PROF_STRING_PLATFORM)+1); sprintf(os, "%s", MA_PROF_STRING_PLATFORM); char *make = new char[strlen(MA_PROF_STRING_VENDOR)+1]; memset(make, 0, strlen(MA_PROF_STRING_VENDOR)+1); sprintf(make, "%s", MA_PROF_STRING_VENDOR); //char *model = "temp";//MA_PROF_STRING_DEVICE; char *model = new char[strlen("temp")+1]; memset(model, 0, strlen("temp")+1); sprintf(model, "%s", "temp"); int touch = 0; #if defined(MA_PROF_SUPPORT_STYLUS) touch = 1; #endif if(mHttp.isOpen()){ mHttp.close(); } mHttp = HttpConnection(this); //work out how long the url will be, the 16 is for the & and = symbals int urlLength = 91 + URLSIZE + Util::intlen(imsi) + Util::intlen(imei) + strlen(os) + strlen(make) + strlen(model) + Util::intlen(touch) + Util::intlen(scrWidth) + Util::intlen(scrHeight); char *url = new char[urlLength+1]; memset(url,'\0',urlLength+1); sprintf(url, "%s?update=1.04&imsi=%d&imei=%d&os=%s&make=%s&model=%s&touch=%d&width=%d&height=%d", URL, imsi, imei, os, make, model, touch, scrWidth, scrHeight); int res = mHttp.create(url, HTTP_GET); if(res < 0) { } else { mHttp.setRequestHeader("AUTH_USER", feed->getUsername().c_str()); mHttp.setRequestHeader("AUTH_PW", feed->getEncrypt().c_str()); feed->addHttp(); mHttp.finish(); } delete [] url; versionChecked = 1; } } else { } }
/** * Event handler for capture events * @param event the event struct. */ void PhoneGapCapture::customEvent(const MAEvent &event) { char pathBuffer[1024]; char messageBuffer[1024]; if (event.type == EVENT_TYPE_CAPTURE) { MACaptureEventData eventData = event.captureData; switch (eventData.type) { case MA_CAPTURE_EVENT_TYPE_VIDEO: // Videos are already stored, we need the filepath maCaptureGetVideoPath( eventData.handle, pathBuffer, sizeof(pathBuffer)); sprintf( messageBuffer, "{\"message\":[{\"fullPath\":\"%s\",\"name\":\"%s\"}]}", pathBuffer, FileNameFromPath(pathBuffer)); mMessageHandler->callSuccess( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_OK, messageBuffer, false); maCaptureDestroyData(eventData.handle); break; case MA_CAPTURE_EVENT_TYPE_IMAGE: { char deviceOS[64]; String extension; char localPath[1024]; maGetSystemProperty( "mosync.device.OS", deviceOS, sizeof(deviceOS)); // File format is different on different platforms. // TODO: What about WP? if (strcmp(deviceOS, "iPhone OS") == 0) { extension = "png"; } else if(strcmp(deviceOS, "Android") == 0) { extension = "jpg"; } else { // TODO: What to use as default? extension = "image"; } // Images need to be stored. We use maLocalTime to // get a unique number for the filename. maGetSystemProperty( "mosync.path.local", localPath, sizeof(localPath)); sprintf( pathBuffer, "%simg%d.%s", localPath, maLocalTime(), extension.c_str()); int result = maCaptureWriteImage( eventData.handle, pathBuffer, sizeof(pathBuffer)); sprintf( messageBuffer, "{\"message\":[{\"fullPath\":\"%s\",\"name\":\"%s\"}]}", pathBuffer, FileNameFromPath(pathBuffer)); if (result == MA_CAPTURE_RES_OK) { mMessageHandler->callSuccess( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_OK, messageBuffer, false); } else { mMessageHandler->callError( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_ERROR, "{\"code\":\"CAPTURE_INTERNAL_ERR\"}", false); } // Free capture data. maCaptureDestroyData(eventData.handle); break; } case MA_CAPTURE_EVENT_TYPE_CANCEL: mMessageHandler->callError( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_ERROR, "{\"code\":\"CAPTURE_NO_MEDIA_FILES\"}", false); break; } // switch } }