Name: wrt-plugins-tizen
Summary: JavaScript plugins for WebRuntime
-Version: 0.4.23
-Release: 1
+Version: 0.4.24
+Release: 0
Group: Development/Libraries
License: Apache License, Version 2.0
Source0: %{name}-%{version}.tar.gz
{
LoggerD(" app id : " << appId);
+ service_set_app_id(service, appId.c_str());
+
+ // get resolved app id for aliased app id cannot be used to app_manager_get_app_info()
+ char* resolved_app_id = NULL;
+ service_get_app_id(service, &resolved_app_id);
+
// Application exist checking. if specific application is not exist, return Not Found Exception.
app_info_h info_h;
- if (app_manager_get_app_info(appId.c_str(), &info_h) != APP_MANAGER_ERROR_NONE) {
+ if (app_manager_get_app_info(resolved_app_id, &info_h) != APP_MANAGER_ERROR_NONE) {
event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+ if (resolved_app_id) {
+ free(resolved_app_id);
+ }
service_destroy(service);
return;
- } else {
- app_info_destroy(info_h);
}
- service_set_app_id(service, appId.c_str());
+ app_info_destroy(info_h);
+ if (resolved_app_id) {
+ free(resolved_app_id);
+ }
}
service_set_operation(service, operation.c_str() );
{
str = name;
free(name);
- LoggerD("name" << str);
}
}
else {
if (address != NULL) {
str = address;
free(address);
- LoggerD("address: " << str);
}
else {
LoggerW("address is NULL");
try {
if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_ADAPTER_NAME)) {
std::string name = BluetoothAdapter::getInstance()->getName();
- LoggerD("name: " << name);
return JSUtil::toJSValueRef(context, name);
}
else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_ADAPTER_POWERED)) {
}
else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_ADDRESS)) {
std::string address = BluetoothAdapter::getInstance()->getAddress();
- LoggerD("address: " << address);
return JSUtil::toJSValueRef(context, address);
}
} catch (const BasePlatformException &err) {
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
void JSCalendarAlarm::initialize(JSContextRef context,
JSContextRef ctx,
const JSObjectRef object);
+ static JSObjectRef constructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
private:
/**
*/
static void finalize(JSObjectRef object);
- /**
- * Constructor for the CalendarAlarm interface.
- */
- static JSObjectRef constructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
static JSValueRef getProperty(JSContextRef context,
JSObjectRef object,
JSStringRef propertyName,
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSValueRef JSCalendarAttendee::getProperty(JSContextRef context,
JSContextRef ctx,
const JSObjectRef object);
+ static JSObjectRef constructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
private:
/**
*/
static void finalize(JSObjectRef object);
- /**
- * Constructor for the CalendarAttendee interface.
- */
- static JSObjectRef constructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
static JSValueRef getProperty(JSContextRef context,
JSObjectRef object,
JSStringRef propertyName,
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //HasInstance,
NULL //ConvertToType
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSObjectRef JSCalendarEvent::createJSCalendarEvent(JSContextRef context, CalendarEventPtr event)
static JSObjectRef createJSCalendarEvent(JSContextRef context, CalendarEventPtr event);
+ static JSObjectRef constructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
private:
/**
* This member variable contains the values which has to be passed when
*/
static void finalize(JSObjectRef object);
- /**
- * Constructor for the CalendarEvent interface.
- */
- static JSObjectRef constructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
/**
* Expand event instances from a recurring event
*/
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSValueRef JSCalendarEventId::getProperty(JSContextRef context,
JSContextRef ctx,
const JSObjectRef object);
+ static JSObjectRef constructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
private:
/**
*/
static void finalize(JSObjectRef object);
- /**
- * Constructor for the CalendarEventId interface.
- */
- static JSObjectRef constructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
static JSValueRef getProperty(JSContextRef context,
JSObjectRef object,
JSStringRef propertyName,
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSValueRef JSCalendarRecurrenceRule::getProperty(JSContextRef context,
JSContextRef ctx,
const JSObjectRef object);
+ static JSObjectRef constructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
private:
/**
*/
static void finalize(JSObjectRef object);
- /**
- * Constructor for the CalendarRecurrenceRule interface.
- */
- static JSObjectRef constructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
static JSValueRef getProperty(JSContextRef context,
JSObjectRef object,
JSStringRef propertyName,
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //HasInstance,
NULL //ConvertToType
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSObjectRef JSCalendarTask::createJSCalendarTask(JSContextRef context, CalendarEventPtr task)
static JSObjectRef createJSCalendarTask(JSContextRef context, CalendarEventPtr task);
+ static JSObjectRef constructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
private:
/**
* This member variable contains the values which has to be passed when
*/
static void finalize(JSObjectRef object);
- /**
- * Constructor for the CalendarTask interface.
- */
- static JSObjectRef constructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
/**
* Getters and setters for properties
*/
#include <GlobalContextManager.h>
#include <Logger.h>
+namespace Options{
+class_definition_options_t CalendarOptions =
+{
+ JS_CLASS,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL,
+ NULL
+};
+
+class_definition_options_t CalendarInterfaceOptions = {
+ JS_INTERFACE,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL, // JSWidget::acquireGlobalContext,
+ NULL,
+ NULL
+};
+}
+
namespace DeviceAPI {
namespace Calendar {
PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
"calendar",
(js_class_template_getter)JSCalendarManager::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ &Options::CalendarOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_INTERFACE_CALENDAR_EVENT,
(js_class_template_getter)JSCalendarEvent::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSCalendarEvent::constructor,
+ &Options::CalendarInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_INTERFACE_CALENDAR_TASK,
(js_class_template_getter)JSCalendarTask::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSCalendarTask::constructor,
+ &Options::CalendarInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_INTERFACE_CALENDAR_ATTENDEE,
(js_class_template_getter)JSCalendarAttendee::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSCalendarAttendee::constructor,
+ &Options::CalendarInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_INTERFACE_CALENDAR_RECURRENCE_RULE,
(js_class_template_getter)JSCalendarRecurrenceRule::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSCalendarRecurrenceRule::constructor,
+ &Options::CalendarInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_INTERFACE_CALENDAR_EVENT_ID,
(js_class_template_getter)JSCalendarEventId::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSCalendarEventId::constructor,
+ &Options::CalendarInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_INTERFACE_CALENDAR_ALARM,
(js_class_template_getter)JSCalendarAlarm::getClassRef,
- NULL)
+ (js_class_constructor_cb_t)JSCalendarAlarm::constructor,
+ &Options::CalendarInterfaceOptions)
PLUGIN_CLASS_MAP_END
}
Try
{
if(!event->getIdIsSet())
- ThrowMsg(InvalidArgumentException, "Invalid contact id");
+ ThrowMsg(InvalidArgumentException, "Invalid");
string contactId = event->getId();
errorCode = contacts_db_get_record(_contacts_contact._uri, contactIdInt, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
- ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ")");
+ ThrowMsg(NotFoundException, "No contact ");
if(!m_isUnifiedAddressBook)
{
int addressBookId = 0;
contacts_record_get_int(contacts_record, _contacts_contact.address_book_id, &addressBookId);
if(addressBookId != m_id)
- ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ") in this address book.");
+ ThrowMsg(NotFoundException, "No contact in this address book.");
}
ContactObjectP2AConverterPtr contactObjConverter(
ThrowMsg(InvalidArgumentException, "No contacts.");
id = ContactUtility::strToInt(contact->getId());
if(id != 0)
- ThrowMsg(InvalidArgumentException, "invalid contact object : Id is already set");
+ ThrowMsg(InvalidArgumentException, "invalid contact object");
}
Catch(InvalidArgumentException)
errorCode = contacts_db_get_record(_contacts_contact._uri, contactId, &get_contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || get_contacts_record == NULL)
- ThrowMsg(PlatformException, "No contact just inserted (id:" << contactId << ")");
+ ThrowMsg(PlatformException, "No contact just inserted");
ContactObjectP2AConverterPtr contactObjConverterForInserted(
new ContactObjectP2AConverter(get_contacts_record, false));
errorCode = contacts_record_set_int(contacts_record, _contacts_contact.address_book_id, m_id);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "Error during add address book id : " << errorCode);
+ ThrowMsg(PlatformException, "Error during add address book : " << errorCode);
}
errorCode = contacts_list_add(contacts_list, contacts_record);
ThrowMsg(InvalidArgumentException, "No contact.");
if(!contact->getIdIsSet() || !contact->getAddressBookIdIsSet())
- ThrowMsg(InvalidArgumentException, "Contact has no ID");
+ ThrowMsg(InvalidArgumentException, "Invalid Contact");
if(!m_isUnifiedAddressBook && contact->getAddressBookId() != getId())
- ThrowMsg(InvalidArgumentException, "Wrong address book ID");
+ ThrowMsg(InvalidArgumentException, "Wrong address book");
}
Catch(InvalidArgumentException)
{
ThrowMsg(InvalidArgumentException, "No contact.");
if(contact->getIdIsSet() == false)
- ThrowMsg(InvalidArgumentException, "Contact has no ID");
+ ThrowMsg(InvalidArgumentException, "Invalid Contact");
if(!m_isUnifiedAddressBook && ( !contact->getAddressBookIdIsSet() || contact->getAddressBookId() != getId()))
- ThrowMsg(InvalidArgumentException, "Wrong address book ID");
+ ThrowMsg(InvalidArgumentException, "Wrong address book");
DPL::SharedPtr<Contact> newContactT =
DPL::StaticPointerCast<Contact>(contact);
contacts_record = newContactT->getPlatformContactObject();
if(contacts_record == NULL)
{
- LoggerD("id : " << contact->getId());
int contactIdInt = ContactUtility::strToInt(contact->getId());
errorCode = contacts_db_get_record(_contacts_contact._uri, contactIdInt, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
- ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ")");
+ ThrowMsg(NotFoundException, "No contact");
}
contactObjConverter = ContactObjectA2PConverterPtr(
new ContactObjectA2PConverter(contact, false, contacts_record) );
string contactIdStr = event->getContactId();
if(!ContactUtility::checkStrIsUInt(contactIdStr))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "Id is wrong" );
int contactId = ContactUtility::strToInt(contactIdStr);
contacts_record_h contacts_record = NULL;
errorCode = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
- ThrowMsg(PlatformException, "No contact id (id:" << contactId << ")");
+ ThrowMsg(PlatformException, "No contact id ");
int addressBookId = 0;
errorCode = contacts_record_get_int(contacts_record, _contacts_simple_contact.address_book_id, &addressBookId);
ThrowMsg(PlatformException, "Error while getting address book id");
if(addressBookId != m_id)
- ThrowMsg(PlatformException, "Contact id (" << contactId << ") is not a member of this address book.");
+ ThrowMsg(PlatformException, "Contact is not a member of this address book.");
}
errorCode = contacts_db_delete_record(_contacts_contact._uri, contactId);
contactIds = event->getContactIds();
if(!contactIds)
- ThrowMsg(InvalidArgumentException, "No contact IDs.");
+ ThrowMsg(InvalidArgumentException, "Invalid contacts");
}
Catch(InvalidArgumentException)
int contactId;
if(!ContactUtility::checkStrIsUInt(contactIdStr))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "Wrong" );
contactId = ContactUtility::strToInt(contactIdStr);
contacts_record_h contacts_record = NULL;
errorCode = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
- ThrowMsg(PlatformException, "No contact id (id:" << contactId << ")");
+ ThrowMsg(PlatformException, "No contact");
int addressBookId = 0;
errorCode = contacts_record_get_int(contacts_record, _contacts_simple_contact.address_book_id, &addressBookId);
ThrowMsg(PlatformException, "Error while getting address book id");
if(addressBookId != m_id)
- ThrowMsg(PlatformException, "Contact id (" << contactId << ") is not a member of this address book.");
+ ThrowMsg(PlatformException, "Contact is not a member of this address book.");
}
ids[count] = contactId;
long id = event->getId();
if(m_watchIdMap.find(id) == m_watchIdMap.end())
- ThrowMsg(NotFoundException, "No watchId : " << id);
+ ThrowMsg(NotFoundException, "No watchId 1: ");
bool success = m_addressBookEmitters.detach(m_watchIdMap[id]);
if(!success)
- ThrowMsg(NotFoundException, "No watchId : " << id);
+ ThrowMsg(NotFoundException, "No watchId 2 ");
m_watchIdMap.erase(id);
Try
{
if(!event->getIdIsSet())
- ThrowMsg(InvalidArgumentException, "Invalid group id");
+ ThrowMsg(InvalidArgumentException, "Invalid group");
string groupId = event->getId();
errorCode = contacts_db_get_record(_contacts_group._uri, groupIdInt, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
- ThrowMsg(NotFoundException, "No group (id:" << groupIdInt << ")");
+ ThrowMsg(NotFoundException, "No group");
if(!m_isUnifiedAddressBook)
{
int addressBookId = 0;
contacts_record_get_int(contacts_record, _contacts_group.address_book_id, &addressBookId);
if(addressBookId != m_id)
- ThrowMsg(NotFoundException, "No group (id:" << groupIdInt << ") in this address book.");
+ ThrowMsg(NotFoundException, "No group in this address book.");
}
ContactGroupPtr group = ContactGroupPtr(new ContactGroup());
ThrowMsg(InvalidArgumentException, "Contact Group is wrong");
if(!m_isUnifiedAddressBook && group->getAddressBookId() != getId())
- ThrowMsg(InvalidArgumentException, "Wrong address book ID");
+ ThrowMsg(InvalidArgumentException, "Wrong address book");
}
Catch(InvalidArgumentException)
{
Try
{
int id = ContactUtility::strToInt(group->getId());
- LoggerD("Load platform object id : " << id);
errorCode = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
ThrowMsg(NotFoundException, "Error during executing contacts_db_get_record()");
ThrowMsg(PlatformException, "Error during executing contacts_db_get_record()");
}
- LoggerD("Update group : " << id);
ContactsSvcObjectConverter::convertToPlatform(group, contacts_record);
errorCode = contacts_db_update_record(contacts_record);
string groupIdStr = event->getContactGroupId();
if(!ContactUtility::checkStrIsUInt(groupIdStr))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << groupIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "wrong" );
int groupId = ContactUtility::strToInt(groupIdStr);
contacts_record_h contacts_record = NULL;
errorCode = contacts_db_get_record(_contacts_group._uri, groupId, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
- ThrowMsg(PlatformException, "No group id (id:" << groupId << ")");
+ ThrowMsg(PlatformException, "No group");
int addressBookId = 0;
errorCode = contacts_record_get_int(contacts_record, _contacts_group.address_book_id, &addressBookId);
if(errorCode != CONTACTS_ERROR_NONE)
- ThrowMsg(PlatformException, "Error while getting address book id");
+ ThrowMsg(PlatformException, "Error while getting address book");
if(addressBookId != m_id)
- ThrowMsg(PlatformException, "Contact id (" << groupId << ") is not a member of this address book.");
+ ThrowMsg(PlatformException, "Contact is not a member of this address book.");
}
errorCode = contacts_db_delete_record(_contacts_group._uri, groupId);
{
int errorCode = 0;
int contactId = ids[i];
- LoggerD("contact id : " << contactId);
contacts_record_h contacts_record = NULL;
ContactConverter.cpp
ContactManagerController.cpp
JSContact.cpp
- JSContactArray.cpp
JSAddressBook.cpp
JSAddressBookChangeCallbackManager.cpp
- JSAddressBookArray.cpp
JSContactGroup.cpp
- JSContactGroupArray.cpp
JSPerson.cpp
- JSPersonArray.cpp
JSContactRef.cpp
JSContactName.cpp
JSContactAnniversary.cpp
- JSContactAnniversaryArray.cpp
- #JSAttributesOfInterestArray.cpp
JSContactAddress.cpp
- JSContactAddressArray.cpp
- JSContactAddressTypeArray.cpp
JSContactManager.cpp
JSContactManagerChangeCallbackManager.cpp
JSContactPhoneNumber.cpp
- JSContactPhoneNumberArray.cpp
- JSContactPhoneNumberTypeArray.cpp
JSContactEmailAddress.cpp
- JSContactEmailAddressArray.cpp
- JSContactEmailAddressTypeArray.cpp
JSContactOrganization.cpp
- JSContactOrganizationArray.cpp
- JSStringArray.cpp
JSContactWebSite.cpp
- JSContactWebSiteArray.cpp
)
ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
#include "ContactFactory.h"
#include "AddressBookController.h"
#include "JSAddressBook.h"
-#include "JSAddressBookArray.h"
#include "JSContact.h"
-#include "JSContactArray.h"
#include "JSPerson.h"
-#include "JSPersonArray.h"
#include "JSContactGroup.h"
-#include "JSContactGroupArray.h"
#include "JSContactRef.h"
#include "JSContactName.h"
#include "JSContactAnniversary.h"
-#include "JSContactAnniversaryArray.h"
#include "JSContactAddress.h"
-#include "JSContactAddressArray.h"
-#include "JSContactAddressTypeArray.h"
#include "JSContactManager.h"
#include "JSContactPhoneNumber.h"
-#include "JSContactPhoneNumberArray.h"
-#include "JSContactPhoneNumberTypeArray.h"
#include "JSContactEmailAddress.h"
-#include "JSContactEmailAddressArray.h"
-#include "JSContactEmailAddressTypeArray.h"
#include "JSContactOrganization.h"
-#include "JSContactOrganizationArray.h"
#include "JSContactWebSite.h"
-#include "JSContactWebSiteArray.h"
-#include "JSStringArray.h"
#include <Logger.h>
#define CONTACT_ATTRIBUTE_ACCOUNT_ID "accountId"
AddressBookArrayPtr ContactConverter::toAddressBookArray(const JSValueRef &jsValue)
{
- if(JSAddressBookArray::isObjectOfClass(m_context, jsValue))
- return JSAddressBookArray::getAddressBookArray(m_context, jsValue);
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "AddressBookArray is not array.");
if (!validator.isNullOrUndefined(birthdayData)) {
if(!validator.isDate(birthdayData))
- ThrowMsg(WrtDeviceApis::Commons::ConversionException, "birthday is not Date");
+ ThrowMsg(WrtDeviceApis::Commons::ConversionException, "invalid birthday");
birthday = toDateTm(birthdayData);
result->setBirthday(birthday);
}
if (!validator.isNullOrUndefined(ringtoneURIData)) {
if(!JSValueIsString(m_context, ringtoneURIData))
- ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ringtoneURI is not string");
+ ThrowMsg(WrtDeviceApis::Commons::ConversionException, "invalid ringtoneURI");
ringtoneURI = toString(ringtoneURIData);
result->setRingtoneURI(ringtoneURI);
}
ContactArrayPtr ContactConverter::toContactArray(const JSValueRef &jsValue)
{
-// // toJSValueRef(ContactArrayPtr) creates user object.
-// if(JSContactArray::isObjectOfClass(m_context, jsValue))
-// return JSContactArray::getContactArray(m_context, jsValue);
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactArray is not array.");
PersonArrayPtr ContactConverter::toPersonArray(const JSValueRef &jsValue)
{
- if(JSPersonArray::isObjectOfClass(m_context, jsValue))
- return JSPersonArray::getPersonArray(m_context, jsValue);
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "PersonArray is not array.");
ContactOrganizationArrayPtr ContactConverter::toContactOrganizationArray(const JSValueRef &jsValue)
{
- if(JSContactOrganizationArray::isObjectOfClass(m_context, jsValue))
- return JSContactOrganizationArray::getContactOrganizationArray(m_context, jsValue);
-
- ContactOrganizationArrayPtr result(new ContactOrganizationArray());
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactOrganizationArray is not array.");
+ ContactOrganizationArrayPtr result(new ContactOrganizationArray());
+
JSObjectRef jsObject = toJSObjectRef(jsValue);
for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
ContactWebSiteArrayPtr ContactConverter::toContactWebSiteArray(const JSValueRef &jsValue)
{
- if(JSContactWebSiteArray::isObjectOfClass(m_context, jsValue))
- return JSContactWebSiteArray::getContactWebSiteArray(m_context, jsValue);
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactWebSiteArray is not array.");
ContactAddressArrayPtr ContactConverter::toContactAddressArray(const JSValueRef &jsValue)
{
- if(JSContactAddressArray::isObjectOfClass(m_context, jsValue))
- return JSContactAddressArray::getContactAddressArray(m_context, jsValue);
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAddressArray is not array.");
StringArrayPtr ContactConverter::toStringArray(const JSValueRef &jsValue)
{
- if(JSStringArray::isObjectOfClass(m_context, jsValue))
- return JSStringArray::getStringArray(m_context, jsValue);
-
if(!JSIsArrayValue(m_context, jsValue))
ThrowMsg(WrtDeviceApis::Commons::ConversionException, "StringArray is not array.");
return static_cast<JSValueRef>(resultObject);
}
-//std::string ContactConverter::toAttributesOfInterest(const JSValueRef &value)
-//{
-// // need validator
-// return toString(value);
-//}
-
-//JSValueRef ContactConverter::toJSValueRefAttributesOfInterestArray(const AttributesOfInterestArrayPtr &arg)
-//{
-// return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributesOfInterestArray::getClassRef(), arg);
-//}
-
-//AttributesOfInterestArrayPtr ContactConverter::toAttributesOfInterestArray(const JSValueRef &jsValue)
-//{
-// if(JSAttributesOfInterestArray::isObjectOfClass(m_context, jsValue))
-// return JSAttributesOfInterestArray::getAttributesOfInterestArray(m_context, jsValue);
-//
-// if(!JSIsArrayValue(m_context, jsValue))
-// ThrowMsg(WrtDeviceApis::Commons::ConversionException, "AttributesOfInterestArray is not array.");
-//
-// AttributesOfInterestArrayPtr result(new AttributesOfInterestArray());
-//
-// JSObjectRef jsObject = toJSObjectRef(jsValue);
-// for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
-// JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
-// result->push_back(toAttributesOfInterest(element));
-// }
-// return result;
-//}
-
bool ContactConverter::initializeAllowedProperties()
{
m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_NAME);
if(addressBookId.empty())
{
//when database is not opened then set result as failed
- ThrowMsg(NotFoundException, "Address book id is empty");
+ ThrowMsg(NotFoundException, "invalid Address book");
}
AddressBookPtr addressBook =
Try {
if(!event->getIdIsSet())
- ThrowMsg(InvalidArgumentException, "Invalid person id");
+ ThrowMsg(InvalidArgumentException, "Invalid person");
string personId = event->getId();
errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(NotFoundException, "No person (id:" << personIdInt << ") : " << errorCode);
+ ThrowMsg(NotFoundException, "No person : " << errorCode);
}
PersonPtr person = PersonPtr(new Person());
Try
{
int id = ContactUtility::strToInt(person->getId());
- LoggerD("Load platform object id : " << id);
errorCode = contacts_db_get_record(_contacts_person._uri, id, &contacts_record);
if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
ThrowMsg(NotFoundException, "Error during executing contacts_db_get_record()");
Try
{
- LoggerD("id : " << person->getId());
int personIdInt = ContactUtility::strToInt(person->getId());
errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(NotFoundException, "No person (id:" << personIdInt << ")");
+ ThrowMsg(NotFoundException, "No person");
}
ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
Try
{
bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
- LoggerD("isEmpty : " << isEmpty);
if(isEmpty){
managerUpdateBatch(event);
}else{
string personIdStr = event->getPersonId();
if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "invalid" );
try {
istringstream iss(personIdStr);
iss >> personId;
} catch (...) {
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "wrong" );
}
int errorCode = contacts_db_delete_record(_contacts_person._uri, personId);
}
Catch (InvalidArgumentException)
{
- LoggerE("Invalid person id : " << _rethrown_exception.GetMessage());
+ LoggerE("Invalid person : " << _rethrown_exception.GetMessage());
event->setResult(false);
event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
return;
personIds = event->getPersonIds();
if(!personIds)
- ThrowMsg(InvalidArgumentException, "No person IDs.");
+ ThrowMsg(InvalidArgumentException, "No person.");
}
Catch(InvalidArgumentException)
int personId;
if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "invalid" );
try
{
}
catch (...)
{
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "wrong" );
}
ids[count] = personId;
Try
{
bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
- LoggerD("isEmpty : " << isEmpty);
if(isEmpty){
managerRemoveBatch(event);
}else{
long id = event->getId();
if(m_watchIdMap.find(id) == m_watchIdMap.end())
- ThrowMsg(NotFoundException, "No watchId : " << id);
+ ThrowMsg(NotFoundException, "No watchId 1 ");
//DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
bool success = m_contactManagerEmitters.detach(m_watchIdMap[id]);
if(!success)
- ThrowMsg(NotFoundException, "No watchId : " << id);
+ ThrowMsg(NotFoundException, "No watchId 2 ");
m_watchIdMap.erase(id);
if(m_abstractContact->getIdIsSet() && (m_forScratch == false))
{
int id = ContactUtility::strToInt(m_abstractContact->getId());
- LoggerD("Load platform object id : " << id);
errorCode = contacts_db_get_record(_contacts_contact._uri, id, &m_platformContact);
if(errorCode != CONTACTS_ERROR_NONE)
ThrowMsg(UnknownException, "error on contacts_db_get_record (errorCode:" << errorCode << ")");
m_platformContactOwnership = true;
}
- LoggerD("for scratch : " << m_forScratch);
-
Try
{
if(m_convertFinished == false)
errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.image, 0, &child_record);
if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
{
- LoggerD("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
errorCode = contacts_record_create(_contacts_image._uri, &child_record);
if(errorCode != CONTACTS_ERROR_NONE)
ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
if(newValueStr != NULL)
{
- LoggerD("image : " << newValueStr);
errorCode = contacts_record_set_str(child_record, _contacts_image.path, newValueStr);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing photoURI E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing photoURI E (err:" << errorCode);
}
}
contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
errorCode = contacts_record_set_str(m_platformContact, _contacts_contact.ringtone_path, newValueStr);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing ringtoneURI E (err:" << errorCode);
}
}
}
errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
{
- LoggerD("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
errorCode = contacts_record_create(_contacts_name._uri, &child_record);
if(errorCode != CONTACTS_ERROR_NONE)
ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing firstName E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing firstName E (err:" << errorCode);
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing lastName E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing lastName E (err:" << errorCode);
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing middleName E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing middleName E (err:" << errorCode);
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing prefix E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing prefix E (err:" << errorCode);
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing suffix E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing suffix E (err:" << errorCode);
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" << errorCode);
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing phoneticLastName E (err:" <<
- errorCode << ", str:" << newValueStr << ")");
+ ThrowMsg(PlatformException, "importing phoneticLastName E (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing firstName N (err:" <<
- errorCode << ", str:" << firstName << ")");
+ ThrowMsg(PlatformException, "importing firstName N (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing lastName N (err:" <<
- errorCode << ", str:" << lastName << ")");
+ ThrowMsg(PlatformException, "importing lastName N (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing middleName N (err:" <<
- errorCode << ", str:" << middleName << ")");
+ ThrowMsg(PlatformException, "importing middleName N (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing prefix N (err:" <<
- errorCode << ", str:" << prefix << ")");
+ ThrowMsg(PlatformException, "importing prefix N (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing suffix N (err:" <<
- errorCode << ", str:" << suffix << ")");
+ ThrowMsg(PlatformException, "importing suffix N (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" <<
- errorCode << ", str:" << phoneticFirstName << ")");
+ ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" << errorCode);
}
}
}
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(child_record, true);
- ThrowMsg(PlatformException, "importing phoneticLastName N (err:" <<
- errorCode << ", str:" << phoneticLastName << ")");
+ ThrowMsg(PlatformException, "importing phoneticLastName N (err:" << errorCode);
}
}
}
errorCode = contacts_record_set_str(child_record, _contacts_company.name, name.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing company name N (err:" << errorCode << ", str:" << name << ")");
+ LoggerW("importing company name N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_company.department, department.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing department N (err:" << errorCode << ", str:" << department << ")");
+ LoggerW("importing department N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_company.job_title, title.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing title N (err:" << errorCode << ", str:" << title << ")");
+ LoggerW("importing title N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_company.role, role.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing role N (err:" << errorCode << ", str:" << role << ")");
+ LoggerW("importing role N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_company.logo, logoURI.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing logoURI N (err:" << errorCode << ", str:" << logoURI << ")");
+ LoggerW("importing logoURI N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_note.note, note.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing note N (err:" << errorCode << ", str:" << note << ")");
+ LoggerW("importing note N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_number.number, number.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set number value to child_record number : " << number);
+ LoggerW("Fail to set number value to child_record number");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_bool(child_record, _contacts_number.is_default, ctsBoolDefault);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set number value to child_record default : " << ctsBoolDefault);
+ LoggerW("Fail to set number value to child_record default ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_int(child_record, _contacts_number.type, ctsIntType);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set number value to child_record type : " << ctsIntType);
+ LoggerW("Fail to set number value to child_record type ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_email.email, emailAddress.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set email value to child_record email : " << emailAddress);
+ LoggerW("Fail to set email value to child_record email ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_bool(child_record, _contacts_email.is_default, ctsBoolDefault);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set email value to child_record default : " << ctsBoolDefault);
+ LoggerW("Fail to set email value to child_record default ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_int(child_record, _contacts_email.type, ctsIntType);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set email value to child_record type : " << ctsIntType);
+ LoggerW("Fail to set email value to child_record type ");
contacts_record_destroy(child_record, true);
continue;
}
child_record = NULL;
if(!ContactUtility::checkStrIsUInt(groupId))
- {
- LoggerW("groupId (" << groupId << ") is wrong.");
continue;
- }
int groupIdInt = ContactUtility::strToInt(groupId);
errorCode = contacts_record_set_int(child_record, _contacts_group_relation.group_id, groupIdInt);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing group id N (err:" << errorCode << ", str:" << groupIdInt << ")");
+ LoggerW("importing group id N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_int(child_record, _contacts_group_relation.contact_id, contactId);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("importing group contact_id N (err:" << errorCode << ", str:" << contactId << ")");
+ LoggerW("importing group contact_id N (err:" << errorCode);
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set event value to child_record type : " << CONTACTS_EVENT_TYPE_BIRTH);
+ LoggerW("Fail to set event value to child_record type, birthday");
contacts_record_destroy(child_record, true);
return;
}
errorCode = contacts_record_set_int(child_record, _contacts_event.date, birthday);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set event value to child_record date : " << birthday);
+ LoggerW("Fail to set event value to child_record date");
contacts_record_destroy(child_record, true);
return;
}
errorCode = contacts_record_set_int(child_record, _contacts_event.date, date);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set event value to child_record date : " << date);
+ LoggerW("Fail to set event value to child_record date");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_event.label, label.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set label value to child_record label : " << label);
+ LoggerW("Fail to set label value to child_record label");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_address.country, country.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set country value to child_record str : " << country);
+ LoggerW("Fail to set country value to child_record str country ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_address.region, region.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set region value to child_record str : " << region);
+ LoggerW("Fail to set region value to child_record str region ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_address.locality, city.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set locality value to child_record str : " << city);
+ LoggerW("Fail to set locality value to child_record str locality ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_address.street, streetAddress.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set street value to child_record str : " << streetAddress);
+ LoggerW("Fail to set street value to child_record str streetAddress ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_address.extended, additionalInformation.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set extended value to child_record str : " << additionalInformation);
+ LoggerW("Fail to set extended value to child_record str additionalInformation ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_address.postal_code, postalCode.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set postal_code value to child_record str : " << postalCode);
+ LoggerW("Fail to set postal_code value to child_record str postalCode ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_bool(child_record, _contacts_address.is_default, ctsBoolDefault);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set favorite value to child_record default : " << ctsBoolDefault);
+ LoggerW("Fail to set favorite value to child_record default ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_int(child_record, _contacts_address.type, ctsIntType);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set default value to child_record type : " << ctsIntType);
+ LoggerW("Fail to set default value to child_record type ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_url.url, url.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set url value to child_record str : " << url);
+ LoggerW("Fail to set url value to child_record str url");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_int(child_record, _contacts_url.type, ctsIntType);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set default value to child_record type : " << ctsIntType);
+ LoggerW("Fail to set default value to child_record type ");
contacts_record_destroy(child_record, true);
continue;
}
errorCode = contacts_record_set_str(child_record, _contacts_nickname.name, nickname.c_str());
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerW("Fail to set nickname value to ctsValue str : " << nickname);
+ LoggerW("Fail to set nickname value to ctsValue str nickname ");
contacts_record_destroy(child_record, true);
continue;
}
bool ContactQueueManager::empty()
{
- LoggerD("count : " << count);
-
if(count > 0)
return false;
else
}
mapIndex++;
- LoggerD("mapIndex : " << mapIndex);
m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
}
}
mapIndex++;
- LoggerD("mapIndex : " << mapIndex);
m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
}
}
mapIndex++;
- LoggerD("mapIndex : " << mapIndex);
m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
}
}
mapIndex++;
- LoggerD("mapIndex : " << mapIndex);
m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
}
}
mapIndex++;
- LoggerD("mapIndex : " << mapIndex);
m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
}
ContactArrayPtr contacts(new ContactArray());
contacts_list_h list = NULL;
- LoggerD("start : " << m_isAddressBookIdSet);
-
if(!m_isAddressBookIdSet)
{
errorCode = contacts_db_get_all_records(_contacts_contact._uri, 0, 0, &list);
errorCode = contacts_list_get_count(list, &record_count);
if(errorCode != CONTACTS_ERROR_NONE)
ThrowMsg(PlatformException, "Fail to get contacts_list_get_count : " << errorCode << " (" << __FUNCTION__ << ")");
+ LoggerD("END: pure contact-svc");
contacts_list_first(list);
for(unsigned int i=0; i<record_count; i++)
if(list != NULL)
contacts_list_destroy(list, true);
- LoggerD("end");
+ LoggerD("END: convertToPlugin Objects");
return contacts;
}
errorCode = contacts_db_get_record(_contacts_contact._uri, id, &record);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerE("No contact (id:" << id << ") : " << errorCode << " (" << __FUNCTION__ << ")");
+ LoggerE("No contact 1 : " << errorCode << " (" << __FUNCTION__ << ")");
return ContactPtr(NULL);
}
errorCode = contacts_record_get_int(record, _contacts_contact.address_book_id, &addressBookId);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerE("No contact (id:" << id << ") 2 : " << errorCode << " (" << __FUNCTION__ << ")");
+ LoggerE("No contact 2 : " << errorCode << " (" << __FUNCTION__ << ")");
return ContactPtr(NULL);
}
LoggerD("end");
}
+#if 0
+void ContactSearchEngine::sortContacts(AttributeProperties& attributeProperties, ContactIdArrayPtr& result,
+ bool is_ascending, ContactIdSetPtr& idSet)
+{
+ const char* view_uri = attributeProperties.viewUri;
+ unsigned int property_contact_id = attributeProperties.propertyContactId;
+ unsigned int property_id = attributeProperties.propertyId;
+
+ LogDebug("entered");
+
+ int errorCode = 0;
+ contacts_query_h query = NULL;
+ contacts_list_h list = NULL;
+
+ errorCode = contacts_query_create(view_uri, &query);
+ if(errorCode != CONTACTS_ERROR_NONE)
+ ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+ errorCode = contacts_query_set_sort(query, property_id, is_ascending);
+ if(errorCode != CONTACTS_ERROR_NONE)
+ ThrowMsg(PlatformException, "contacts_query_set_sort error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+ errorCode = contacts_db_get_records_with_query(query, 0, 0, &list);
+ if(errorCode != CONTACTS_ERROR_NONE)
+ ThrowMsg(PlatformException, "contacts_db_get_records_with_query error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+ unsigned int record_count = 0;
+ errorCode = contacts_list_get_count(list, &record_count);
+ if(errorCode != CONTACTS_ERROR_NONE)
+ ThrowMsg(PlatformException, "contacts_list_get_count error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+ std::set<int>::iterator it;
+
+ contacts_list_first(list);
+ for(unsigned int i=0; i<record_count; i++)
+ {
+ contacts_record_h record;
+ errorCode = contacts_list_get_current_record_p(list, &record);
+ if(errorCode != CONTACTS_ERROR_NONE)
+ ThrowMsg(PlatformException, "contacts_list_get_current_record_p error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+ int value = 0;
+ errorCode = contacts_record_get_int(record, property_contact_id, &value);
+ if(errorCode != CONTACTS_ERROR_NONE)
+ ThrowMsg(PlatformException, "contacts_record_get_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+ it = idSet->find(value);
+ if(it != idSet->end())
+ result->push_back(value);
+
+ contacts_list_next(list);
+ }
+
+ if(list != NULL)
+ contacts_list_destroy(list, true);
+
+ if(query != NULL)
+ contacts_query_destroy(query);
+
+ LogDebug("end");
+}
+#endif
+
void ContactSearchEngine::sortContacts(AttributeProperties& attributeProperties, ContactIdArrayPtr& result,
bool is_ascending, ContactIdSetPtr& idSet)
{
m_latestVersion, &change_record_list, &latestVersion);
if(errorCode != CONTACTS_ERROR_NONE)
{
- LoggerD("Fail to get the updated contacts for addressbook : " << addressBookId << ", errorCode : " << errorCode);
+ LoggerD("Fail to get the updated contacts for addressbook, errorCode : " << errorCode);
if(change_record_list != NULL)
contacts_list_destroy(change_record_list, true);
}else{
if(record_count == 0)
{
- LoggerD("No updated contacts for address book : " << addressBookId);
+ LoggerD("No updated contacts");
continue;
}
void ContactsSvcChangeListenerManager::personsChangedCallback(char* changes)
{
- LoggerD("entered : " << changes);
if(!m_personsChangedCallbackRegistered)
return;
errorCode = contacts_record_set_bool(record, _contacts_person.is_favorite, boolValue);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing isFavorite E (err:" <<
- errorCode << ", value:" << boolValue << ")");
+ ThrowMsg(PlatformException, "importing isFavorite E (err:" << errorCode);
}
const char *newValueStr = NULL;
if(newValueStr != NULL)
{
- LoggerD("update photoURI : " << newValueStr);
int personId = ContactUtility::strToInt(person->getId());
contacts_filter_h filter = NULL;
contacts_record_get_int(record, _contacts_simple_contact.id, &id);
contacts_record_get_str_p(record, _contacts_simple_contact.image_thumbnail_path, &charValue);
- LoggerD("id : " << id);
- LoggerD("charValue : " << charValue);
/*
if((charValue == NULL) && g_strcmp0(newValueStr, EMPTY_STRING) == 0){
is_success = true;
query = NULL;
list = NULL;
- LoggerD("targetId : " << targetId);
-
errorCode = contacts_query_create(_contacts_image._uri, &query);
if(errorCode != CONTACTS_ERROR_NONE)
ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
errorCode = contacts_person_set_default_property(CONTACTS_PERSON_PROPERTY_IMAGE, personId, imageId);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing photoURI E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing photoURI E (err:" << errorCode);
}
}
}
errorCode = contacts_record_set_str(record, _contacts_person.ringtone_path, newValueStr);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing ringtoneURI E (err:" << errorCode);
}
}
errorCode = contacts_record_set_str(record, _contacts_group.name, newValueStr);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing name E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing name E (err:" << errorCode);
}
}
errorCode = contacts_record_set_str(record, _contacts_group.image_path, newValueStr);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing photoURI E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing photoURI E (err:" << errorCode);
}
}
errorCode = contacts_record_set_str(record, _contacts_group.ringtone_path, newValueStr);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
- errorCode << ", str:" << abstractValueStr << ")");
+ ThrowMsg(PlatformException, "importing ringtoneURI E (err:" << errorCode);
}
}
}
}
if(m_idMap.find(id) == m_idMap.end())
- ThrowMsg(NotFoundException, "No AddressBook id:" << id);
+ ThrowMsg(NotFoundException, "No AddressBook1 ");
int index = m_idMap[id];
if(static_cast<int>(m_addressBooks->size()) <= index)
- ThrowMsg(NotFoundException, "No AddressBook id:" << id);
+ ThrowMsg(NotFoundException, "No AddressBook2 ");
return m_addressBooks->at(index);
}
continue;
}
- LoggerD(" AddressBook [id:" << id << ", name:" << name <<
- ", accId:" << accountId << ", mode:" << mode << "]");
+ LoggerD(" AddressBook");
AddressBook *addressBook = new AddressBook(false);
addressBook->setId(id);
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSAddressBookArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSAddressBookArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSAddressBookArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSAddressBookArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSAddressBookArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSAddressBookArray::m_jsClassRef = JSClassCreate(
- JSAddressBookArray::getClassInfo());
-
-JSValueRef JSAddressBookArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AddressBookArrayPtr addressBooks = priv->getObject();
- if (addressBooks) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(addressBooks->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSAddressBookArray::createArray(JSContextRef context,
- const AddressBookArrayPtr &addressBooks)
-{
- JSAddressBookArrayPriv *priv = new JSAddressBookArrayPriv(context, addressBooks);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSAddressBookArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-bool JSAddressBookArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-AddressBookArrayPtr JSAddressBookArray::getAddressBookArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSAddressBookArrayPriv *priv = static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-JSClassRef JSAddressBookArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSAddressBookArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSAddressBookArray::finalize(JSObjectRef object)
-{
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSAddressBookArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AddressBookArrayPtr addressBooks = priv->getObject();
- if (index < addressBooks->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSAddressBookArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AddressBookArrayPtr addressBooks = priv->getObject();
- if (index < addressBooks->size()) {
- AddressBookPtr result = addressBooks->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSAddressBookArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- AddressBookPtr addressBook(NULL);
- if (!JSValueIsUndefined(context, value)) {
- addressBook = converter->toAddressBook(value);
- }
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AddressBookArrayPtr addressBooks = priv->getObject();
- if (!addressBooks) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (addressBooks->size() <= index) {
- addressBooks->resize(index + 1);
- }
- (*addressBooks)[index] = addressBook;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSAddressBookArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- AddressBookPtr addressBook(NULL);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AddressBookArrayPtr addressBooks = priv->getObject();
- if (!addressBooks) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (addressBooks->size() > index) {
- (*addressBooks)[index] = addressBook;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSAddressBookArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AddressBookArrayPtr addressBooks = priv->getObject();
-
- int count = addressBooks->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSAddressBookArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- AddressBookArrayPtr addressBooks = AddressBookArrayPtr(new AddressBookArray());
- JSAddressBookArrayPriv *newPrivateObject = new JSAddressBookArrayPriv(context, addressBooks);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current addressBooks
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- for (size_t i = 0; i < currentAddressBooks->size(); ++i) {
- addressBooks->push_back(currentAddressBooks->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- addressBooks->push_back(converter->toAddressBook(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAddressBookArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentAddressBooks->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentAddressBooks->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAddressBookArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- if (currentAddressBooks->size() > 0) {
- AddressBookPtr result = currentAddressBooks->at(
- currentAddressBooks->size() - 1);
- currentAddressBooks->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAddressBookArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentAddressBooks->push_back(converter->toAddressBook(arguments[i]));
- }
- return converter->toJSValueRef(currentAddressBooks->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAddressBookArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- std::reverse(currentAddressBooks->begin(), currentAddressBooks->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAddressBookArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- if (currentAddressBooks->size() > 0) {
- AddressBookPtr result = currentAddressBooks->at(0);
- currentAddressBooks->erase(currentAddressBooks->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAddressBookArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- AddressBookArrayPtr addressBooks = AddressBookArrayPtr(new AddressBookArray());
- JSAddressBookArrayPriv *newPrivateObject = new JSAddressBookArrayPriv(
- context,
- addressBooks);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current addressBooks
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentAddressBooks->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentAddressBooks->size()) {
- last = currentAddressBooks->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- addressBooks->push_back(currentAddressBooks->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAddressBookArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAddressBookArrayPriv* priv =
- static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
- AddressBookArrayPtr currentAddressBooks = priv->getObject();
- std::sort(currentAddressBooks->begin(), currentAddressBooks->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAddressBookArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAddressBookArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSAddressBookArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAddressBookArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSAddressBookArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_ADDRESS_BOOK_ARRAY_H_
-#define _TIZEN_CONTACT_JS_ADDRESS_BOOK_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "IAddressBook.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<AddressBookArrayPtr>::Type JSAddressBookArrayPriv;
-
-class JSAddressBookArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const AddressBookArrayPtr &anniversaries);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static AddressBookArrayPtr getAddressBookArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_ADDRESS_BOOK_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSAttributesOfInterestArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSAttributesOfInterestArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSAttributesOfInterestArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- NULL, //deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSAttributesOfInterestArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSAttributesOfInterestArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSAttributesOfInterestArray::m_jsClassRef = JSClassCreate(
- JSAttributesOfInterestArray::getClassInfo());
-
-JSValueRef JSAttributesOfInterestArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- //LoggerD("enter");
- Try
- {
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AttributesOfInterestArrayPtr typeArray = priv->getObject();
- if (typeArray) {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- return converter->toJSValueRef(typeArray->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSAttributesOfInterestArray::createArray(JSContextRef context,
- const AttributesOfInterestArrayPtr &typeArray)
-{
- JSAttributesOfInterestArrayPriv *priv = new JSAttributesOfInterestArrayPriv(context, typeArray);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSAttributesOfInterestArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSAttributesOfInterestArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSAttributesOfInterestArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-AttributesOfInterestArrayPtr JSAttributesOfInterestArray::getAttributesOfInterestArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSAttributesOfInterestArrayPriv *priv = static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSAttributesOfInterestArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
- //LoggerD("enter");
-}
-
-void JSAttributesOfInterestArray::finalize(JSObjectRef object)
-{
- //LoggerD("enter");
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSAttributesOfInterestArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- //LoggerD("enter");
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AttributesOfInterestArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSAttributesOfInterestArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- //LoggerD("enter");
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AttributesOfInterestArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- std::string result = typeArray->at(index);
- if (!result.empty()) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSAttributesOfInterestArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- //LoggerD("enter");
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- std::string str;
- if (!JSValueIsUndefined(context, value)) {
- str = converter->toString(value);
- }
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AttributesOfInterestArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (typeArray->size() <= index) {
- typeArray->resize(index + 1);
- }
- (*typeArray)[index] = str;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSAttributesOfInterestArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- AttributesOfInterestArrayPtr interests = priv->getObject();
-
- int count = interests->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSAttributesOfInterestArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("enter");
- Try
- {
- AttributesOfInterestArrayPtr typeArray =
- AttributesOfInterestArrayPtr(new AttributesOfInterestArray());
- JSAttributesOfInterestArrayPriv *newPrivateObject =
- new JSAttributesOfInterestArrayPriv(context, typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- typeArray->push_back(currentStrings->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- typeArray->push_back(converter->toString(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAttributesOfInterestArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- Try
- {
- std::string result;
- std::string separator(",");
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- result += currentStrings->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAttributesOfInterestArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = currentStrings->at(
- currentStrings->size() - 1);
- currentStrings->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAttributesOfInterestArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentStrings->push_back(converter->toString(arguments[i]));
- }
- return converter->toJSValueRef(currentStrings->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAttributesOfInterestArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- std::reverse(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAttributesOfInterestArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = currentStrings->at(0);
- currentStrings->erase(currentStrings->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAttributesOfInterestArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("enter");
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- AttributesOfInterestArrayPtr typeArray = AttributesOfInterestArrayPtr(new StringArray());
- JSAttributesOfInterestArrayPriv *newPrivateObject = new JSAttributesOfInterestArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentStrings->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentStrings->size()) {
- last = currentStrings->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- typeArray->push_back(currentStrings->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSAttributesOfInterestArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSAttributesOfInterestArrayPriv* priv =
- static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
- AttributesOfInterestArrayPtr currentStrings = priv->getObject();
- std::sort(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAttributesOfInterestArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAttributesOfInterestArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSAttributesOfInterestArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSAttributesOfInterestArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- //LoggerD("entered");
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSAttributesOfInterestArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_ATTRIBUTES_OF_INTEREST_ARRAY_H_
-#define _TIZEN_CONTACT_JS_ATTRIBUTES_OF_INTEREST_ARRAY_H_
-
-#include <vector>
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<AttributesOfInterestArrayPtr>::Type JSAttributesOfInterestArrayPriv;
-
-class JSAttributesOfInterestArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const AttributesOfInterestArrayPtr &Strings);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static AttributesOfInterestArrayPtr getAttributesOfInterestArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_ATTRIBUTES_OF_INTEREST_ARRAY_H_
#include <JSTizenException.h>
#include "ContactConverter.h"
#include "JSContactAddress.h"
-#include "JSContactAddressTypeArray.h"
#include <Logger.h>
#define CONTACT_CLASS_NAME "ContactAddress"
#include <CommonsJavaScript/PrivateObject.h>
#include <Commons/IEvent.h>
#include "ContactAddress.h"
-#include "JSContactEmailAddressTypeArray.h"
namespace DeviceAPI {
namespace Contact {
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactAddressArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactAddressArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactAddressArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactAddressArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactAddressArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactAddressArray::m_jsClassRef = JSClassCreate(
- JSContactAddressArray::getClassInfo());
-
-JSValueRef JSContactAddressArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressArrayPtr contactAddresses = priv->getObject();
- if (contactAddresses) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(contactAddresses->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactAddressArray::createArray(JSContextRef context,
- const ContactAddressArrayPtr &contactAddresses)
-{
- JSContactAddressArrayPriv *priv = new JSContactAddressArrayPriv(context, contactAddresses);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactAddressArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactAddressArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSContactAddressArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactAddressArrayPtr JSContactAddressArray::getContactAddressArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactAddressArrayPriv *priv = static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSContactAddressArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactAddressArray::finalize(JSObjectRef object)
-{
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactAddressArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressArrayPtr contactAddresses = priv->getObject();
- if (index < contactAddresses->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactAddressArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressArrayPtr contactAddresses = priv->getObject();
- if (index < contactAddresses->size()) {
- ContactAddressPtr result = contactAddresses->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactAddressArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactAddressPtr contactAddress(NULL);
- if (!JSValueIsUndefined(context, value)) {
- contactAddress = converter->toContactAddress(value);
- }
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressArrayPtr contactAddresses = priv->getObject();
- if (!contactAddresses) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (contactAddresses->size() <= index) {
- contactAddresses->resize(index + 1);
- }
- (*contactAddresses)[index] = contactAddress;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactAddressArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactAddressPtr contactAddress(NULL);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressArrayPtr contactAddresses = priv->getObject();
- if (!contactAddresses) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (contactAddresses->size() > index) {
- (*contactAddresses)[index] = contactAddress;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactAddressArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressArrayPtr addresses = priv->getObject();
-
- int count = addresses->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactAddressArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactAddressArrayPtr contactAddresses = ContactAddressArrayPtr(new ContactAddressArray());
- JSContactAddressArrayPriv *newPrivateObject = new JSContactAddressArrayPriv(context, contactAddresses);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current contactAddresses
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- for (size_t i = 0; i < currentContactAddresses->size(); ++i) {
- contactAddresses->push_back(currentContactAddresses->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- contactAddresses->push_back(converter->toContactAddress(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentContactAddresses->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentContactAddresses->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- if (currentContactAddresses->size() > 0) {
- ContactAddressPtr result = currentContactAddresses->at(
- currentContactAddresses->size() - 1);
- currentContactAddresses->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentContactAddresses->push_back(converter->toContactAddress(arguments[i]));
- }
- return converter->toJSValueRef(currentContactAddresses->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- std::reverse(currentContactAddresses->begin(), currentContactAddresses->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- if (currentContactAddresses->size() > 0) {
- ContactAddressPtr result = currentContactAddresses->at(0);
- currentContactAddresses->erase(currentContactAddresses->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactAddressArrayPtr contactAddresses = ContactAddressArrayPtr(new ContactAddressArray());
- JSContactAddressArrayPriv *newPrivateObject = new JSContactAddressArrayPriv(
- context,
- contactAddresses);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current contactAddresses
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentContactAddresses->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentContactAddresses->size()) {
- last = currentContactAddresses->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- contactAddresses->push_back(currentContactAddresses->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressArrayPriv* priv =
- static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressArrayPtr currentContactAddresses = priv->getObject();
- std::sort(currentContactAddresses->begin(), currentContactAddresses->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactAddressArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactAddressArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_ADDRESS_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_ADDRESS_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactAddress.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactAddressArrayPtr>::Type JSContactAddressArrayPriv;
-
-class JSContactAddressArray
-{
- public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactAddressArrayPtr &contactAddresses);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactAddressArrayPtr getContactAddressArray(JSContextRef context, JSValueRef value);
-
- private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-} // Contact
-} // DeviceAPI
-
-#endif /* _TIZEN_CONTACT_JS_CONTACT_ADDRESS_ARRAY_H_ */
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactAddressTypeArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactAddressTypeArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactAddressTypeArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactAddressTypeArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactAddressTypeArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactAddressTypeArray::m_jsClassRef = JSClassCreate(
- JSContactAddressTypeArray::getClassInfo());
-
-JSValueRef JSContactAddressTypeArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressTypeArrayPtr typeArray = priv->getObject();
- if (typeArray) {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- return converter->toJSValueRef(typeArray->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactAddressTypeArray::createArray(JSContextRef context,
- const ContactAddressTypeArrayPtr &typeArray)
-{
- JSContactAddressTypeArrayPriv *priv = new JSContactAddressTypeArrayPriv(context, typeArray);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactAddressTypeArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactAddressTypeArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSContactAddressTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactAddressTypeArrayPtr JSContactAddressTypeArray::getContactAddressTypeArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactAddressTypeArrayPriv *priv = static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSContactAddressTypeArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactAddressTypeArray::finalize(JSObjectRef object)
-{
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactAddressTypeArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressTypeArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactAddressTypeArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressTypeArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- std::string result = converter->toContactAddressTypeStr(typeArray->at(index));
- if (!result.empty()) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactAddressTypeArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- std::string str;
- if (!JSValueIsUndefined(context, value)) {
- str = converter->toString(value);
- }
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressTypeArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (typeArray->size() <= index) {
- typeArray->resize(index + 1);
- }
- (*typeArray)[index] = converter->toContactAddressType(str);
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactAddressTypeArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressTypeArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (typeArray->size() > index) {
- (*typeArray)[index] = converter->toContactAddressType("");
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactAddressTypeArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAddressTypeArrayPtr addressTypes = priv->getObject();
-
- int count = addressTypes->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactAddressTypeArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactAddressTypeArrayPtr typeArray = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
- JSContactAddressTypeArrayPriv *newPrivateObject = new JSContactAddressTypeArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- for (size_t i = 0; i < currentTypes->size(); ++i) {
- typeArray->push_back(currentTypes->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of types
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- typeArray->push_back(converter->toContactAddressType(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressTypeArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentTypes->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- result += currentTypes->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressTypeArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- if (currentTypes->size() > 0) {
- std::string result = converter->toContactAddressTypeStr(currentTypes->at(currentTypes->size()-1));
- currentTypes->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressTypeArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentTypes->push_back(converter->toContactAddressType(arguments[i]));
- }
- return converter->toJSValueRef(currentTypes->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressTypeArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- std::reverse(currentTypes->begin(), currentTypes->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressTypeArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- if (currentTypes->size() > 0) {
- std::string result = converter->toContactAddressTypeStr(currentTypes->at(0));
- currentTypes->erase(currentTypes->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressTypeArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- ContactAddressTypeArrayPtr typeArray = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
- JSContactAddressTypeArrayPriv *newPrivateObject = new JSContactAddressTypeArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentTypes->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentTypes->size()) {
- last = currentTypes->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- typeArray->push_back(currentTypes->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAddressTypeArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSContactAddressTypeArrayPriv* priv =
- static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAddressTypeArrayPtr currentTypes = priv->getObject();
- std::sort(currentTypes->begin(), currentTypes->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressTypeArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressTypeArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactAddressTypeArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAddressTypeArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactAddressTypeArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_ADDRESS_TYPE_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_ADDRESS_TYPE_ARRAY_H_
-
-#include <vector>
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactAddress.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactAddressTypeArrayPtr>::Type JSContactAddressTypeArrayPriv;
-
-class JSContactAddressTypeArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactAddressTypeArrayPtr &Strings);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactAddressTypeArrayPtr getContactAddressTypeArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_ADDRESS_TYPE_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactAnniversaryArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactAnniversaryArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactAnniversaryArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactAnniversaryArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactAnniversaryArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactAnniversaryArray::m_jsClassRef = JSClassCreate(
- JSContactAnniversaryArray::getClassInfo());
-
-JSValueRef JSContactAnniversaryArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAnniversaryArrayPtr anniversaries = priv->getObject();
- if (anniversaries) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(anniversaries->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactAnniversaryArray::createArray(JSContextRef context,
- const ContactAnniversaryArrayPtr &anniversaries)
-{
- JSContactAnniversaryArrayPriv *priv = new JSContactAnniversaryArrayPriv(context, anniversaries);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactAnniversaryArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-bool JSContactAnniversaryArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactAnniversaryArrayPtr JSContactAnniversaryArray::getContactAnniversaryArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactAnniversaryArrayPriv *priv = static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-JSClassRef JSContactAnniversaryArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSContactAnniversaryArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactAnniversaryArray::finalize(JSObjectRef object)
-{
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactAnniversaryArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAnniversaryArrayPtr anniversaries = priv->getObject();
- if (index < anniversaries->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactAnniversaryArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAnniversaryArrayPtr anniversaries = priv->getObject();
- if (index < anniversaries->size()) {
- ContactAnniversaryPtr result = anniversaries->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactAnniversaryArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactAnniversaryPtr anniversary(NULL);
- if (!JSValueIsUndefined(context, value)) {
- anniversary = converter->toContactAnniversary(value);
- }
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAnniversaryArrayPtr anniversaries = priv->getObject();
- if (!anniversaries) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (anniversaries->size() <= index) {
- anniversaries->resize(index + 1);
- }
- (*anniversaries)[index] = anniversary;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactAnniversaryArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactAnniversaryPtr anniversary(NULL);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAnniversaryArrayPtr anniversaries = priv->getObject();
- if (!anniversaries) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (anniversaries->size() > index) {
- (*anniversaries)[index] = anniversary;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactAnniversaryArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactAnniversaryArrayPtr anniversaries = priv->getObject();
-
- int count = anniversaries->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactAnniversaryArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactAnniversaryArrayPtr anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
- JSContactAnniversaryArrayPriv *newPrivateObject = new JSContactAnniversaryArrayPriv(context, anniversaries);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current anniversaries
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- for (size_t i = 0; i < currentAnniversaries->size(); ++i) {
- anniversaries->push_back(currentAnniversaries->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- anniversaries->push_back(converter->toContactAnniversary(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAnniversaryArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentAnniversaries->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentAnniversaries->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAnniversaryArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- if (currentAnniversaries->size() > 0) {
- ContactAnniversaryPtr result = currentAnniversaries->at(
- currentAnniversaries->size() - 1);
- currentAnniversaries->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAnniversaryArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentAnniversaries->push_back(converter->toContactAnniversary(arguments[i]));
- }
- return converter->toJSValueRef(currentAnniversaries->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAnniversaryArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- std::reverse(currentAnniversaries->begin(), currentAnniversaries->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAnniversaryArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- if (currentAnniversaries->size() > 0) {
- ContactAnniversaryPtr result = currentAnniversaries->at(0);
- currentAnniversaries->erase(currentAnniversaries->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAnniversaryArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactAnniversaryArrayPtr anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
- JSContactAnniversaryArrayPriv *newPrivateObject = new JSContactAnniversaryArrayPriv(
- context,
- anniversaries);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current anniversaries
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentAnniversaries->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentAnniversaries->size()) {
- last = currentAnniversaries->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- anniversaries->push_back(currentAnniversaries->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactAnniversaryArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactAnniversaryArrayPriv* priv =
- static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
- std::sort(currentAnniversaries->begin(), currentAnniversaries->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAnniversaryArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAnniversaryArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactAnniversaryArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactAnniversaryArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactAnniversaryArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactAnniversary.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactAnniversaryArrayPtr>::Type JSContactAnniversaryArrayPriv;
-
-class JSContactAnniversaryArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactAnniversaryArrayPtr &anniversaries);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactAnniversaryArrayPtr getContactAnniversaryArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactArray::m_jsClassRef = JSClassCreate(
- JSContactArray::getClassInfo());
-
-JSValueRef JSContactArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactArrayPtr contacts = priv->getObject();
- if (contacts) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(contacts->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactArray::createArray(JSContextRef context,
- const ContactArrayPtr &contacts)
-{
- JSContactArrayPriv *priv = new JSContactArrayPriv(context, contacts);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSContactArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactArrayPtr JSContactArray::getContactArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactArrayPriv *priv = static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSContactArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactArray::finalize(JSObjectRef object)
-{
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactArrayPtr contacts = priv->getObject();
- if (index < contacts->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactArrayPtr contacts = priv->getObject();
- if (index < contacts->size()) {
- ContactPtr result = contacts->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactPtr contact(NULL);
- if (!JSValueIsUndefined(context, value)) {
- contact = converter->toContact(value);
- }
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactArrayPtr contacts = priv->getObject();
- if (!contacts) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (contacts->size() <= index) {
- contacts->resize(index + 1);
- }
- (*contacts)[index] = contact;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactPtr contact(NULL);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactArrayPtr contacts = priv->getObject();
- if (!contacts) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (contacts->size() > index) {
- (*contacts)[index] = contact;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactArrayPtr contacts = priv->getObject();
-
- int count = contacts->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactArrayPtr contacts = ContactArrayPtr(new ContactArray());
- JSContactArrayPriv *newPrivateObject = new JSContactArrayPriv(context, contacts);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current contacts
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- for (size_t i = 0; i < currentContacts->size(); ++i) {
- contacts->push_back(currentContacts->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- contacts->push_back(converter->toContact(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentContacts->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentContacts->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- if (currentContacts->size() > 0) {
- ContactPtr result = currentContacts->at(
- currentContacts->size() - 1);
- currentContacts->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentContacts->push_back(converter->toContact(arguments[i]));
- }
- return converter->toJSValueRef(currentContacts->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- std::reverse(currentContacts->begin(), currentContacts->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- if (currentContacts->size() > 0) {
- ContactPtr result = currentContacts->at(0);
- currentContacts->erase(currentContacts->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactArrayPtr contacts = ContactArrayPtr(new ContactArray());
- JSContactArrayPriv *newPrivateObject = new JSContactArrayPriv(
- context,
- contacts);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current contacts
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentContacts->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentContacts->size()) {
- last = currentContacts->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- contacts->push_back(currentContacts->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactArrayPriv* priv =
- static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactArrayPtr currentContacts = priv->getObject();
- std::sort(currentContacts->begin(), currentContacts->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "IContact.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactArrayPtr>::Type JSContactArrayPriv;
-
-class JSContactArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactArrayPtr &contactAddresses);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactArrayPtr getContactArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_ARRAY_H_
#include <JSTizenExceptionFactory.h>
#include <JSTizenException.h>
#include "ContactConverter.h"
-#include "JSContactEmailAddressTypeArray.h"
#include "JSContactEmailAddress.h"
#include <Logger.h>
ContactConverterFactory::ConverterType converter =
ContactConverterFactory::getConverter(context);
- if(JSContactEmailAddressTypeArray::isObjectOfClass(context, value))
- emailAddress->setTypes(JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(context, value));
- else
- emailAddress->setTypes(converter->toContactEmailAddressTypeArray(value));
+ emailAddress->setTypes(converter->toContactEmailAddressTypeArray(value));
emailAddress->resetTypesJSObj();
}
Catch(WrtDeviceApis::Commons::Exception)
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactEmailAddressArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactEmailAddressArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactEmailAddressArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactEmailAddressArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactEmailAddressArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactEmailAddressArray::m_jsClassRef = JSClassCreate(
- JSContactEmailAddressArray::getClassInfo());
-
-JSValueRef JSContactEmailAddressArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
- if (emailAddresses) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(emailAddresses->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactEmailAddressArray::createArray(JSContextRef context,
- const ContactEmailAddressArrayPtr &emailAddresses)
-{
- JSContactEmailAddressArrayPriv *priv = new JSContactEmailAddressArrayPriv(context, emailAddresses);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-bool JSContactEmailAddressArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactEmailAddressArrayPtr JSContactEmailAddressArray::getContactEmailAddressArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactEmailAddressArrayPriv *priv = static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-const JSClassDefinition* JSContactEmailAddressArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactEmailAddressArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSContactEmailAddressArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactEmailAddressArray::finalize(JSObjectRef object)
-{
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactEmailAddressArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
- if (index < emailAddresses->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactEmailAddressArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
- if (index < emailAddresses->size()) {
- ContactEmailAddressPtr result = emailAddresses->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactEmailAddressArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactEmailAddressPtr emailAddress(NULL);
- if (!JSValueIsUndefined(context, value)) {
- emailAddress = converter->toContactEmailAddress(value);
- }
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
- if (!emailAddresses) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (emailAddresses->size() <= index) {
- emailAddresses->resize(index + 1);
- }
- (*emailAddresses)[index] = emailAddress;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactEmailAddressArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactEmailAddressPtr emailAddress(NULL);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
- if (!emailAddresses) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (emailAddresses->size() > index) {
- (*emailAddresses)[index] = emailAddress;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactEmailAddressArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
-
- int count = emailAddresses->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactEmailAddressArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactEmailAddressArrayPtr emailAddresses = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
- JSContactEmailAddressArrayPriv *newPrivateObject = new JSContactEmailAddressArrayPriv(context, emailAddresses);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current emailAddresses
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- for (size_t i = 0; i < currentEmailAddresses->size(); ++i) {
- emailAddresses->push_back(currentEmailAddresses->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- emailAddresses->push_back(converter->toContactEmailAddress(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentEmailAddresses->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentEmailAddresses->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- if (currentEmailAddresses->size() > 0) {
- ContactEmailAddressPtr result = currentEmailAddresses->at(
- currentEmailAddresses->size() - 1);
- currentEmailAddresses->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentEmailAddresses->push_back(converter->toContactEmailAddress(arguments[i]));
- }
- return converter->toJSValueRef(currentEmailAddresses->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- std::reverse(currentEmailAddresses->begin(), currentEmailAddresses->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- if (currentEmailAddresses->size() > 0) {
- ContactEmailAddressPtr result = currentEmailAddresses->at(0);
- currentEmailAddresses->erase(currentEmailAddresses->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactEmailAddressArrayPtr emailAddresses = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
- JSContactEmailAddressArrayPriv *newPrivateObject = new JSContactEmailAddressArrayPriv(
- context,
- emailAddresses);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current emailAddresses
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentEmailAddresses->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentEmailAddresses->size()) {
- last = currentEmailAddresses->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- emailAddresses->push_back(currentEmailAddresses->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressArrayPriv* priv =
- static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
- std::sort(currentEmailAddresses->begin(), currentEmailAddresses->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactEmailAddressArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactEmailAddressArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactEmailAddress.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactEmailAddressArrayPtr>::Type JSContactEmailAddressArrayPriv;
-
-class JSContactEmailAddressArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactEmailAddressArrayPtr &emailAddresses);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactEmailAddressArrayPtr getContactEmailAddressArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactEmailAddressTypeArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactEmailAddressTypeArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactEmailAddressTypeArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactEmailAddressTypeArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactEmailAddressTypeArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactEmailAddressTypeArray::m_jsClassRef = JSClassCreate(
- JSContactEmailAddressTypeArray::getClassInfo());
-
-JSValueRef JSContactEmailAddressTypeArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(NullPointerException);
- }
- ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
- if (typeArray) {
- BasicConverter converter = BasicConverterFactory::getConverter(context);
- return converter->toJSValueRef(typeArray->size());
- }
- }
- Catch(Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactEmailAddressTypeArray::createArray(JSContextRef context,
- const ContactEmailAddressTypeArrayPtr &typeArray)
-{
- JSContactEmailAddressTypeArrayPriv *priv = new JSContactEmailAddressTypeArrayPriv(context, typeArray);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-bool JSContactEmailAddressTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactEmailAddressTypeArrayPtr JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(InvalidArgumentException);
- }
- JSContactEmailAddressTypeArrayPriv *priv = static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(NullPointerException);
- }
- return priv->getObject();
-}
-
-const JSClassDefinition* JSContactEmailAddressTypeArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactEmailAddressTypeArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSContactEmailAddressTypeArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactEmailAddressTypeArray::finalize(JSObjectRef object)
-{
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactEmailAddressTypeArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- BasicConverter converter = BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(NullPointerException);
- }
- ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- return true;
- }
- }
- Catch(Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactEmailAddressTypeArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(NullPointerException);
- }
- ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- std::string result = converter->toContactEmailAddressTypeStr(typeArray->at(index));
- if (!result.empty()) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactEmailAddressTypeArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- std::string str;
- if (!JSValueIsUndefined(context, value)) {
- str = converter->toString(value);
- }
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(NullPointerException);
- }
- ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(NullPointerException);
- }
- if (typeArray->size() <= index) {
- typeArray->resize(index + 1);
- }
- (*typeArray)[index] = converter->toContactEmailAddressType(str);
- return true;
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactEmailAddressTypeArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (typeArray->size() > index) {
- (*typeArray)[index] = converter->toContactEmailAddressType("");
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactEmailAddressTypeArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactEmailAddressTypeArrayPtr types = priv->getObject();
-
- int count = types->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactEmailAddressTypeArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactEmailAddressTypeArrayPtr typeArray = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
- JSContactEmailAddressTypeArrayPriv *newPrivateObject = new JSContactEmailAddressTypeArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- typeArray->push_back(currentStrings->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- typeArray->push_back(converter->toContactEmailAddressType(att));
- }
- }
- return result;
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressTypeArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- BasicConverter converter = BasicConverterFactory::getConverter(context);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- result += currentStrings->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressTypeArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = converter->toContactEmailAddressTypeStr(currentStrings->at(currentStrings->size() - 1));
- currentStrings->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentStrings->push_back(converter->toContactEmailAddressType(arguments[i]));
- }
- return converter->toJSValueRef(currentStrings->size());
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressTypeArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- Converter converter(context);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- std::reverse(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = converter->toContactEmailAddressTypeStr(currentStrings->at(0));
- currentStrings->erase(currentStrings->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- BasicConverter converter = BasicConverterFactory::getConverter(context);
- ContactEmailAddressTypeArrayPtr typeArray = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
- JSContactEmailAddressTypeArrayPriv *newPrivateObject = new JSContactEmailAddressTypeArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentStrings->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentStrings->size()) {
- last = currentStrings->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- typeArray->push_back(currentStrings->at(i));
- }
-
- return result;
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactEmailAddressTypeArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- BasicConverter converter = BasicConverterFactory::getConverter(context);
- JSContactEmailAddressTypeArrayPriv* priv =
- static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
- std::sort(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactEmailAddressTypeArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactEmailAddressTypeArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_TYPE_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_TYPE_ARRAY_H_
-
-#include <vector>
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactEmailAddress.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactEmailAddressTypeArrayPtr>::Type JSContactEmailAddressTypeArrayPriv;
-
-class JSContactEmailAddressTypeArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactEmailAddressTypeArrayPtr &Strings);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactEmailAddressTypeArrayPtr getContactEmailAddressTypeArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_TYPE_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactGroupArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactGroupArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactGroupArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactGroupArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactGroupArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactGroupArray::m_jsClassRef = JSClassCreate(
- JSContactGroupArray::getClassInfo());
-
-JSValueRef JSContactGroupArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactGroupArrayPtr groups = priv->getObject();
- if (groups) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(groups->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactGroupArray::createArray(JSContextRef context,
- const ContactGroupArrayPtr &groups)
-{
- JSContactGroupArrayPriv *priv = new JSContactGroupArrayPriv(context, groups);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-bool JSContactGroupArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactGroupArrayPtr JSContactGroupArray::getContactGroupArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactGroupArrayPriv *priv = static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-const JSClassDefinition* JSContactGroupArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactGroupArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSContactGroupArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactGroupArray::finalize(JSObjectRef object)
-{
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactGroupArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactGroupArrayPtr groups = priv->getObject();
- if (index < groups->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactGroupArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactGroupArrayPtr groups = priv->getObject();
- if (index < groups->size()) {
- ContactGroupPtr result = groups->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactGroupArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactGroupPtr group(NULL);
- if (!JSValueIsUndefined(context, value)) {
- group = converter->toContactGroup(value);
- }
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactGroupArrayPtr groups = priv->getObject();
- if (!groups) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (groups->size() <= index) {
- groups->resize(index + 1);
- }
- (*groups)[index] = group;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactGroupArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactGroupPtr group(NULL);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactGroupArrayPtr groups = priv->getObject();
- if (!groups) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (groups->size() > index) {
- (*groups)[index] = group;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactGroupArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactGroupArrayPtr groups = priv->getObject();
-
- int count = groups->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactGroupArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactGroupArrayPtr groups = ContactGroupArrayPtr(new ContactGroupArray());
- JSContactGroupArrayPriv *newPrivateObject = new JSContactGroupArrayPriv(context, groups);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current groups
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- for (size_t i = 0; i < currentGroups->size(); ++i) {
- groups->push_back(currentGroups->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- groups->push_back(converter->toContactGroup(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactGroupArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentGroups->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentGroups->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactGroupArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- if (currentGroups->size() > 0) {
- ContactGroupPtr result = currentGroups->at(
- currentGroups->size() - 1);
- currentGroups->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactGroupArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentGroups->push_back(converter->toContactGroup(arguments[i]));
- }
- return converter->toJSValueRef(currentGroups->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactGroupArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- std::reverse(currentGroups->begin(), currentGroups->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactGroupArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- if (currentGroups->size() > 0) {
- ContactGroupPtr result = currentGroups->at(0);
- currentGroups->erase(currentGroups->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactGroupArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactGroupArrayPtr groups = ContactGroupArrayPtr(new ContactGroupArray());
- JSContactGroupArrayPriv *newPrivateObject = new JSContactGroupArrayPriv(
- context,
- groups);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current groups
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentGroups->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentGroups->size()) {
- last = currentGroups->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- groups->push_back(currentGroups->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactGroupArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactGroupArrayPriv* priv =
- static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactGroupArrayPtr currentGroups = priv->getObject();
- std::sort(currentGroups->begin(), currentGroups->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactGroupArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactGroupArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactGroupArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactGroupArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactGroupArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_GROUP_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_GROUP_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactGroup.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactGroupArrayPtr>::Type JSContactGroupArrayPriv;
-
-class JSContactGroupArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactGroupArrayPtr &groups);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactGroupArrayPtr getContactGroupArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_GROUP_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactOrganizationArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactOrganizationArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactOrganizationArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactOrganizationArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactOrganizationArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactOrganizationArray::m_jsClassRef = JSClassCreate(
- JSContactOrganizationArray::getClassInfo());
-
-JSValueRef JSContactOrganizationArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactOrganizationArrayPtr organizations = priv->getObject();
- if (organizations) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(organizations->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactOrganizationArray::createArray(JSContextRef context,
- const ContactOrganizationArrayPtr &organizations)
-{
- JSContactOrganizationArrayPriv *priv = new JSContactOrganizationArrayPriv(context, organizations);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-bool JSContactOrganizationArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactOrganizationArrayPtr JSContactOrganizationArray::getContactOrganizationArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactOrganizationArrayPriv *priv = static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-const JSClassDefinition* JSContactOrganizationArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactOrganizationArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSContactOrganizationArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactOrganizationArray::finalize(JSObjectRef object)
-{
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactOrganizationArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactOrganizationArrayPtr organizations = priv->getObject();
- if (index < organizations->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactOrganizationArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactOrganizationArrayPtr organizations = priv->getObject();
- if (index < organizations->size()) {
- ContactOrganizationPtr result = organizations->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactOrganizationArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactOrganizationPtr organization(NULL);
- if (!JSValueIsUndefined(context, value)) {
- organization = converter->toContactOrganization(value);
- }
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactOrganizationArrayPtr organizations = priv->getObject();
- if (!organizations) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (organizations->size() <= index) {
- organizations->resize(index + 1);
- }
- (*organizations)[index] = organization;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactOrganizationArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactOrganizationPtr organization(NULL);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactOrganizationArrayPtr organizations = priv->getObject();
- if (!organizations) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (organizations->size() > index) {
- (*organizations)[index] = organization;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactOrganizationArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactOrganizationArrayPtr organizations = priv->getObject();
-
- int count = organizations->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactOrganizationArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactOrganizationArrayPtr organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
- JSContactOrganizationArrayPriv *newPrivateObject = new JSContactOrganizationArrayPriv(context, organizations);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current organizations
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- for (size_t i = 0; i < currentOrganizations->size(); ++i) {
- organizations->push_back(currentOrganizations->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- organizations->push_back(converter->toContactOrganization(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactOrganizationArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentOrganizations->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentOrganizations->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactOrganizationArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- if (currentOrganizations->size() > 0) {
- ContactOrganizationPtr result = currentOrganizations->at(
- currentOrganizations->size() - 1);
- currentOrganizations->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactOrganizationArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentOrganizations->push_back(converter->toContactOrganization(arguments[i]));
- }
- return converter->toJSValueRef(currentOrganizations->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactOrganizationArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- std::reverse(currentOrganizations->begin(), currentOrganizations->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactOrganizationArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- if (currentOrganizations->size() > 0) {
- ContactOrganizationPtr result = currentOrganizations->at(0);
- currentOrganizations->erase(currentOrganizations->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactOrganizationArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactOrganizationArrayPtr organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
- JSContactOrganizationArrayPriv *newPrivateObject = new JSContactOrganizationArrayPriv(
- context,
- organizations);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current organizations
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentOrganizations->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentOrganizations->size()) {
- last = currentOrganizations->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- organizations->push_back(currentOrganizations->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactOrganizationArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactOrganizationArrayPriv* priv =
- static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
- std::sort(currentOrganizations->begin(), currentOrganizations->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactOrganizationArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactOrganizationArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactOrganizationArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactOrganizationArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactOrganizationArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactOrganization.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactOrganizationArrayPtr>::Type JSContactOrganizationArrayPriv;
-
-class JSContactOrganizationArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactOrganizationArrayPtr &organizations);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactOrganizationArrayPtr getContactOrganizationArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_ARRAY_H_
#include <JSTizenExceptionFactory.h>
#include <JSTizenException.h>
#include "ContactConverter.h"
-#include "JSContactPhoneNumberTypeArray.h"
#include "JSContactPhoneNumber.h"
#include <Logger.h>
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactPhoneNumberArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactPhoneNumberArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactPhoneNumberArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactPhoneNumberArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactPhoneNumberArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactPhoneNumberArray::m_jsClassRef = JSClassCreate(
- JSContactPhoneNumberArray::getClassInfo());
-
-JSValueRef JSContactPhoneNumberArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
- if (contactPhoneNumbers) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(contactPhoneNumbers->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactPhoneNumberArray::createArray(JSContextRef context,
- const ContactPhoneNumberArrayPtr &contactPhoneNumbers)
-{
- JSContactPhoneNumberArrayPriv *priv = new JSContactPhoneNumberArrayPriv(context, contactPhoneNumbers);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactPhoneNumberArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactPhoneNumberArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSContactPhoneNumberArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactPhoneNumberArrayPtr JSContactPhoneNumberArray::getContactPhoneNumberArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactPhoneNumberArrayPriv *priv = static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSContactPhoneNumberArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactPhoneNumberArray::finalize(JSObjectRef object)
-{
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactPhoneNumberArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
- if (index < contactPhoneNumbers->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactPhoneNumberArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
- if (index < contactPhoneNumbers->size()) {
- ContactPhoneNumberPtr result = contactPhoneNumbers->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactPhoneNumberArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactPhoneNumberPtr contactPhoneNumber(NULL);
- if (!JSValueIsUndefined(context, value)) {
- contactPhoneNumber = converter->toContactPhoneNumber(value);
- }
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
- if (!contactPhoneNumbers) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (contactPhoneNumbers->size() <= index) {
- contactPhoneNumbers->resize(index + 1);
- }
- (*contactPhoneNumbers)[index] = contactPhoneNumber;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactPhoneNumberArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactPhoneNumberPtr contactPhoneNumber(NULL);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
- if (!contactPhoneNumbers) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (contactPhoneNumbers->size() > index) {
- (*contactPhoneNumbers)[index] = contactPhoneNumber;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactPhoneNumberArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberArrayPtr phoneNumbers = priv->getObject();
-
- int count = phoneNumbers->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactPhoneNumberArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactPhoneNumberArrayPtr contactPhoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
- JSContactPhoneNumberArrayPriv *newPrivateObject = new JSContactPhoneNumberArrayPriv(context, contactPhoneNumbers);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current contactPhoneNumbers
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- for (size_t i = 0; i < currentContactPhoneNumbers->size(); ++i) {
- contactPhoneNumbers->push_back(currentContactPhoneNumbers->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- contactPhoneNumbers->push_back(converter->toContactPhoneNumber(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentContactPhoneNumbers->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentContactPhoneNumbers->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- if (currentContactPhoneNumbers->size() > 0) {
- ContactPhoneNumberPtr result = currentContactPhoneNumbers->at(
- currentContactPhoneNumbers->size() - 1);
- currentContactPhoneNumbers->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentContactPhoneNumbers->push_back(converter->toContactPhoneNumber(arguments[i]));
- }
- return converter->toJSValueRef(currentContactPhoneNumbers->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- std::reverse(currentContactPhoneNumbers->begin(), currentContactPhoneNumbers->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- if (currentContactPhoneNumbers->size() > 0) {
- ContactPhoneNumberPtr result = currentContactPhoneNumbers->at(0);
- currentContactPhoneNumbers->erase(currentContactPhoneNumbers->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactPhoneNumberArrayPtr contactPhoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
- JSContactPhoneNumberArrayPriv *newPrivateObject = new JSContactPhoneNumberArrayPriv(
- context,
- contactPhoneNumbers);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current contactPhoneNumbers
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentContactPhoneNumbers->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentContactPhoneNumbers->size()) {
- last = currentContactPhoneNumbers->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- contactPhoneNumbers->push_back(currentContactPhoneNumbers->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberArrayPriv* priv =
- static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
- std::sort(currentContactPhoneNumbers->begin(), currentContactPhoneNumbers->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactPhoneNumberArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactPhoneNumberArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactPhoneNumber.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactPhoneNumberArrayPtr>::Type JSContactPhoneNumberArrayPriv;
-
-class JSContactPhoneNumberArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactPhoneNumberArrayPtr &contactPhoneNumbers);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactPhoneNumberArrayPtr getContactPhoneNumberArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactPhoneNumberTypeArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactPhoneNumberTypeArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactPhoneNumberTypeArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactPhoneNumberTypeArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactPhoneNumberTypeArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactPhoneNumberTypeArray::m_jsClassRef = JSClassCreate(
- JSContactPhoneNumberTypeArray::getClassInfo());
-
-JSValueRef JSContactPhoneNumberTypeArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
- if (typeArray) {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- return converter->toJSValueRef(typeArray->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSContactPhoneNumberTypeArray::createArray(JSContextRef context,
- const ContactPhoneNumberTypeArrayPtr &typeArray)
-{
- JSContactPhoneNumberTypeArrayPriv *priv = new JSContactPhoneNumberTypeArrayPriv(context, typeArray);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactPhoneNumberTypeArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactPhoneNumberTypeArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSContactPhoneNumberTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactPhoneNumberTypeArrayPtr JSContactPhoneNumberTypeArray::getContactPhoneNumberTypeArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactPhoneNumberTypeArrayPriv *priv = static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSContactPhoneNumberTypeArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactPhoneNumberTypeArray::finalize(JSObjectRef object)
-{
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactPhoneNumberTypeArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
- if (index < typeArray->size()) {
- std::string result = converter->toContactPhoneNumberTypeStr(typeArray->at(index));
- if (!result.empty()) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactPhoneNumberTypeArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- std::string str;
- if (!JSValueIsUndefined(context, value)) {
- str = converter->toString(value);
- }
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (typeArray->size() <= index) {
- typeArray->resize(index + 1);
- }
- (*typeArray)[index] = converter->toContactPhoneNumberType(str);
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactPhoneNumberTypeArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
- if (!typeArray) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (typeArray->size() > index) {
- (*typeArray)[index] = converter->toContactPhoneNumberType("");
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactPhoneNumberTypeArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactPhoneNumberTypeArrayPtr phoneNumbers = priv->getObject();
-
- int count = phoneNumbers->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
- JSContactPhoneNumberTypeArrayPriv *newPrivateObject = new JSContactPhoneNumberTypeArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- typeArray->push_back(currentStrings->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- typeArray->push_back(converter->toContactPhoneNumberType(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- result += currentStrings->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result =
- converter->toContactPhoneNumberTypeStr(currentStrings->at(currentStrings->size() - 1));
- currentStrings->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentStrings->push_back(converter->toContactPhoneNumberType(arguments[i]));
- }
- return converter->toJSValueRef(currentStrings->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::Converter converter(context);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- std::reverse(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = converter->toContactPhoneNumberTypeStr(currentStrings->at(0));
- currentStrings->erase(currentStrings->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
- ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
- JSContactPhoneNumberTypeArrayPriv *newPrivateObject = new JSContactPhoneNumberTypeArrayPriv(
- context,
- typeArray);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current typeArray
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentStrings->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentStrings->size()) {
- last = currentStrings->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- typeArray->push_back(currentStrings->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::Converter converter(context);
- JSContactPhoneNumberTypeArrayPriv* priv =
- static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
- std::sort(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactPhoneNumberTypeArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactPhoneNumberTypeArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_TYPE_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_TYPE_ARRAY_H_
-
-#include <vector>
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactPhoneNumber.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ContactPhoneNumberTypeArrayPtr>::Type JSContactPhoneNumberTypeArrayPriv;
-
-class JSContactPhoneNumberTypeArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactPhoneNumberTypeArrayPtr &Strings);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactPhoneNumberTypeArrayPtr getContactPhoneNumberTypeArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_TYPE_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactWebSiteArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSContactWebSiteArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSContactWebSiteArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSContactWebSiteArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSContactWebSiteArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSContactWebSiteArray::m_jsClassRef = JSClassCreate(
- JSContactWebSiteArray::getClassInfo());
-
-JSValueRef JSContactWebSiteArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactWebSiteArrayPtr webSites = priv->getObject();
- if (webSites) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(webSites->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactWebSiteArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-ContactWebSiteArrayPtr JSContactWebSiteArray::getContactWebSiteArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSContactWebSiteArrayPriv *priv = static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-JSObjectRef JSContactWebSiteArray::createArray(JSContextRef context,
- const ContactWebSiteArrayPtr &webSites)
-{
- JSContactWebSiteArrayPriv *priv = new JSContactWebSiteArrayPriv(context, webSites);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSContactWebSiteArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSContactWebSiteArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSContactWebSiteArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSContactWebSiteArray::finalize(JSObjectRef object)
-{
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSContactWebSiteArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactWebSiteArrayPtr webSites = priv->getObject();
- if (index < webSites->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSContactWebSiteArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactWebSiteArrayPtr webSites = priv->getObject();
- if (index < webSites->size()) {
- ContactWebSitePtr result = webSites->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSContactWebSiteArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactWebSitePtr webSite(NULL);
- if (!JSValueIsUndefined(context, value)) {
- webSite = converter->toContactWebSite(value);
- }
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactWebSiteArrayPtr webSites = priv->getObject();
- if (!webSites) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (webSites->size() <= index) {
- webSites->resize(index + 1);
- }
- (*webSites)[index] = webSite;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSContactWebSiteArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- ContactWebSitePtr webSite(NULL);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactWebSiteArrayPtr webSites = priv->getObject();
- if (!webSites) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (webSites->size() > index) {
- (*webSites)[index] = webSite;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSContactWebSiteArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- ContactWebSiteArrayPtr webSites = priv->getObject();
-
- int count = webSites->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSContactWebSiteArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactWebSiteArrayPtr webSites = ContactWebSiteArrayPtr(new ContactWebSiteArray());
- JSContactWebSiteArrayPriv *newPrivateObject = new JSContactWebSiteArrayPriv(context, webSites);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current webSites
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- for (size_t i = 0; i < currentWebSites->size(); ++i) {
- webSites->push_back(currentWebSites->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- webSites->push_back(converter->toContactWebSite(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactWebSiteArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentWebSites->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentWebSites->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactWebSiteArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- if (currentWebSites->size() > 0) {
- ContactWebSitePtr result = currentWebSites->at(
- currentWebSites->size() - 1);
- currentWebSites->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactWebSiteArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentWebSites->push_back(converter->toContactWebSite(arguments[i]));
- }
- return converter->toJSValueRef(currentWebSites->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactWebSiteArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- std::reverse(currentWebSites->begin(), currentWebSites->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactWebSiteArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- if (currentWebSites->size() > 0) {
- ContactWebSitePtr result = currentWebSites->at(0);
- currentWebSites->erase(currentWebSites->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactWebSiteArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- ContactWebSiteArrayPtr webSites = ContactWebSiteArrayPtr(new ContactWebSiteArray());
- JSContactWebSiteArrayPriv *newPrivateObject = new JSContactWebSiteArrayPriv(
- context,
- webSites);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current webSites
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentWebSites->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentWebSites->size()) {
- last = currentWebSites->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- webSites->push_back(currentWebSites->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSContactWebSiteArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSContactWebSiteArrayPriv* priv =
- static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
- ContactWebSiteArrayPtr currentWebSites = priv->getObject();
- std::sort(currentWebSites->begin(), currentWebSites->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactWebSiteArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactWebSiteArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSContactWebSiteArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSContactWebSiteArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSContactWebSiteArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_ARRAY_H_
-#define _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "ContactWebSite.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT< ContactWebSiteArrayPtr >::Type JSContactWebSiteArrayPriv;
-
-class JSContactWebSiteArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const ContactWebSiteArrayPtr &webSites);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static ContactWebSiteArrayPtr getContactWebSiteArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSPersonArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSPersonArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSPersonArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSPersonArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSPersonArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSPersonArray::m_jsClassRef = JSClassCreate(
- JSPersonArray::getClassInfo());
-
-JSValueRef JSPersonArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- PersonArrayPtr groups = priv->getObject();
- if (groups) {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- return converter->toJSValueRef(groups->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSPersonArray::createArray(JSContextRef context,
- const PersonArrayPtr &groups)
-{
- JSPersonArrayPriv *priv = new JSPersonArrayPriv(context, groups);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-bool JSPersonArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-PersonArrayPtr JSPersonArray::getPersonArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSPersonArrayPriv *priv = static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-const JSClassDefinition* JSPersonArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSPersonArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-void JSPersonArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSPersonArray::finalize(JSObjectRef object)
-{
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSPersonArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- PersonArrayPtr groups = priv->getObject();
- if (index < groups->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSPersonArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- PersonArrayPtr groups = priv->getObject();
- if (index < groups->size()) {
- PersonPtr result = groups->at(index);
- if (result) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSPersonArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- PersonPtr group(NULL);
- if (!JSValueIsUndefined(context, value)) {
- group = converter->toPerson(value);
- }
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- PersonArrayPtr groups = priv->getObject();
- if (!groups) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (groups->size() <= index) {
- groups->resize(index + 1);
- }
- (*groups)[index] = group;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-bool JSPersonArray::deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- PersonPtr group(NULL);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- PersonArrayPtr groups = priv->getObject();
- if (!groups) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (groups->size() > index) {
- (*groups)[index] = group;
- }
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSPersonArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- PersonArrayPtr groups = priv->getObject();
-
- int count = groups->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSPersonArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- PersonArrayPtr groups = PersonArrayPtr(new PersonArray());
- JSPersonArrayPriv *newPrivateObject = new JSPersonArrayPriv(context, groups);
- JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
- //copy current groups
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- for (size_t i = 0; i < currentPersons->size(); ++i) {
- groups->push_back(currentPersons->at(i));
- }
-
- //copy submitted arrays
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- groups->push_back(converter->toPerson(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSPersonArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentPersons->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- //FIXME : to be changed to support join
- //result += currentPersons->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSPersonArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- if (currentPersons->size() > 0) {
- PersonPtr result = currentPersons->at(
- currentPersons->size() - 1);
- currentPersons->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSPersonArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentPersons->push_back(converter->toPerson(arguments[i]));
- }
- return converter->toJSValueRef(currentPersons->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSPersonArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- std::reverse(currentPersons->begin(), currentPersons->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSPersonArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- if (currentPersons->size() > 0) {
- PersonPtr result = currentPersons->at(0);
- currentPersons->erase(currentPersons->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSPersonArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- PersonArrayPtr groups = PersonArrayPtr(new PersonArray());
- JSPersonArrayPriv *newPrivateObject = new JSPersonArrayPriv(
- context,
- groups);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current groups
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentPersons->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentPersons->size()) {
- last = currentPersons->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- groups->push_back(currentPersons->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSPersonArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- JSPersonArrayPriv* priv =
- static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
- PersonArrayPtr currentPersons = priv->getObject();
- std::sort(currentPersons->begin(), currentPersons->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSPersonArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSPersonArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSPersonArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSPersonArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSPersonArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_PERSON_ARRAY_H_
-#define _TIZEN_CONTACT_JS_PERSON_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "IPerson.h"
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<PersonArrayPtr>::Type JSPersonArrayPriv;
-
-class JSPersonArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const PersonArrayPtr &groups);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static PersonArrayPtr getPersonArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static bool deleteProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_PERSON_ARRAY_H_
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSStringArray.cpp
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "ContactConverter.h"
-#include "JSStringArray.h"
-#include <Logger.h>
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Contact {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSStringArray::m_classInfo = {
- 0,
- kJSClassAttributeNone,
- ARRAY,
- 0,
- m_property,
- m_function,
- initialize,
- finalize,
- hasProperty,
- getProperty,
- setProperty,
- NULL, //deleteProperty,
- getPropertyNames,
- NULL, //callAsFunction,
- NULL, //callAsConstructor,
- NULL, //hasInstance,
- NULL, //convertToType,
-};
-
-JSStaticValue JSStringArray::m_property[] = {
- { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSStringArray::m_function[] = {
- { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
- { 0, 0, 0 }
-};
-
-JSClassRef JSStringArray::m_jsClassRef = JSClassCreate(
- JSStringArray::getClassInfo());
-
-JSValueRef JSStringArray::getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- Try
- {
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- StringArrayPtr strs = priv->getObject();
- if (strs) {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- return converter->toJSValueRef(strs->size());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid conversion");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSStringArray::createArray(JSContextRef context,
- const StringArrayPtr &strs)
-{
- JSStringArrayPriv *priv = new JSStringArrayPriv(context, strs);
- return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSStringArray::getClassInfo()
-{
- return &(m_classInfo);
-}
-
-JSClassRef JSStringArray::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-bool JSStringArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
- return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-StringArrayPtr JSStringArray::getStringArray(JSContextRef context, JSValueRef value)
-{
- if (!isObjectOfClass(context, value)) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object) {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSStringArrayPriv* priv = static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
-}
-
-void JSStringArray::initialize(JSContextRef context,
- JSObjectRef object)
-{
-}
-
-void JSStringArray::finalize(JSObjectRef object)
-{
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- delete priv;
- JSObjectSetPrivate(object, NULL);
-}
-
-bool JSStringArray::hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName)
-{
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- StringArrayPtr strs = priv->getObject();
- if (index < strs->size()) {
- return true;
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- //not reporting error is intended
- }
- return false;
-}
-
-JSValueRef JSStringArray::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
-{
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- StringArrayPtr strs = priv->getObject();
- if (index < strs->size()) {
- std::string result = strs->at(index);
- if (!result.empty()) {
- return converter->toJSValueRef(result);
- }
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
- return JSValueMakeUndefined(context);
-}
-
-bool JSStringArray::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
-{
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- Try
- {
- size_t index = converter->toSizeT(propertyName);
- std::string str;
- if (!JSValueIsUndefined(context, value)) {
- str = converter->toString(value);
- }
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- StringArrayPtr strs = priv->getObject();
- if (!strs) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- if (strs->size() <= index) {
- strs->resize(index + 1);
- }
- (*strs)[index] = str;
- return true;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
- }
- return false;
-}
-
-void JSStringArray::getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames)
-{
- ContactConverterFactory::ConverterType converter =
- ContactConverterFactory::getConverter(context);
- Try
- {
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
- if (!priv) {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- StringArrayPtr strings = priv->getObject();
-
- int count = strings->size();
-
- for(int i=0; i < count; i++)
- {
- ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
- JSPropertyNameAccumulatorAddName(propertyNames, name.get());
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("invalid property");
- }
-}
-
-JSValueRef JSStringArray::concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- StringArrayPtr strs = StringArrayPtr(new StringArray());
- JSStringArrayPriv *newPrivateObject = new JSStringArrayPriv(
- context,
- strs);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current strs
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- strs->push_back(currentStrings->at(i));
- }
-
- //copy submitted arrays
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- for (size_t i = 0; i < argumentCount; ++i) {
- if (!JSIsArrayValue(context, arguments[i])) {
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
- // process array of strings
- JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
- unsigned int len = JSGetArrayLength(context, arrayObj);
- for (unsigned int e = 0; e < len; ++e) {
- JSValueRef att = JSGetArrayElement(context, arrayObj, e);
- strs->push_back(converter->toString(att));
- }
- }
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- std::string result;
- std::string separator(",");
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
- separator = converter->toString(arguments[0]);
- }
- for (size_t i = 0; i < currentStrings->size(); ++i) {
- if (i != 0) {
- result += separator;
- }
- result += currentStrings->at(i);
- }
- return converter->toJSValueRef(result);
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = currentStrings->at(
- currentStrings->size() - 1);
- currentStrings->pop_back();
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- for (size_t i = 0; i < argumentCount; ++i) {
- currentStrings->push_back(converter->toString(arguments[i]));
- }
- return converter->toJSValueRef(currentStrings->size());
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- std::reverse(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- if (currentStrings->size() > 0) {
- std::string result = currentStrings->at(0);
- currentStrings->erase(currentStrings->begin());
- return converter->toJSValueRef(result);
- }
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- if (argumentCount < 1) {
- return JSValueMakeUndefined(context);
- }
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- StringArrayPtr strs = StringArrayPtr(new StringArray());
- JSStringArrayPriv *newPrivateObject = new JSStringArrayPriv(
- context,
- strs);
- JSValueRef result = JSObjectMake(context,
- getClassRef(), newPrivateObject);
-
- //copy current strs
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- std::size_t first = converter->toSizeT(arguments[0]);
- std::size_t last = currentStrings->size() - 1;
- if (argumentCount > 1) {
- last = converter->toSizeT(arguments[1]);
- if (last >= currentStrings->size()) {
- last = currentStrings->size() - 1;
- }
- }
- for (size_t i = first; i <= last; ++i) {
- strs->push_back(currentStrings->at(i));
- }
-
- return result;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- Try
- {
- WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
- WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
- JSStringArrayPriv* priv =
- static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
- StringArrayPtr currentStrings = priv->getObject();
- std::sort(currentStrings->begin(), currentStrings->end());
- return thisObject;
- }
- Catch(WrtDeviceApis::Commons::Exception)
- {
- LoggerE("error occured");
- }
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSStringArray::unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
+++ /dev/null
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file JSStringArray.h
- * @author Kisub Song (kisubs.song@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef _TIZEN_CONTACT_JS_STRING_ARRAY_H_
-#define _TIZEN_CONTACT_JS_STRING_ARRAY_H_
-
-#include <vector>
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-
-namespace DeviceAPI {
-namespace Contact {
-
-typedef std::vector<std::string> StringArray;
-typedef DPL::SharedPtr<StringArray> StringArrayPtr;
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<StringArrayPtr>::Type JSStringArrayPriv;
-
-class JSStringArray
-{
-public:
-
- static const JSClassDefinition* getClassInfo();
-
- static JSClassRef getClassRef();
-
- static JSObjectRef createArray(JSContextRef context,
- const StringArrayPtr &Strings);
-
- static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
- static StringArrayPtr getStringArray(JSContextRef context, JSValueRef value);
-
-private:
-
- /**
- * The callback invoked when an object is first created.
- */
- static void initialize(JSContextRef context,
- JSObjectRef object);
-
- /**
- * The callback invoked when an object is finalized.
- */
- static void finalize(JSObjectRef object);
-
- static JSValueRef getLength(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool hasProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName);
-
- static JSValueRef getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception);
-
- static bool setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception);
-
- static void getPropertyNames(JSContextRef context,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef propertyNames);
-
- static JSValueRef concat(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef join(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef pop(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef push(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef reverse(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef shift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef slice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef sort(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef splice(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef toString(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef unshift(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
- static JSValueRef valueOf(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static bool checkValue(const std::string &value);
-
- static JSClassRef m_jsClassRef;
- /**
- * This structure describes a statically declared function property.
- */
- static JSStaticFunction m_function[];
-
- /**
- * This structure contains properties and callbacks that define a type of object.
- */
- static JSClassDefinition m_classInfo;
-
- /**
- * This member variable contains the initialization values for the static properties of this class.
- * The values are given according to the data structure JSPropertySpec
- */
- static JSStaticValue m_property[];
-};
-
-} // Contact
-} // DeviceAPI
-
-#endif // _TIZEN_CONTACT_JS_STRING_ARRAY_H_
string personIdStr = event->getPersonId();
if(!ContactUtility::checkStrIsUInt(personIdStr))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "wrong " );
try {
personId = ContactUtility::strToInt(personIdStr);
selfPersonId = ContactUtility::strToInt(m_id);
} catch (...) {
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "invalid" );
}
errorCode = contacts_db_get_record(_contacts_person._uri, personId, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(contacts_record, true);
- ThrowMsg(NotFoundException, "No person (id:" << personId << ")");
+ ThrowMsg(NotFoundException, "No person");
}
contacts_record_destroy(contacts_record, true);
contacts_record = NULL;
- LoggerD("Linking person : " << personId);
-
errorCode = contacts_person_link_person(selfPersonId, personId);
if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(contacts_record, true);
- ThrowMsg(NotFoundException, "No person (id:" << selfPersonId << ")");
+ ThrowMsg(NotFoundException, "No person");
}
PersonPtr person = PersonPtr(new Person());
ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
}
Catch (InvalidArgumentException)
{
- LoggerE("Invalid person id : " << _rethrown_exception.GetMessage());
+ LoggerE("Invalid person : " << _rethrown_exception.GetMessage());
event->setResult(false);
event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
return;
string contactIdStr = event->getContactId();
if(!ContactUtility::checkStrIsUInt(contactIdStr))
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "wrong" );
try {
selfPersonId = ContactUtility::strToInt(m_id);
contactId = ContactUtility::strToInt(contactIdStr);
} catch (...) {
- ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+ ThrowMsg(InvalidArgumentException, "invalid" );
}
errorCode = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(contacts_record, true);
- ThrowMsg(NotFoundException, "No contact (id:" << contactId << ")");
+ ThrowMsg(NotFoundException, "No contact");
}
int contactsPersonId = 0;
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(contacts_record, true);
- ThrowMsg(NotFoundException, "Contact (id:" << contactId << ") is not a member of person");
+ ThrowMsg(NotFoundException, "Contact is not a member of person");
}
contacts_record_destroy(contacts_record, true);
contacts_record = NULL;
if(contactsPersonId != selfPersonId)
{
- ThrowMsg(OutOfRangeException, "Contact (id:" << contactId << ") is not a member of person");
+ ThrowMsg(OutOfRangeException, "Contact is not a member of person");
}
- LoggerD("Unlinking contact : " << contactId);
-
int newPersonId = 0;
int errorCode = contacts_person_unlink_contact(selfPersonId, contactId, &newPersonId);
if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
ThrowMsg(NotFoundException, "Error during executing contacts_person_unlink_contact()");
else if (errorCode != CONTACTS_ERROR_NONE)
ThrowMsg(PlatformException, "Error during executing contacts_person_unlink_contact()");
- LoggerD("newPersonId : " << newPersonId);
errorCode = contacts_db_get_record(_contacts_person._uri, newPersonId, &contacts_record);
if(errorCode != CONTACTS_ERROR_NONE)
{
- ThrowMsg(NotFoundException, "No person (id:" << newPersonId << ")");
+ ThrowMsg(NotFoundException, "No person");
}
PersonPtr person = PersonPtr(new Person());
ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
if(errorCode != CONTACTS_ERROR_NONE)
{
contacts_record_destroy(contacts_record, true);
- ThrowMsg(NotFoundException, "No person (id:" << selfPersonId << ")");
+ ThrowMsg(NotFoundException, "invalid person");
}
person = PersonPtr(new Person());
ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
{
m_callback = new MultiCallbackUserData(globalCtx);
- LOGD("%s:%d, thread_id=%ld", __FUNCTION__, __LINE__, pthread_self());
- LOGD("%s:%d, context=%p", __FUNCTION__, __LINE__, globalCtx);
// onstarted
JSValueRef oncontentadded = JSUtil::getProperty(globalCtx , object, "oncontentadded");
if(!JSValueIsUndefined(globalCtx,oncontentadded)) {
Converter converter(context);
- std::string providerId = converter.toString(arguments[0]);
- std::string dataId = converter.toString(arguments[1]);
- std::string type = converter.toString(arguments[2]);
+ std::string providerId = converter.toString(reserveArguments[0]);
+ std::string dataId = converter.toString(reserveArguments[1]);
+ std::string type = converter.toString(reserveArguments[2]);
if (type == SQL_DATA_CONTROL)
if (RESULT_TRUE_FROM_OSP != result[0])
{
// 1 : error msg
- ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
+ if (result[1].find("E_KEY_NOT_FOUND") != std::string::npos)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::NotFoundException, result[1]);
+ }
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
+ }
}
event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
if (RESULT_TRUE_FROM_OSP != result[0])
{
// 1 : error msg
- ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
+ if (result[1].find("E_KEY_NOT_FOUND") != std::string::npos)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::NotFoundException, result[1]);
+ }
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
+ }
}
event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
if (RESULT_TRUE_FROM_OSP != result[0])
{
// 1 : error msg
- ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
+ if (result[1].find("E_KEY_NOT_FOUND") != std::string::npos)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::NotFoundException, result[1]);
+ }
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
+ }
}
event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSValueRef JSSyncInfo::getProperty(JSContextRef context,
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSValueRef JSSyncProfileInfo::getProperty(JSContextRef context,
NULL, //deleteProperty,
NULL, //getPropertyNames,
NULL, //callAsFunction,
- constructor,
+ NULL, //constructor,
NULL, //hasInstance,
NULL, //convertToType,
};
Catch(UnsupportedException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(InvalidArgumentException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(ConversionException)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
Catch(Exception)
{
LoggerW("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ *exception = error;
+ return error;
}
-
- return NULL;
}
JSValueRef JSSyncServiceInfo::getProperty(JSContextRef context,
#include "DataSyncListenerManager.h"
#include <Logger.h>
+namespace Options{
+class_definition_options_t DataSyncOptions =
+{
+ JS_CLASS,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL,
+ NULL
+};
+
+class_definition_options_t DataSyncInterfaceOptions = {
+ JS_INTERFACE,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL, // JSWidget::acquireGlobalContext,
+ NULL,
+ NULL
+};
+}
+
using namespace WrtDeviceApis::Commons;
using namespace DeviceAPI::Common;
PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
"datasync",
(js_class_template_getter)JSDataSyncManager::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ &Options::DataSyncOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_SYNC_INFO_INTERFACE,
(js_class_template_getter)JSSyncInfo::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSSyncInfo::constructor,
+ &Options::DataSyncInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_SYNC_SERVICE_INFO_INTERFACE,
(js_class_template_getter)JSSyncServiceInfo::getClassRef,
- NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+ (js_class_constructor_cb_t)JSSyncServiceInfo::constructor,
+ &Options::DataSyncInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
TIZEN_SYNC_PROFILE_INFO_INTERFACE,
(js_class_template_getter)JSSyncProfileInfo::getClassRef,
- NULL)
+ (js_class_constructor_cb_t)JSSyncProfileInfo::constructor,
+ &Options::DataSyncInterfaceOptions)
PLUGIN_CLASS_MAP_END
}
try
{
if(argumentCount >= 2 &&
- !JSValueIsUndefined(context, arguments[1]) &&
!JSValueIsNull(context, arguments[1]))
localMessagePort = MessagePortJSUtil::JSValueToLocalMessagePort(context, arguments[1]);
}
// appId
JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
- priv->setApplicationId(JSUtil::JSValueToString(context, appId));
+ if (!JSValueIsNull(context, appId))
+ priv->setApplicationId(JSUtil::JSValueToString(context, appId));
#if 0
// progressType
#define MAX_THUMBNAIL_LENGTH 4
extern "C" int service_create_event(bundle *data, struct service_s **service);
-extern "C" int service_to_bundle(service_h service, bundle **data);
+//tern "C" int service_to_bundle(service_h service, bundle **data);
//callback functions.
static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
if (arrayValue)
free(arrayValue);
}
-
+
+#if 0
bundle *bundle_data=NULL;
if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
NULL,NULL, bundle_data);
}
+#endif
}
IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
SEListenerManagerSingleton::Instance().registerListener(listenerItem, privateObject->getContext());
- return convert.toJSValueRefLong(static_cast<long>(emitter->getId()));
+ return convert.toJSValueRef(static_cast<unsigned long>(emitter->getId()));
} Catch (ConversionException) {
LoggerE("ConversionException");
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
{
m_initTimer = NULL;
m_canceled = false;
- m_lastValue = NULL;
m_storageCnt = 0;
m_tmpStorageCnt = 0;
m_Systeminfo = NULL;
+ m_setLastValue = false;
++m_uniqId;
}
EventWatchSysteminfo::~EventWatchSysteminfo()
{
- if(m_lastValue)
- {
- JSCallbackManagerPtr m_cbm = DPL::StaticPointerCast< JSCallbackManager >(getPrivateData());
- JSValueUnprotect(m_cbm->getContext(), m_lastValue);
- }
LoggerD("destroy event data, id=" << m_id);
removeTimer();
}
void EventWatchSysteminfo::getWatchValue(int cnt)
{
- LoggerD("enter");
m_tmpStorageCnt = cnt;
processGetValue();
}
m_id = id;
}
-JSValueRef EventWatchSysteminfo::getPropertyValue(JSContextRef context, JSValueRef value, std::string key)
-{
- JSObjectRef object = NULL;
- JSValueRef* exception = NULL;
- JSStringRef propertyName = NULL;
-
- object = JSValueToObject(context, value, exception);
- propertyName = JSStringCreateWithUTF8CString(key.c_str());
-
- return JSObjectGetProperty(context, object, propertyName, exception);
-}
-
void EventWatchSysteminfo::processGetValue()
{
LoggerD("thread=" << DPL::Thread::GetCurrentThread());
+ JSValueRef lastValue = NULL;
+ JSValueRef lastValueList[MAX_STORAGE_CNT];
+ JSValueRef tmpValue = NULL;
+ JSValueRef tmpValueList[MAX_STORAGE_CNT];
+ JSStringRef propertyName = NULL;
+ std::string key;
+ JSObjectRef object = NULL;
+ double level = 0.0, brightness = 0.0, load = 0.0;
+ bool isCharging = false;
+ double capacity[MAX_STORAGE_CNT];
+ double availableCapacity[MAX_STORAGE_CNT];
+ bool isRemovable[MAX_STORAGE_CNT];
+ int watchType = m_BaseProperty->getWatchType();
+
if(m_canceled) {
LoggerD("Watch event is cancelled aleardy.");
return;
JSCallbackManagerPtr m_cbm = DPL::StaticPointerCast< JSCallbackManager >(getPrivateData());
JSContextRef context = m_cbm->getContext();
- JSValueRef tmpValue = NULL;
- if(!m_lastValue) {
- m_lastValue = m_BaseProperty->getValue(context, (void*)((Systeminfo*)m_Systeminfo)->getConnectionHandle());
+ if (!m_setLastValue) {
+ lastValue = m_BaseProperty->getValue(context, (void*)((Systeminfo*)m_Systeminfo)->getConnectionHandle());
+ switch(watchType) {
+ case WATCH_TYPE_BATTERY :
+ key = "level";
+ object = JSValueToObject(context, lastValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ m_propertyValue.batterInfo.level = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ key = "isCharging";
+ object = JSValueToObject(context, lastValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ m_propertyValue.batterInfo.isCharging = JSValueToBoolean(context, JSObjectGetProperty(context, object, propertyName, NULL));
+ break;
+
+ case WATCH_TYPE_CPU :
+ key = "load";
+ object = JSValueToObject(context, lastValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ m_propertyValue.cpuInfo.load = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+ break;
+
+ case WATCH_TYPE_STORAGE:
+ if (m_tmpStorageCnt > MAX_STORAGE_CNT) {
+ Throw(WrtDeviceApis::Commons::Exception);
+ }
+
+ for (int i=0; i<m_tmpStorageCnt; i++) {
+ lastValueList[i] = JSGetArrayElement(context, JSValueToObject(context, lastValue, NULL), i);
+
+ key = "capacity";
+ object = JSValueToObject(context, lastValueList[i], NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ m_propertyValue.storageInfo[i].capacity = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ key = "availableCapacity";
+ object = JSValueToObject(context, lastValueList[i], NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ m_propertyValue.storageInfo[i].availableCapacity = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ key = "isRemovable";
+ object = JSValueToObject(context, lastValueList[i], NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ m_propertyValue.storageInfo[i].isRemovable = JSValueToBoolean(context, JSObjectGetProperty(context, object, propertyName, NULL));
+ }
+
+ m_storageCnt = m_tmpStorageCnt;
+ break;
+
+ default :
+ LoggerD("default value");
+ break;
+ }
+ m_setLastValue = true;
return;
}
- else {
- JSValueUnprotect(context, m_lastValue);
- }
- JSValueRef* exception = NULL;
- if (m_BaseProperty->getWatchType() == WATCH_TYPE_CPU) {
+ if (watchType == WATCH_TYPE_CPU) {
tmpValue = ((Systeminfo*)m_Systeminfo)->getCpuValue(context);
} else {
tmpValue = m_BaseProperty->getValue(context, (void*)((Systeminfo*)m_Systeminfo)->getConnectionHandle());
}
- Converter converter(context);
if (!tmpValue) {
return;
}
- LoggerD("watchType : " << m_BaseProperty->getWatchType());
-
- if (m_BaseProperty->getWatchType() == WATCH_TYPE_BATTERY) {
- std::string key = "level";
- JSValueRef propertyLevel = getPropertyValue(context, tmpValue, key);
- double level = JSValueToNumber(context, propertyLevel, exception);
- propertyLevel = getPropertyValue(context, m_lastValue, key);
- double prevLevel = JSValueToNumber(context, propertyLevel, exception);
-
- key = "isCharging";
- JSValueRef propertyCharging = getPropertyValue(context, tmpValue, key);
- bool isCharging = JSValueToBoolean(context, propertyCharging);
- propertyCharging = getPropertyValue(context, m_lastValue, key);
- bool prevIsCharging = JSValueToBoolean(context, propertyCharging);
-
- if(level != prevLevel || isCharging != prevIsCharging) {
- if (((m_WatchOption.highThreshold > 0) && (level > m_WatchOption.highThreshold))
- || ((m_WatchOption.lowThreshold > 0) && (level < m_WatchOption.lowThreshold))
- || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_DISPLAY) {
- std::string key = "brightness";
- JSValueRef propertyBrightness = getPropertyValue(context, tmpValue, key);
- double brightness = JSValueToNumber(context, propertyBrightness, exception);
- propertyBrightness = getPropertyValue(context, m_lastValue, key);
- double prevBrightness = JSValueToNumber(context, propertyBrightness, exception);
-
- if(brightness != prevBrightness) {
- if (((m_WatchOption.highThreshold > 0) && (brightness > m_WatchOption.highThreshold))
- || ((m_WatchOption.lowThreshold > 0) && (brightness < m_WatchOption.lowThreshold))
- || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_WIFINETWORK) {
- std::string key = "status";
- JSValueRef propertyStatus = getPropertyValue(context, tmpValue, key);
- JSStringRef status = JSValueToStringCopy(context, propertyStatus, exception);
- propertyStatus = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevStatus = JSValueToStringCopy(context, propertyStatus, exception);
-
- key = "ssid";
- JSValueRef propertySsid = getPropertyValue(context, tmpValue, key);
- JSStringRef ssid = JSValueToStringCopy(context, propertySsid, exception);
- propertySsid = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevSsid = JSValueToStringCopy(context, propertySsid, exception);
-
- key = "signalStrength";
- JSValueRef propertySignalStrength = getPropertyValue(context, tmpValue, key);
- double signalStrength = JSValueToNumber(context, propertySignalStrength, exception);
- propertySignalStrength = getPropertyValue(context, m_lastValue, key);
- double prevSignalStrength = JSValueToNumber(context, propertySignalStrength, exception);
-
- if(!JSStringIsEqual(status,prevStatus) || !JSStringIsEqual(ssid,prevSsid) || signalStrength != prevSignalStrength) {
- if (((m_WatchOption.highThreshold > 0) && (signalStrength > m_WatchOption.highThreshold))
- || ((m_WatchOption.lowThreshold > 0) && (signalStrength < m_WatchOption.lowThreshold))
+
+ LoggerD("watchType : " << watchType);
+ switch(watchType) {
+ case WATCH_TYPE_BATTERY :
+ key = "level";
+ object = JSValueToObject(context, tmpValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ level = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ key = "isCharging";
+ object = JSValueToObject(context, tmpValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ isCharging = JSValueToBoolean(context, JSObjectGetProperty(context, object, propertyName, NULL));
+
+ if (m_propertyValue.batterInfo.level != level || m_propertyValue.batterInfo.isCharging != isCharging) {
+ if (((m_WatchOption.highThreshold > 0) && (level > m_WatchOption.highThreshold))
+ || ((m_WatchOption.lowThreshold > 0) && (level < m_WatchOption.lowThreshold))
|| ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
+ m_cbm->callOnSuccess(tmpValue);
+ setTimer();
+ }
}
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_CELLULARNETWORK) {
- std::string key = "status";
- JSValueRef propertyStatus = getPropertyValue(context, tmpValue, key);
- JSStringRef status = JSValueToStringCopy(context, propertyStatus, exception);
- propertyStatus = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevStatus = JSValueToStringCopy(context, propertyStatus, exception);
-
- key = "apn";
- JSValueRef propertyApn = getPropertyValue(context, tmpValue, key);
- JSStringRef apn = JSValueToStringCopy(context, propertyApn, exception);
- propertyApn = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevApn = JSValueToStringCopy(context, propertyApn, exception);
-
- key = "mcc";
- JSValueRef propertyMcc = getPropertyValue(context, tmpValue, key);
- double mcc = JSValueToNumber(context, propertyMcc, exception);
- propertyMcc = getPropertyValue(context, m_lastValue, key);
- double prevMcc = JSValueToNumber(context, propertyMcc, exception);
-
- key = "mnc";
- JSValueRef propertyMnc = getPropertyValue(context, tmpValue, key);
- double mnc = JSValueToNumber(context, propertyMnc, exception);
- propertyMnc = getPropertyValue(context, m_lastValue, key);
- double prevMnc = JSValueToNumber(context, propertyMnc, exception);
-
- key = "lac";
- JSValueRef propertyLac = getPropertyValue(context, tmpValue, key);
- JSStringRef lac = JSValueToStringCopy(context, propertyLac, exception);
- propertyLac = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevLac = JSValueToStringCopy(context, propertyLac, exception);
-
- key = "cellId";
- JSValueRef propertyCellId = getPropertyValue(context, tmpValue, key);
- JSStringRef cellId = JSValueToStringCopy(context, propertyCellId, exception);
- propertyCellId = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevCellId = JSValueToStringCopy(context, propertyCellId, exception);
-
- key = "isRoaming";
- JSValueRef propertyRoam = getPropertyValue(context, tmpValue, key);
- bool roam = JSValueToBoolean(context, propertyRoam);
- propertyRoam = getPropertyValue(context, m_lastValue, key);
- bool prevRoam = JSValueToBoolean(context, propertyRoam);
-
- key = "isFlightMode";
- JSValueRef propertyFlight = getPropertyValue(context, tmpValue, key);
- bool flight = JSValueToBoolean(context, propertyFlight);
- propertyFlight = getPropertyValue(context, m_lastValue, key);
- bool prevFlight = JSValueToBoolean(context, propertyFlight);
-
- if ( !JSStringIsEqual(status, prevStatus) || !JSStringIsEqual(apn, prevApn) || mcc != prevMcc || mnc != prevMnc
- || roam != prevRoam || flight != prevFlight || !JSStringIsEqual(lac, prevLac) || !JSStringIsEqual(cellId, prevCellId)) {
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_CPU) {
- std::string key = "load";
- JSValueRef propertyLoad = getPropertyValue(context, tmpValue, key);
- double load = JSValueToNumber(context, propertyLoad, exception);
- propertyLoad = getPropertyValue(context, m_lastValue, key);
- double prevLoad = JSValueToNumber(context, propertyLoad, exception);
-
- if(load != prevLoad) {
- if (((m_WatchOption.highThreshold > 0) && (load > m_WatchOption.highThreshold))
+ m_propertyValue.batterInfo.level = level;
+ m_propertyValue.batterInfo.isCharging = isCharging;
+ break;
+
+ case WATCH_TYPE_CPU :
+ key = "load";
+ object = JSValueToObject(context, tmpValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ load = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ if (m_propertyValue.cpuInfo.load != load) {
+ if (((m_WatchOption.highThreshold > 0) && (load > m_WatchOption.highThreshold))
|| ((m_WatchOption.lowThreshold > 0) && (load < m_WatchOption.lowThreshold))
|| ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
+ m_cbm->callOnSuccess(tmpValue);
+ setTimer();
+ }
+ }
+ m_propertyValue.cpuInfo.load = load;
+ break;
+
+ case WATCH_TYPE_STORAGE :
+ if (m_tmpStorageCnt > MAX_STORAGE_CNT) {
+ Throw(Exception);
+ }
+
+ for (int i=0; i<m_tmpStorageCnt; i++) {
+ tmpValueList[i] = JSGetArrayElement(context, JSValueToObject(context, tmpValue, NULL), i);
+ key = "capacity";
+ object = JSValueToObject(context, tmpValueList[i], NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ capacity[i] = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ key = "availableCapacity";
+ object = JSValueToObject(context, tmpValueList[i], NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ availableCapacity[i] = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+
+ key = "isRemovable";
+ object = JSValueToObject(context, tmpValueList[i], NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ isRemovable[i] = JSValueToBoolean(context, JSObjectGetProperty(context, object, propertyName, NULL));
+ }
+
+ if (m_tmpStorageCnt == m_storageCnt) {
+ for (int k=0; k<m_tmpStorageCnt; k++) {
+ if (m_propertyValue.storageInfo[k].capacity != capacity[k] || m_propertyValue.storageInfo[k].availableCapacity != availableCapacity[k]
+ || m_propertyValue.storageInfo[k].isRemovable != isRemovable[k]) {
+ LoggerD("make callback");
+ m_cbm->callOnSuccess(tmpValue);
+ setTimer();
+ break;
+ }
+ }
+ } else {
m_cbm->callOnSuccess(tmpValue);
setTimer();
}
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_STORAGE) {
- JSValueRef tmpValueList[MAX_STORAGE_CNT];
- JSValueRef lastValueList[MAX_STORAGE_CNT];
- if (m_tmpStorageCnt > MAX_STORAGE_CNT) {
- Throw(Exception);
- }
-
- for (int i=0; i<m_tmpStorageCnt; i++) {
- tmpValueList[i] = JSGetArrayElement(context, JSValueToObject(context, tmpValue, NULL), i);
- }
- for (int j=0; j<m_storageCnt; j++) {
- lastValueList[j] = JSGetArrayElement(context, JSValueToObject(context, m_lastValue, NULL), j);
- }
+ m_storageCnt = m_tmpStorageCnt;
+ for (int j=0; j<m_tmpStorageCnt; j++) {
+ m_propertyValue.storageInfo[j].capacity = capacity[j];
+ m_propertyValue.storageInfo[j].availableCapacity = availableCapacity[j];
+ m_propertyValue.storageInfo[j].isRemovable = isRemovable[j];
+ }
+ break;
- if (m_tmpStorageCnt == m_storageCnt) {
- LoggerD("enter");
- for (int i=0; i<m_tmpStorageCnt; i++) {
- LoggerD("enter");
- std::string key = "type";
- JSValueRef propertyType = getPropertyValue(context, tmpValueList[i], key);
- JSStringRef type = JSValueToStringCopy(context, propertyType, exception);
- propertyType = getPropertyValue(context, lastValueList[i], key);
- JSStringRef prevType = JSValueToStringCopy(context, propertyType, exception);
-
- key = "capacity";
- JSValueRef propertyCapacity = getPropertyValue(context, tmpValueList[i], key);
- double capacity = JSValueToNumber(context, propertyCapacity, exception);
- propertyCapacity = getPropertyValue(context, lastValueList[i], key);
- double prevCapacity = JSValueToNumber(context, propertyCapacity, exception);
- LoggerD("capacity : " << capacity << "prevCapacity : " << prevCapacity);
-
- key = "availableCapacity";
- JSValueRef propertyAvailableCapacity = getPropertyValue(context, tmpValueList[i], key);
- double availableCapacity = JSValueToNumber(context, propertyAvailableCapacity, exception);
- propertyAvailableCapacity = getPropertyValue(context, lastValueList[i], key);
- double prevAvailableCapacity = JSValueToNumber(context, propertyAvailableCapacity, exception);
- LoggerD("availableCapacity : " << availableCapacity << "prevAvailableCapacity : " << prevAvailableCapacity);
-
- key = "isRemoveable";
- JSValueRef propertyIsRemoveable = getPropertyValue(context, tmpValueList[i], key);
- bool isRemoveable = JSValueToBoolean(context, propertyIsRemoveable);
- propertyIsRemoveable = getPropertyValue(context, lastValueList[i], key);
- double prevIsRemoveable = JSValueToBoolean(context, propertyIsRemoveable);
- LoggerD("isRemoveable : " << propertyIsRemoveable << "prevIsRemoveable : " << prevIsRemoveable);
-
- if (!JSStringIsEqual(type, prevType) || capacity != prevCapacity || availableCapacity != prevAvailableCapacity
- || isRemoveable != prevIsRemoveable) {
- LoggerD("make callback");
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- m_lastValue = tmpValue;
+ case WATCH_TYPE_DISPLAY :
+ key = "brightness";
+ object = JSValueToObject(context, tmpValue, NULL);
+ propertyName = JSStringCreateWithUTF8CString(key.c_str());
+ brightness = JSValueToNumber(context, JSObjectGetProperty(context, object, propertyName, NULL), NULL);
+ if (((m_WatchOption.highThreshold > 0) && (brightness > m_WatchOption.highThreshold))
+ || ((m_WatchOption.lowThreshold > 0) && (brightness < m_WatchOption.lowThreshold))
+ || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
+ LoggerD("make callback");
+ m_cbm->callOnSuccess(tmpValue);
+ setTimer();
}
- } else {
- LoggerD("enter");
- m_cbm->callOnSuccess(tmpValue);
- m_storageCnt = m_tmpStorageCnt;
- m_lastValue = tmpValue;
- setTimer();
- }
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_DEVICE_ORIENTATION) {
- std::string key = "status";
- JSValueRef propertyStatus = getPropertyValue(context, tmpValue, key);
- double status = JSValueToNumber(context, propertyStatus, exception);
- propertyStatus = getPropertyValue(context, m_lastValue, key);
- double prevStatus = JSValueToNumber(context, propertyStatus, exception);
- LoggerD("status : " << status << "prevStatus : " << prevStatus);
- if (status != prevStatus) {
+ break;
+
+ case WATCH_TYPE_WIFINETWORK :
+ case WATCH_TYPE_CELLULARNETWORK :
+ case WATCH_TYPE_DEVICE_ORIENTATION :
+ case WATCH_TYPE_NETWORK :
+ case WATCH_TYPE_LOCALE :
+ case WATCH_TYPE_PERIPHERAL :
LoggerD("make callback");
m_cbm->callOnSuccess(tmpValue);
setTimer();
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_NETWORK) {
- std::string key = "networkType";
- JSValueRef propertyNetworkType = getPropertyValue(context, tmpValue, key);
- JSStringRef networkType = JSValueToStringCopy(context, propertyNetworkType, exception);
- propertyNetworkType = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevNetworkType = JSValueToStringCopy(context, propertyNetworkType, exception);
- LoggerD("networkType : " << networkType << "prevNetworkType : " << prevNetworkType);
- if (!JSStringIsEqual(networkType ,prevNetworkType)) {
- LoggerD("make callback");
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_LOCALE) {
- std::string key = "country";
- JSValueRef propertyCountry = getPropertyValue(context, tmpValue, key);
- JSStringRef country = JSValueToStringCopy(context, propertyCountry, exception);
- propertyCountry = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevCountry = JSValueToStringCopy(context, propertyCountry, exception);
- LoggerD("country : " << country << " prevCountry : " << prevCountry);
-
- key = "language";
- JSValueRef propertyLanguage = getPropertyValue(context, tmpValue, key);
- JSStringRef language = JSValueToStringCopy(context, propertyLanguage, exception);
- propertyLanguage = getPropertyValue(context, m_lastValue, key);
- JSStringRef prevLanguage = JSValueToStringCopy(context, propertyLanguage, exception);
- LoggerD("language : " << language << " prevLanguage : " << prevLanguage);
-
- if (!JSStringIsEqual(language, prevLanguage) || !JSStringIsEqual(country, prevCountry)) {
- LoggerD("make callback");
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- m_lastValue = tmpValue;
- } else if (m_BaseProperty->getWatchType() == WATCH_TYPE_PERIPHERAL) {
- std::string key = "isVideoOutputOn";
- JSValueRef propertyisVideoOutputOn = getPropertyValue(context, tmpValue, key);
- bool isVideoOutputOn = JSValueToBoolean(context, propertyisVideoOutputOn);
- propertyisVideoOutputOn = getPropertyValue(context, m_lastValue, key);
- bool prevIsVideoOutputOn = JSValueToBoolean(context, propertyisVideoOutputOn);
-
- if(isVideoOutputOn != prevIsVideoOutputOn) {
- m_cbm->callOnSuccess(tmpValue);
- setTimer();
- }
- m_lastValue = tmpValue;
+ break;
}
-
- JSValueProtect(context, m_lastValue);
}
void EventWatchSysteminfo::setTimer()
namespace Systeminfo {
class EventWatchSysteminfo;
+struct BatteryPropertyValue {
+ double level;
+ bool isCharging;
+};
+
+struct CpuPropertyValue {
+ double load;
+};
+
+struct StoragePropertyValue {
+ unsigned long long capacity;
+ unsigned long long availableCapacity;
+ bool isRemovable;
+};
+
+struct PropertyValue {
+ BatteryPropertyValue batterInfo;
+ CpuPropertyValue cpuInfo;
+ StoragePropertyValue storageInfo[3];
+};
+
class EventWatchSysteminfo : public WrtDeviceApis::Commons::IEvent<EventWatchSysteminfo>
{
private :
long m_id;
int m_watchType;
bool m_canceled;
- JSValueRef m_lastValue;
DPL::Mutex m_mutex;
int m_storageCnt;
int m_tmpStorageCnt;
+ PropertyValue m_propertyValue;
+ bool m_setLastValue;
public :
EventWatchSysteminfo();
void getWatchValue(int cnt = 1);
int getId() const;
void setId(int id);
- JSValueRef getPropertyValue(JSContextRef context, JSValueRef value, std::string key);
void processGetValue();
void setTimer();
void removeTimer();
case WATCH_TYPE_CELLULARNETWORK:
if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback);
+ vconf_ignore_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback);
+ vconf_ignore_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback);
if (m_networkRegist == REGIST_CELLULAR) {
connection_unset_ip_address_changed_cb(m_connectionHandle);
m_networkRegist = REGIST_NOT;
void Systeminfo::getWatchValue(const int watchType)
{
+ LoggerD(" watch type : " << watchType);
+
if (watchType == WATCH_TYPE_BATTERY) {
EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
case WATCH_TYPE_CELLULARNETWORK:
if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
+ vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
+ vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
if (m_networkRegist == REGIST_NOT) {
connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
m_networkRegist = REGIST_CELLULAR;