ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
ADD_DEFINITIONS("-DEXPORT_API=")
ADD_DEFINITIONS("-Wall")
+ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
#ADD_DEFINITIONS("-Werror")
#ADD_DEFINITIONS("-Wextra")
ADD_DEFINITIONS("-DAPPLICATION_API_BACKWARD_COMPATIBILITY")
Name: wrt-plugins-tizen
Summary: JavaScript plugins for WebRuntime
-Version: 0.4.20
+Version: 0.4.21
Release: 0
Group: Development/Libraries
License: Apache License, Version 2.0
Description: wrt-plugins-tizen-${module_name}
Version: @CMAKE_PROJECT_VERSION@
Requires:
-Libs: -L${libdir} -lwrt-plugins-tizen-tizen
+Libs: -L${libdir} -lwrt-plugins-tizen-${module_name}
Cflags: -I${includedir}/${module_name}
\ No newline at end of file
#include "AlarmConverter.h"
#include <app.h>
#include <time.h>
+#include <JSUtil.h>
#include "plugin_config.h"
#include "JSAlarmAbsolute.h"
priv->setByDayRecurrence(daysOfTheWeek);
}
} else {
- unsigned long long interval = validator.toULongLong(1);
+ long interval = validator.toLong(1);
+ if (interval < 0) {
+ throw InvalidValuesException("period can not be negative value");
+ }
+
if (!JSValueIsNull(ctx, arguments[1])) {
priv->setInterval(interval);
} else {
AbsoluteRecurrence::Type alarmType = privateData->getRecurrenceType();
if(alarmType == AbsoluteRecurrence::Interval) {
- Converter converter(ctx);
- int interval = privateData->getInterval();
+ long interval = privateData->getInterval();
if (interval == -1 ) {
return JSValueMakeNull(ctx);
} else {
- return converter.toJSValueRef(interval);
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, interval);
}
} else {
return JSValueMakeNull(ctx);
std::vector<std::string> daysOfTheWeek = privateData->getByDayRecurrence();
if(daysOfTheWeek.size() > 0) {
- for(unsigned int i=0; i<daysOfTheWeek.size(); i++) {
+ for(size_t i = 0; i<daysOfTheWeek.size(); i++) {
JSValueRef val = converter.toJSValueRef(daysOfTheWeek.at(i));
if(!JSSetArrayElement(ctx, jsResult, i, val)) {
throw UnknownException("Could not insert value into js array");
}
delay = alarmPtr->getDelay();
- int interval = alarmPtr->getPeriod();
+ long interval = alarmPtr->getPeriod();
service = alarmPtr->getService();
service_set_app_id(service, appId.c_str());
int ret = alarm_cancel(alarmId);
TIME_TRACER_ITEM_END("(remove)alarm_cancel", 0);
- if (ret == ALARM_ERROR_NONE) {
- // no error;
- } else if (ret == ALARM_ERROR_INVALID_PARAMETER) {
+ if (ret != ALARM_ERROR_NONE) {
throw NotFoundException("Alarm not found");
- } else {
- throw UnknownException("Platform thrown unknown error");
}
+
TIME_TRACER_ITEM_END(__FUNCTION__, 0);
return JSValueMakeUndefined(ctx);
} catch (const BasePlatformException &err) {
int alarmId = 0;
std::stringstream(id) >> alarmId;
+ if (alarmId <= 0) {
+ LogError("id is wrong : " << alarmId);
+ throw InvalidValuesException("Invalid ID");
+ }
+
TIME_TRACER_ITEM_BEGIN("(get)alarm_get_service", 0);
int ret = alarm_get_service(alarmId, &service);
TIME_TRACER_ITEM_END("(get)alarm_get_service", 0);
DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
return JSWebAPIException::throwException(ctx, exception, err);
}
-
-#if 0
- if(argumentCount <1) {
- ThrowMsg(ConversionException, "Wrong parameter type.");
- } else {
- alarmId = converter.toInt(arguments[0]);
- }
-
- service_h handle = NULL;
- char* alarmType = NULL;
- int error = alarm_get_service(alarmId, &handle);
- if(error != ALARM_ERROR_NONE) {
- ThrowMsg(NotFoundException, "Alarm not found");
- }
-
- error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
- if(SERVICE_ERROR_NONE!=error) {
- LogInfo("Getting data failed: "<<error);
- service_destroy(handle);
- ThrowMsg(PlatformException, "Unknown error occurred.");
- }
-
- if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE))
- {
- AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
- if(converter.toAlarmAbsolutePtr(alarmId, handle, privateData) == false) {
- ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
- }
-
- return JSAlarmAbsolute::createJSObject(ctx, privateData);
-
- } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
- AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
- if(converter.toAlarmRelativePtr(alarmId, handle, privateData) == false) {
- ThrowMsg(ConversionException, "Relative alarm conversion failed.");
- }
- return JSAlarmRelative::createJSObject(ctx, privateData);
- }
- } Catch(ConversionException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
- } Catch(UnsupportedException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
- } Catch(InvalidArgumentException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
- } Catch (NotFoundException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
- } Catch(Exception) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
- }
-
- return JSValueMakeUndefined(ctx);
-#endif
}
DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
return JSWebAPIException::throwException(ctx, exception, err);
}
-#if 0
- int elementIndex = 0;
-
- LogInfo("Alarms id size: " << alarmIds.size());
- for(unsigned int i = 0; i < alarmIds.size(); i++)
- {
- service_h handle = NULL;
- char* alarmType = NULL;
- error = alarm_get_service(alarmIds.at(i), &handle);
- if(ALARM_ERROR_NONE!=error) {
- LogInfo("Getting service failed: "<<error);
- continue;
- }
-
- error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
- if(SERVICE_ERROR_NONE!=error) {
- LogInfo("Getting data failed: "<<error);
- service_destroy(handle);
- continue;
- }
-
- LogInfo("Alarm id: " << alarmIds.at(i));
- LogInfo("Alarm Type: " << alarmType);
-
- if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) {
- LogInfo("Enter getAll Natvie alarm id = " << alarmIds.at(i));
- AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
- LogInfo("Success to make Native alarmPtr");
-
- if(converter.toAlarmAbsolutePtr(alarmIds.at(i), handle, privateData) == false) {
- ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
- }
-
- JSValueRef obj = JSAlarmAbsolute::createJSObject(ctx, privateData);
- if(!JSSetArrayElement(ctx, jsResult, elementIndex, obj))
- {
- ThrowMsg(UnknownException, "JS array creation failed.");
- }
- } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
- AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
- if(converter.toAlarmRelativePtr(alarmIds.at(i), handle, privateData) == false) {
- ThrowMsg(ConversionException, "Relative alarm conversion failed.");
- }
- JSValueRef obj = JSAlarmRelative::createJSObject(ctx, privateData);
- if(!JSSetArrayElement(ctx, jsResult, elementIndex, obj))
- {
- ThrowMsg(UnknownException, "JS array creation failed.");
- }
- }
- service_destroy(handle);
- elementIndex++;
- }
- return jsResult;
-
- } Catch(ConversionException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
- } Catch(UnsupportedException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
- } Catch(InvalidArgumentException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
- } Catch (NotFoundException) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
- } Catch(Exception) {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
- }
-#endif
}
JSValueRef JSAlarmManager::getProperty(JSContextRef context,
{
try {
if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_MINUTE)) {
- return JSUtil::toJSValueRef(context, (unsigned long long)60);
+ return JSUtil::toJSValueRef(context, (long)60);
} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_HOUR)) {
- return JSUtil::toJSValueRef(context, (unsigned long long)3600);
+ return JSUtil::toJSValueRef(context, (long)3600);
} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_DAY)) {
- return JSUtil::toJSValueRef(context, (unsigned long long)86400);
+ return JSUtil::toJSValueRef(context, (long)86400);
} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_WEEK)) {
- return JSUtil::toJSValueRef(context, (unsigned long long)604800);
+ return JSUtil::toJSValueRef(context, (long)604800);
}
} catch (const BasePlatformException &err) {
LogWarning("Getting property is failed. %s", err.getMessage().c_str());
return NULL;
}
-#if 0
-JSValueRef JSAlarmManager::getMin(JSContextRef ctx,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Converter converter(ctx);
- return converter.toJSValueRef(60);
-}
-
-
-JSValueRef JSAlarmManager::getHour(JSContextRef ctx,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Converter converter(ctx);
- return converter.toJSValueRef(3600);
-}
-
-JSValueRef JSAlarmManager::getDay(JSContextRef ctx,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Converter converter(ctx);
- return converter.toJSValueRef(86400);
-}
-
-JSValueRef JSAlarmManager::getWeek(JSContextRef ctx,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Converter converter(ctx);
- return converter.toJSValueRef(604800);
-}
-
-static ail_cb_ret_e appinfoCallback(const ail_appinfo_h appinfo, void *user_data)
-{
- if (appinfo == NULL || user_data == NULL) {
- return AIL_CB_RET_CANCEL;
- }
-
- char** pkgStrPtr = (char**)user_data;
- char* tmpStr = NULL;
- ail_error_e ret;
-
- ret = ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &tmpStr);
- if (ret != AIL_ERROR_OK) {
- return AIL_CB_RET_CONTINUE;
- }
-
- if (tmpStr != NULL) {
- *pkgStrPtr = strdup(tmpStr);
- }
- return AIL_CB_RET_CANCEL;
-}
-
-// get package name by id
-char* JSAlarmManager::getPackageById(const char* appId)
-{
- LogDebug("<<< appId:[" << appId << "]");
-
- ail_filter_h filter;
- ail_error_e ret;
- char* pkg = NULL;
-
- if (appId == NULL) {
- return NULL;
- }
-
-
- ret = ail_filter_new(&filter);
- if (ret != AIL_ERROR_OK) {
- return NULL;
- }
-
- ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_PACKAGEID_STR , appId);
- if (ret != AIL_ERROR_OK) {
- ail_filter_destroy(filter);
- return NULL;
- }
-
- ail_filter_list_appinfo_foreach(filter, appinfoCallback, &pkg);
- ail_filter_destroy(filter);
-
- LogDebug(">>> pkg:[" << pkg << "]");
- return pkg;
-}
-#endif
-
} // Alarm
} // TizenApis
JSObjectRef object,
JSStringRef propertyName,
JSValueRef* exception);
-#if 0
- static JSValueRef getMin(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
- static JSValueRef getHour(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
- static JSValueRef getDay(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
- static JSValueRef getWeek(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
- static char* getPackageById(const char* appId);
-#endif
static JSClassDefinition m_jsClassInfo;
static JSClassRef m_jsClassRef;
#include "JSAlarmRelative.h"
#include "JSAlarmManager.h"
+#include <JSUtil.h>
+
#include <app.h>
#include <time.h>
try {
ArgumentValidator validator(ctx, argumentCount, arguments);
- unsigned long long delay = validator.toULongLong(0);
- unsigned long long period = validator.toULongLong(1, true, 0);
+ long delay = validator.toLong(0);
+ if (delay < 0) {
+ throw InvalidValuesException("delay cannot be negative value");
+ }
+ long period = validator.toLong(1, true, 0);
+ if (period < 0) {
+ throw InvalidValuesException("period cannot be negative value");
+ }
if ((argumentCount > 1) && !JSValueIsNull(ctx, arguments[1])) {
return JSValueToObject(ctx, createJSObject(ctx, delay, period), exception);
return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
}
+
JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, int interval)
{
AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative());
struct tm current;
time_t currentTime;
time_t nextTime;
- Converter converter(ctx);
int id;
try {
nextTime = mktime(&date);
currentTime = mktime(¤t);
- int result = nextTime - currentTime;
+ long result = nextTime - currentTime;
LogDebug("nextTime: "<<nextTime<<", currentTime: "<<currentTime<<", result: "<<result);
throw UnknownException("Unknown exception occurred.");
}
- JSValueRef jsResult = converter.toJSValueRef(result);
- return jsResult;
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, result);
} catch (const BasePlatformException &err) {
return JSWebAPIException::throwException(ctx, exception, err);
} catch (...) {
JSStringRef propertyName,
JSValueRef* exception)
{
- Converter converter(ctx);
- int delay;
+ long delay;
try {
AlarmRelativePtr privateData = getPrivData(object);
delay = privateData->getDelay();
LogInfo("JSAlarmRelative delay = " << delay);
- if(delay >= 0) {
- return converter.toJSValueRef(delay);
- } else {
- // Impossible
- throw UnknownException("Invalid delay value.");
- }
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, delay);
} catch (const BasePlatformException &err) {
return JSWebAPIException::throwException(ctx, exception, err);
} catch (...) {
JSStringRef propertyName,
JSValueRef* exception)
{
-
- Converter converter(ctx);
- int period =0;
+ long period =0;
try {
AlarmRelativePtr privateData = getPrivData(object);
period = privateData->getPeriod();
LogInfo("JSAlarmRelative interval = " << period);
- if(period < 0) {
+ if(period == -1) {
return JSValueMakeNull(ctx);
} else {
- return converter.toJSValueRef(period);
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, period);
}
} catch (const BasePlatformException &err) {
return JSWebAPIException::throwException(ctx, exception, err);
AppManagerWrapper::AppManagerWrapper() :
- m_registeredCallback(false),
+ m_manager_handle(NULL),
m_watchIdAcc(0)
{
}
AppManagerWrapper::~AppManagerWrapper()
{
- if(m_registeredCallback)
+ if(m_manager_handle != NULL)
{
unregisterAppListChangedCallbacks();
}
return;
}
- if(!m_registeredCallback)
+ if(!m_manager_handle)
{
registerAppListChangedCallbacks();
}
return true;
}
- std::vector<std::string> *applist = (std::vector<std::string> *)user_data;
- applist->push_back(app_id);
+ if(user_data == NULL) {
+ LogWarning("No user data to store appId");
+ return true;
+ }
+
+ AppManagerWrapper *appManager = (AppManagerWrapper *)user_data;
+ appManager->applist.push_back(app_id);
return true;
}
-
-void AppManagerWrapper::appListChangedCallback(app_manger_event_type_e event_type,
- const char *appId,
- void *user_data)
+void AppManagerWrapper::appListChangedCallback(app_manger_event_type_e event_type, const char *pkgId, void *user_data)
{
- if(user_data == NULL)
- {
- LogWarning("app_manager listener passed NULL user_data");
+ if(user_data == NULL) {
+ LogWarning("No user data to store appId");
return;
}
AppManagerWrapper *appManager = (AppManagerWrapper *)user_data;
- appManager->appListChangedCallback(event_type, appId);
-}
-
-void AppManagerWrapper::appListChangedCallback(app_manger_event_type_e event_type,
- const char *appId)
-{
- package_info_h package_info;
- std::vector<std::string> applist;
-
if (event_type == APP_MANAGER_EVENT_UNINSTALLED) {
- appListAppUninstalled(appId);
+ for (size_t i = 0; i < appManager->applist.size(); i++) {
+ appListAppUninstalled(appManager->applist.at(i).c_str());
+ }
} else {
- int ret = package_manager_get_package_info(appId, &package_info);
+ package_info_h package_info;
+
+ int ret = package_manager_get_package_info(pkgId, &package_info);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogDebug("Cannot create package info by : " << appId);
+ LogDebug("Cannot create package info by : " << pkgId);
return;
}
- ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, app_callback, (void *)&applist);
+ ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, app_callback, user_data);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
LogDebug("failed while getting appids");
return;
LogDebug("Cannot destroy package info");
}
- for (size_t i = 0; i < applist.size(); i++) {
+ for (size_t i = 0; i < appManager->applist.size(); i++) {
switch(event_type)
{
case APP_MANAGER_EVENT_INSTALLED:
- appListAppInstalled(applist.at(i).c_str());
+ appListAppInstalled(appManager->applist.at(i).c_str());
break;
case APP_MANAGER_EVENT_UPDATED:
- appListAppUpdated(applist.at(i).c_str());
+ appListAppUpdated(appManager->applist.at(i).c_str());
break;
default:
LogWarning("app_manager listener gave wrong event_type : " << event_type);
}
}
}
+
+ // clean-up applist
+ appManager->applist.clear();
}
}
}
+
+
+int AppManagerWrapper::app_list_changed_cb_broker(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data)
+{
+ static app_manger_event_type_e event_type;
+
+ if (!strcasecmp(key, "start")) {
+ if (!strcasecmp(val, "install")) {
+ event_type = APP_MANAGER_EVENT_INSTALLED;
+ } else if (!strcasecmp(val, "uninstall")) {
+ // After uninstallation, we cannot get app ids from package name.
+ // So, we have to store app ids which is included to target package.
+ package_info_h package_info;
+
+ int ret = package_manager_get_package_info(package, &package_info);
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+ LogDebug("Cannot create package info by : " << package);
+ }
+
+ ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, app_callback, data);
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+ LogDebug("failed while getting appids");
+ }
+
+ ret = package_info_destroy(package_info);
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+ LogDebug("Cannot destroy package info");
+ }
+ event_type = APP_MANAGER_EVENT_UNINSTALLED;
+ } else if (!strcasecmp(val, "update")) {
+ event_type = APP_MANAGER_EVENT_UPDATED;
+ }
+ } else if (!strcasecmp(key, "end") && !strcasecmp(val, "ok")) {
+ if (event_type >= 0) {
+ if (data != NULL) {
+ AppManagerWrapper *appManager = (AppManagerWrapper *)data;
+ appManager->appListChangedCallback(event_type, package, data);
+ }
+ }
+ }
+
+ return APP_MANAGER_ERROR_NONE;
+}
+
+
void AppManagerWrapper::registerAppListChangedCallbacks()
{
- if(m_registeredCallback)
- {
+ if (m_manager_handle != NULL) {
LogWarning("Callback already registered.");
return;
}
- // AppManagerWrapper will be used as a singleton object,
- // so this pointer of it can be passed as a parameter of a async function.
- int result = app_manager_set_app_list_changed_cb(appListChangedCallback, this);
- if (result != APP_MANAGER_ERROR_NONE)
- {
- LogWarning("app_manager_set_app_list_changed_cb() returns APP_MANAGER_ERROR_INVALID_PARAMETER");
-
+ m_manager_handle = pkgmgr_client_new(PC_LISTENING);
+ if (m_manager_handle == NULL) {
ThrowMsg(InvalidArgumentException, "Error while registering listener to app_manager");
}
- m_registeredCallback = true;
+ pkgmgr_client_listen_status(m_manager_handle, app_list_changed_cb_broker, this);
}
void AppManagerWrapper::unregisterAppListChangedCallbacks()
{
- if(!m_registeredCallback)
- {
- LogWarning("Callback already unregistered.");
+ if (m_manager_handle == NULL) {
+ LogWarning("No callback registered");
return;
}
- app_manager_unset_app_list_changed_cb();
-
- m_registeredCallback = false;
+ pkgmgr_client_free(m_manager_handle);
+ m_manager_handle = NULL;
}
// @20130125-wscho: current pkgmanager has a problem while db operation.
private:
static bool app_callback(package_info_app_component_type_e comp_type, const char *app_id, void *user_data);
-
- // callback for app_manager_set_app_list_changed_cb
- static void appListChangedCallback(app_manger_event_type_e event_type,
- const char *package,
- void *user_data);
-
- void appListChangedCallback(app_manger_event_type_e event_type,
- const char *package);
+ void appListChangedCallback(app_manger_event_type_e event_type, const char *pkgId, void *user_data);
+ static int app_list_changed_cb_broker(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data);
void appListAppInstalled(const char *appId);
void appListAppUninstalled(const char *appId);
typedef std::set<IAppManagerAppListChangedCallbacks *> AppListChangedCallbacksSet;
AppListChangedCallbacksSet m_callbacks;
- bool m_registeredCallback;
-
+ pkgmgr_client *m_manager_handle;
long m_watchIdAcc;
public:
+ std::vector<std::string> applist;
+
+public:
friend class DPL::Singleton<AppManagerWrapper>;
};
return;
}
+ // if kill request is come for current context, throw InvalidValueException by spec
+ if (pid == getppid())
+ {
+ event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+ return;
+ }
+
char *appIdCStr = NULL;
ret = app_manager_get_app_id(pid, &appIdCStr);
if (ret != APP_MANAGER_ERROR_NONE)
}
MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[SET_POWERED]);
+ object->mUserDataList[SET_POWERED].reset();
if(result == BT_ERROR_NONE) {
if(callback)
callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
}
}
-
- object->mUserDataList[SET_POWERED].reset();
}
else { // unexpected event
LogWarning("Bluetooth state is changed unexpectedly");
if(object->mUserDataList[SET_NAME] != NULL && !strcmp(object->mRequestedName.c_str(), name)) { // requested event
MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[SET_NAME]);
+ object->mUserDataList[SET_NAME].reset();
if(callback)
- callback->invokeCallback("success");
+ callback->invokeCallback("success");
- object->mUserDataList[SET_NAME].reset();
bt_adapter_unset_name_changed_cb();
}
else { // unexpected event
}
MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[SET_VISIBLE]);
+ object->mUserDataList[SET_VISIBLE].reset();
if(result == BT_ERROR_NONE) {
if(callback)
UnknownException error("Unknown error");
callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
}
- }
+ }
- object->mUserDataList[SET_VISIBLE].reset();
bt_adapter_unset_visibility_mode_changed_cb();
}
else { // unexpected event
}
else {
if(callback) {
- JSContextRef context = callback->getContext();
- UnknownException error("Unknown error");
- callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
LogDebug("Reset DISCOVER_DEVICES");
object->mUserDataList[DISCOVER_DEVICES].reset();
- }
+ JSContextRef context = callback->getContext();
+ UnknownException error("Unknown error");
+ callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
+ }
+
+ /*
if(object->mUserDataList[STOP_DISCOVERY] == NULL) // because same core API callback is used
bt_adapter_unset_device_discovery_state_changed_cb();
+ */
}
}
else { // unexpected event
JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(callback->getContext(), object->mFoundDevices[i]);
devices[i] = deviceObj;
}
+
+ LogDebug("Reset DISCOVER_DEVICES");
+ object->mUserDataList[DISCOVER_DEVICES].reset();
callback->invokeCallback(
"onfinished",
}
else { // There is no found device
LogDebug("There is no found device");
+
+ LogDebug("Reset DISCOVER_DEVICES");
+ object->mUserDataList[DISCOVER_DEVICES].reset();
+
callback->invokeCallback(
"onfinished",
JSObjectMakeArray(callback->getContext(), 0, NULL, NULL) );
}
-
- LogDebug("Reset DISCOVER_DEVICES");
- object->mUserDataList[DISCOVER_DEVICES].reset();
}
}
if(callback) {
LogDebug("Call successCallback of stopDiscovery()");
- callback->invokeCallback("success");
object->mUserDataList[STOP_DISCOVERY].reset();
+ callback->invokeCallback("success");
}
}
- bt_adapter_unset_device_discovery_state_changed_cb();
+ //bt_adapter_unset_device_discovery_state_changed_cb();
}
else {
LogWarning("result MUST be BT_ERROR_NONE or BT_ERROR_CANCELLED when BT_ADAPTER_DEVICE_DISCOVERY_FINISHED");
!strcmp(object->mCreateBondingAddress.c_str(), deviceInfo->remote_address)) { // requested event
MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[CREATE_BONDING]);
+ object->mUserDataList[CREATE_BONDING].reset();
if(result == BT_ERROR_NONE && deviceInfo != NULL) {
if(callback) {
UnknownException error("Unknown error");
callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
}
- }
+ }
- object->mUserDataList[CREATE_BONDING].reset();
bt_device_unset_bond_created_cb();
object->mCreateBondingAddress.clear();
}
!strcmp(object->mDestroyBondingAddress.c_str(), remoteAddress)) { // requested event
MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[DESTROY_BONDING]);
+ object->mUserDataList[DESTROY_BONDING].reset();
if(result == BT_ERROR_NONE) {
if(callback)
UnknownException error("Unknown error");
callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
}
- }
+ }
- object->mUserDataList[DESTROY_BONDING].reset();
bt_device_unset_bond_destroyed_cb();
object->mDestroyBondingAddress.clear();
}
}
}
else if(connection->local_role == BT_SOCKET_CLIENT) {
- std::string remoteAddress(connection->remote_address);
- ConnReqMultiMapT::iterator iter;
- do {
- iter = object->mConnReqMap.find(remoteAddress);
- if(iter != object->mConnReqMap.end() && !strcmp(iter->second->mUUID.c_str(), connection->service_uuid)) {
- LogDebug("Find");
- break;
+
+ if(state == BT_SOCKET_CONNECTED) { // connected when Client
+ std::string remoteAddress(connection->remote_address);
+ ConnReqMultiMapT::iterator iter;
+ do {
+ iter = object->mConnReqMap.find(remoteAddress);
+ if(iter != object->mConnReqMap.end() && !strcmp(iter->second->mUUID.c_str(), connection->service_uuid)) {
+ LogDebug("Find");
+ break;
+ }
+ } while(iter != object->mConnReqMap.end());
+
+ if(iter == object->mConnReqMap.end()) {
+ LogWarning("Connection state is changed unexpectedly");
+ return;
}
- } while(iter != object->mConnReqMap.end());
-
- if(iter == object->mConnReqMap.end()) {
- LogWarning("Connection state is changed unexpectedly");
- return;
- }
- MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(iter->second->mUserData);
+ MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(iter->second->mUserData);
- if(state == BT_SOCKET_CONNECTED) { // connected when Client
if(result == BT_ERROR_NONE) {
// Update mConnectedSocket
BluetoothSocketPtr socket = new BluetoothSocket(connection);
object->mConnectedSocket.insert(std::pair<int, BluetoothSocketPtr>(connection->socket_fd, socket));
bt_socket_set_data_received_cb(onSocketReceivedCB, userData);
-
+
// Call successcallback of connectToServiceByUUID
JSContextRef context = callback->getContext();
JSObjectRef socketObj = JSBluetoothSocket::createJSObject(context, socket);
callback->invokeCallback("success", socketObj);
// Update mConnReqMap
- object->mConnReqMap.erase(iter);
+ object->mConnReqMap.erase(iter);
}
else {
- // Call errorcallback of connectToServiceByUUID
- JSContextRef context = callback->getContext();
- InvalidValuesException error("Invalid value");
+ // Call errorcallback of connectToServiceByUUID
+ JSContextRef context = callback->getContext();
+ NotFoundException error("Not found");
if(callback)
callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
// Update mConnReqMap
- object->mConnReqMap.erase(iter);
+ object->mConnReqMap.erase(iter);
}
return;
}
if(bt_adapter_set_state_changed_cb(onStateChangedCB, this) != BT_ERROR_NONE) {
LogError("bt_adapter_set_state_changed_cb() failed");
}
+
+ if(bt_adapter_set_device_discovery_state_changed_cb(onDiscoveryStateChangedCB, this) != BT_ERROR_NONE) {
+ LogError("bt_adapter_set_device_discovery_state_changed_cb() failed");
+ }
}
BluetoothAdapter::~BluetoothAdapter()
if(mUserDataList[DISCOVER_DEVICES] == NULL) {
mUserDataList[DISCOVER_DEVICES] = userData;
-
+
+ /*
if(mUserDataList[STOP_DISCOVERY] == NULL)
bt_adapter_set_device_discovery_state_changed_cb(onDiscoveryStateChangedCB, this);
+ */
} else {
LogError("Already requested");
UnknownException *error = new UnknownException("Already requested");
case BT_ERROR_NONE:
{
LogDebug("bt_adapter_start_device_discovery() succeeded");
- return;
+ return;
}
default:
{
}
mUserDataList[DISCOVER_DEVICES].reset();
+ /*
if(mUserDataList[STOP_DISCOVERY] == NULL) {
bt_adapter_unset_device_discovery_state_changed_cb();
- }
+ }
+ */
}
void BluetoothAdapter::stopDiscovery(MultiCallbackUserDataPtr userData)
if(mUserDataList[STOP_DISCOVERY] == NULL) {
mUserDataList[STOP_DISCOVERY] = userData;
-
+
+ /*
if(mUserDataList[DISCOVER_DEVICES] == NULL)
bt_adapter_set_device_discovery_state_changed_cb(onDiscoveryStateChangedCB, this);
+ */
} else {
LogDebug("Already requested");
UnknownException *error = new UnknownException("Already requested");
}
mUserDataList[STOP_DISCOVERY].reset();
+ /*
if(mUserDataList[DISCOVER_DEVICES] == NULL) {
bt_adapter_unset_device_discovery_state_changed_cb();
- }
+ }
+ */
} else { // Not enabled
ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is turned off");
BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
if(bt_socket_disconnect_rfcomm(mConnectedSocket) != BT_ERROR_NONE) {
LogError("bt_socket_disconnect_rfcomm() failed");
- return;
+ throw UnknownException("Unknown error");
}
mIsConnected = false;
- if(!BluetoothAdapter::getInstance()->closeConnectedSocket(mConnectedSocket)) {
- throw UnknownException("Unknown error");
- }
}
} // Bluetooth
std::vector<BookmarkDataPtr> deletebookmarks = _getCompleteCB(searchData);
result = favorites_bookmark_delete_bookmark((searchData->m_bookmark)->m_id);
if (result == FAVORITES_ERROR_NONE) {
- for (int i = 0; i < deletebookmarks.size(); ++i) {
+ for (std::size_t i = 0; i < deletebookmarks.size(); ++i) {
result = favorites_bookmark_delete_bookmark(deletebookmarks[i]->m_id);
if (result != FAVORITES_ERROR_NONE)
break;
NULL, //getPropertyNames
NULL, // callAsFunction
NULL, // constructor
- JSBookmarkFolder::hasInstance,
+ NULL,
NULL // convertToType
};
}
}
-bool JSBookmarkFolder::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
- return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
JSObjectRef JSBookmarkFolder::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
LogDebug("Enter");
try{
ArgumentValidator validator(ctx, argumentCount, arguments);
std::string title = validator.toString(0);
- return createJSObject(ctx, title);
+ JSObjectRef bookmarkFolder = createJSObject(ctx, title);
+ if (bookmarkFolder) {
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, bookmarkFolder, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+ return bookmarkFolder;
+ } else
+ throw TypeMismatchException("Can't create BookmarkFolder");
} catch(const BasePlatformException& err){
JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, err);
*exception = error;
static JSObjectRef createJSObject(JSContextRef context, void * priv);
#endif
static JSValueRef getParent(JSContextRef context, JSObjectRef object);
- static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
private:
NULL, //getPropertyNames
NULL, // callAsFunction
NULL, // constructor
- JSBookmarkItem::hasInstance,
+ NULL,
NULL // convertToType
};
}
}
-bool JSBookmarkItem::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
- return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
JSObjectRef JSBookmarkItem::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
LogDebug("JSBookmarkItem::constructor()");
ArgumentValidator validator(ctx, argumentCount, arguments);
try{
std::string title = validator.toString(0);
std::string url = validator.toString(1);
- return createJSObject(ctx, title, url);
+ JSObjectRef bookmarkItem = createJSObject(ctx, title, url);
+ if (bookmarkItem) {
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, bookmarkItem, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+ return bookmarkItem;
+ } else
+ throw TypeMismatchException("Can't create BookmarkItem");
}catch(const BasePlatformException& err){
JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, err);
*exception = error;
#if 0
static JSObjectRef createJSObject(JSContextRef context, void * priv);
#endif
- static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
private:
if(updateMode) {
LogDebug("Update mode.");
- result = JSCalendarEvent::getPrivateObject(arg);
+ CalendarEventPtr resultPtr(new CalendarEvent());
+ result = resultPtr;
+
+ // Set the unparsed attributes.
+ CalendarEventPtr oldItem = JSCalendarEvent::getPrivateObject(arg);
+ result->setId(oldItem->getId());
+ result->setParentId(oldItem->getParentId());
+ result->setCalendarId(oldItem->getCalendarId());
+ result->setRecurrenceId(oldItem->getRecurrenceId());
+ result->setCalendarType(oldItem->getCalendarType());
} else {
LogDebug("Constructor mode.");
CalendarEventPtr resultPtr(new CalendarEvent());
}
//It's important to set startTime before duration to set end date
- if (!JSValueIsUndefined(m_context, startTimeData)) {
+ if (!JSValueIsUndefined(m_context, startTimeData) && !JSValueIsNull(m_context, startTimeData)) {
result->setStartTime((long long int) (timeUtilConverter.getTimeInMilliseconds(startTimeData)/1000));
result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(startTimeData).timezone);
LogInfo("start time converted from TZDate: "<<result->getStartTime()<<", time zone: "<<result->getTimeZone());
LogDebug("Start time undefined.");
}
- if (!JSValueIsUndefined(m_context, durationData)) {
+ if (!JSValueIsUndefined(m_context, durationData) && !JSValueIsNull(m_context, durationData)) {
long long length = timeUtilConverter.getDurationLength(durationData);
int unit = timeUtilConverter.getDurationUnit(durationData);
LogDebug("duration length: "<<length<<", unit "<<unit);
*categories = toVectorOfStrings(categoriesData);
result->setCategories(categories);
}
-
+
if (!JSValueIsUndefined(m_context, statusData)) {
result->setStatus(toEventStatus(toString(statusData)));
} else {
EventAttendeeListPtr attendees = toVectorOfAttendeesFromReference(attendeesData);
result->setAttendees(attendees);
}
- if (!JSValueIsUndefined(m_context, geolocationData)) {
+
+ if (!JSValueIsUndefined(m_context, geolocationData) && !JSValueIsNull(m_context, geolocationData)) {
DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(m_context, geolocationData);
result->setGeolocation(geoLocation);
}
+
if (!JSValueIsUndefined(m_context, visibilityData)) {
result->setVisibility(toEventVisibility(toString(visibilityData)));
}
if (!JSValueIsUndefined(m_context, availabilityData)) {
result->setAvailability(toEventAvailability(toString(availabilityData)));
}
- if (!JSValueIsUndefined(m_context, recurrenceRuleData)) {
- if(updateMode) {
- result->setRecurrenceRule(toEventRecurrenceRule(recurrenceRuleData));
- } else {
- result->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(m_context, recurrenceRuleData, NULL)));
- }
+ if (!JSValueIsUndefined(m_context, recurrenceRuleData) && !JSValueIsNull(m_context, recurrenceRuleData)) {
+ result->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(m_context, recurrenceRuleData, NULL)));
}
if (!JSValueIsUndefined(m_context, priorityData)) {
result->setPriority(toTaskPriority(toString(priorityData)));
}
- if (!JSValueIsUndefined(m_context, endDateData)) {
+ if (!JSValueIsUndefined(m_context, endDateData) && !JSValueIsNull(m_context, endDateData)) {
if( result->getTimeZone().empty() ) {
result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(endDateData).timezone);
}
result->setEndTime((long long int) (timeUtilConverter.getTimeInMilliseconds(endDateData)/1000));
}
- if (!JSValueIsUndefined(m_context, dueDateData)) {
+ if (!JSValueIsUndefined(m_context, dueDateData) && !JSValueIsNull(m_context, dueDateData)) {
if( result->getTimeZone().empty() ) {
result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(dueDateData).timezone);
}
result->setEndTime((long long int) (timeUtilConverter.getTimeInMilliseconds(dueDateData)/1000));
}
- if (!JSValueIsUndefined(m_context, completedDateData)) {
+ if (!JSValueIsUndefined(m_context, completedDateData) && !JSValueIsNull(m_context, completedDateData)) {
if( result->getTimeZone().empty() ) {
result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(completedDateData).timezone);
}
m_recurrenceId(UNDEFINED_TIME),
m_attendees(new EventAttendeeList()),
m_isDetached(false),
- m_attributesOfInterest(new AttributeList()),
m_geolocation(new DeviceAPI::Tizen::SimpleCoordinates(UNDEFINED_GEO, UNDEFINED_GEO)),
m_timeZone(DEFAULT_TIMEZONE),
m_priority(LOW_PRIORITY),
m_isDetached = original.getIsDetached();
- AttributeListPtr attributesPtr( new AttributeList() );
- m_attributesOfInterest = attributesPtr;
- *m_attributesOfInterest = *(original.getAttributesOfInterest());
-
DeviceAPI::Tizen::SimpleCoordinatesPtr geolocationPtr( new DeviceAPI::Tizen::SimpleCoordinates(original.getGeolocation()->getLatitude(), original.getGeolocation()->getLongitude()));
m_geolocation = geolocationPtr;
m_isDetached = value;
}
-AttributeListPtr CalendarEvent::getAttributesOfInterest() const
-{
- return m_attributesOfInterest;
-}
-
-void CalendarEvent::setAttributesOfInterest(AttributeListPtr value)
-{
- m_attributesOfInterest = value;
-}
-
DeviceAPI::Tizen::SimpleCoordinatesPtr CalendarEvent::getGeolocation() const
{
return m_geolocation;
#define UNDEFINED_GEO CALENDAR_RECORD_NO_COORDINATE
#define UNDEFINED_ID "-1"
-typedef std::vector<std::string> AttributeList;
-typedef DPL::SharedPtr<AttributeList> AttributeListPtr;
-
/* This object represents a single calendar event */
class CalendarEvent
{
bool getIsDetached() const;
void setIsDetached(bool value);
- void setAttributesOfInterest(AttributeListPtr value);
- AttributeListPtr getAttributesOfInterest() const;
-
DeviceAPI::Tizen::SimpleCoordinatesPtr getGeolocation() const;
void setGeolocation(DeviceAPI::Tizen::SimpleCoordinatesPtr value);
long long int m_recurrenceId;
EventAttendeeListPtr m_attendees;
bool m_isDetached;
- AttributeListPtr m_attributesOfInterest;
DeviceAPI::Tizen::SimpleCoordinatesPtr m_geolocation;
std::string m_timeZone;
TaskPriority m_priority;
EventRecurrenceRulePtr rrule = m_abstractEvent->getRecurrenceRule();
if (NULL==rrule) {
- LogDebug("rrule is not set.");
+ LogWarning("No way! Rrule is not set!");
return;
} else if(EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
LogDebug("No recurrence frequency.");
- return;
} else if(EventRecurrenceRule::UNDEFINED_RECURRENCE==rrule->getFrequency()) {
LogDebug("Undefined recurrence frequency.");
- return;
} else {
LogDebug("frequency "<<rrule->getFrequency());
}
// set frequency
switch (rrule->getFrequency()) {
case EventRecurrenceRule::NO_RECURRENCE:
+ case EventRecurrenceRule::UNDEFINED_RECURRENCE:
if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_NONE)) {
LogWarning("Failed setting frequency.");
}
}
break;
}
- case EventRecurrenceRule::UNDEFINED_RECURRENCE:
default:
LogWarning("Invalid reccurence rule frequency "<<rrule->getFrequency());
break;
class IEventWatchChanges : public WrtDeviceApis::Commons::IEvent<IEventWatchChanges>
{
- AttributeListPtr m_attributesOfInterest;
bool m_result;
long m_watchId;
OnEventsChangedEmitterPtr m_emitter;
return m_result;
}
- void setAttributes(AttributeListPtr value)
- {
- m_attributesOfInterest = value;
- }
- AttributeListPtr getAttributes() const
- {
- return m_attributesOfInterest;
- }
-
void setWatchId(long value)
{
m_watchId = value;
return value;
}
+bool ArgumentValidator::isOmitted(int index){
+ if( index < mArgc)
+ return false;
+ return true;
+}
+bool ArgumentValidator::isNull(int index){
+ if( !isOmitted(index) && JSValueIsNull(mContext, mArgv[index]) ){
+ return true;
+ }
+ return false;
+}
+bool ArgumentValidator::isUndefined(int index){
+ if( !isOmitted(index) && JSValueIsUndefined(mContext, mArgv[index]) ){
+ return true;
+ }
+ return false;
+}
+
double ArgumentValidator::toNumber(int index, bool nullable, double defaultvalue) const{
JSValueRef value = getArgument(index, nullable);
if( JSValueIsNull(mContext, value) && nullable){
JSObjectRef toArrayObject(int index, bool nullable = false) const;
JSValueRef toJSValueRef(int index, bool nullable = false) const;
+ bool isOmitted(int index);
+ bool isNull(int index);
+ bool isUndefined(int index);
+
JSObjectRef toCallbackObject(int index, bool nullable, const char *callback, ...) const;
std::vector<std::string> toStringVector(int index, bool nullable = false) const;
vector<string> mHistory;
string mLine;
int mHistoryIndex;
- char mCurrentPos;
+ int mCurrentPos;
+ int mCurrentPosTmp;
+ int mLineLength;
public:
LineBuffer():mHistoryIndex(0), mCurrentPos(0){
tcgetattr(0, &gSave);
putchar('\b');
}
}
+
+ void cleanLine(){
+ int diff = mLineLength - mCurrentPosTmp;
+ while( diff-- > 0 ){
+ moveCursor(false);
+ }
+ backSpace(mLineLength);
+ }
+
void applyHistory( unsigned int index ){
if( mHistory.size() > index ){
mLine = mHistory[index];
mCurrentPos = mLine.size();
}
}
+
+ void moveCursor( bool Left ){
+ putchar(27);putchar(91);
+ if( Left )
+ putchar(68);
+ else
+ putchar(67);
+ }
+
+ void moveCurrentCursorPosition(){
+ int diff = mLine.size() - mCurrentPos;
+
+ while( diff-- > 0 ){
+ moveCursor(true);
+ }
+ }
+
bool checkSpecialKeys(int a){
if( a == 8 ){
- if( mLine.size() != 0){
+ if( mLine.size() != 0 && mCurrentPos != 0){
mCurrentPos--;
- mLine.erase(mCurrentPos);
+ mLine.erase(mCurrentPos,1);
}
return true;
}
break;
case 67:
//RIGHT
+ if( mCurrentPos < mLine.size())
+ mCurrentPos++;
break;
case 68:
//LEFT
+ if( mCurrentPos > 0 )
+ mCurrentPos--;
break;
case 51:
+ //delete
+ getch();
+ if( mCurrentPos < mLine.size())
+ mLine.erase(mCurrentPos,1);
+ break;
+ case 52:
+ //end
+ getch();
+ mCurrentPos = mLine.size();
+ break;
+ case 49:
+ //home
+ mCurrentPos = 0;
getch();
- backSpace(1);
break;
default:
getch();
printf("%s", prompt);
mCurrentPos = 0;
mLine.clear();
+ mLineLength = mLine.size();
+ mCurrentPosTmp = mCurrentPos;
while(1){
int a = getch();
- backSpace(mLine.size());
+ cleanLine();
if( a == 10 )
break;
mCurrentPos++;
}
cout << mLine;
+ moveCurrentCursorPosition();
+ mLineLength = mLine.size();
+ mCurrentPosTmp = mCurrentPos;
}
cout << mLine;
if( mLine.size() > 0 ){
sortModeObj= argValidator.toObject(4,true);
// count
- if(argumentCount >= 6){
-// if(!JSValueIsNull(context, arguments[5]) && !JSValueIsUndefined(context, arguments[5])){
+ if(argumentCount >= 6){
+ if(!JSValueIsNull(context, arguments[5])){
long count = argValidator.toLong(5, true, 0);
if( count >= 0L ){
dplEvent->setLimit(count);
else{
throw InvalidValuesException( "count should be positive.");
}
-// }
+ }
}
if(argumentCount >= 7){
// offset
return result;
}
+JSValueRef Converter::toJSValueRef(unsigned long long arg)
+{
+ return JSValueMakeNumber(m_context, arg);
+}
+
+
+
IPathPtr Converter::toPath(const JSValueRef& arg)
{
Try {
JSContextRef context);
JSValueRef toJSValueRef(unsigned char* data,
std::size_t num);
+ JSValueRef toJSValueRef(unsigned long long arg);
IPathPtr toPath(const JSValueRef& arg);
* Gets size of this node.
* @return Size.
*/
- virtual std::size_t getSize() const = 0;
+ virtual unsigned long long getSize() const = 0;
/**
* Gets creation date of this node.
* Gets stream's size.
* @return Size or -1 if unavailable (e.g. stream is write-only).
*/
- virtual long getSize() const = 0;
+ virtual unsigned long long getSize() const = 0;
virtual void setCharSet(const std::string &charSet) = 0;
virtual std::string getCharSet() const = 0;
}
return converter.toJSValueRef(static_cast<unsigned long>(pos));
} else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_BYTES_AVAILABLE)) {
- long bytes = stream->getSize() - stream->getPosition();
- return converter.toJSValueRef(static_cast<unsigned long>(bytes));
+ unsigned long long bytes = stream->getSize() - stream->getPosition();
+ return converter.toJSValueRef(static_cast<unsigned long long>(bytes));
}
} catch (const WrtDeviceApis::Commons::ConversionException& ex) {
LogWarning("trying to get incorrect value");
}
}
-std::size_t Node::getSize() const
+unsigned long long Node::getSize() const
{
if (m_type == NT_DIRECTORY) {
ThrowMsg(Commons::PlatformException,
NodeType getType() const;
int getPermissions() const;
void setPermissions(int perms);
- std::size_t getSize() const;
+ unsigned long long getSize() const;
std::time_t getCreated() const;
std::time_t getModified() const;
INodePtr getParent() const;
namespace Filesystem {
typedef DPL::Optional<std::string> OptionalString;
typedef DPL::Optional<std::time_t> OptionalDate;
-typedef DPL::Optional<std::size_t> OptionalSize;
+typedef DPL::Optional<unsigned long long> OptionalSize;
class NodeFilter
{
}
}
-long Stream::getSize() const
+unsigned long long Stream::getSize() const
{
std::fstream::streampos pos = m_stream.tellg();
if (pos == -1) {
return -1;
}
- long result = m_stream.tellg();
+ unsigned long long result = m_stream.tellg();
m_stream.seekg(pos, std::_S_beg);
return (result == -1 ? result : result + 1);
int getMode() const;
- long getSize() const;
+ unsigned long long getSize() const;
private:
template<typename T>
else
{
std::string message = "Message type " + arg + " not supported.";
- throw DeviceAPI::Common::InvalidValuesException(message.c_str());
+ throw DeviceAPI::Common::TypeMismatchException(message.c_str());
}
}
EventTagActionReadPtr event = ((EventNFCPtrs<EventTagActionRead> *)data)->getEventPtrs();
LogDebug("message handler :" << message);
- unsigned char *rawdata;
+ unsigned char *rawdata = NULL;
int size;
if (nfc_ndef_message_get_rawdata(message, &rawdata, &size) != NFC_ERROR_NONE) {
LogError("Can't get record's rawdata");
+ if (rawdata)
+ free(rawdata);
return;
}
static void TargetReceivedCallback(nfc_p2p_target_h target, nfc_ndef_message_h message, void *user_data) {
LogDebug("Callback TargetReceivedCallback.");
if (user_data) {
- unsigned char *rawdata;
+ unsigned char *rawdata = NULL;
int size;
if (nfc_ndef_message_get_rawdata(message, &rawdata, &size) != NFC_ERROR_NONE) {
LogError("Can't get rawdata of message");
+ if (rawdata)
+ free(rawdata);
return;
}
}
std::vector<unsigned char> NdefMessage::toByte() {
- unsigned char *rawdata;
+ unsigned char *rawdata = NULL;
int size;
NFCUtil util;
int result = nfc_ndef_message_get_rawdata(handle, &rawdata, &size);
- if (result != NFC_ERROR_NONE)
+ if (result != NFC_ERROR_NONE) {
+ if (rawdata)
+ free(rawdata);
util.throwNFCException(result, "Can't get serial bytes of NDEF message");
-
+ }
LogDebug(rawdata);
std::vector<unsigned char> byteData = util.toVector(rawdata, size);
if (rawdata)
priv->setProgressType(progType); //set progress Type
return true;
-
}
else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
{
}
try {
-
std::string property;
size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
if (jsSize > 0) {
}
else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
- {
- // progressValue
-
- LogInfo("Progress Type=" << priv->getProgressType());
-
- // progressValue
- unsigned long progressVal = 0;
- if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
- {
- progressVal = (unsigned long)( (priv->getProgressValue()*100) );
- }
- else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
- {
- progressVal = (unsigned long)priv->getProgressValue();
- }
-
- LogInfo("Progress Value=" << progressVal);
-
+ {
+ // progressValue
+ LogInfo("Progress Type=" << priv->getProgressType());
+
+ // progressValue
+ unsigned long progressVal = 0;
+ if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
+ {
+ progressVal = (unsigned long)( (priv->getProgressValue()*100) );
+ }
+ else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
+ {
+ progressVal = (unsigned long)priv->getProgressValue();
+ }
+
+ LogInfo("Progress Value=" << progressVal);
+
+ if( priv->getNotiType() != NOTI_TYPE_PROGRESS && progressVal == 0)
+ {
+ return JSValueMakeNull(context);
+ }
+ else
+ {
return JSUtil::toJSValueRef(context, progressVal);
+ }
}
}
LogWarning(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
return NULL;
}
-
+
+ return NULL;
}
JSObjectSetProperty(context, obj, ctorName, constructor,
kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
JSStringRelease(ctorName);
-
+
try {
+ //Status Notification Type.
NotificationType notiType = NOTI_TYPE_NONE;
std::string strStatusType = validator.toString(0, false, "");
LogInfo("Notification Type : " << strStatusType);
else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
notiType = NOTI_TYPE_PROGRESS;
else
- throw TypeMismatchException("status type mismatch.");
+ throw TypeMismatchException("notification status type mismatch.");
StatusNotification *priv = new StatusNotification(notiType);
priv->setTitle(validator.toString(1, false, "")); //title
- JSObjectRef notiInitDict = validator.toObject(2, true);
+ JSObjectRef notiInitDict = validator.toObject(2, true);
- if (notiInitDict)
- {
- //content
- try {
- JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
- if (!JSValueIsUndefined(context, contentValue))
- priv->setContent(JSUtil::JSValueToString(context, contentValue));
- }
- catch ( const BasePlatformException& err)
+ if (notiInitDict)
+ {
+ LogInfo("Set Notification Init Dictionary");
+ //content
+ JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
+ if (!JSValueIsUndefined(context, contentValue))
+ {
+ priv->setContent(JSUtil::JSValueToString(context, contentValue));
+ }
+
+ //icon
+ try {
+ JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
+ if (!JSValueIsUndefined(context, iconValue))
{
- LogWarning("notification's content convertion is failed." << err.getMessage().c_str());
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
+ priv->setIconPath(path->getFullPath());
}
+ }
+ catch (...)
+ {
+ throw InvalidValuesException("Icon file path is invaild");
+ }
+#if 0
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage());
+ }
+#endif
- //icon
- try {
- JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
- if (!JSValueIsUndefined(context, iconValue))
- {
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
- priv->setIconPath(path->getFullPath());
- }
- }
- catch ( const BasePlatformException& err)
+ //sound
+ try {
+ JSValueRef soundValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);
+ if (!JSValueIsUndefined(context, soundValue))
{
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
- }
-
- //sound
- try {
- JSValueRef soundValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);
- if (!JSValueIsUndefined(context, soundValue))
- {
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
- priv->setSoundPath(path->getFullPath());
- }
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's sound path convertion is failed." << err.getMessage().c_str());
- }
-
- //vibration
- try {
- JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
- if (!JSValueIsUndefined(context, vibrationValue))
- {
- priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
- }
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's vibration value convertion is failed." << err.getMessage().c_str());
- }
-
- //appControl
- try {
- JSValueRef appControlValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
- if (!JSValueIsUndefined(context, appControlValue))
- {
- priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
- }
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's App Control convertion is failed." << err.getMessage().c_str());
- }
-
- //appID
- try {
- JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
- if (!JSValueIsUndefined(context, appIdValue))
- {
- priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
- }
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
+ priv->setSoundPath(path->getFullPath());
}
+ }
+ catch (...)
+ {
+ throw InvalidValuesException("sound file path is invaild");
+ }
+
+ //vibration
+ JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
+ priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
+
+ //appControl
+ JSValueRef appControlValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
+ if (!JSValueIsUndefined(context, appControlValue))
+ priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
+
+ //appID
+ JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
+ if (!JSValueIsUndefined(context, appIdValue))
+ priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
+
+ //progressType
+ NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+
+ JSStringRef propertyName = JSStringCreateWithUTF8CString(STATUS_NOTIFICATION_PROGRESS_TYPE);
+ bool has = JSObjectHasProperty(context, notiInitDict, propertyName);
+ JSStringRelease(propertyName);
+ if (has)
+ {
+ JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
+ std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
+ LogInfo("==Progress Type : " << strProgressType);
+ if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+ progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+ else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+ progressType = NOTI_PROGRESS_TYPE_SIZE;
+ else
+ throw TypeMismatchException("Invalid Progress Type.");
+ }
+ priv->setProgressType(progressType);
-
- //progressType
- NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
- try {
- JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
- if (!JSValueIsUndefined(context, progressTypeValue))
- {
- std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
- LogInfo("Progress Type : " << strProgressType);
-
-
- if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
- progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
- else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
- progressType = NOTI_PROGRESS_TYPE_SIZE;
- else
- throw InvalidValuesException("Invalid Progress Type.");
-
- priv->setProgressType(progressType);
- }
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
- }
-
- //ProgressValue
- try {
- JSValueRef progressValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);
- if (!JSValueIsUndefined(context, progressValue))
- {
- if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
- {
- if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
- throw InvalidValuesException("The percentage progress value must be between 0 and 100");
- priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
- }
- else
- {
- priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
- }
-
- }
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
- }
-
- //DetailInfo
- try {
- JSValueRef detailInfoValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
-
- std::vector<NotificationDetailInfo*> detailInfos;
- if (JSIsArrayValue(context, detailInfoValue))
- {
- JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
- for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
- {
- JSValueRef element = JSGetArrayElement(context, arrayobj, i);
- JSObjectRef object = JSUtil::JSValueToObject(context, element);
- if (object)
- {
- NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
- std::string main = item->getMainText();
- std::string sub = item->getSubText();
- LogInfo("Main : " << main << " Sub : " << sub);
-
- NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
- detailInfos.push_back(detailinfo);
- }
- }
- }
- priv->setDetailInfos(detailInfos);
- }
- catch ( const BasePlatformException& err)
- {
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
- }
-
- //backgroundimage
- try {
- JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
- if (!JSValueIsUndefined(context, backgroundImageValue))
- {
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
- priv->setBackground(path->getFullPath());
- }
- }
- catch ( const BasePlatformException& err)
+#if 0
+ JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
+ if (progressTypeValue)
+ {
+
+ }
+ if (!JSValueIsUndefined(context, progressTypeValue))
+ {
+ std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
+ LogInfo("==Progress Type : " << strProgressType);
+ if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+ progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+ else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+ progressType = NOTI_PROGRESS_TYPE_SIZE;
+ else
+ throw TypeMismatchException("Invalid Progress Type.");
+ }
+ priv->setProgressType(progressType);
+#endif
+ //ProgressValue
+ JSValueRef progressValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);
+ if (!JSValueIsUndefined(context, progressValue))
+ {
+ if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
+ {
+ if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
+ throw TypeMismatchException("The percentage progress value must be between 0 and 100");
+ priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
+ }
+ else
+ {
+ priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
+ }
+ }
+
+ //DetailInfo
+ JSValueRef detailInfoValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
+
+ std::vector<NotificationDetailInfo*> detailInfos;
+ if (JSIsArrayValue(context, detailInfoValue))
+ {
+ JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
+ for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
{
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+ JSObjectRef object = JSUtil::JSValueToObject(context, element);
+ if (object)
+ {
+ NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+ std::string main = item->getMainText();
+ std::string sub = item->getSubText();
+ LogInfo("Main : " << main << " Sub : " << sub);
+
+ NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
+ detailInfos.push_back(detailinfo);
+ }
}
+ }
+ priv->setDetailInfos(detailInfos);
- //number
- try {
- JSValueRef numberValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
- if (!JSValueIsUndefined(context, numberValue))
- {
- priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
- }
- }
- catch ( const BasePlatformException& err)
+ //backgroundimage
+ try {
+ JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
+ if (!JSValueIsUndefined(context, backgroundImageValue))
{
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
- }
-
- //thumbnail
- try {
- JSValueRef thumbnailsValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
- if (!JSValueIsUndefined(context, thumbnailsValue))
- {
- priv->setThumbnails(JSUtil::JSArrayToStringVector(context, thumbnailsValue));
- }
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
+ priv->setBackground(path->getFullPath());
}
- catch ( const BasePlatformException& err)
+ }
+ catch(...)
+ {
+ throw TypeMismatchException("The backgound image path is invalid : ");
+ }
+
+ //number
+ JSValueRef numberValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
+ if (!JSValueIsUndefined(context, numberValue))
+ {
+ priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
+ }
+
+ //thumbnail
+ try {
+ JSValueRef thumbnailsValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
+ if (!JSValueIsUndefined(context, thumbnailsValue))
{
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
- }
-
- //subIconPath
- try {
- JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
- if (!JSValueIsUndefined(context, subIconPathValue))
- {
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
- priv->setSubIconPath( path->getFullPath());
- }
+
+ std::vector<std::string> thumbnailPaths;
+ if( JSIsArrayValue(context, thumbnailsValue)){
+ JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnailsValue);
+ for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
+ JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+ DeviceAPI::Filesystem::IPathPtr thumbnailPath =
+ DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
+ LogInfo("thumbnail Path = " << thumbnailPath->getFullPath());
+ thumbnailPaths.push_back(thumbnailPath->getFullPath());
+ }
+ }
+ priv->setThumbnails(thumbnailPaths);
}
- catch ( const BasePlatformException& err)
+ }
+ catch ( ... )
+ {
+ throw TypeMismatchException("thumbnail path convertion is failed.");
+ }
+
+ //subIconPath
+ try {
+ JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
+ if (!JSValueIsUndefined(context, subIconPathValue))
{
- LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
+ priv->setSubIconPath( path->getFullPath());
}
-
}
+ catch (...)
+ {
+ throw TypeMismatchException("subIcon path convertion is failed.");
+ }
+
+ }
setPrivateObject(context, obj, priv);
LogWarning(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
*exception = error;
- return NULL;
+ return error;
}
return obj;
if (priv) {
JSObjectSetPrivate(object, static_cast<void*>(priv));
}
+ else
+ throw TypeMismatchException("StatusNotification object is invaild.");
//type
std::string typeVal(NOTIFICATION_TYPE_VALUE);
JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
-
//id
if (priv->getID() >= 0)
{
JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
//content
- JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
- JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
+ if (priv->getStrContent())
+ JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
+ JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
+ else
+ JSUtil::setProperty(context, object, NOTIFICATION_CONTENT, JSValueMakeNull(context), kJSPropertyAttributeNone);
//iconPath
- JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
- JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
+ if (!priv->getIconPath().empty())
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
+ JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
//subIconPath
- JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
- JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
+ if ( !priv->getSubIconPath().empty())
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
+ JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
//number
- JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
- JSUtil::toJSValueRef(context, (unsigned long)priv->getNumber()), kJSPropertyAttributeNone);
+ if (priv->getStrNumber()){
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
+ JSUtil::toJSValueRef(context, priv->getNumber()), kJSPropertyAttributeNone);
+ }
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER, JSValueMakeNull(context), kJSPropertyAttributeNone);
// backgroundImagePath
- JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
+ if ( !priv->getBackground().empty())
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
-
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
+
// thumbnails
-
std::vector<std::string> thumbnails = priv->getThumbnails();
LogInfo("Thumbnail Size : " << thumbnails.size());
JSValueRef tumbnailvalueArray[thumbnails.size()];
jsThumbnails, kJSPropertyAttributeNone);
// soundPath
- JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
+ if ( !priv->getSoundPath().empty() )
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
// vibration
JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
// appId
- JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
- JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
+ if (!priv->getApplicationId().empty())
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
+ JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone);
#if 0
// progressType & Value
jsResult, kJSPropertyAttributeNone);
// appControl
- DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
- if (appCtrlPriv)
- {
+ if ( !(priv->getApplicationControl())->getOperation().empty())
+ {
+ DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, jsAppCtrl, kJSPropertyAttributeNone);
}
+ else
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, JSValueMakeNull(context), kJSPropertyAttributeNone);
}
}
+char* StatusNotification::getStrContent()
+{
+ LogInfo("get Content handle: " << m_notiHandle);
+ if (m_notiHandle)
+ {
+ char *content = NULL;
+
+ if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
+ {
+ throw UnknownException("get notification Content error");
+ }
+
+ return content;
+ }
+ else
+ {
+ throw UnknownException("notification handle is null");
+ }
+}
+
void StatusNotification::setContent(std::string content)
{
LogInfo("Content : " << content);
if (service_create(&m_service) != SERVICE_ERROR_NONE)
{
LogWarning("Create Service Failed..");
- throw DeviceAPI::Common::UnknownException ("service creation error");
+ throw UnknownException("service creation error");
}
}
m_launchFlag = true;
if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
{
- throw DeviceAPI::Common::UnknownException ("service set appId error");
+ throw UnknownException("service set appId error");
}
}
}
{
LogWarning("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
}
- throw DeviceAPI::Common::UnknownException ("get notification service error ");
+ throw UnknownException ("get notification service error ");
}
else
{
if (service == NULL)
{
- throw DeviceAPI::Common::UnknownException ("get notification service ok, but service null");
+ throw UnknownException ("get notification service ok, but service null");
}
}
}
{
if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
{
- throw DeviceAPI::Common::UnknownException ("get a appId error");
+ throw UnknownException ("get a appId error");
}
if (appIdStr != NULL)
}
}
-unsigned int StatusNotification::getNumber()
+long StatusNotification::getNumber()
{
LogInfo("Handle = " << m_notiHandle);
if (m_notiHandle)
{
- int number = 0;
+ long number = 0;
char *strNumber = NULL;
if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
if (strNumber)
std::istringstream(strNumber) >> number;
+ else
+ LogInfo("Number Is NULL");
LogInfo("number = " << number);
- if (number < 0 )
- number = 0;
return number;
}
else
}
}
-void StatusNotification::setNumber(const unsigned int number)
+const char* StatusNotification::getStrNumber()
+{
+ LogInfo("Handle = " << m_notiHandle);
+ if (m_notiHandle)
+ {
+ char *strNumber = NULL;
+
+ if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
+ {
+ throw UnknownException( "get notification background error");
+ }
+
+ if (!strNumber)
+ {
+ return NULL;
+ }
+
+ return strNumber;
+ }
+ else
+ {
+ LogDebug("noti Handle is NULL");
+ return NULL;
+ }
+}
+
+void StatusNotification::setNumber(const long number)
{
LogInfo("Number = " << number);
if (m_notiHandle)
stream << number;
if (stream.fail()) {
throw UnknownException(
- "Couldn't convert e-mail account id");
+ "Couldn't convert notification number");
}
std::string strNumber = stream.str();
if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
{
- throw UnknownException( "set notification sound error");
+ throw UnknownException( "set notification text error");
}
setUpdatedFlag(true);
}
time_t getPostedTime();
std::string getTitle();
void setTitle(std::string title);
+
std::string getContent();
+ char* getStrContent();
void setContent(std::string content);
std::string getIconPath() ;
std::string getBackground() ;
void setBackground(const std::string imagePath) ;
- unsigned int getNumber() ;
- void setNumber(const unsigned int number) ;
-
+ long getNumber() ;
+ const char* getStrNumber() ;
+ void setNumber(const long number) ;
//void setStatusType(NotificationType type);
DeviceAPI::Application::ApplicationControlPtr getApplicationControl();
std::vector<std::string> m_thumbs; //thumbnail images path
std::vector<NotificationDetailInfo*> m_detailInfos; // detail Info
-
-#if 0
-public:
- StatusNotification();
- virtual ~StatusNotification();
-
- std::string getStatusType() const;
- void setStatusType(std::string statusType);
-
- std::string getIconPath() const;
- void setIconPath(std::string iconPath);
-
- std::string getSubIconPath() const;
- void setSubIconPath(std::string subIconPath);
-
- long getNumber() const;
- void setNumber(long number);
-
- std::vector<NotificationDetailInfo*> getDetailInfo() const;
- void setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo);
-
- std::string getBackgroundImagePath() const;
- void setBackgroundImagePath(std::string backgroundImagePath);
-
- std::vector<std::string> getThumbnails() const;
- void setThumbnails(std::vector<std::string> thumbnails);
-
- std::string getSoundPath() const;
- void setSoundPath(std::string soundPath);
-
- bool getVibration() const;
- void setVibration(bool vibration);
-
- ApplicationControl getAppControl() const;
- void setAppControl(ApplicationControl appControl);
-
- ApplicationId getAppId() const;
- void setAppId(ApplicationId appId);
-
- std::string getProgressType() const;
- void setProgressType(std::string progressType);
-
- unsigned long getProgressValue() const;
- void setProgressValue(unsigned long progressValue);
-
-private:
- std::string m_statusType;
- std::string m_iconPath;
- std::string m_subIconPath;
- long m_number;
- std::vector<NotificationDetailInfo*> m_detailInfo;
- std::string m_backgroundImagePath;
- std::vector<std::string> m_thumbnails;
- std::string m_soundPath;
- bool m_vibration;
- ApplicationControl m_appControl;
- ApplicationId m_appId;
- std::string m_progressType;
- unsigned long m_progressValue;
-
-#endif
};
string path = validator.toString(0);
- JSObjectRef eventCBObj = validator.toCallbackObject(1, true, "onprogress", "oncomplete", NULL);
+ JSObjectRef eventCBObj = validator.toCallbackObject(1, false, "onprogress", "oncomplete", NULL);
JSObjectRef errCB = validator.toFunction(2, true);
CallbackUserData *onprogressCb = NULL;
string id = validator.toString(0);
//JSObjectRef eventCBObj = validator.toObject(1, true);
- JSObjectRef eventCBObj = validator.toCallbackObject(1, true, "onprogress", "oncomplete", NULL);
+ JSObjectRef eventCBObj = validator.toCallbackObject(1, false, "onprogress", "oncomplete", NULL);
JSObjectRef errCB = validator.toFunction(2, true);
CallbackUserData *onprogressCb = NULL;
switch (event_state) {
case PACAKGE_MANAGER_EVENT_STATE_COMPLETED: {
- LogDebug("destroy client handle");
if (callback->getOnComplete()) {
Converter converter(context);
callback->getOnComplete()->callSuccessCallback(converter.toJSValueRef(package));
}
+ LogDebug("destroy client handle");
// this api is not supported from platform.
//package_manager_request_destroy(callback->getHandle());
package_manager_client_destroy(callback->getHandle());
+ callback->setHandle(NULL);
//clean-up callback object
delete callback;
// this api is not supported from platform.
//package_manager_request_destroy(callback->getHandle());
package_manager_client_destroy(callback->getHandle());
+ callback->setHandle(NULL);
//clean-up callback object
delete callback;
// this api is not supported from platform.
//package_manager_request_destroy(callback->getHandle());
package_manager_client_destroy(callback->getHandle());
+ callback->setHandle(NULL);
//clean-up callback object
delete callback;
#include <PlatformException.h>
#include <Logger.h>
#include <JSUtil.h>
+#include <vconf.h>
using namespace DeviceAPI::Common;
using namespace std;
namespace DeviceAPI {
namespace Power {
-
PowerResource::PowerResource(const char *resource)
{
if( strcmp(resource,"SCREEN") == 0 )
throw UnknownException("Platform error while getting max brightness");
}
- ret = device_set_brightness(0, maxBrightness);
- if( DEVICE_ERROR_NONE!=ret){
- LOGE("Platform error while setting %d brightness: %d", maxBrightness, ret);
- throw UnknownException("Platform error while setting max brightness");
- }
+ setPlatformBrightness( maxBrightness );
LOGI("Succeeded setting the brightness to a max level: %d", maxBrightness);
ret = power_lock_state(POWER_STATE_NORMAL, 0);
if( POWER_ERROR_NONE!=ret )
LOGI("Platform return value from dim unlock: %d", ret);
- ret = device_set_brightness_from_settings(0);
- if( DEVICE_ERROR_NONE!=ret){
- LOGE("Platform error while setting restore brightness %d", ret);
- throw UnknownException("Platform error while setting restore brightness");
+ if( mBrightStateEnable ){
+ ret = device_set_brightness_from_settings(0);
+ if( DEVICE_ERROR_NONE!=ret){
+ LOGE("Platform error while setting restore brightness %d", ret);
+ throw UnknownException("Platform error while setting restore brightness");
+ }
}
mBrightStateEnable = false;
}
double PowerManager::getScreenBrightness(){
- int ret, brightness;
- ret = device_get_brightness(0, &brightness);
- if( DEVICE_ERROR_NONE!=ret ){
- LOGE("Platform error while get brightness %d", ret);
- throw UnknownException("Platform error while get brightness");
- }
+ int brightness;
+ brightness = getPlatformBrightness();
LOGI("Brightness value: %d", brightness);
return brightness/100.0;
}
throw UnknownException("Platform error while getting max brightness");
}
int nativeBrightness = (int)(brightness*maxBrightness);
- ret = device_set_brightness(0, nativeBrightness);
- if( DEVICE_ERROR_NONE!=ret ){
- LOGE("Platform error while setting %d brightness : %d",nativeBrightness, ret);
- throw UnknownException("Platform error while setting brightness.");
- }
+
+ setPlatformBrightness(nativeBrightness);
LOGI("Set the brightness value: %d", nativeBrightness);
}
mListener.remove(callback);
}
+void PowerManager::setPlatformBrightness(int brightness){
+
+
+ if( mCurrentState.mState == PowerState::SCREENDIM ){
+ mCurrentBrightness = brightness;
+ LOGI("Current state is not normal state the value is saved in cache: %d", brightness);
+ mShouldBeReadFromCache = true;
+ return;
+ }else
+ mShouldBeReadFromCache = false;
+
+ int ret = device_set_brightness(0, brightness);
+ if( ret != 0){
+ LOGE("Platform error while setting %d brightness: %d", brightness, ret);
+ throw UnknownException("Platform error while setting brightness.");
+ }
+ mCurrentBrightness = brightness;
+}
+
+int PowerManager::getPlatformBrightness(){
+ int brightness = 0;
+ int ret = 0;
+
+ int isCustomMode = 0;
+ vconf_get_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, &isCustomMode);
+ if( (isCustomMode && mCurrentBrightness != -1) || mShouldBeReadFromCache ){
+ LOGI("return custom brightness %d", mCurrentBrightness);
+ return mCurrentBrightness;
+ }
+
+ ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness);
+ if( ret != 0 ){
+ LOGE("Platform error while getting brightness: %d", ret);
+ throw UnknownException("Platform error while getting brightness");
+ }
+ LOGE("VCONFKEY_SETAPPL_LCD_BRIGHTNESS %d", brightness);
+
+ return brightness;
+}
+
+
+void PowerManager::restoreSettedBrightness(){
+ int isCustomMode = 0;
+ vconf_get_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, &isCustomMode);
+ if( isCustomMode || mShouldBeReadFromCache ){
+ if( mCurrentBrightness == -1 ){
+ // brightness was changed in other process
+ restoreScreenBrightness();
+ }else{
+ setPlatformBrightness(mCurrentBrightness);
+ }
+ }
+ mShouldBeReadFromCache = false;
+}
+
void PowerManager::broadcastScreenState(PowerState current){
if( mCurrentState == current)
return;
+ PowerState PreviousState = mCurrentState;
+ mCurrentState = current;
+
+ if( mCurrentState.mState == PowerState::SCREENNORMAL && PreviousState.mState == PowerState::SCREENDIM ){
+ //restore ScreenBrightness
+ try{
+ restoreSettedBrightness();
+ }
+ catch( const BasePlatformException& err){
+ LOGE("Error restore custom brightness %s", err.getMessage().c_str());
+ }
+ }
+ if( mCurrentState.mState == PowerState::SCREENNORMAL && PreviousState.mState == PowerState::SCREENOFF){
+ mShouldBeReadFromCache = false;
+ }
+
list<CallbackUserData*> tmplist(mListener);
list<CallbackUserData*>::iterator itr = tmplist.begin();
while( itr != tmplist.end() ){
CallbackUserData *callback = *itr;
if( callback != NULL ){
- JSValueRef previousState = JSUtil::toJSValueRef(callback->getContext(), mCurrentState.toString());
- JSValueRef currentState = JSUtil::toJSValueRef(callback->getContext(), current.toString());
+ JSValueRef previousState = JSUtil::toJSValueRef(callback->getContext(), PreviousState.toString());
+ JSValueRef currentState = JSUtil::toJSValueRef(callback->getContext(), mCurrentState.toString());
JSValueRef args[2] = { previousState, currentState };
callback->callSuccessCallback(2, args);
}
++itr;
}
- mCurrentState = current;
}
-PowerManager::PowerManager():mCurrentState(PowerState::SCREENNORMAL),mBrightStateEnable(false){
+PowerManager::PowerManager():mCurrentState(PowerState::SCREENNORMAL),mBrightStateEnable(false),mCurrentBrightness(-1),mShouldBeReadFromCache(false){
power_state_e platform_state = power_get_state();
switch( platform_state ){
case POWER_STATE_NORMAL :
static PowerManager* getInstance();
private:
+ int getPlatformBrightness();
+ void setPlatformBrightness(int i);
+ void restoreSettedBrightness();
static void onPlatformStateChangedCB(power_state_e state, void *user_data);
PowerManager();
virtual ~PowerManager();
std::list<Common::CallbackUserData*> mListener;
PowerState mCurrentState;
bool mBrightStateEnable;
+ int mCurrentBrightness;
+ bool mShouldBeReadFromCache;
};
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
- constructor, //CallAsConstructor,
- hasInstance, //HasInstance,
+ NULL, //CallAsConstructor,
+ NULL, //HasInstance,
NULL //ConvertToType
};
void JSTZDate::initialize(JSContextRef context, JSObjectRef object)
{
LogDebug("entered Nothing to do.");
-
- if (!JSObjectGetPrivate(object)) {
- LogDebug("Private object not set... setting it.");
- TZDatePtr tzDate(new TZDate(FALSE));
- TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
- if (!JSObjectSetPrivate(object, priv)) {
- delete priv;
- }
- }
}
void JSTZDate::finalize(JSObjectRef object)
TimeUtilConverter converter(ctx);
Try {
+ JSObjectRef tzDate = NULL;
+
if (argumentCount == 0) {
- return createJSObject(ctx);
+ tzDate = createJSObject(ctx);
} else if (argumentCount <= 2) {
std::string timezone = "";
if ((argumentCount == 2) && !JSValueIsNull(ctx, arguments[1]) && !JSValueIsUndefined(ctx, arguments[1])) {
timezone = converter.toString(arguments[1]);
}
- if (JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0]))
- return createJSObject(ctx, timezone);
-
- struct tm date = converter.toDateTm(arguments[0]);
- LogDebug("date = " << date.tm_year << "." << date.tm_mon << "." << date.tm_mday);
- LogDebug(date.tm_hour << ":" << date.tm_min << ":" << date.tm_sec);
- LogDebug("isdst?" << date.tm_isdst);
-
- prop.timezone = timezone;
- prop.year = date.tm_year + 1900;
- prop.month = date.tm_mon;
- prop.day = date.tm_mday;
- prop.hours = date.tm_hour;
- prop.minutes = date.tm_min;
- prop.seconds = date.tm_sec;
-
- JSStringRef getMillisecondsName = JSStringCreateWithUTF8CString("getMilliseconds");
- JSValueRef getMiliSecFuction = JSObjectGetProperty(ctx, converter.toJSObjectRef(arguments[0]), getMillisecondsName, exception);
- JSStringRelease(getMillisecondsName);
- if (getMiliSecFuction) {
- JSObjectRef function = JSValueToObject(ctx, getMiliSecFuction, exception);
- JSValueRef result = JSObjectCallAsFunction(ctx, function, converter.toJSObjectRef(arguments[0]), 0, NULL, exception);
- prop.milliseconds = converter.toLong(result);
- LogDebug("getMilliseconds = " << prop.milliseconds);
+ if (JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0])) {
+ tzDate = createJSObject(ctx, timezone);
+ } else {
+ struct tm date = converter.toDateTm(arguments[0]);
+ LogDebug("date = " << date.tm_year << "." << date.tm_mon << "." << date.tm_mday);
+ LogDebug(date.tm_hour << ":" << date.tm_min << ":" << date.tm_sec);
+ LogDebug("isdst?" << date.tm_isdst);
+
+ prop.timezone = timezone;
+ prop.year = date.tm_year + 1900;
+ prop.month = date.tm_mon;
+ prop.day = date.tm_mday;
+ prop.hours = date.tm_hour;
+ prop.minutes = date.tm_min;
+ prop.seconds = date.tm_sec;
+
+ JSStringRef getMillisecondsName = JSStringCreateWithUTF8CString("getMilliseconds");
+ JSValueRef getMiliSecFuction = JSObjectGetProperty(ctx, converter.toJSObjectRef(arguments[0]), getMillisecondsName, exception);
+ JSStringRelease(getMillisecondsName);
+ if (getMiliSecFuction) {
+ JSObjectRef function = JSValueToObject(ctx, getMiliSecFuction, exception);
+ JSValueRef result = JSObjectCallAsFunction(ctx, function, converter.toJSObjectRef(arguments[0]), 0, NULL, exception);
+ prop.milliseconds = converter.toLong(result);
+ LogDebug("getMilliseconds = " << prop.milliseconds);
+ }
+ tzDate = createJSObject(ctx, prop);
}
- return createJSObject(ctx, prop);
} else {
prop.year = converter.toLong(arguments[0]);
if ((prop.year >= 0) && (prop.year <= 99))
}
}
}
- return createJSObject(ctx, prop);
+ tzDate = createJSObject(ctx, prop);
+ }
+
+ if (tzDate) {
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, tzDate, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+ return tzDate;
}
} Catch(ConversionException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ *exception = error;
+ return error;
} Catch (InvalidArgumentException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+ *exception = error;
+ return error;
} Catch (PlatformException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
} Catch (WrtDeviceApis::Commons::Exception) {
LogError("Exception: " << _rethrown_exception.GetMessage());
}
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ *exception = error;
+ return error;
}
const JSClassRef JSTZDate::getClassRef()
{
return &m_classInfo;
}
-bool JSTZDate::hasInstance(JSContextRef context,
- JSObjectRef constructor,
- JSValueRef possibleInstance,
- JSValueRef* exception)
-{
- return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
JSValueRef JSTZDate::getTimezone(JSContextRef context, JSObjectRef function,
JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
LogDebug("entered");
static JSObjectRef createJSObject(JSContextRef context, const double milliseconds, const std::string &timezone);
static JSObjectRef createJSObject(JSContextRef context, const TZDateProperties &properties);
static JSObjectRef createJSObject(JSContextRef context, const long year, const long month, const long day, const long hours, const long minutes, const long seconds, const long milliseconds, const std::string &timezone);
+
+
+ static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
private:
enum CompareType {
DIFFERENCE,
*/
static void finalize(JSObjectRef object);
- static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
- /**
- * The callback invoked when an object is used as the target of an 'instanceof' expression.
- */
- static bool hasInstance(JSContextRef context,
- JSObjectRef constructor,
- JSValueRef possibleInstance,
- JSValueRef* exception);
-
static JSValueRef getTimezone(JSContextRef context, JSObjectRef function,
JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
static JSValueRef toTimezone(JSContextRef context, JSObjectRef function,
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
- constructor, //CallAsConstructor,
- hasInstance,
+ NULL, //CallAsConstructor,
+ NULL,
NULL, //ConvertToType
};
void JSTimeDuration::initialize(JSContextRef context, JSObjectRef object)
{
LogDebug("entered Nothing to do.");
-
- if (!JSObjectGetPrivate(object)) {
- LogDebug("Private object not set... setting it.");
- DurationProperties durations;
- DurationPropertiesPtr durationProps(new DurationProperties(durations));
- TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps);
-
- if (!JSObjectSetPrivate(object, priv)) {
- delete priv;
- }
- }
}
void JSTimeDuration::finalize(JSObjectRef object)
ThrowMsg(ConversionException, "Argument(unit) is invalid(wrong type unit)");
}
}
- return createJSObject(ctx, duration);
+ JSObjectRef timeDuration = createJSObject(ctx, duration);
+ if (timeDuration) {
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, timeDuration, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+ return timeDuration;
+ }
} Catch(NullPointerException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ *exception = error;
+ return error;
} Catch(UnknownException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ *exception = error;
+ return error;
} Catch(ConversionException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ *exception = error;
+ return error;
} Catch (InvalidArgumentException) {
LogError("Exception: " << _rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
- return NULL;
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+ *exception = error;
+ return error;
} Catch (WrtDeviceApis::Commons::Exception) {
LogWarning("Trying to get incorrect value");
}
- *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
- return NULL;
-}
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ *exception = error;
+ return error;
-bool JSTimeDuration::hasInstance(JSContextRef context,
- JSObjectRef constructor,
- JSValueRef possibleInstance,
- JSValueRef* exception)
-{
- return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
}
JSValueRef JSTimeDuration::diffTimeDuration(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type) {
*/
static const JSClassRef getClassRef();
static JSObjectRef createJSObject(JSContextRef context, const DurationProperties &durations);
+
+ static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
private:
enum CompareType {
DIFFERENCE,
static bool setProperty(JSContextRef context, JSObjectRef object,
JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
- static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
- /**
- * The callback invoked when an object is used as the target of an 'instanceof' expression.
- */
- static bool hasInstance(JSContextRef context,
- JSObjectRef constructor,
- JSValueRef possibleInstance,
- JSValueRef* exception);
-
static JSValueRef diffTimeDuration(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type);
static JSValueRef difference(JSContextRef context, JSObjectRef function,
JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
using namespace WrtDeviceApis;
using namespace WrtDeviceApis::Commons;
+class_definition_options_t ConstructorClassOptions =
+{
+ JS_INTERFACE,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL,
+ NULL,
+ NULL
+};
+
void on_widget_start_callback(int widgetId) {
LogDebug("[TIZEN\\TimeUtil] on_widget_start_callback ("<<widgetId<<")");
Try
PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
PLUGIN_CLASS_MAP_BEGIN
- PLUGIN_CLASS_MAP_ADD_CLASS(
- WRT_JS_EXTENSION_OBJECT_TIZEN,
- "time",
- (js_class_template_getter)DeviceAPI::Time::JSTimeUtil::getClassRef,
- NULL)
- PLUGIN_CLASS_MAP_ADD_CLASS(
- WRT_JS_EXTENSION_OBJECT_TIZEN,
- "TZDate",
- (js_class_template_getter)DeviceAPI::Time::JSTZDate::getClassRef,
- NULL)
- PLUGIN_CLASS_MAP_ADD_CLASS(
- WRT_JS_EXTENSION_OBJECT_TIZEN,
- "TimeDuration",
- (js_class_template_getter)DeviceAPI::Time::JSTimeDuration::getClassRef,
- NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ "time",
+ (js_class_template_getter)JSTimeUtil::getClassRef,
+ NULL)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ "TZDate",
+ (js_class_template_getter)JSTZDate::getClassRef,
+ reinterpret_cast<js_class_constructor_cb_t>(JSTZDate::constructor),
+ &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ "TimeDuration",
+ (js_class_template_getter)JSTimeDuration::getClassRef,
+ reinterpret_cast<js_class_constructor_cb_t>(JSTimeDuration::constructor),
+ &ConstructorClassOptions)
PLUGIN_CLASS_MAP_END
} // Time