+++ /dev/null
-Jongman Park <jman.park@samsung.com>
-Ja-young Gu <jygu@samsung.com>
-Kyeongchul Kim <kyeongchul.kim@samsung.com>
-DongHoo Park <donghoo.park@samsung.>
-Youngman Park <youngman.park@samsung.com>
-Inho Oh <inho48.oh@samsung.com>
# Set required packages
INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED glib-2.0 dbus-glib-1 dlog tcore iniparser)
+pkg_check_modules(pkgs REQUIRED glib-2.0 gio-2.0 gio-unix-2.0 tcore libtzplatform-config iniparser)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/include/ ${CMAKE_SOURCE_DIR}/cmake_tmp )
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -fvisibility=hidden -fPIC")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wcast-align")
-ADD_DEFINITIONS("-DFEATURE_DLOG_DEBUG")
-ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"PACKETSERVICE\"")
+### Purge unused code ###
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections")
+
+ADD_DEFINITIONS("-DFEATURE_TLOG_DEBUG")
+ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"PS\"")
+ADD_DEFINITIONS("-DPLUGIN_VERSION=${VERSION}")
+ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))")
MESSAGE(${CMAKE_C_FLAGS})
-MESSAGE(${CMAKE_EXE_LINKER_FLAGS})
+MESSAGE(${pkgs_LDFLAGS})
SET(SRCS
- src/main.c
- src/master.c
- src/modem.c
- src/service.c
- src/context.c
- src/error.c
- src/tcore-interface.c
+ src/main.c
+ src/master.c
+ src/modem.c
+ src/service.c
+ src/context.c
+ src/tcore-interface.c
)
-# library build
-ADD_LIBRARY(ps-plugin SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(ps-plugin ${pkgs_LDFLAGS})
-SET_TARGET_PROPERTIES(ps-plugin PROPERTIES PREFIX "" OUTPUT_NAME ps-plugin)
+SET(INTROSPECTION_PATH ${CMAKE_SOURCE_DIR}/introspection)
-ADD_CUSTOM_TARGET(ps-iface-master-glue.h
- COMMAND dbus-binding-tool --mode=glib-server --prefix=ps_iface_master
- --output=${CMAKE_SOURCE_DIR}/include/ps-iface-master-glue.h
- ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-master.xml
- DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-master.xml
-)
-ADD_CUSTOM_TARGET(ps-iface-modem-glue.h
- COMMAND dbus-binding-tool --mode=glib-server --prefix=ps_iface_modem
- --output=${CMAKE_SOURCE_DIR}/include/ps-iface-modem-glue.h
- ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-modem.xml
- DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-modem.xml
-)
-ADD_CUSTOM_TARGET(ps-iface-service-glue.h
- COMMAND dbus-binding-tool --mode=glib-server --prefix=ps_iface_service
- --output=${CMAKE_SOURCE_DIR}/include/ps-iface-service-glue.h
- ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-service.xml
- DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-service.xml
-)
-ADD_CUSTOM_TARGET(ps-iface-context-glue.h
- COMMAND dbus-binding-tool --mode=glib-server --prefix=ps_iface_context
- --output=${CMAKE_SOURCE_DIR}/include/ps-iface-context-glue.h
- ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-context.xml
- DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/ps-iface-context.xml
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_BINARY_DIR}/generated-code.c
+ COMMAND gdbus-codegen --interface-prefix com.tcore.ps.
+ --generate-c-code generated-code
+ --c-namespace PacketService
+ --c-generate-object-manager
+ --generate-docbook generated-docs
+ ${INTROSPECTION_PATH}/master.xml
+ ${INTROSPECTION_PATH}/modem.xml
+ ${INTROSPECTION_PATH}/service.xml
+ ${INTROSPECTION_PATH}/context.xml
+ COMMENT "Generating GDBus .c/.h"
)
-ADD_DEPENDENCIES(${PROJECT_NAME} ps-iface-master-glue.h)
-ADD_DEPENDENCIES(${PROJECT_NAME} ps-iface-modem-glue.h)
-ADD_DEPENDENCIES(${PROJECT_NAME} ps-iface-service-glue.h)
-ADD_DEPENDENCIES(${PROJECT_NAME} ps-iface-context-glue.h)
+# library build
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${CMAKE_BINARY_DIR}/generated-code.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME})
# install
INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/ps-plugin.conf DESTINATION ${SYSCONFDIR}/dbus-1/system.d)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/dnet_db.sql DESTINATION ${DATAROOTDIR}/ps-plugin)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/dnet_db_data.sql DESTINATION ${DATAROOTDIR}/ps-plugin)
-INSTALL(TARGETS ps-plugin LIBRARY DESTINATION ${LIB_INSTALL_DIR}/telephony/plugins)
+INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR}/telephony/plugins)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME tel-plugin-packetservice)
+++ /dev/null
-/*
- * tel-plugin-packetservice
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
- *
- * 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.
- *
- */
-
-#ifndef __PS_CONTEXT_H__
-#define __PS_CONTEXT_H__
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct PsContext PsContext;
-typedef struct PsContextClass PsContextClass;
-
-#define PS_TYPE_CONTEXT ( ps_context_get_type() )
-#define PS_CONTEXT(obj) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), PS_TYPE_CONTEXT, PsContext ) )
-#define PS_IS_CONTEXT(obj) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), PS_TYPE_CONTEXT) )
-
-#define PS_CONTEXT_CLASS(klass) ( G_TYPE_CHECK_CLASS_CAST( (klass), PS_TYPE_CONTEXT, PsContextClass ) )
-#define PS_IS_CONTEXT_CLASS(klass) ( G_TYPE_CHECK_CLASS_TYPE( (klass), PS_TYPE_CONTEXT ) )
-#define PS_CONTEXT_GET_CLASS(obj) ( G_TYPE_INSTANCE_GET_CLASS( (obj), PS_TYPE_CONTEXT, PsContextClass ) )
-
-GType ps_context_get_type(void);
-
-G_END_DECLS
-
-#endif /* __PS_CONTEXT_H__ */
+++ /dev/null
-/*
- * tel-plugin-packetservice
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
- *
- * 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.
- *
- */
-
-#ifndef __PS_ERROR_H__
-#define __PS_ERROR_H__
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-typedef enum {
- PS_ERR_INTERNAL,
- PS_ERR_NO_SERVICE,
- PS_ERR_TRASPORT,
- PS_ERR_NO_PROFILE,
- PS_ERR_WRONG_PROFILE,
- PS_ERR_MAX
-} PS_ERR;
-
-GQuark ps_error_quark(void);
-
-#define PS_ERROR ( ps_error_quark() )
-
-G_END_DECLS
-
-#endif /* __PS_ERROR_H__ */
+++ /dev/null
-/*
- * tel-plugin-packetservice
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
- *
- * 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.
- *
- */
-
-#ifndef __PS_MASTER_H__
-#define __PS_MASTER_H__
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct PsMaster PsMaster;
-typedef struct PsMasterClass PsMasterClass;
-
-#define PS_TYPE_MASTER ( ps_master_get_type() )
-#define PS_MASTER(obj) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), PS_TYPE_MASTER, PsMaster ) )
-#define PS_IS_MASTER(obj) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), PS_TYPE_MASTER) )
-
-#define PS_MASTER_CLASS(klass) ( G_TYPE_CHECK_CLASS_CAST( (klass), PS_TYPE_MASTER, PsMasterClass ) )
-#define PS_IS_MASTER_CLASS(klass) ( G_TYPE_CHECK_CLASS_TYPE( (klass), PS_TYPE_MASTER ) )
-#define PS_MASTER_GET_CLASS(obj) ( G_TYPE_INSTANCE_GET_CLASS( (obj), PS_TYPE_MASTER, PsMasterClass ) )
-
-GType ps_master_get_type(void);
-
-G_END_DECLS
-
-#endif /* __PS_MASTER_H__ */
+++ /dev/null
-/*
- * tel-plugin-packetservice
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
- *
- * 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.
- *
- */
-
-#ifndef __PS_MODEM_H__
-#define __PS_MODEM_H__
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct PsModem PsModem;
-typedef struct PsModemClass PsModemClass;
-
-#define PS_TYPE_MODEM ( ps_modem_get_type() )
-#define PS_MODEM(obj) ( G_TYPE_CHECK_INSTANCE_CAST( (obj),PS_TYPE_MODEM, PsModem ) )
-#define PS_IS_MODEM(obj) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), PS_TYPE_MODEM) )
-
-#define PS_MODEM_CLASS(klass) ( G_TYPE_CHECK_CLASS_CAST( (klass), PS_TYPE_MODEM, PsModemClass ) )
-#define PS_IS_MODEM_CLASS(klass) ( G_TYPE_CHECK_CLASS_TYPE( (klass), PS_TYPE_MODEM ) )
-#define PS_MODEM_GET_CLASS(obj) ( G_TYPE_INSTANCE_GET_CLASS( (obj), PS_TYPE_MODEM, PsModemClass ) )
-
-GType ps_modem_get_type(void);
-
-G_END_DECLS
-
-#endif /* __PS_MODEM_H__ */
+++ /dev/null
-/*
- * tel-plugin-packetservice
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
- *
- * 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.
- *
- */
-
-#ifndef __PS_SERVICE_H__
-#define __PS_SERVICE_H__
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct PsService PsService;
-typedef struct PsServiceClass PsServiceClass;
-
-#define PS_TYPE_SERVICE ( ps_service_get_type() )
-#define PS_SERVICE(obj) ( G_TYPE_CHECK_INSTANCE_CAST( (obj),PS_TYPE_SERVICE, PsService ) )
-#define PS_IS_SERVICE(obj) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), PS_TYPE_SERVICE) )
-
-#define PS_SERVICE_CLASS(klass) ( G_TYPE_CHECK_CLASS_CAST( (klass), PS_TYPE_SERVICE, PsServiceClass ) )
-#define PS_IS_SERVICE_CLASS(klass) ( G_TYPE_CHECK_CLASS_TYPE( (klass), PS_TYPE_SERVICE ) )
-#define PS_SERVICE_GET_CLASS(obj) ( G_TYPE_INSTANCE_GET_CLASS( (obj), PS_TYPE_SERVICE, PsServiceClass ) )
-
-GType ps_service_get_type(void);
-
-G_END_DECLS
-
-#endif /* __PS_SERVICE_H__ */
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
#ifndef __PS_H__
#define __PS_H__
#include <stdlib.h>
#include <string.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#include <tcore.h>
#include <plugin.h>
#include <storage.h>
#include <server.h>
#include <core_object.h>
+#include <type/ps.h>
#include <hal.h>
+#include "generated-code.h"
+
+#define FAIL_RESPONSE(ivc,msg) g_dbus_method_invocation_return_error (ivc, \
+ G_DBUS_ERROR, G_DBUS_ERROR_FAILED, msg);
+
+
+#define PS_NO_PENDING_REQUEST 0x00
+
+#define PS_NETWORK_SEARCH_PENDING 0x01
+#define PS_RESET_NETWORK_SEARCH_FLAG 0x0E
+
+#define PS_NETWORK_SELECTION_PENDING 0x02
+#define PS_NETWORK_RESET_SELECTION_FLAG 0x0D
+
+#define PS_NETWORK_SELECT_MODE 0x04
+#define PS_NETWORK_RESET_SELECT_MODE_FLAG 0x0B
+
+#define PS_NETWORK_GET_MODE 0x08
+#define PS_NETWORK_RESET_GET_MODE_FLAG 0x07
+
/*Storage Key value*/
#define KEY_3G_ENABLE STORAGE_KEY_3G_ENABLE
#define KEY_DATA_ROAMING_SETTING STORAGE_KEY_SETAPPL_STATE_DATA_ROAMING_BOOL
+#define KEY_DATA_ROAMING_APP_SETTING STORAGE_KEY_SETAPPL_STATE_DATA_ROAMING_APP_STATUS
+#define KEY_POWER_SAVING_MODE STORAGE_KEY_POWER_SAVING_MODE
+#define KEY_PM_STATE STORAGE_KEY_PM_STATE
+#define KEY_NETWORK_RESTRICT_MODE STORAGE_KEY_SETAPPL_NETWORK_RESTRICT_MODE
+
+#define PS_ERR_INTERNAL "Internal Error"
+#define PS_ERR_NO_SERVICE "NO service"
+#define PS_ERR_TRASPORT "No Transport"
+#define PS_ERR_NO_PROFILE "No Profile"
+#define PS_ERR_WRONG_PROFILE "Wrong Profile"
+#define PS_ERR_MAX "Unknown Error"
+
+/* Tizen Power saving mode */
+#define POWER_SAVING_MODE_NORMAL 0
+#define POWER_SAVING_MODE_ECO 1
+#define POWER_SAVING_MODE_ECO_PLUS 2
+#define POWER_SAVING_MODE_SURVIVAL 3
+
+typedef struct {
+ gchar *path;
+ TcorePlugin *plg;
+ GDBusConnection *conn;
+ PacketServiceMaster *if_obj;
+ GHashTable *modems;
+} PsMaster;
+
+typedef struct {
+ gchar* path;
+ gpointer p_master;
+ TcorePlugin *plg;
+ CoreObject *co_modem;
+ GDBusConnection *conn;
+ PacketServiceModem *if_obj;
+
+ /*Value from modem*/
+ gchar* operator;
+ gboolean powered;
+ gboolean sim_init;
+ gboolean flight_mode;
+
+ gboolean roaming_allowed;
+ gboolean roaming;
+
+ gboolean data_allowed;
+ GHashTable *services;
+}PsModem;
+
+typedef struct {
+ gchar *path;
+ TcorePlugin *plg;
+ GDBusConnection *conn;
+ PacketServiceService *if_obj;
+
+ gpointer p_modem;
+ CoreObject *co_network;
+ CoreObject *co_ps;
+
+ gboolean ps_attached;
+ gboolean roaming;
+ gboolean restricted;
+ TelNetworkAct act;
+
+ GHashTable *contexts;
+} PsService;
+
+typedef struct {
+ gchar* path;
+ gchar* mccmnc;
+ GDBusConnection *conn;
+ PacketServiceContext *if_obj;
+ TcorePlugin *plg;
+
+ gboolean alwayson;
+ gboolean default_internet;
+ gboolean hidden;
+ gboolean editable;
+ gboolean ps_defined;
+ gboolean b_active;
+ gpointer p_service;
+ gint profile_id;
+ CoreObject *co_context;
+
+ gpointer async_context;
+ gpointer user_data;
+} PsContext;
+
+typedef struct {
+ GDBusConnection *conn;
+ guint bus_id;
+ TcorePlugin *p;
+ GSList *master;
+} PsCustom;
+
+
+void _packet_service_cleanup();
+TcoreHookReturn __on_hook_modem_added(Server *server,
+ TcoreServerNotification command, guint data_len, void *data,
+ void *user_data);
/*MASTER*/
-gpointer _ps_master_create_master(DBusGConnection *conn, TcorePlugin *p);
+void __remove_master(gpointer master, gpointer user_data);
+gpointer _ps_master_create_master(GDBusConnection *conn, TcorePlugin *p);
gboolean _ps_master_create_modems(gpointer master);
-gboolean _ps_master_get_storage_value(gpointer master, enum tcore_storage_key key);
-gboolean _ps_master_set_storage_value(gpointer master, enum tcore_storage_key key, gboolean value);
+gboolean _ps_master_get_storage_value_bool(gpointer master, TcoreStorageKey key);
+gboolean _ps_master_get_storage_value_int(gpointer master, TcoreStorageKey key);
+gboolean _ps_master_set_storage_value_bool(gpointer master, TcoreStorageKey key, gboolean value);
+gboolean _ps_master_set_storage_value_int(gpointer master, TcoreStorageKey key, gint value);
/*MODEM*/
-gpointer _ps_modem_create_modem(DBusGConnection *conn, TcorePlugin *p, gpointer master,
+void __remove_modem_handler(gpointer modem);
+gpointer _ps_modem_create_modem(GDBusConnection *conn, TcorePlugin *p, gpointer master,
gchar* modem_name, gpointer co_modem);
gboolean _ps_modem_processing_flight_mode(gpointer object, gboolean enable);
gboolean _ps_modem_processing_power_enable(gpointer modem, gboolean enable);
gboolean _ps_modem_get_data_allowed(gpointer modem);
gboolean _ps_modem_set_data_roaming_allowed(gpointer modem, gboolean value);
gboolean _ps_modem_get_data_roaming_allowed(gpointer modem);
+gboolean _ps_modem_get_roaming(gpointer object);
+void _ps_modem_set_roaming(gpointer object, gboolean value);
+gboolean _ps_modem_set_psmode(gpointer modem, gint value);
+gboolean _ps_modem_get_psmode(gpointer modem);
gboolean _ps_modem_get_flght_mode(gpointer object);
gboolean _ps_modem_get_sim_init(gpointer object);
gboolean _ps_modem_get_power(gpointer object);
gchar* _ps_modem_ref_operator(gpointer object);
-gboolean _ps_modem_get_properties(gpointer modem, GHashTable *properties);
+gboolean _ps_modem_get_properties_handler(gpointer object, GVariantBuilder * properties);
+GVariant* _ps_modem_get_properties(gpointer object, GVariantBuilder *properties);
GHashTable* _ps_modem_ref_services(gpointer modem);
gchar* _ps_modem_ref_path(gpointer modem);
gpointer _ps_modem_ref_plugin(gpointer modem);
gpointer _ps_modem_ref_dbusconn(gpointer modem);
gpointer _ps_modem_ref_co_modem(gpointer modem);
+gpointer _ps_modem_ref_work_queue(gpointer modem);
/*SERVICE*/
-gpointer _ps_service_create_service(DBusGConnection *conn, TcorePlugin *p,
+void __remove_service_handler(gpointer service);
+gpointer _ps_service_create_service(GDBusConnection *conn, TcorePlugin *p,
gpointer modem, CoreObject *co_network, CoreObject *co_ps, gchar* path);
gboolean _ps_service_ref_context(gpointer object, gpointer context);
gboolean _ps_service_ref_contexts(gpointer service, GHashTable *contexts, gchar *operator);
gboolean _ps_service_unref_context(gpointer service, gpointer context);
-gboolean _ps_service_get_properties(gpointer service, GHashTable *properties);
+gboolean _ps_service_get_properties_handler(gpointer object, GVariantBuilder *properties);
+GVariant* _ps_service_get_properties(gpointer object, GVariantBuilder *properties);
gchar* _ps_service_ref_path(gpointer service);
gpointer _ps_service_ref_plugin(gpointer service);
gpointer _ps_service_ref_co_network(gpointer service);
gpointer _ps_service_ref_co_ps(gpointer service);
-gboolean _ps_service_set_context_info(gpointer service, struct tnoti_ps_pdp_ipconfiguration *devinfo);
-int _ps_service_define_context(gpointer object, gpointer context);
-int _ps_service_activate_context(gpointer service, gpointer context);
-gboolean _ps_service_deactivate_context(gpointer service, gpointer context);
+gpointer _ps_service_ref_modem(gpointer object);
+gboolean _ps_service_set_context_info(gpointer service, TcorePsPdpIpConf *devinfo);
+gint _ps_service_define_context(gpointer object, gpointer context);
+gint _ps_service_activate_context(gpointer service, gpointer context);
+gint _ps_service_deactivate_context(gpointer service, gpointer context);
+void _ps_service_set_retry_timeout_value(int value);
void _ps_service_connection_timer(gpointer service, gpointer context);
void _ps_service_reset_connection_timer(gpointer context);
-void _ps_service_connect_default_context(gpointer service);
+int _ps_service_connect_default_context(gpointer service);
void _ps_service_remove_contexts(gpointer object);
void _ps_service_disconnect_contexts(gpointer service);
gboolean _ps_service_processing_network_event(gpointer service, gboolean ps_attached, gboolean roaming);
gpointer _ps_service_return_default_context(gpointer object);
-gboolean _ps_service_set_connected(gpointer service, int context_id, gboolean enabled);
-void _ps_service_set_ps_defined(gpointer *object, gboolean value, int cid);
+gboolean _ps_service_set_connected(gpointer service, gint context_id, gboolean enabled);
+void _ps_service_set_ps_defined(gpointer *object, gboolean value, gint cid);
gboolean _ps_service_set_ps_attached(gpointer service, gboolean value);
+//gboolean _ps_service_set_number_of_pdn_cnt(gpointer object, gchar *operator);
gboolean _ps_service_set_roaming(gpointer service, gboolean value);
gboolean _ps_service_get_roaming(gpointer object);
+gboolean _ps_service_set_restricted(gpointer object, gboolean value);
+gboolean _ps_service_get_restricted(gpointer object);
gboolean _ps_service_set_access_technology(gpointer service,
- enum telephony_network_access_technology value);
-enum telephony_ps_state
- _ps_service_check_cellular_state(gpointer object);
+ TelNetworkAct value);
+TcorePsState _ps_service_check_cellular_state(gpointer object);
/*CONTEXT*/
+void __remove_context_handler(gpointer context);
gboolean _ps_context_initialize(gpointer plugin);
gboolean _ps_context_reset_profile_table(void);
gboolean _ps_context_fill_profile_table_from_ini_file(void);
gboolean _ps_context_reset_hashtable(void);
-GHashTable* _ps_context_create_hashtable(DBusGConnection *conn, TcorePlugin *p, gchar *mccmnc);
+GHashTable* _ps_context_create_hashtable(GDBusConnection *conn, TcorePlugin *p, gchar *mccmnc);
GHashTable* _ps_context_ref_hashtable(void);
gboolean _ps_context_add_context(gpointer modem, gchar *operator, GHashTable *property);
-gboolean _ps_context_get_properties(gpointer context, GHashTable *properties);
+gboolean _ps_context_get_properties_handler(gpointer context, GVariantBuilder *properties);
+GVariant* _ps_context_get_properties(gpointer context, GVariantBuilder *properties);
gboolean _ps_context_set_service(gpointer context, gpointer service);
gpointer _ps_context_ref_service(gpointer object);
gboolean _ps_context_get_alwayson_enable(gpointer object);
gchar* _ps_context_ref_path(gpointer context);
gpointer _ps_context_ref_co_context(gpointer context);
gboolean _ps_context_set_connected(gpointer context, gboolean enabled);
-gboolean _ps_context_set_ps_defined(gpointer *object, gboolean value, int cid);
+gboolean _ps_context_set_ps_defined(gpointer *object, gboolean value, gint cid);
gboolean _ps_context_get_ps_defined(gpointer *object);
gboolean _ps_context_set_alwayson_enable(gpointer object, gboolean enabled);
gboolean _ps_context_get_default_internet(gpointer object);
gboolean _ps_context_remove_context(gpointer context);
+gboolean _ps_context_reset_user_data(gpointer object);
+gpointer _ps_context_get_user_data(gpointer object);
+TelReturn _ps_connection_hdlr(gpointer object);
+void _ps_default_connection_hdlr(gpointer object);
+gint _ps_context_get_number_of_pdn(gchar *operator);
+gboolean _ps_context_handle_ifaceup(gpointer user_data);
+gboolean _ps_context_handle_ifacedown(gpointer user_data);
+
/*PLUGIN INTERFACE*/
gboolean _ps_hook_co_modem_event(gpointer modem);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
- <interface name="com.tcore.ps.context">
- <method name="GetProperties">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{ss}" name="context_property" direction="out" />
- </method>
- <method name="GetProfile">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{ss}" name="profile_property" direction="out" />
- </method>
- <method name="Activate">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="s" name="context_path" direction="out" />
- </method>
- <method name="Deactivate">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="s" name="context_path" direction="out" />
- </method>
- <method name="SetDefaultConnection">
- <arg type="b" name="result" direction="out" />
- </method>
- <method name="ModifyProfile">
- <arg type="a{ss}" name="profile_property" direction="in" />
- <arg type="b" name="result" direction="out" />
- </method>
- <method name="RemoveProfile">
- <arg type="b" name="result" direction="out" />
- </method>
- <signal name="PropertyChanged">
- <arg type="a{ss}" name="context_property" direction="out" />
- </signal>
- </interface>
-</node>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
- <interface name="com.tcore.ps.master">
- <method name="GetModems">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{sa{ss}}" name="modem_hash" direction="out" />
- </method>
- <method name="GetProfileList">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="as" name="profile_list" direction="out" />
- </method>
- <method name="AddProfile">
- <arg type="a{ss}" name="profile_property" direction="in" />
- <arg type="b" name="result" direction="out" />
- </method>
- <method name="ResetProfile">
- <arg type="b" name="result" direction="out" />
- </method>
- <signal name="ModemAdded">
- <arg type="a{ss}" name="modem" direction="out" />
- </signal>
- <signal name="ModemRemoved">
- <arg type="o" name="modem_path" direction="out" />
- </signal>
- </interface>
-</node>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
- <interface name="com.tcore.ps.modem">
- <method name="GetProperties">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{ss}" name="modem_property" direction="out" />
- </method>
- <method name="GetServices">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{sa{ss}}" name="service_hash" direction="out" />
- </method>
- <signal name="PropertyChanged">
- <arg type="a{ss}" name="modem_property" direction="out" />
- </signal>
- <signal name="ServiceAdded">
- <arg type="a{ss}" name="service" direction="out" />
- </signal>
- <signal name="ServiceRemoved">
- <arg type="s" name="service_path" direction="out" />
- </signal>
- </interface>
-</node>
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
- <interface name="com.tcore.ps.service">
- <method name="GetProperties">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{ss}" name="service_property" direction="out" />
- </method>
- <method name="GetContexts">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="yes"/>
- <arg type="a{sa{ss}}" name="context_hash" direction="out" />
- </method>
- <signal name="PropertyChanged">
- <arg type="a{ss}" name="service_property" direction="out" />
- </signal>
- <signal name="ContextAdded">
- <arg type="a{ss}" name="context" direction="out" />
- </signal>
- <signal name="ContextRemoved">
- <arg type="s" name="context_path" direction="out" />
- </signal>
- </interface>
-</node>
-
--- /dev/null
+<node>
+ <interface name="com.tcore.ps.context">
+ <method name="GetProperties">
+ <arg type="a{ss}" name="context_property" direction="out" />
+ </method>
+ <method name="GetProfile">
+ <arg type="a{ss}" name="profile_property" direction="out" />
+ </method>
+ <method name="Activate">
+ <arg type="s" name="context_path" direction="out" />
+ </method>
+ <method name="Deactivate">
+ <arg type="s" name="context_path" direction="out" />
+ </method>
+ <method name="SetDefaultConnection">
+ <arg type="b" name="result" direction="out" />
+ </method>
+ <method name="ModifyProfile">
+ <arg type="a{ss}" name="profile_property" direction="in" />
+ <arg type="b" name="result" direction="out" />
+ </method>
+ <method name="RemoveProfile">
+ <arg type="b" name="result" direction="out" />
+ </method>
+ <signal name="PropertyChanged">
+ <arg type="a{ss}" name="context_property" direction="out" />
+ </signal>
+ </interface>
+</node>
--- /dev/null
+<node>
+ <interface name="com.tcore.ps.master">
+ <method name="GetModems">
+ <arg type="a{sa{ss}}" name="modem_hash" direction="out" />
+ </method>
+ <method name="GetProfileList">
+ <arg type="as" name="profile_list" direction="out" />
+ </method>
+ <method name="AddProfile">
+ <arg type="a{ss}" name="profile_property" direction="in" />
+ <arg type="b" name="result" direction="out" />
+ </method>
+ <method name="ResetProfile">
+ <arg type="i" name="type" direction="in" />
+ <arg type="b" name="result" direction="out" />
+ </method>
+ <signal name="ModemAdded">
+ <arg type="a{ss}" name="modem" direction="out" />
+ </signal>
+ <signal name="ModemRemoved">
+ <arg type="o" name="modem_path" direction="out" />
+ </signal>
+ </interface>
+</node>
--- /dev/null
+<node>
+ <interface name="com.tcore.ps.modem">
+ <method name="GetProperties">
+ <arg type="a{ss}" name="modem_property" direction="out" />
+ </method>
+ <method name="GetServices">
+ <arg type="a{sa{ss}}" name="service_hash" direction="out" />
+ </method>
+ <signal name="PropertyChanged">
+ <arg type="a{ss}" name="modem_property" direction="out" />
+ </signal>
+ <signal name="ServiceAdded">
+ <arg type="a{ss}" name="service" direction="out" />
+ </signal>
+ <signal name="ServiceRemoved">
+ <arg type="s" name="service_path" direction="out" />
+ </signal>
+ </interface>
+</node>
--- /dev/null
+<node>
+ <interface name="com.tcore.ps.service">
+ <method name="GetProperties">
+ <arg type="a{ss}" name="service_property" direction="out" />
+ </method>
+ <method name="GetContexts">
+ <arg type="a{sa{ss}}" name="context_hash" direction="out" />
+ </method>
+ <signal name="PropertyChanged">
+ <arg type="a{ss}" name="service_property" direction="out" />
+ </signal>
+ <signal name="ContextAdded">
+ <arg type="a{ss}" name="context" direction="out" />
+ </signal>
+ <signal name="ContextRemoved">
+ <arg type="s" name="context_path" direction="out" />
+ </signal>
+ </interface>
+</node>
+%define major 3
+%define minor 0
+%define patchlevel 1
+
Name: tel-plugin-packetservice
Summary: Telephony Packet Service library
-Version: 0.1.34
+Version: %{major}.%{minor}.%{patchlevel}
Release: 1
Group: System/Libraries
License: Apache-2.0
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: cmake
+BuildRequires: python
+BuildRequires: python-xml
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gio-unix-2.0)
BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(dbus-glib-1)
-BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(tcore)
BuildRequires: pkgconfig(iniparser)
BuildRequires: pkgconfig(libtzplatform-config)
-
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
%description
Telephony Packet Service library
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
-#include "ps-context.h"
-
+#include "generated-code.h"
#include "ps.h"
-#include "ps-error.h"
+
+#include <glib.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <iniparser.h>
+#include <tzplatform_config.h>
#include <tcore.h>
#include <plugin.h>
#include <server.h>
#include <storage.h>
#include <core_object.h>
+#include <co_ps.h>
#include <co_context.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <iniparser.h>
-#include <tzplatform_config.h>
-
#define PROP_DEFAULT FALSE
#define PROP_DEFAULT_STR NULL
-#define BOOL2STRING(a) ((a==TRUE) ? ("TRUE"):("FALSE"))
-
-/*Properties*/
-enum {
- PROP_CONTEXT_O,
-
- PROP_CONTEXT_PATH,
- PROP_CONTEXT_CONN,
- PROP_CONTEXT_PLUGIN,
- PROP_CONTEXT_MCCMNC
-};
-
-enum {
- SIG_CONTEXT_PROPERTY_CHANGED,
- SIG_CONTEXT_LAST
-};
-
-static guint32 signals[SIG_CONTEXT_LAST] = { 0, };
-
-struct PsContextClass {
- GObjectClass parent;
-
- //method and signals
- void (*property_changed)(PsContext *context, GHashTable *context_property);
-};
-
-struct PsContext {
- GObject parent;
-
- gchar* path;
- gchar* mccmnc;
- DBusGConnection *conn;
- TcorePlugin *plg;
-
- gboolean alwayson;
- gboolean default_internet;
- gboolean hidden;
- gboolean editable;
- gboolean ps_defined;
- gpointer p_service;
- int profile_id;
- CoreObject *co_context;
-};
-
-static Storage *strg_db;
+#define BOOL2STRING(a) ((a == TRUE) ? ("TRUE"):("FALSE"))
+#define DELAY_TO_SIGNAL_EMIT 1
+
+static TcoreStorage *strg_db;
static gpointer handle;
static GHashTable *contexts;
-G_DEFINE_TYPE(PsContext, ps_context, G_TYPE_OBJECT);
-
-static void __ps_context_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-static void __ps_context_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void __ps_context_emit_property_changed_signal(PsContext *context);
+static void _ps_context_setup_interface(PacketServiceContext *context, PsContext *context_data);
-gboolean ps_iface_context_get_properties(PsContext *pscontext, DBusGMethodInvocation *context);
-gboolean ps_iface_context_get_profile(PsContext *pscontext, DBusGMethodInvocation *context);
-gboolean ps_iface_context_activate(PsContext *pscontext, DBusGMethodInvocation *context);
-gboolean ps_iface_context_deactivate(PsContext *pscontext, DBusGMethodInvocation *context);
-gboolean ps_iface_context_set_default_connection(PsContext *pscontext, gboolean* result, GError **error);
-gboolean ps_iface_context_modify_profile(PsContext *pscontext, GHashTable *profile_property, gboolean* result, GError **error);
-gboolean ps_iface_context_remove_profile(PsContext *pscontext, gboolean* result, GError **error);
-
-static void __ps_context_emit_property_changed_signal(PsContext *context);
-
-static void __remove_context(gpointer data);
static gboolean __remove_contexts(gpointer key, gpointer value, gpointer user_data);
static gboolean __ps_context_remove_context(gpointer context);
static gboolean __ps_context_create_storage_handle(gpointer plugin);
static gboolean __ps_context_create_context_hash(void);
-static gchar* __ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id);
+static gchar *__ps_context_create_path(char *profile_name, gint profile_id, gint svc_ctg_id);
static gboolean __ps_context_create_co_context(gpointer context, GHashTable *property);
static gboolean __ps_context_update_profile(PsContext *context, GHashTable *property);
static gboolean __ps_context_update_database(PsContext *context);
static gboolean __ps_context_update_default_internet_to_db(PsContext *context, gboolean enabled);
static gboolean __ps_context_remove_database(PsContext *context);
-static int __ps_context_insert_network_id_to_database(gchar *mccmnc);
-static int __ps_context_load_network_id_from_database(gchar *mccmnc);
-static gchar* __ps_context_load_network_name_from_database(int network_id);
-static int __ps_context_load_profile_id_from_database(void);
-static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int index);
-static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id);
-static int __ps_context_get_network_id(gchar *mccmnc);
-static gboolean __ps_context_get_profile_properties(gpointer context, GHashTable *properties);
+static gint __ps_context_insert_network_id_to_database(gchar *mccmnc);
+static gint __ps_context_load_network_id_from_database(gchar *mccmnc);
+static gchar *__ps_context_load_network_name_from_database(gint network_id);
+static gint __ps_context_load_profile_id_from_database(void);
+static gint __ps_context_load_num_of_pdn_from_database(gchar *mccmnc);
+static gboolean __ps_context_insert_profile_tuple(dictionary *dic, gint index);
+static gint __ps_context_insert_profile_to_database(GHashTable *property, gint network_id);
+static gint __ps_context_get_network_id(gchar *mccmnc);
+GVariant *__ps_context_get_profile_properties(gpointer context, GVariantBuilder *properties);
static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled);
-#include "ps-iface-context-glue.h"
-
-static void ps_context_init(PsContext *context)
-{
- dbg("context initialize");
-
- context->path = NULL;
- context->mccmnc = NULL;
- context->conn = NULL;
- context->plg = NULL;
-
- context->alwayson = PROP_DEFAULT;
- context->default_internet = PROP_DEFAULT;
- context->hidden = PROP_DEFAULT;
- context->editable = PROP_DEFAULT;
- context->p_service = NULL;
- context->profile_id = 0;
- context->co_context = NULL;
-
- return;
-}
-
-static void ps_context_class_init(PsContextClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- //class init
- dbg("context class init");
-
- object_class->get_property = __ps_context_get_property;
- object_class->set_property = __ps_context_set_property;
-
- //dbus register
- dbus_g_object_type_install_info(PS_TYPE_CONTEXT, &dbus_glib_ps_iface_context_object_info);
-
- //property add
- g_object_class_install_property(
- object_class,
- PROP_CONTEXT_CONN,
- g_param_spec_boxed("conn", "CONNECTION", "DBus connection", DBUS_TYPE_G_CONNECTION,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property(
- object_class,
- PROP_CONTEXT_PATH,
- g_param_spec_string("path", "PATH", "Context Path", PROP_DEFAULT_STR,
- G_PARAM_READWRITE));
- g_object_class_install_property(
- object_class,
- PROP_CONTEXT_MCCMNC,
- g_param_spec_string("mccmnc", "MCCMNC", "Profile Country and Context Provider Code",
- PROP_DEFAULT_STR, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- g_object_class_install_property(
- object_class,
- PROP_CONTEXT_PLUGIN,
- g_param_spec_pointer("plg", "PLUGIN", "Plug in Object",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- //add signal handler
- signals[SIG_CONTEXT_PROPERTY_CHANGED] = g_signal_new("property-changed",
- G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(PsContextClass, property_changed), NULL, NULL,
- g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
-
- return;
-}
-
-static void __ps_context_set_property(GObject *object, guint prop_id, const GValue *value,
- GParamSpec *pspec)
-{
- PsContext *context = PS_CONTEXT(object);
-
- switch (prop_id) {
- case PROP_CONTEXT_CONN: {
- context->conn = g_value_get_boxed(value);
- msg("context (%p) set conn(%p)", context, context->conn);
- }
- break;
- case PROP_CONTEXT_PLUGIN: {
- context->plg = g_value_get_pointer(value);
- msg("context (%p) set plg(%p)", context, context->plg);
- }
- break;
- case PROP_CONTEXT_PATH: {
- if (context->path) {
- g_free(context->path);
- }
- context->path = g_value_dup_string(value);
- msg("context (%p) path(%s)", context, context->path);
- }
- break;
- case PROP_CONTEXT_MCCMNC: {
- if (context->mccmnc) {
- g_free(context->mccmnc);
- }
- context->mccmnc = g_value_dup_string(value);
- msg("context (%p) mccmnc(%s)", context, context->mccmnc);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- } //end of switch
-
- return;
-}
-
-static void __ps_context_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
- return;
-}
-
-static void __ps_context_emit_property_changed_signal(PsContext *context)
-{
- GHashTable *property;
-
- property = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_context_get_properties(context, property);
- g_signal_emit(context, signals[SIG_CONTEXT_PROPERTY_CHANGED], 0, property);
- g_hash_table_destroy(property);
- dbg("context (%p) emit the context property changed signal", context);
- return;
-}
-
-gboolean ps_iface_context_get_properties(PsContext *pscontext, DBusGMethodInvocation *context)
-{
- GHashTable *property;
-
- dbg("Get properties of context(%s)", _ps_context_ref_path(pscontext));
- property = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_context_get_properties(pscontext, property);
-
- dbus_g_method_return(context, property);
- g_hash_table_destroy(property);
- return TRUE;
-}
-
-gboolean ps_iface_context_get_profile(PsContext *pscontext, DBusGMethodInvocation *context)
-{
- GHashTable *profile;
-
- dbg("Get profile properties of context(%s)", _ps_context_ref_path(pscontext));
- profile = g_hash_table_new(g_str_hash, g_str_equal);
- __ps_context_get_profile_properties(pscontext, profile);
-
- dbus_g_method_return(context, profile);
- g_hash_table_destroy(profile);
- return TRUE;
-}
-
-gboolean ps_iface_context_activate(PsContext *pscontext, DBusGMethodInvocation *context)
-{
- int rv = 0;
- int context_state = 0;
- GError *error = NULL;
-
- dbg("Activate context - Path: [%s]", _ps_context_ref_path(pscontext));
-
- /* Support Always ON connection */
- _ps_context_set_alwayson_enable(pscontext, TRUE);
-
- /* Reset connection timer */
- _ps_service_reset_connection_timer(pscontext);
-
- /* Service Activate context */
- rv = _ps_service_activate_context(pscontext->p_service, pscontext);
- if (rv != TCORE_RETURN_SUCCESS) {
- err("Context Activation - FAIL");
- g_set_error(&error, PS_ERROR, PS_ERR_TRASPORT, "fail to activate context err(%d)", rv);
- goto FAIL;
- }
- dbg("Context Activation - SUCCESS");
-
- dbus_g_method_return(context, pscontext->path);
-
- /* Get context State, Set connected if it is already Activated */
- context_state = tcore_context_get_state(pscontext->co_context);
- if (context_state == CONTEXT_STATE_ACTIVATED) {
- dbg("Conetxt State - Already connected");
- _ps_context_set_connected(pscontext, TRUE);
- }
-
- return TRUE;
-
-FAIL:
- dbus_g_method_return_error(context, error);
- return TRUE;
-}
-
-gboolean ps_iface_context_deactivate(PsContext *pscontext, DBusGMethodInvocation *context)
-{
- int rv = 0;
- int context_state = 0;
- GError *error = NULL;
-
- dbg("deactivate context(%s)", _ps_context_ref_path(pscontext));
-
- _ps_service_reset_connection_timer(pscontext);
- _ps_context_set_alwayson_enable(pscontext, FALSE);
- rv = _ps_service_deactivate_context(pscontext->p_service, pscontext);
- if (rv != TCORE_RETURN_SUCCESS) {
- dbg("fail to deactivate context connection");
- g_set_error(&error, PS_ERROR, PS_ERR_TRASPORT, "fail to deactivate context err(%d)", rv);
- goto FAIL;
- }
-
- dbg("success to deactivate context");
- dbus_g_method_return(context, pscontext->path);
-
- context_state = tcore_context_get_state(pscontext->co_context);
- if (context_state == CONTEXT_STATE_DEACTIVATED) {
- dbg("context is already disconnected");
- _ps_context_set_connected(pscontext, FALSE);
- }
-
- return TRUE;
-
-FAIL:
- dbus_g_method_return_error(context, error);
- return TRUE;
-}
-
-gboolean ps_iface_context_set_default_connection(PsContext *pscontext, gboolean* result, GError **error)
-{
-/*
- * if current default and target profile is the same, just return success
- *
- * in different case, current connection should be diconnected, and trying to connection new one
- */
- int role = CONTEXT_ROLE_UNKNOWN;
- gpointer cur_default_ctx = NULL;
- gpointer service = NULL;
-
- role = tcore_context_get_role(pscontext->co_context);
- if(role != CONTEXT_ROLE_INTERNET){
- dbg("only internet profile type can be set to default internet profile");
- *result = FALSE;
- return TRUE;
- }
-
- service = pscontext->p_service;
- cur_default_ctx = _ps_service_return_default_context(service);
-
- dbg("default ctx(%p), request ctx(%p)", cur_default_ctx, pscontext);
- if(cur_default_ctx == pscontext){
- dbg("already default internet connection");
- *result = TRUE;
- return TRUE;
- }
-
- //unset current profile
- _ps_context_set_alwayson_enable(cur_default_ctx, FALSE);
- __ps_context_set_default_connection_enable(cur_default_ctx, FALSE);
- //disconnect connection
- _ps_service_deactivate_context(((PsContext *)cur_default_ctx)->p_service, cur_default_ctx);
- //db update - release default connection
- __ps_context_update_default_internet_to_db((PsContext *)cur_default_ctx, FALSE);
-
- //db update - set default connection
- __ps_context_update_default_internet_to_db(pscontext, TRUE);
- //set request profile
- __ps_context_set_default_connection_enable(pscontext, TRUE);
- _ps_context_set_alwayson_enable(pscontext, TRUE);
- //request to connect
- _ps_service_connect_default_context(pscontext->p_service);
- dbg("complete to change the default connection");
-
- *result = TRUE;
- return TRUE;
-}
-
-gboolean ps_iface_context_modify_profile(PsContext *context, GHashTable *profile_property,
- gboolean* result, GError **error)
+void __remove_context_handler(gpointer data)
{
- gboolean rv = FALSE;
- int context_state = 0;
+ PsContext *context = data;
- *result = TRUE;
- dbg("modify context's profile properties");
+ dbg("Entered");
- rv = __ps_context_update_profile(context, profile_property);
- if (rv != TRUE) {
- g_set_error(error, PS_ERROR, PS_ERR_INTERNAL, "fail to modify profile");
- *result = FALSE;
- return TRUE;
+ if (!context) {
+ dbg("Context is Null");
+ return;
}
- context_state = tcore_context_get_state(context->co_context);
- if (context_state == CONTEXT_STATE_DEACTIVATED)
- return TRUE;
+ /*Need to UNexport and Unref the master Object */
+ g_object_unref(context->if_obj);
- _ps_service_deactivate_context(context->p_service, context);
- context_state = tcore_context_get_state(context->co_context);
- if (context_state == CONTEXT_STATE_DEACTIVATED) {
- dbg("context is already disconnected");
- _ps_context_set_connected(context, FALSE);
- }
+ dbg("context removed for the path [%s]", context->path);
- return TRUE;
+ g_free(context->path);
+ g_free(context->mccmnc);
+ g_free(context);
}
-gboolean ps_iface_context_remove_profile(PsContext *context, gboolean* result, GError **error)
+static void __ps_context_emit_property_changed_signal(PsContext *context)
{
- gchar* ctx_path = NULL;
- gboolean rv = FALSE;
+ GVariant *gv = NULL;
+ GVariantBuilder property;
- ctx_path = g_strdup(_ps_context_ref_path(context));
+ dbg("Get context Properties");
+ gv = _ps_context_get_properties(context, &property);
- __ps_context_remove_database(context);
- rv = __ps_context_remove_context(context);
- g_hash_table_remove(contexts, ctx_path);
-
- *result = rv;
- g_free(ctx_path);
- return TRUE;
-}
-
-static void __remove_context(gpointer data)
-{
- dbg("context removed");
- return;
+ dbg("Emit property changed signal - context [%p]", context);
+ packet_service_context_emit_property_changed(context->if_obj, gv);
}
static gboolean __remove_contexts(gpointer key, gpointer value, gpointer user_data)
{
- gchar *context_path = (gchar *) key;
- dbg("context(%s) remove", context_path);
+ gchar *context_path = (gchar *)key;
+
+ dbg("Removing context [%s]", context_path);
__ps_context_remove_context(value);
- return TRUE;
-}
-gboolean _ps_context_remove_context(gpointer context)
-{
- dbus_g_connection_unregister_g_object(((PsContext *)context)->conn, (GObject *) context);
- g_hash_table_remove(contexts, _ps_context_ref_path(context));
- g_object_unref(context);
return TRUE;
}
static gboolean __ps_context_remove_context(gpointer context)
{
- dbg("remove context and profile");
+ PsContext *pscontext = context;
- _ps_service_reset_connection_timer(context);
+ dbg("Remove context [%p] and profile", pscontext);
+ _ps_service_reset_connection_timer(pscontext);
- dbus_g_connection_unregister_g_object(((PsContext *)context)->conn, (GObject *) context);
+ /* Remove interface */
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(pscontext->if_obj));
- _ps_context_set_alwayson_enable(context, FALSE);
- _ps_service_deactivate_context(((PsContext *)context)->p_service, context);
- _ps_context_set_connected(context, FALSE);
- _ps_service_unref_context(((PsContext *)context)->p_service, context);
+ _ps_context_set_alwayson_enable(pscontext, FALSE);
+ _ps_service_deactivate_context(pscontext->p_service, pscontext);
+ _ps_context_set_connected(pscontext, FALSE);
+ _ps_service_unref_context(pscontext->p_service, pscontext);
- tcore_context_free(((PsContext *)context)->co_context);
- g_object_unref(context);
+ tcore_context_free(pscontext->co_context);
return TRUE;
}
static gboolean __ps_context_create_storage_handle(gpointer plugin)
{
- TcorePlugin *p = plugin;
- Server *s = tcore_plugin_ref_server(p);
+ Server *s = tcore_plugin_ref_server((TcorePlugin *)plugin);
const char *path = NULL;
strg_db = tcore_server_find_storage(s, "database");
path = tzplatform_mkpath(TZ_SYS_DB,".dnet.db");
handle = tcore_storage_create_handle(strg_db, path);
- if (!handle)
+ if (!handle) {
err("fail to create database handle");
+ return FALSE;
+ }
dbg("storage(%p) handle (%p)", strg_db, handle);
return TRUE;
static gboolean __ps_context_create_context_hash()
{
- g_return_val_if_fail(contexts == NULL, FALSE);
+ tcore_check_return_value(contexts == NULL, FALSE);
- contexts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, __remove_context);
+ contexts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, __remove_context_handler);
if (contexts == NULL) {
err("fail to create context hashtable");
return FALSE;
return TRUE;
}
-static gchar* __ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id)
+static gchar* __ps_context_create_path(gchar *profile_name, gint profile_id, gint svc_ctg_id)
{
- gchar **strv, *str, *path;
- gchar *delimiters = " !\"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~";
-
- strv = g_strsplit_set(profile_name, delimiters, -1);
- str = g_strjoinv("_", strv);
- dbg("converted string %s", str);
- path = g_strdup_printf("/context/%s_%d_%d", str, profile_id, svc_ctg_id);
- g_strfreev(strv);
- g_free(str);
+ gchar *path = NULL, *in_path = NULL;
+ int str_len = 0, index = 0;
+
+ if (!profile_name) {
+ dbg("profile_name is null");
+ return NULL;
+ }
+
+ str_len = strlen(profile_name);
+ in_path = g_strdup("/context/");
+
+ for (index = 0; index < str_len; index++ ) {
+ gchar *buf = NULL, *tmp = NULL;
+ buf = g_strdup_printf("%02x", profile_name[index]);
+ tmp = g_strconcat(in_path, buf, NULL);
+
+ g_free(buf);
+ g_free(in_path);
+
+ in_path = g_strdup(tmp);
+ g_free(tmp);
+ }
+
+ dbg("converted name(%s) path(%s)", profile_name, in_path);
+
+ path = g_strdup_printf("%s_%d_%d", in_path, profile_id, svc_ctg_id);
dbg("path (%s)", path);
+ g_free(in_path);
return path;
}
CoreObject *co_context = NULL;
gchar *path = NULL;
- int profile_id = 0;
+ gint profile_id = 0;
gchar *profile_name = NULL;
gchar *apn = NULL;
gchar *auth_id = NULL, *auth_pwd = NULL, *home_url = NULL, *proxy_addr = NULL;
- int auth_type = 0,svc_ctg_id = 0;
+ gint auth_type = 0, svc_ctg_id = 0;
gboolean hidden = FALSE, editable = FALSE, default_conn = FALSE;
- dbg("Create context");
-
g_hash_table_iter_init(&iter, (GHashTable *) property);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
if (g_str_equal(key, "3") == TRUE) { /*Profile ID*/
- profile_id = atoi((const char*) value);
+ profile_id = atoi((const gchar*) value);
dbg("profile id (%d)", profile_id);
- }
- else if (g_str_equal(key, "4") == TRUE) {
- profile_name = g_strdup((const char*) value);
+ } else if (g_str_equal(key, "4") == TRUE) {
+ profile_name = g_strdup((const gchar*) value);
dbg("profile name (%s)", profile_name);
- }
- else if (g_str_equal(key, "5") == TRUE) {
- apn = g_strdup((const char*) value);
+ } else if (g_str_equal(key, "5") == TRUE) {
+ apn = g_strdup((const gchar*) value);
dbg("APN (%s)", apn);
- }
- else if (g_str_equal(key, "6") == TRUE) {
- auth_type = atoi((const char*) value);
+ } else if (g_str_equal(key, "6") == TRUE) {
+ auth_type = atoi((const gchar*) value);
dbg("auth type (%d)", auth_type);
- }
- else if (g_str_equal(key, "7") == TRUE) {
- auth_id = g_strdup((const char*) value);
+ } else if (g_str_equal(key, "7") == TRUE) {
+ auth_id = g_strdup((const gchar*) value);
dbg("auth id (%s)", auth_id);
- }
- else if (g_str_equal(key, "8") == TRUE) {
- auth_pwd = g_strdup((const char*) value);
+ } else if (g_str_equal(key, "8") == TRUE) {
+ auth_pwd = g_strdup((const gchar*) value);
dbg("auth pwd (%s)", auth_pwd);
- }
- else if (g_str_equal(key, "9") == TRUE) {
- proxy_addr = g_strdup((const char*) value);
+ } else if (g_str_equal(key, "9") == TRUE) {
+
+ if (!value || g_strcmp0((const gchar*) value, "") == 0 ) {
+ proxy_addr = g_strdup((const gchar*) value);
+ }
+ else {
+ gboolean b_regex = FALSE;
+ b_regex = g_regex_match_simple("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+:[0-9]*", (const gchar*) value, 0, 0);
+
+ if (b_regex) {
+ int port_num = 0;
+ gchar **tmp_proxy = NULL;
+
+ tmp_proxy = g_strsplit_set((const gchar*) value, ".:", -1);
+ port_num = atoi(tmp_proxy[4]);
+
+ if (port_num <= 0) {
+ proxy_addr = g_strdup_printf("%d.%d.%d.%d",
+ atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]));
+ }
+ else {
+ proxy_addr = g_strdup_printf("%d.%d.%d.%d:%d",
+ atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]), port_num);
+ }
+ g_strfreev(tmp_proxy);
+ }
+ else {
+ proxy_addr = g_strdup((const gchar*) value);
+ }//not in regular experssion
+ }
+
dbg("proxy addr (%s)", proxy_addr);
- }
- else if (g_str_equal(key, "10") == TRUE) {
- home_url = g_strdup((const char*) value);
+ } else if (g_str_equal(key, "10") == TRUE) {
+ home_url = g_strdup((const gchar*) value);
dbg("home url (%s)", home_url);
- }
- else if (g_str_equal(key, "19") == TRUE) {
- svc_ctg_id = atoi((const char*) value);
+ } else if (g_str_equal(key, "19") == TRUE) {
+ svc_ctg_id = atoi((const gchar*) value);
dbg("context category type (%d)", svc_ctg_id);
- }
- else if (g_str_equal(key, "20") == TRUE) {
- hidden = atoi((const char*) value);
+ } else if (g_str_equal(key, "20") == TRUE) {
+ hidden = atoi((const gchar*) value);
dbg("hidden profile (%d)", hidden);
- }
- else if (g_str_equal(key, "21") == TRUE) {
- editable = atoi((const char*) value);
+ } else if (g_str_equal(key, "21") == TRUE) {
+ editable = atoi((const gchar*) value);
dbg("editable profile (%d)", editable);
- }
- else if (g_str_equal(key, "22") == TRUE) {
- default_conn = atoi((const char*) value);
+ } else if (g_str_equal(key, "22") == TRUE) {
+ default_conn = atoi((const gchar*) value);
dbg("default connection profile (%d)", default_conn);
}
}
context = (PsContext *) object;
co_context = tcore_context_new(context->plg, NULL);
- tcore_context_set_state(co_context, CONTEXT_STATE_DEACTIVATED);
+ tcore_context_set_state(co_context, TCORE_CONTEXT_STATE_DEACTIVATED);
tcore_context_set_role(co_context, svc_ctg_id);
tcore_context_set_apn(co_context, apn);
tcore_context_set_auth(co_context, auth_type);
context->path = g_strdup(path);
context->co_context = co_context;
- msg(" Profile ID: [%d]", context->profile_id);
- msg(" Profile Hidden: [%d]", (context->hidden ? "YES" : "NO"));
- msg(" Profile Editable: [%d]", (context->editable ? "YES" : "NO"));
- msg(" Profile - Default Internet: [%s]",
- (context->default_internet ? "YES" : "NO"));
- msg(" Path: [%s]", context->path);
- msg(" Context: [0x%x]", context->co_context);
-
- /* Free memory */
g_free(path);
+ g_free(apn);
+ g_free(auth_pwd);
+ g_free(proxy_addr);
+ g_free(home_url);
+ g_free(profile_name);
return TRUE;
}
-static gpointer __ps_context_create_context(DBusGConnection *conn, TcorePlugin *p,
+static gpointer __ps_context_create_context(GDBusConnection *conn, TcorePlugin *p,
gchar *mccmnc, GHashTable *property)
{
- guint rv = 0;
+ PacketServiceContext *context;
GError *error = NULL;
- DBusGProxy *proxy;
- GObject *object = NULL;
+ PsContext *new_context;
gchar *path = NULL;
- proxy = dbus_g_proxy_new_for_name(conn, "org.freedesktop.DBus", "/org/freedesktop/DBus",
- "org.freedesktop.DBus");
+ dbg("Entered");
- if (!dbus_g_proxy_call(proxy, "RequestName", &error, G_TYPE_STRING, PS_DBUS_SERVICE,
- G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &rv, G_TYPE_INVALID)) {
- err("Failed to acquire context(%s) error(%s)", PS_DBUS_SERVICE, error->message);
- return NULL;
+ /*Initializing the master list for internal referencing*/
+ new_context = g_try_malloc0(sizeof(PsContext));
+ if (NULL == new_context) {
+ err("Unable to allocate memory for context");
+ goto FAILURE;
}
-
- object = g_object_new(PS_TYPE_CONTEXT, "conn", conn, "plg", p, "mccmnc", mccmnc);
-
- __ps_context_create_co_context(object, property);
- _ps_context_set_alwayson_enable(object, TRUE);
- path = _ps_context_ref_path(object);
-
- dbus_g_connection_register_g_object(conn, g_strdup(path), object);
- msg("context(%p) register dbus path(%s)", object, path);
-
- return object;
+ dbg("creating the skeleton object");
+ context = packet_service_context_skeleton_new();
+ if (NULL == context)
+ goto FAILURE;
+
+ dbg("Assigning the memory location for the internal data");
+ new_context->conn = conn;
+ new_context->plg = p;
+ new_context->if_obj = context;
+
+ __ps_context_create_co_context(new_context, property);
+ _ps_context_set_alwayson_enable(new_context, TRUE);
+ path = _ps_context_ref_path(new_context);
+ _ps_context_setup_interface(context,new_context);
+
+ dbg("registering the interface object");
+
+ dbg("exporting the interface object to the dbus connection");
+ /*exporting the interface object to the path mention for master*/
+ g_dbus_interface_skeleton_export((G_DBUS_INTERFACE_SKELETON(context)),
+ conn,
+ path,
+ &error);
+
+ g_assert_no_error (error);
+
+ dbg("Successfully new object created for the interface for path [%s]",path);
+ return new_context;
+
+FAILURE:
+ /*To do : handle failure */
+ dbg("Unable to allocate memory for the new object");
+ return NULL;
}
static gboolean __ps_context_update_profile(PsContext *context, GHashTable *property)
g_hash_table_iter_init(&iter, property);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
if (g_str_equal(key, "apn") == TRUE) {
- tcore_context_set_apn(co_context, (const char *) value);
+ tcore_context_set_apn(co_context, (const gchar *) value);
}
else if (g_str_equal(key, "auth_type") == TRUE) {
int i_tmp = 0;
- i_tmp = atoi((const char *) value);
+ i_tmp = atoi((const gchar *) value);
tcore_context_set_auth(co_context, i_tmp);
}
else if (g_str_equal(key, "auth_id") == TRUE) {
- tcore_context_set_username(co_context, (const char *) value);
+ tcore_context_set_username(co_context, (const gchar *) value);
}
else if (g_str_equal(key, "auth_pwd") == TRUE) {
- tcore_context_set_password(co_context, (const char *) value);
+ tcore_context_set_password(co_context, (const gchar *) value);
}
else if (g_str_equal(key, "proxy_addr") == TRUE) {
- tcore_context_set_proxy(co_context, (const char *) value);
+ tcore_context_set_proxy(co_context, (const gchar *) value);
}
else if (g_str_equal(key, "home_url") == TRUE) {
- tcore_context_set_mmsurl(co_context, (const char *) value);
+ tcore_context_set_mmsurl(co_context, (const gchar *) value);
}
}
{
gchar *s_id = NULL, *s_enabled = NULL;
gboolean rv = FALSE;
- char szQuery[3000];
-
+ gchar query[3000];
GHashTable *in_param;
+
+ tcore_check_return_value(context != NULL, FALSE);
+
in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
- strcpy(szQuery, " update pdp_profile set ");
- strcat(szQuery, " default_internet_con = ?");
- strcat(szQuery, " where profile_id = ?");
+ strcpy(query, " update pdp_profile set ");
+ strcat(query, " default_internet_con = ?");
+ strcat(query, " where profile_id = ?");
s_id = g_strdup_printf("%d", context->profile_id);
s_enabled = g_strdup_printf("%d", enabled);
g_hash_table_insert(in_param, "1", g_strdup(s_enabled));
g_hash_table_insert(in_param, "2", g_strdup(s_id));
- rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
+ rv = tcore_storage_update_query_database(strg_db, handle, query, in_param);
g_hash_table_destroy(in_param);
g_free(s_id);
gchar *s_id = NULL, *s_authtype = NULL;
gchar *s_apn = NULL, *s_username = NULL, *s_pwd = NULL, *s_proxy = NULL, *s_mms = NULL;
gboolean rv = FALSE;
- char szQuery[3000];
+ gchar query[3000];
+ TcoreContextAuth authtype;
GHashTable *in_param;
in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
- strcpy(szQuery, " update pdp_profile set ");
- strcat(szQuery, " apn = ?, auth_type = ?, auth_id = ?, auth_pwd = ?, ");
- strcat(szQuery, " proxy_ip_addr = ?, home_url = ?");
- strcat(szQuery, " where profile_id = ?");
+ strcpy(query, " update pdp_profile set ");
+ strcat(query, " apn = ?, auth_type = ?, auth_id = ?, auth_pwd = ?, ");
+ strcat(query, " proxy_ip_addr = ?, home_url = ?");
+ strcat(query, " where profile_id = ?");
+ tcore_context_get_auth(context->co_context, &authtype);
s_id = g_strdup_printf("%d", context->profile_id);
- s_authtype = g_strdup_printf("%d", tcore_context_get_auth(context->co_context));
+ s_authtype = g_strdup_printf("%d", authtype);
- s_apn = tcore_context_get_apn(context->co_context);
- s_username = tcore_context_get_username(context->co_context);
- s_pwd = tcore_context_get_password(context->co_context);
- s_proxy = tcore_context_get_proxy(context->co_context);
- s_mms = tcore_context_get_mmsurl(context->co_context);
+ tcore_context_get_apn(context->co_context, &s_apn);
+ tcore_context_get_username(context->co_context, &s_username);
+ tcore_context_get_password(context->co_context, &s_pwd);
+ tcore_context_get_proxy(context->co_context, &s_proxy);
+ tcore_context_get_mmsurl(context->co_context, &s_mms);
+ dbg("Profile parameter extracted");
g_hash_table_insert(in_param, "1", g_strdup(s_apn));
g_hash_table_insert(in_param, "2", g_strdup(s_authtype));
g_hash_table_insert(in_param, "3", g_strdup(s_username));
g_hash_table_insert(in_param, "6", g_strdup(s_mms));
g_hash_table_insert(in_param, "7", g_strdup(s_id));
- rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
+ dbg("Profile Parameter inserted in data base ");
+ rv = tcore_storage_update_query_database(strg_db, handle, query, in_param);
g_hash_table_destroy(in_param);
g_free(s_id);
g_free(s_authtype);
- g_free(s_apn);
- g_free(s_username);
- g_free(s_pwd);
- g_free(s_proxy);
- g_free(s_mms);
+ dbg("Exiting");
return rv;
}
{
gchar *s_id = NULL;
gboolean rv = FALSE;
- char szQuery[1000];
+ gchar query[1000];
GHashTable *in_param;
in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery, " delete from pdp_profile where profile_id = ? ");
+ memset(query, 0, sizeof(query));
+ strcpy(query, " delete from pdp_profile where profile_id = ? ");
s_id = g_strdup_printf("%d", context->profile_id);
g_hash_table_insert(in_param, "1", g_strdup(s_id));
- rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, in_param);
+ rv = tcore_storage_remove_query_database(strg_db, handle, query, in_param);
g_free(s_id);
g_hash_table_destroy(in_param);
return rv;
}
-static int __ps_context_insert_network_id_to_database(gchar *mccmnc)
+static gint __ps_context_insert_network_id_to_database(gchar *mccmnc)
{
- char szQuery[5000];
- int network_id = 0;
+ gchar query[5000];
+ gint network_id = 0;
gboolean rv = FALSE;
gchar *insert_key = NULL;
GHashTableIter iter;
out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
(GDestroyNotify) g_hash_table_destroy);
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery,"select max(network_info_id) as network_id from network_info");
+ memset(query, 0, sizeof(query));
+ strcpy(query,"select max(network_info_id) as network_id from network_info");
- tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
+ tcore_storage_read_query_database(strg_db, handle, query, NULL, out_param, 1);
g_hash_table_iter_init(&iter, out_param);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
GHashTableIter iter2;
gpointer key2, value2;
- if(value){
+ if (value) {
g_hash_table_iter_init(&iter2, (GHashTable *) value);
while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
dbg("key2(%s) value2(%s)",key2, value2);
if (g_str_equal(key2, "0") == TRUE) {
- if (!value2 || g_strcmp0((const char*) value2, "") == 0 ) {
+ if (!value2 || g_strcmp0((const gchar*) value2, "") == 0 ) {
network_id = 0;
- }
- else{
- network_id = atoi((const char*) value2);
+ } else {
+ network_id = atoi((const gchar*) value2);
}
}
}
network_id++;
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery," insert into network_info( network_info_id, network_name, mccmnc) values( ?, ?, ?) ");
+ memset(query, 0, sizeof(query));
+ strcpy(query," insert into network_info( network_info_id, network_name, mccmnc) values( ?, ?, ?) ");
insert_key = g_strdup_printf("%d", network_id);
g_hash_table_insert(in_param, "1", g_strdup(insert_key));
g_hash_table_insert(in_param, "2", "TEMP_NETWORK");
g_hash_table_insert(in_param, "3", g_strdup(mccmnc));
- rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
- if(!rv)
+ rv = tcore_storage_insert_query_database(strg_db, handle, query, in_param);
+ if (!rv) {
+ err("unable to insert query into database");
return 0;
-
+ }
g_free(insert_key);
return network_id;
}
-static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id)
+static gint __ps_context_insert_profile_to_database(GHashTable *property, gint network_id)
{
- int profile_id = 0;
- char szQuery[5000];
+ gint profile_id = 0;
+ gchar query[5000];
gboolean rv = FALSE;
GHashTableIter iter;
if (g_str_equal(key, "apn") == TRUE) {
apn = g_strdup(value);
- }
- else if (g_str_equal(key, "keyword") == TRUE) {
+ } else if (g_str_equal(key, "keyword") == TRUE) {
keyword = g_strdup(value);
- }
- else if (g_str_equal(key, "auth_type") == TRUE) {
+ } else if (g_str_equal(key, "auth_type") == TRUE) {
auth_type = g_strdup(value);
- }
- else if (g_str_equal(key, "auth_id") == TRUE) {
+ } else if (g_str_equal(key, "auth_id") == TRUE) {
auth_id = g_strdup(value);
- }
- else if (g_str_equal(key, "auth_pwd") == TRUE) {
+ } else if (g_str_equal(key, "auth_pwd") == TRUE) {
auth_pwd = g_strdup(value);
- }
- else if (g_str_equal(key, "proxy_addr") == TRUE) {
+ } else if (g_str_equal(key, "proxy_addr") == TRUE) {
proxy_addr = g_strdup(value);
- }
- else if (g_str_equal(key, "home_url") == TRUE) {
+ } else if (g_str_equal(key, "home_url") == TRUE) {
home_url = g_strdup(value);
- }
- else if (g_str_equal(key, "svc_ctg_id") == TRUE) {
+ } else if (g_str_equal(key, "svc_ctg_id") == TRUE) {
svc_id = g_strdup(value);
}
}
- /*
- * Whether a profile is created with no proxy address and port,
- * settings application is passing ':' as proxy_addr value.
- * Checking proxy _address creation on application is needed, but
- * address:port formatting is also double check in packet service
- * telephony plugin.
- */
- if (g_strcmp0(proxy_addr, ":") == 0) {
- dbg("Invalid proxy address, set it to NULL");
- g_free(proxy_addr);
- proxy_addr = NULL;
- }
-
dbg("apn (%s), auth_type (%s), auth_id(%s), auth_pwd(%s), proxy_addr(%s), home_url(%s), svc_id(%s)",
apn, auth_type, auth_id, auth_pwd, proxy_addr, home_url, svc_id);
profile_id = __ps_context_load_profile_id_from_database();
- if(profile_id < 0){
+ if (profile_id < 0) {
dbg("fail to get last profile id");
return 0;
}
dbg("last profile id(%d)", profile_id);
profile_id++;
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery," insert into pdp_profile( ");
- strcat(szQuery," profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, ");
- strcat(szQuery," pdp_protocol, proxy_ip_addr, home_url, linger_time, ");
- strcat(szQuery," network_info_id, svc_category_id, hidden, editable, default_internet_con) values( ");
- strcat(szQuery," ?, ?, ?, ?, ?, ?,");//1,2,3,4,5,6
- strcat(szQuery," 1, ?, ?, 300,");//7,8
- strcat(szQuery," ?, ?, 0, 1, ?)");//9,10,11
+ memset(query, 0, sizeof(query));
+ strcpy(query," insert into pdp_profile( ");
+ strcat(query," profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, ");
+ strcat(query," pdp_protocol, proxy_ip_addr, home_url, linger_time, ");
+ strcat(query," network_info_id, svc_category_id, hidden, editable, default_internet_con, user_defined) values( ");
+ strcat(query," ?, ?, ?, ?, ?, ?,");//1,2,3,4,5,6
+ strcat(query," 1, ?, ?, 300,");//7,8
+ strcat(query," ?, ?, 0, 1, 0, 1)");//9,10
insert_key1 = g_strdup_printf("%d", profile_id);
insert_key2 = g_strdup_printf("%d", network_id);
network_name = __ps_context_load_network_name_from_database(network_id);
- if(keyword){
- profile_name = g_strdup_printf("%s (%s)", network_name, keyword);
- }
- else{
+ if (keyword) {
+ profile_name = g_strdup_printf("%s", keyword);
+ } else {
profile_name = g_strdup_printf("%s", network_name);
}
dbg("profile name (%s)", profile_name);
g_hash_table_insert(in_param, "9", g_strdup(insert_key2));
g_hash_table_insert(in_param, "10", g_strdup(svc_id));
- /* If profile received is Internet type */
- if (g_strcmp0(svc_id, "1") == 0) {
- dbg("Set new internet profile as default Internet connection");
- g_hash_table_insert(in_param, "11", g_strdup("1"));
- /* Profile is MMS or other type don't set it as default */
- } else
- g_hash_table_insert(in_param, "11", g_strdup("0"));
-
g_free(insert_key1);g_free(insert_key2);g_free(profile_name);
g_free(apn);g_free(auth_type);g_free(auth_id);g_free(auth_pwd);
g_free(proxy_addr);g_free(home_url);g_free(svc_id);
- rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
+ rv = tcore_storage_insert_query_database(strg_db, handle, query, in_param);
g_hash_table_destroy(in_param);
- if(!rv)
+ if (!rv) {
+ err("unable to insert query into database");
return 0;
-
+ }
return profile_id;
}
-static int __ps_context_load_network_id_from_database(gchar *mccmnc)
+static gint __ps_context_load_network_id_from_database(gchar *mccmnc)
{
- char szQuery[5000];
- int network_id = 0;
+ gchar query[5000];
+ gint network_id = 0;
GHashTableIter iter;
gpointer key, value;
GHashTable *in_param, *out_param;
out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
(GDestroyNotify) g_hash_table_destroy);
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery,"select network_info_id from network_info where mccmnc = ? ");
+ memset(query, 0, sizeof(query));
+ strcpy(query,"select network_info_id from network_info where mccmnc = ? ");
g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
- tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
+ tcore_storage_read_query_database(strg_db, handle, query, in_param, out_param, 1);
g_hash_table_iter_init(&iter, out_param);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
GHashTableIter iter2;
gpointer key2, value2;
- if(value){
+ if (value) {
g_hash_table_iter_init(&iter2, (GHashTable *) value);
while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
if (g_str_equal(key2, "0") == TRUE) {
- if (!value2 || g_strcmp0((const char*) value2, "") == 0) {
+ if (!value2 || g_strcmp0((const gchar*) value2, "") == 0) {
network_id = 0;
- }
- else{
- network_id = atoi((const char*) value2);
+ } else {
+ network_id = atoi((const gchar*) value2);
}
}
}
return network_id;
}
-static gchar* __ps_context_load_network_name_from_database(int network_id)
+static gchar* __ps_context_load_network_name_from_database(gint network_id)
{
- char szQuery[5000];
+ gchar query[5000];
gchar *network_name = NULL;
gchar *insert_key1 = NULL;
GHashTableIter iter;
out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
(GDestroyNotify) g_hash_table_destroy);
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery,"select network_name from network_info where network_info_id = ? ");
+ memset(query, 0, sizeof(query));
+ strcpy(query,"select network_name from network_info where network_info_id = ? ");
insert_key1 = g_strdup_printf("%d", network_id);
g_hash_table_insert(in_param, "1", g_strdup(insert_key1));
- tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
+ tcore_storage_read_query_database(strg_db, handle, query, in_param, out_param, 1);
g_hash_table_iter_init(&iter, out_param);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
GHashTableIter iter2;
gpointer key2, value2;
- if(value){
+ if (value) {
g_hash_table_iter_init(&iter2, (GHashTable *) value);
while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
if (g_str_equal(key2, "0") == TRUE) {
return network_name;
}
-static int __ps_context_load_profile_id_from_database(void)
+static gint __ps_context_load_profile_id_from_database(void)
{
- char szQuery[5000];
- int profile_id = 0;
+ gchar query[5000];
+ gint profile_id = 0;
GHashTableIter iter;
gpointer key, value;
GHashTable *out_param;
out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
(GDestroyNotify) g_hash_table_destroy);
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery,"select max(profile_id) as last_profile from pdp_profile");
+ memset(query, 0, sizeof(query));
+ strcpy(query,"select max(profile_id) as last_profile from pdp_profile");
- tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
+ tcore_storage_read_query_database(strg_db, handle, query, NULL, out_param, 1);
g_hash_table_iter_init(&iter, out_param);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
GHashTableIter iter2;
gpointer key2, value2;
- if(value){
+ if (value) {
g_hash_table_iter_init(&iter2, (GHashTable *) value);
while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
if (g_str_equal(key2, "0") == TRUE) {
- if(!value2 || g_strcmp0((const char*) value2, "") == 0){
+ if (!value2 || g_strcmp0((const gchar*) value2, "") == 0) {
profile_id = 0;
- }
- else{
- profile_id = atoi((const char*) value2);
+ } else {
+ profile_id = atoi((const gchar*) value2);
}
}
}
return profile_id;
}
-static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int index)
+static gint __ps_context_load_num_of_pdn_from_database(gchar *mccmnc)
{
- gboolean rv = FALSE;
- GHashTable *in_param;
+ gchar query[5000];
+ gint num_of_pdn = 0;
+ GHashTableIter iter;
+ gpointer key, value;
+ GHashTable *in_param, *out_param;
in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
+ out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ (GDestroyNotify) g_hash_table_destroy);
- {//profile id
- gchar *profile_id;
- gchar* item_key = NULL;
- item_key = g_strdup_printf("connection:profile_id_%d", index);
- profile_id = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "1", g_strdup(profile_id));
- g_free(item_key);
- }
-
- {//profile name
- gchar *profile_name;
- gchar* item_key = NULL;
- item_key = g_strdup_printf("connection:profile_name_%d", index);
- profile_name = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "2", g_strdup(profile_name));
- g_free(item_key);
- }
-
- {//apn
- gchar *apn;
- gchar *item_key = NULL;
- item_key = g_strdup_printf("connection:apn_%d", index);
- apn = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "3", g_strdup(apn));
- g_free(item_key);
- }
-
- {//auth type
- gchar *auth_type;
- gchar *item_key = NULL;
- item_key = g_strdup_printf("connection:auth_type_%d", index);
- auth_type = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "4", g_strdup(auth_type));
- g_free(item_key);
- }
-
- {//auth id
- gchar *auth_id;
- gchar *item_key = NULL;
- item_key = g_strdup_printf("connection:auth_id_%d", index);
- auth_id = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "5", g_strdup(auth_id));
- g_free(item_key);
- }
-
- {//auth pwd
- gchar *auth_pwd;
- gchar *item_key = NULL;
- item_key = g_strdup_printf("connection:auth_pwd_%d", index);
- auth_pwd = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "6", g_strdup(auth_pwd));
- g_free(item_key);
- }
-
- {//pdp protocol
- gchar *pdp_protocol;
- gchar *item_key = NULL;
- item_key = g_strdup_printf("connection:pdp_protocol_%d", index);
- pdp_protocol = iniparser_getstring(dic, item_key, NULL);
- g_hash_table_insert(in_param, "7", g_strdup(pdp_protocol));
- g_free(item_key);
- }
-
- {// proxy ip
- gchar *proxy_ip_addr;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:proxy_ip_addr_%d", index);
- proxy_ip_addr = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "8", g_strdup(proxy_ip_addr));
- g_free(section_key);
- }
+ memset(query, 0, sizeof(query));
+ strcpy(query,"select a.max_pdp_3g from max_pdp a, network_info b ");
+ strcat(query,"where a.network_info_id = b.network_info_id and b.mccmnc = ? ");
- {//home url
- gchar *home_url;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:home_url_%d", index);
- home_url = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "9", g_strdup(home_url));
- g_free(section_key);
- }
+ g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
+ tcore_storage_read_query_database(strg_db, handle, query, in_param, out_param, 1);
- {//linger time
- gchar *linger_time;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:linger_time_%d", index);
- linger_time = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "10", g_strdup(linger_time));
- g_free(section_key);
- }
+ g_hash_table_iter_init(&iter, out_param);
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ GHashTableIter iter2;
+ gpointer key2, value2;
- {//traffic class
- gchar *traffic_class;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:traffic_class_%d", index);
- traffic_class = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "11", g_strdup(traffic_class));
- g_free(section_key);
- }
-
- {//is static ip address
- gchar *is_static_ip_addr;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:is_static_ip_addr_%d", index);
- is_static_ip_addr = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "12", g_strdup(is_static_ip_addr));
- g_free(section_key);
- }
-
- {//ip address if static ip is true
- gchar *ip_addr;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:ip_addr_%d", index);
- ip_addr = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "13", g_strdup(ip_addr));
- g_free(section_key);
- }
-
- {//is static dns address
- gchar *is_static_dns_addr;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:is_static_dns_addr_%d", index);
- is_static_dns_addr = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "14", g_strdup(is_static_dns_addr));
- g_free(section_key);
- }
-
- {//dns address 1
- gchar *dns_addr1;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:dns_addr1_%d", index);
- dns_addr1 = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "15", g_strdup(dns_addr1));
- g_free(section_key);
- }
-
- {//dns address 2
- gchar *dns_addr2;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:dns_addr2_%d", index);
- dns_addr2 = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "16", g_strdup(dns_addr2));
- g_free(section_key);
- }
-
- {//network info id
- gchar *network_info_id;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:network_info_id_%d", index);
- network_info_id = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "17", g_strdup(network_info_id));
- g_free(section_key);
- }
-
- {//service category id
- gchar *svc_category_id;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:svc_category_id_%d", index);
- svc_category_id = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "18", g_strdup(svc_category_id));
- g_free(section_key);
+ if (value) {
+ g_hash_table_iter_init(&iter2, (GHashTable *) value);
+ while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
+ if (g_str_equal(key2, "0") == TRUE) {
+ if (!value2 || g_strcmp0((const gchar*) value2, "") == 0) {
+ num_of_pdn = 3;
+ dbg("there is no value / use default");
+ } else {
+ num_of_pdn = atoi((const gchar*) value2);
+ dbg("value (%d)", num_of_pdn);
+ }
+ }
+ }
+ break;
+ }
}
- {//hidden
- gchar *hidden;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:hidden_%d", index);
- hidden = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "19", g_strdup(hidden));
- g_free(section_key);
+ if (num_of_pdn <= 0) {
+ dbg("loaded value is wrong");
+ num_of_pdn = 3;
}
- {//editable
- gchar *editable;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:editable_%d", index);
- editable = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "20", g_strdup(editable));
- g_free(section_key);
- }
+ g_hash_table_destroy(in_param);
+ g_hash_table_destroy(out_param);
- {//default internet connection
- gchar *default_internet_con;
- gchar *section_key = NULL;
- section_key = g_strdup_printf("connection:default_internet_con_%d", index);
- default_internet_con = iniparser_getstring(dic, section_key, NULL);
- g_hash_table_insert(in_param, "21", g_strdup(default_internet_con));
- g_free(section_key);
- }
+ return num_of_pdn;
+}
- {//insert data into table
- char szQuery[5000];
+static gboolean __ps_context_insert_profile_tuple(dictionary *dic, gint index)
+{
+ gboolean rv = FALSE;
+ GHashTable *in_param;
+ gchar *item_key = NULL;
+ gchar *profile = NULL;
+ gchar query[5000] = {0,};
- memset(szQuery, 0, sizeof(szQuery));
- strcpy(szQuery," insert into pdp_profile( ");
- strcat(szQuery," profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, ");
- strcat(szQuery," pdp_protocol, proxy_ip_addr, home_url, linger_time,");
- strcat(szQuery," traffic_class, is_static_ip_addr, ip_addr, is_static_dns_addr,dns_addr1, dns_addr2,");
- strcat(szQuery," network_info_id, svc_category_id, hidden, editable, default_internet_con) values( ");
- strcat(szQuery," ?, ?, ?, ?, ?, ?,");//1,2,3,4,5,6(auth_pwd)
- strcat(szQuery," ?, ?, ?, ?,");//7,8,9,10(linger_time)
- strcat(szQuery," ?, ?, ?, ?, ?, ?,");//11,12,13,14,15,16(dns_addr2)
- strcat(szQuery," ?, ?, ?, ?, ?)");//17,18,19,20,21(default_internet_con)
+ in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
- rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
- dbg("insert into pdp_profile result(%d)", rv);
- g_hash_table_destroy(in_param);
- }
+ /* Profile id */
+ item_key = (gchar *) g_strdup_printf("connection:profile_id_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "1", g_strdup(profile));
+ g_free(item_key);
+
+ /* Profile name */
+ item_key = (gchar *)g_strdup_printf("connection:profile_name_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "2", g_strdup(profile));
+ g_free(item_key);
+
+ /* APN */
+ item_key = (gchar *)g_strdup_printf("connection:apn_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "3", g_strdup(profile));
+ g_free(item_key);
+
+
+ /* Auth Type */
+ item_key =(gchar *) g_strdup_printf("connection:auth_type_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "4", g_strdup(profile));
+ g_free(item_key);
+
+ /* Auth ID */
+ item_key = (gchar *)g_strdup_printf("connection:auth_id_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "5", g_strdup(profile));
+ g_free(item_key);
+
+ /* Auth Password */
+ item_key = g_strdup_printf("connection:auth_pwd_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "6", g_strdup(profile));
+ g_free(item_key);
+
+ /* PDP Protocol */
+ item_key = g_strdup_printf("connection:pdp_protocol_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "7", g_strdup(profile));
+ g_free(item_key);
+
+ /* proxy ip */
+ item_key = g_strdup_printf("connection:proxy_ip_addr_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "8", g_strdup(profile));
+ g_free(item_key);
+
+ /* Home URL */
+ item_key = g_strdup_printf("connection:home_url_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "9", g_strdup(profile));
+ g_free(item_key);
+
+ /* Linger Time */
+ item_key = g_strdup_printf("connection:linger_time_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "10", g_strdup(profile));
+ g_free(item_key);
+
+ /* Traffic Class */
+ item_key = g_strdup_printf("connection:traffic_class_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "11", g_strdup(profile));
+ g_free(item_key);
+
+
+ /* Static IP Address */
+ item_key = g_strdup_printf("connection:is_static_ip_addr_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "12", g_strdup(profile));
+ g_free(item_key);
+
+ /* IP Address if static ip is true */
+ item_key = g_strdup_printf("connection:ip_addr_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "13", g_strdup(profile));
+ g_free(item_key);
+
+ /* Static DNS Address */
+ item_key = g_strdup_printf("connection:is_static_dns_addr_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "14", g_strdup(profile));
+ g_free(item_key);
+
+ /* DNS Address 1 */
+ item_key = g_strdup_printf("connection:dns_addr1_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "15", g_strdup(profile));
+ g_free(item_key);
+
+ /* DNS Address 2 */
+ item_key = g_strdup_printf("connection:dns_addr2_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "16", g_strdup(profile));
+ g_free(item_key);
+
+ /* Network INFO ID */
+ item_key = g_strdup_printf("connection:network_info_id_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "17", g_strdup(profile));
+ g_free(item_key);
+
+ /* Service Category ID */
+ item_key = g_strdup_printf("connection:svc_category_id_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "18", g_strdup(profile ));
+ g_free(item_key);
+
+ /* Hidden */
+ item_key = g_strdup_printf("connection:hidden_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "19", g_strdup(profile ));
+ g_free(item_key);
+
+ /* Editable */
+ item_key = g_strdup_printf("connection:editable_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "20", g_strdup(profile));
+ g_free(item_key);
+
+ /* Default Internet Connection */
+ item_key = g_strdup_printf("connection:default_internet_con_%d", index);
+ profile = (gchar *) iniparser_getstring(dic, item_key, NULL);
+ g_hash_table_insert(in_param, "21", g_strdup(profile));
+ g_free(item_key);
+
+ /* Insert data into table */
+
+ memset(query, 0, sizeof(query));
+ strcpy(query," insert into pdp_profile( ");
+ strcat(query," profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, ");
+ strcat(query," pdp_protocol, proxy_ip_addr, home_url, linger_time,");
+ strcat(query," traffic_class, is_static_ip_addr, ip_addr, is_static_dns_addr,dns_addr1, dns_addr2,");
+ strcat(query," network_info_id, svc_category_id, hidden, editable, default_internet_con, user_defined) values( ");
+ strcat(query," ?, ?, ?, ?, ?, ?,");//1,2,3,4,5,6(auth_pwd)
+ strcat(query," ?, ?, ?, ?,");//7,8,9,10(linger_time)
+ strcat(query," ?, ?, ?, ?, ?, ?,");//11,12,13,14,15,16(dns_addr2)
+ strcat(query," ?, ?, ?, ?, ?, 0)");//17,18,19,20,21(default_internet_con)
+
+ rv = tcore_storage_insert_query_database(strg_db, handle, query, in_param);
+ dbg("insert into pdp_profile result(%d)", rv);
+ g_hash_table_destroy(in_param);
return rv;
}
-static int __ps_context_get_network_id(gchar *mccmnc)
+static gint __ps_context_get_network_id(gchar *mccmnc)
{
- int network_id;
+ gint network_id;
network_id = __ps_context_load_network_id_from_database(mccmnc);
dbg("network id(%d)", network_id);
- if(network_id > 0)
+ if (network_id > 0)
return network_id;
network_id = __ps_context_insert_network_id_to_database(mccmnc);
- if(network_id <= 0 )
+ if (network_id <= 0 ) {
+ err("unable to insert mccmnc into database");
return -1;
+ }
return network_id;
}
-static gboolean __ps_context_get_profile_properties(gpointer object, GHashTable *properties)
+GVariant * __ps_context_get_profile_properties(gpointer object, GVariantBuilder *properties)
{
gchar *s_authtype = NULL, *s_role = NULL;
PsContext *context = NULL;
+ gchar *apn, *username, *password, *proxy_addr, *home_url;
+ TcoreContextAuth auth;
+ TcoreContextRole role;
+ gchar *profile;
+
- g_return_val_if_fail(object != NULL, FALSE);
- g_return_val_if_fail(properties != NULL, FALSE);
+ tcore_check_return_value(object != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
context = (PsContext *) object;
dbg("get profile properties");
-
- s_authtype = g_strdup_printf("%d", tcore_context_get_auth(context->co_context));
- s_role = g_strdup_printf("%d", tcore_context_get_role(context->co_context));
-
- g_hash_table_insert(properties, "path", g_strdup(context->path));
- g_hash_table_insert(properties, "apn", tcore_context_get_apn(context->co_context));
- g_hash_table_insert(properties, "auth_type", g_strdup(s_authtype));
- g_hash_table_insert(properties, "auth_id", tcore_context_get_username(context->co_context));
- g_hash_table_insert(properties, "auth_pwd", tcore_context_get_password(context->co_context));
- g_hash_table_insert(properties, "proxy_addr", tcore_context_get_proxy(context->co_context));
- g_hash_table_insert(properties, "home_url", tcore_context_get_mmsurl(context->co_context));
- g_hash_table_insert(properties, "svc_ctg_id", g_strdup(s_role));
- g_hash_table_insert(properties, "profile_name", tcore_context_get_profile_name(context->co_context));
- g_hash_table_insert(properties, "hidden", g_strdup(BOOL2STRING(context->hidden)));
- g_hash_table_insert(properties, "editable", g_strdup(BOOL2STRING(context->editable)));
- g_hash_table_insert(properties, "default_internet_conn", g_strdup(BOOL2STRING(context->default_internet)));
+ tcore_context_get_auth(context->co_context, &auth);
+ s_authtype = g_strdup_printf("%d", auth);
+ tcore_context_get_role(context->co_context, &role);
+ s_role = g_strdup_printf("%d", role);
+
+ tcore_context_get_apn(context->co_context , &apn);
+ tcore_context_get_username(context->co_context,&username);
+ tcore_context_get_password(context->co_context, &password);
+ tcore_context_get_proxy(context->co_context, &proxy_addr);
+ tcore_context_get_mmsurl(context->co_context, &home_url);
+ tcore_context_get_profile_name(context->co_context, &profile);
+
+ g_variant_builder_init(properties,G_VARIANT_TYPE("a{ss}"));
+
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(context->path));
+ if (apn) {
+ g_variant_builder_add(properties, "{ss}", "apn", apn);
+ }
+ if (s_authtype) {
+ g_variant_builder_add(properties, "{ss}", "auth_type", g_strdup(s_authtype));
+ }
+ if (username) {
+ g_variant_builder_add(properties, "{ss}", "auth_id", username);
+ }
+ if (password) {
+ g_variant_builder_add(properties, "{ss}", "auth_pwd", password);
+ }
+ if (proxy_addr) {
+ g_variant_builder_add(properties, "{ss}", "proxy_addr", proxy_addr);
+ }
+ if (home_url) {
+ g_variant_builder_add(properties, "{ss}", "home_url", home_url);
+ }
+ if (s_role) {
+ g_variant_builder_add(properties, "{ss}", "svc_ctg_id", g_strdup(s_role));
+ }
+ g_variant_builder_add(properties, "{ss}", "profile_name", profile );
+ g_variant_builder_add(properties, "{ss}", "hidden", g_strdup(BOOL2STRING(context->hidden)));
+ g_variant_builder_add(properties, "{ss}", "editable", g_strdup(BOOL2STRING(context->editable)));
+ g_variant_builder_add(properties, "{ss}", "default_internet_conn", g_strdup(BOOL2STRING(context->default_internet)));
g_free(s_authtype);
g_free(s_role);
- return TRUE;
+ return g_variant_builder_end(properties);
}
static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled)
{
PsContext *context = object;
- int role = CONTEXT_ROLE_UNKNOWN;
- g_return_val_if_fail(context != NULL, FALSE);
+ TcoreContextRole role ;
+ tcore_check_return_value(context != NULL, FALSE);
+
+ tcore_context_get_role(context->co_context, &role);
- role = tcore_context_get_role(context->co_context);
- if(role == CONTEXT_ROLE_INTERNET){
+ if (role == TCORE_CONTEXT_ROLE_INTERNET) {
context->default_internet = enabled;
}
return TRUE;
}
-static gpointer __ps_context_add_context(gpointer modem, gchar *mccmnc, int profile_id)
+static gpointer __ps_context_add_context(gpointer modem, gchar *mccmnc, gint profile_id)
{
- char szQuery[5000];
- DBusGConnection *conn = NULL;
+ gchar query[5000];
+ GDBusConnection *conn = NULL;
TcorePlugin *p = NULL;
GHashTableIter iter;
conn = _ps_modem_ref_dbusconn(modem);
p = _ps_modem_ref_plugin(modem);
- memset(szQuery, '\0', sizeof(szQuery));
- strcpy(szQuery, "select");
- strcat(szQuery, " a.network_info_id, a.network_name, a.mccmnc,"); //0 , 1, 2
- strcat(szQuery, " b.profile_id, b.profile_name, b.apn, "); //3, 4, 5
- strcat(szQuery, " b.auth_type, b.auth_id, b.auth_pwd,"); //6, 7, 8
- strcat(szQuery, " b.proxy_ip_addr, b.home_url, b.pdp_protocol, "); //9, 10 , 11
- strcat(szQuery, " b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr,"); //12, 13, 14, 15
- strcat(szQuery, " b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, b.default_internet_con"); //16, 17, 18, 19, 20, 21, 22
- strcat(szQuery, " from network_info a, pdp_profile b");
- strcat(szQuery, " where b.profile_id = ? and a.network_info_id = b.network_info_id ");
+ memset(query, '\0', sizeof(query));
+ strcpy(query, "select");
+ strcat(query, " a.network_info_id, a.network_name, a.mccmnc,"); //0 , 1, 2
+ strcat(query, " b.profile_id, b.profile_name, b.apn, "); //3, 4, 5
+ strcat(query, " b.auth_type, b.auth_id, b.auth_pwd,"); //6, 7, 8
+ strcat(query, " b.proxy_ip_addr, b.home_url, b.pdp_protocol, "); //9, 10 , 11
+ strcat(query, " b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr,"); //12, 13, 14, 15
+ strcat(query, " b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, b.default_internet_con"); //16, 17, 18, 19, 20, 21, 22
+ strcat(query, " from network_info a, pdp_profile b");
+ strcat(query, " where b.profile_id = ? and a.network_info_id = b.network_info_id ");
insert_key1 = g_strdup_printf("%d", profile_id);
g_hash_table_insert(in_param, "1", g_strdup(insert_key1));
- tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 23);
+ tcore_storage_read_query_database(strg_db, handle, query, in_param, out_param, 23);
g_hash_table_iter_init(&iter, out_param);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
{
gboolean rv = FALSE;
GHashTable *in_param;
- char szQuery[5000];
+ gchar query[5000];
- memset(szQuery, '\0', sizeof(szQuery));
- strcat(szQuery, " delete from pdp_profile");
+ memset(query, '\0', sizeof(query));
+ strcat(query, " delete from pdp_profile");
in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
- rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, in_param);
+ rv = tcore_storage_remove_query_database(strg_db, handle, query, in_param);
g_hash_table_destroy(in_param);
return rv;
}
+/* Funtion : _ps_context_remove_context
+ * Description : removes and unregister the interface for the context
+ */
+gboolean _ps_context_remove_context(gpointer context)
+{
+ PsContext *pscontext = context;
+
+ dbg("Entered");
+
+ /*Unexporting the interface for the modem*/
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(pscontext->if_obj));
+
+ /*Removing the context from the static list */
+ g_hash_table_remove(contexts, _ps_context_ref_path(pscontext));
+
+ dbg("Exiting");
+ return TRUE;
+}
+
+
gboolean _ps_context_fill_profile_table_from_ini_file(void)
{
- int index = 1;
- int data_exist = 0;
+ gint index = 1;
+ gint data_exist = 0;
dictionary *dic = NULL;
dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection.ini");
- if(dic == NULL){
+ if (dic == NULL) {
dbg("fail to load the csc default file");
return FALSE;
}
- do{
+ do {
gchar *section_key = NULL;
section_key = g_strdup_printf("connection:profile_id_%d", index);
dbg("section key (%s)", section_key);
data_exist = iniparser_find_entry(dic, section_key);
- if(!data_exist){
+ if (!data_exist) {
g_free(section_key);
iniparser_freedict(dic);
dbg("no more data in ini");
return TRUE;
}
- __ps_context_insert_profile_tuple(dic, index);
+ __ps_context_insert_profile_tuple (dic, index);
g_free(section_key);
index++;
- }while(data_exist);
+ } while (data_exist);
return TRUE;
}
gboolean _ps_context_reset_hashtable(void)
{
- if(!contexts)
+ if (!contexts)
return TRUE;
g_hash_table_foreach_remove(contexts, __remove_contexts, NULL);
return TRUE;
}
-GHashTable* _ps_context_create_hashtable(DBusGConnection *conn, TcorePlugin *p, gchar *mccmnc)
+GHashTable* _ps_context_create_hashtable(GDBusConnection *conn, TcorePlugin *p, gchar *mccmnc)
{
- char szQuery[5000];
+ gchar query[5000];
GHashTableIter iter;
gpointer key, value;
GHashTable *in_param, *out_param;
out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
(GDestroyNotify) g_hash_table_destroy);
- dbg("Create profile by mccmnc: [%s]", mccmnc);
+ dbg("create profile by mccmnc (%s)", mccmnc);
- memset(szQuery, '\0', sizeof(szQuery));
- strcpy(szQuery, "select");
- strcat(szQuery, " a.network_info_id, a.network_name, a.mccmnc,"); //0 , 1, 2
- strcat(szQuery, " b.profile_id, b.profile_name, b.apn, "); //3, 4, 5
- strcat(szQuery, " b.auth_type, b.auth_id, b.auth_pwd,"); //6, 7, 8
- strcat(szQuery, " b.proxy_ip_addr, b.home_url, b.pdp_protocol, "); //9, 10 , 11
- strcat(szQuery, " b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr,"); //12, 13, 14, 15
- strcat(szQuery, " b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, b.default_internet_con"); //16,17, 18, 19, 20, 21, 22
- strcat(szQuery, " from network_info a, pdp_profile b");
- strcat(szQuery, " where a.mccmnc= ? and a.network_info_id = b.network_info_id ");
+ memset(query, '\0', sizeof(query));
+ strcpy(query, "select");
+ strcat(query, " a.network_info_id, a.network_name, a.mccmnc,"); //0 , 1, 2
+ strcat(query, " b.profile_id, b.profile_name, b.apn, "); //3, 4, 5
+ strcat(query, " b.auth_type, b.auth_id, b.auth_pwd,"); //6, 7, 8
+ strcat(query, " b.proxy_ip_addr, b.home_url, b.pdp_protocol, "); //9, 10 , 11
+ strcat(query, " b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr,"); //12, 13, 14, 15
+ strcat(query, " b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, b.default_internet_con"); //16,17, 18, 19, 20, 21, 22
+ strcat(query, " from network_info a, pdp_profile b");
+ strcat(query, " where a.mccmnc= ? and a.network_info_id = b.network_info_id ");
g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
- dbg("Inserted mccmnc to Hash Table");
-
- tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 23);
+ tcore_storage_read_query_database(strg_db, handle, query, in_param, out_param, 23);
g_hash_table_iter_init(&iter, out_param);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
path = _ps_context_ref_path(object);
g_hash_table_insert(contexts, g_strdup(path), object);
- dbg("Inserted to Hash Table - context: [%p] Path: [%s]", object, path);
+ dbg("context (%p, %s) insert to hash", object, path);
}
g_hash_table_destroy(in_param);
g_hash_table_destroy(out_param);
-
+ dbg("Exiting");
return contexts;
}
GHashTable* _ps_context_ref_hashtable(void)
{
- g_return_val_if_fail(contexts != NULL, NULL);
+ tcore_check_return_value(contexts != NULL, NULL);
return contexts;
}
GHashTableIter iter;
gpointer key, value;
- int network_id = 0;
- int profile_id = 0;
+ gint network_id = 0;
+ gint profile_id = 0;
network_id = __ps_context_get_network_id(operator);
- if(network_id <= 0){
- dbg("fail to add network info");
+ if (network_id <= 0) {
+ err("fail to add network info");
return FALSE;
}
profile_id = __ps_context_insert_profile_to_database(property, network_id);
- if(profile_id <= 0){
- dbg("fail to insert profile info to database");
+ if (profile_id <= 0) {
+ err("fail to insert profile info to database");
return FALSE;
}
context = __ps_context_add_context(modem, operator, profile_id);
- if(!context)
+ if (!context) {
+ err("fail to add context");
return FALSE;
-
+ }
services = _ps_modem_ref_services(modem);
- if(!services)
+ if (!services) {
+ err("Fail to ref service ");
return FALSE;
-
+ }
g_hash_table_iter_init(&iter, services);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
_ps_service_ref_context(value, context);
return TRUE;
}
-gboolean _ps_context_get_properties(gpointer object, GHashTable *properties)
+gboolean _ps_context_get_properties_handler(gpointer object, GVariantBuilder *properties)
{
- int context_state = 0;
+ TcoreContextState state;
gboolean active = FALSE;
PsContext *context = object;
+ gchar *ip4, *dns1, *dns2, *gw, *proxy, *dev_name;
dbg("get context properties");
- g_return_val_if_fail(context != NULL, FALSE);
- g_return_val_if_fail(properties != NULL, FALSE);
+ tcore_check_return_value(context != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
- context_state = tcore_context_get_state(context->co_context);
- if (context_state == CONTEXT_STATE_ACTIVATED)
+ tcore_context_get_state(context->co_context, &state);
+ if (state == TCORE_CONTEXT_STATE_ACTIVATED)
active = TRUE;
- g_hash_table_insert(properties, "path", g_strdup(context->path));
- g_hash_table_insert(properties, "active", g_strdup(BOOL2STRING(active)));
- g_hash_table_insert(properties, "ipv4_address", tcore_context_get_ipv4_addr(context->co_context));
- g_hash_table_insert(properties, "ipv4_gateway", tcore_context_get_ipv4_gw(context->co_context));
- g_hash_table_insert(properties, "ipv4_dns1", tcore_context_get_ipv4_dns1(context->co_context));
- g_hash_table_insert(properties, "ipv4_dns2", tcore_context_get_ipv4_dns2(context->co_context));
- g_hash_table_insert(properties, "ipv6_address", "::" );
- g_hash_table_insert(properties, "ipv6_gateway", "::" );
- g_hash_table_insert(properties, "ipv6_dns1", "::" );
- g_hash_table_insert(properties, "ipv6_dns2", "::" );
- g_hash_table_insert(properties, "proxy", tcore_context_get_proxy(context->co_context));
- g_hash_table_insert(properties, "dev_name", tcore_context_get_ipv4_devname(context->co_context));
+
+ tcore_context_get_ipv4_addr(context->co_context,&ip4);
+ tcore_context_get_ipv4_gw(context->co_context, &gw);
+ tcore_context_get_ipv4_dns1(context->co_context, &dns1);
+ tcore_context_get_ipv4_dns2(context->co_context, &dns2);
+ tcore_context_get_proxy(context->co_context, &proxy);
+ tcore_context_get_ipv4_devname(context->co_context, &dev_name);
+
+ g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
+
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(context->path));
+ g_variant_builder_add(properties, "{ss}", "active",g_strdup(BOOL2STRING(active)));
+ if (ip4) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_address", ip4);
+ }
+ if (gw) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_gateway", gw);
+ }
+ if (dns1) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_dns1", dns1);
+ }
+ if (dns2) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_dns2", dns2);
+ }
+ g_variant_builder_add(properties, "{ss}", "ipv6_address", g_strdup("::"));
+ g_variant_builder_add(properties, "{ss}", "ipv6_gateway", g_strdup("::"));
+ g_variant_builder_add(properties, "{ss}", "ipv6_dns1", g_strdup("::"));
+ g_variant_builder_add(properties, "{ss}", "ipv6_dns2", g_strdup("::"));
+ if (proxy) {
+ g_variant_builder_add(properties, "{ss}", "proxy", proxy);
+ }
+ if (dev_name) {
+ g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
+ }
+ g_variant_builder_add(properties, "{ss}", "default_internet_conn", g_strdup(BOOL2STRING(context->default_internet)));
+ g_variant_builder_close(properties);
return TRUE;
}
-gboolean _ps_context_set_alwayson_enable(gpointer object, gboolean enabled)
+
+GVariant * _ps_context_get_properties(gpointer object, GVariantBuilder *properties)
{
+ TcoreContextState context_state ;
+ gboolean active = FALSE;
PsContext *context = object;
- int role = CONTEXT_ROLE_UNKNOWN;
+ gchar *dev_name = NULL;
+ gchar *proxy = NULL;
+ gchar *ipv4_address,*ipv4_gateway,*ipv4_dns1,*ipv4_dns2;
+
+ dbg("get context properties");
+ tcore_check_return_value(context != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
+
+ tcore_context_get_state(context->co_context, &context_state);
+ if (context_state == TCORE_CONTEXT_STATE_ACTIVATED)
+ active = TRUE;
+
+ active &= context->b_active;
+
+ tcore_context_get_ipv4_addr(context->co_context, &ipv4_address) ;
+ tcore_context_get_ipv4_gw(context->co_context, &ipv4_gateway );
+ tcore_context_get_ipv4_dns1(context->co_context, &ipv4_dns1);
+ tcore_context_get_ipv4_dns2(context->co_context , &ipv4_dns2);
+ tcore_context_get_proxy(context->co_context, &proxy);
+ tcore_context_get_ipv4_devname(context->co_context, &dev_name);
+
+ g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
+
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(context->path));
+ g_variant_builder_add(properties, "{ss}", "active",g_strdup(BOOL2STRING(active)));
+ if (ipv4_address) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
+ }
+ if (ipv4_gateway) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
+ }
+ if (ipv4_dns1) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
+ }
+ if (ipv4_dns2) {
+ g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
+ }
+ g_variant_builder_add(properties, "{ss}", "ipv6_address", g_strdup("::"));
+ g_variant_builder_add(properties, "{ss}", "ipv6_gateway", g_strdup("::"));
+ g_variant_builder_add(properties, "{ss}", "ipv6_dns1", g_strdup("::"));
+ g_variant_builder_add(properties, "{ss}", "ipv6_dns2", g_strdup("::"));
+ if (proxy) {
+ g_variant_builder_add(properties, "{ss}", "proxy", proxy);
+ }
+ if (dev_name) {
+ g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
+ }
+ g_variant_builder_add(properties, "{ss}", "default_internet_conn", g_strdup(BOOL2STRING(context->default_internet)));
- dbg("Set Always ON: [%s]", (enabled ? "YES" : "NO"));
+ dbg("Exiting");
+ return g_variant_builder_end(properties);
+}
- g_return_val_if_fail(context != NULL, FALSE);
+gboolean _ps_context_set_alwayson_enable(gpointer object, gboolean enabled)
+{
+ PsContext *context = object;
+ TcoreContextRole role;
+ tcore_check_return_value(context != NULL, FALSE);
+
+ tcore_context_get_role(context->co_context, &role);
- role = tcore_context_get_role(context->co_context);
- dbg("Role: [%d] Default Internet: [%s]",
- role, (context->default_internet ? "YES" : "NO"));
- if(role == CONTEXT_ROLE_INTERNET && context->default_internet) {
- dbg("Setting Always ON: [%s]", (enabled ? "YES" : "NO"));
+ if (role == TCORE_CONTEXT_ROLE_INTERNET && context->default_internet) {
context->alwayson = enabled;
}
gboolean _ps_context_get_default_internet(gpointer object)
{
PsContext *context = object;
- int role = CONTEXT_ROLE_UNKNOWN;
- g_return_val_if_fail(context != NULL, FALSE);
+ TcoreContextRole role;
+ tcore_check_return_value(context != NULL, FALSE);
- role = tcore_context_get_role(context->co_context);
- if(role == CONTEXT_ROLE_INTERNET && context->default_internet){
+ tcore_context_get_role(context->co_context, &role);
+ if (role == TCORE_CONTEXT_ROLE_INTERNET && context->default_internet) {
return TRUE;
}
gboolean _ps_context_set_service(gpointer object, gpointer service)
{
PsContext *context = object;
-
- dbg("Setting Service: [0x%x]", service);
-
- g_return_val_if_fail(context != NULL, FALSE);
+ tcore_check_return_value(context != NULL, FALSE);
context->p_service = service;
return TRUE;
gpointer _ps_context_ref_service(gpointer object)
{
PsContext *context = object;
- g_return_val_if_fail(context != NULL, FALSE);
+ tcore_check_return_value(context != NULL, FALSE);
return context->p_service;
}
gchar* _ps_context_ref_path(gpointer object)
{
PsContext *context = object;
- g_return_val_if_fail(context != NULL, NULL);
+ tcore_check_return_value(context != NULL, NULL);
return context->path;
}
gboolean _ps_context_get_alwayson_enable(gpointer object)
{
PsContext *context = object;
- g_return_val_if_fail(context != NULL, FALSE);
+ tcore_check_return_value(context != NULL, FALSE);
return context->alwayson;
}
gpointer _ps_context_ref_co_context(gpointer object)
{
PsContext *context = object;
- g_return_val_if_fail(context != NULL, NULL);
+ tcore_check_return_value(context != NULL, NULL);
return context->co_context;
}
{
gchar *ipv4 = NULL;
PsContext *context = object;
- g_return_val_if_fail(context != NULL, FALSE);
- dbg("Set Service State: [%s]",
- (enabled ? "CONNECTED" : "NOT CONNECTED"));
-
- /* Get IPv4 Address */
- ipv4 = tcore_context_get_ipv4_addr(context->co_context);
+ tcore_context_get_ipv4_addr(context->co_context, &ipv4);
dbg("IPv4 Address: [%s]", ipv4);
+ g_free(ipv4);
if (enabled) {
- dbg("Set state - ACTIVATED");
- tcore_context_set_state(context->co_context, CONTEXT_STATE_ACTIVATED);
- /* If IP address is 0.0.0.0, deactivate the context */
- if( g_str_equal(ipv4, "0.0.0.0") == TRUE ){
- dbg("IP Address: [0.0.0.0] - Deactivate context!!!");
+ tcore_context_set_state(context->co_context, TCORE_CONTEXT_STATE_ACTIVATED);
+
+ if ( g_str_equal(ipv4, "0.0.0.0") == TRUE ) {
+ dbg("ip address is 0.0.0.0");
_ps_service_deactivate_context(context->p_service, context);
return TRUE;
}
- /* Reset connection timer */
_ps_service_reset_connection_timer(context);
+
}
else {
dbg("Set state - DEACTIVATED");
- tcore_context_set_state(context->co_context, CONTEXT_STATE_DEACTIVATED);
+ tcore_context_set_state(context->co_context, TCORE_CONTEXT_STATE_DEACTIVATED);
/* Reset device information */
tcore_context_reset_devinfo(context->co_context);
-
- /* Reset connection timer */
- _ps_service_connection_timer(context->p_service, context);
+ __ps_context_emit_property_changed_signal(context);
}
- /* Emit Property changed signal */
- __ps_context_emit_property_changed_signal(context);
-
- /* Free memory */
- g_free(ipv4);
-
return TRUE;
}
gboolean _ps_context_set_ps_defined(gpointer *object, gboolean value, int cid)
{
PsContext *context = (PsContext *)object;
-
- g_return_val_if_fail(context != NULL, FALSE);
-
- if(tcore_context_get_id(context->co_context) == (unsigned int)cid){
+ guint id;
+ tcore_check_return_value(context != NULL, FALSE);
+ tcore_context_get_id(context->co_context, &id);
+ if (id == (unsigned int)cid) {
context->ps_defined = value;
- dbg("Context: [0x%x] Context define: [%s]",
- context, (context->ps_defined ? "YES" : "NO"));
+ dbg("context(%p) ps_defined(%d) cid(%d)", context, context->ps_defined, cid);
return TRUE;
}
+ dbg("context(%p) does not have cid(%d)",context, cid);
- dbg("Context ID [%d] not found in Context: [0x%x]", cid, context);
return FALSE;
}
return context->ps_defined;
}
+
+gboolean _ps_context_reset_user_data(gpointer object)
+{
+ PsContext *context = (PsContext *)object;
+
+ tcore_check_return_value(context != NULL, FALSE);
+ context->user_data = NULL;
+
+ return TRUE;
+}
+
+gpointer _ps_context_get_user_data(gpointer object)
+{
+ PsContext *context = (PsContext *)object;
+ return context->user_data;
+}
+
+TelReturn _ps_connection_hdlr(gpointer object)
+{
+ TelReturn rv = TEL_RETURN_FAILURE;
+ PsContext *pscontext = object;
+
+ _ps_context_set_alwayson_enable(pscontext, TRUE);
+ rv = _ps_service_activate_context(pscontext->p_service, pscontext);
+ if (rv != TEL_RETURN_SUCCESS) {
+ dbg("fail to activate context connection");
+ return rv;
+ }
+
+ dbg("success to activate context");
+ return rv;
+}
+
+void _ps_default_connection_hdlr(gpointer object)
+{
+ //int rv = TEL_RETURN_FAILURE;
+ PsContext *pscontext = (PsContext *)object;
+
+ _ps_service_reset_connection_timer(pscontext);
+ __ps_context_update_default_internet_to_db(pscontext, TRUE);
+
+ //set request profile
+ __ps_context_set_default_connection_enable(pscontext, TRUE);
+ _ps_context_set_alwayson_enable(pscontext, TRUE);
+ __ps_context_emit_property_changed_signal(pscontext);
+#if 0
+ //request to connect
+ rv = _ps_service_connect_default_context(pscontext->p_service);
+ if (rv == TEL_RETURN_PS_NETWORK_NOT_READY) {
+ int cid = -1;
+ PsService * p_service = (PsService *)pscontext->p_service;
+
+ dbg("PS is not attached yet, release resources.");
+
+ tcore_context_get_id(pscontext->co_context , &cid);
+ _ps_context_set_ps_defined((gpointer)pscontext, FALSE, cid);
+ tcore_ps_set_cid_active(p_service->co_ps, cid, FALSE);
+ tcore_ps_clear_context_id(p_service->co_ps, pscontext->co_context);
+ }
+#endif
+ dbg("complete to change the default connection");
+ return;
+}
+
+gint _ps_context_get_number_of_pdn(gchar *operator)
+{
+ gint num_of_pdn = 0;
+
+ num_of_pdn = __ps_context_load_num_of_pdn_from_database(operator);
+ dbg("loaded num_of_pdn (%d)", num_of_pdn);
+
+ return num_of_pdn;
+}
+
+gboolean _ps_context_handle_ifaceup(gpointer user_data)
+{
+ PsContext *pscontext = user_data;
+ TcoreContextState context_state ;
+ gchar *devname = NULL;
+ tcore_context_get_state(pscontext->co_context , &context_state);
+ dbg("context_state: %d", context_state);
+ if (context_state == TCORE_CONTEXT_STATE_ACTIVATED) {
+ tcore_context_get_ipv4_devname(pscontext->co_context, &devname );
+ dbg("Celluar profile: Emit property signal to provide IP configuration, devname(%s)", devname);
+ pscontext->b_active = TRUE;
+ if (TEL_RETURN_SUCCESS != tcore_util_netif(devname, TRUE)) {
+ dbg("Failed to bring up interface");
+ }
+ /*
+ * 20131212, Deprecated: Fixed by HTTP stack.
+ * ===============================================================================
+ * 20130801, JIRA DCM-2221: HTTP communication behavior while bearer switching
+ * Observations: When contiguous HTTP requests while ME handovers from wi-fi to 3G,
+ * libcurl does not make Aborted event to application
+ * even if libcurl receives socket closed event by SIOCKILLADDR.
+ * So, we add work-around patch set here.
+ * ===============================================================================
+ */
+ __ps_context_emit_property_changed_signal(pscontext);
+ return TRUE;
+ }
+ return FALSE;
+}
+#if 0
+gboolean _ps_context_handle_ifacedown(gpointer user_data)
+{
+ PsContext *pscontext = user_data;
+ gchar * devname;
+ gchar *ipv4;
+ TcoreContextState context_state ;
+
+ tcore_context_get_state(pscontext->co_context, &context_state);
+ dbg("context_state: %d", context_state);
+ if (context_state == TCORE_CONTEXT_STATE_ACTIVATED) {
+ tcore_context_get_ipv4_devname(pscontext->co_context, &devname);
+ dbg("Cellular profile: Do not send PDP deactivation request message to Modem.");
+ pscontext->b_active = FALSE;
+ dbg("reset socket connections, devname(%s)", devname);
+ tcore_context_get_ipv4_addr(pscontext->co_context, &ipv4);
+ tcore_util_reset_ipv4_socket(devname, ipv4);
+ if (TEL_RETURN_SUCCESS != tcore_util_netif(devname, FALSE)) {
+ dbg("Failed to bring down interface");
+ }
+ __ps_context_emit_property_changed_signal(pscontext);
+ return TRUE;
+ }
+ return FALSE;
+}
+#endif
+
+static gboolean on_context_get_properties (PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GVariant *gv = NULL;
+ GVariantBuilder property;
+
+ dbg("Entered");
+ gv = _ps_context_get_properties(user_data, &property);
+ packet_service_context_complete_get_properties(obj_context, invocation, gv);
+ return TRUE;
+}
+
+static gboolean on_context_get_profile (PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GVariant *gv = NULL;
+ GVariantBuilder profile;
+
+ dbg("Entered");
+ gv = __ps_context_get_profile_properties(user_data, &profile);
+ packet_service_context_complete_get_profile(obj_context, invocation, gv);
+ return TRUE;
+}
+
+static gboolean on_context_handle_activate (PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ gint rv = 0;
+ TelReturn result = TEL_RETURN_FAILURE;
+
+ gchar *apn = NULL;
+ TcoreContextState context_state = 0;
+ gpointer p_service = NULL; gpointer co_ps = NULL;
+ gpointer c_def_context = NULL; unsigned int cid_def = 0;
+
+ PsContext *pscontext = user_data;
+
+ dbg("Entered");
+ if (pscontext == NULL) {
+ err("activation request object is NULL");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ p_service = pscontext->p_service;
+ if (!p_service) {
+ err("service object is null");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ co_ps = _ps_service_ref_co_ps(p_service);
+ if (!co_ps) {
+ err("core object is null");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ dbg("activate context(%s)", _ps_context_ref_path(pscontext));
+
+ tcore_context_get_apn(pscontext->co_context, &apn);
+ if (!apn) {
+ err("requested apn is null");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ tcore_context_get_state(pscontext->co_context, &context_state);
+ if (context_state != TCORE_CONTEXT_STATE_DEACTIVATED) {
+ warn("operation is in progress");
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ dbg("requested context(%p) co_context(%p) apn (%s)", pscontext, pscontext->co_context, apn);
+ //check apn is activated or not
+ rv = tcore_ps_is_active_apn(co_ps, (const gchar*)apn);
+ if (rv) {
+ dbg("requested apn is already activated");
+
+ result = _ps_connection_hdlr(pscontext);
+ if (result != TEL_RETURN_SUCCESS) {
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
+ tcore_context_get_state(pscontext->co_context, &context_state);
+ if (context_state == TCORE_CONTEXT_STATE_ACTIVATED) {
+ dbg("context is already connected");
+ _ps_context_set_connected(pscontext, TRUE);
+ }
+
+ dbg("success to open connection request");
+ return TRUE;
+ }
+
+ //find the current default connection
+ c_def_context = _ps_service_return_default_context(p_service);
+ tcore_context_get_id(((PsContext *)c_def_context)->co_context, &cid_def );
+ if (cid_def == 0) {
+ err("it is not avaiable to open connection");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ //check the status of def context
+ tcore_context_get_state(((PsContext *)c_def_context)->co_context, &context_state);
+ if (context_state != TCORE_CONTEXT_STATE_ACTIVATED) {
+ err("default connection is in progress");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ _ps_service_reset_connection_timer(c_def_context);
+
+#if 0
+ ((PsContext *)c_def_context)->user_data = pscontext;
+ result = tcore_ps_deactivate_cid(co_ps, cid_def);
+ if (result != TEL_RETURN_SUCCESS) {
+ err("fail to deactivate exist network connection");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+#endif
+ packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
+ return TRUE;
+
+}
+
+static gboolean on_context_handle_deactivate (PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+
+ gboolean rv = FALSE;
+
+ TcoreContextState context_state;
+ PsContext *pscontext = user_data;
+
+ dbg("Entered");
+ if (pscontext == NULL) {
+ err("deactivation request object is NULL");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ tcore_context_get_state(pscontext->co_context, &context_state);
+ if (context_state != TCORE_CONTEXT_STATE_ACTIVATED) {
+ err("operation is in progress");
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ dbg("deactivate context(%s)", _ps_context_ref_path(pscontext));
+
+ _ps_service_reset_connection_timer(pscontext);
+ _ps_context_set_alwayson_enable(pscontext, FALSE);
+
+ rv = _ps_service_deactivate_context(pscontext->p_service, pscontext);
+ if (rv != TEL_RETURN_SUCCESS) {
+ err("fail to deactivate context connection");
+ FAIL_RESPONSE(invocation, PS_ERR_TRASPORT);
+ return TRUE;
+ }
+
+ dbg("success to deactivate context");
+ packet_service_context_complete_deactivate(obj_context, invocation, pscontext->path);
+
+ tcore_context_get_state(pscontext->co_context, &context_state);
+ if (context_state == TCORE_CONTEXT_STATE_DEACTIVATED) {
+ dbg("context is already disconnected");
+ pscontext->ps_defined = FALSE;
+ _ps_context_set_connected(pscontext, FALSE);
+ }
+
+ return TRUE;
+}
+
+static gboolean on_context_set_default_connection (PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ TcoreContextRole role;
+ TcoreContextState context_state;
+
+ gpointer co_ps = NULL;
+ gpointer service = NULL;
+ gpointer cur_default_ctx = NULL;
+ PsContext *pscontext = user_data;
+
+ dbg("enter set default connection PsContext(%p)", pscontext);
+ if (pscontext == NULL) {
+ err("activation request object is NULL");
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
+ return TRUE;
+ }
+
+ dbg("start default connection");
+ tcore_context_get_role(pscontext->co_context, &role);
+ if (role != TCORE_CONTEXT_ROLE_INTERNET) {
+ warn("only internet profile type can be set to default internet profile");
+ FAIL_RESPONSE(invocation, PS_ERR_WRONG_PROFILE);
+ return TRUE;
+ }
+
+ service = pscontext->p_service;
+ cur_default_ctx = _ps_service_return_default_context(service);
+ dbg("current default connection (%p)", cur_default_ctx);
+
+ if (!cur_default_ctx) {
+ err("No current default connection.");
+ goto OUT;
+ }
+
+ if (pscontext == cur_default_ctx) {
+ err("already default internet connection.");
+ goto OUT;
+ }
+#if 0
+ // First, send deactivation request first.
+ rv = _ps_service_deactivate_context(((PsContext *)cur_default_ctx)->p_service, cur_default_ctx);
+ if (rv == TEL_RETURN_PS_ACTIVATING) {
+ dbg("fail to deactivate default connection, rv(%d)", rv);
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+#endif
+ /* Normal deactivation case. */
+ tcore_context_get_state(((PsContext *)cur_default_ctx)->co_context, &context_state);
+ if (context_state == TCORE_CONTEXT_STATE_DEACTIVATING) {
+ dbg("deactivation request in current ps (%p)", cur_default_ctx);
+ ((PsContext *)cur_default_ctx)->user_data = pscontext;
+ }
+ else{
+ guint cid = 0;
+
+ dbg("[Not normal] deactivation request in current ps (%p)", cur_default_ctx);
+
+ tcore_context_get_id(((PsContext *)cur_default_ctx)->co_context, &cid);
+ _ps_context_set_ps_defined(cur_default_ctx, FALSE, cid);
+ co_ps = _ps_service_ref_co_ps(service);
+ //tcore_ps_set_cid_active((CoreObject *)co_ps, cid, FALSE);
+ tcore_ps_clear_context_id((CoreObject *)co_ps, ((PsContext *)cur_default_ctx)->co_context);
+ }
+
+ //unset default info of previous connection
+ _ps_context_set_alwayson_enable(cur_default_ctx, FALSE);
+ __ps_context_set_default_connection_enable(cur_default_ctx, FALSE);
+
+ //db update - release default connection
+ dbg("context(%p): release default connection property.", cur_default_ctx);
+ __ps_context_update_default_internet_to_db((PsContext *)cur_default_ctx, FALSE);
+ /* Allow Connman to update profile information. */
+ __ps_context_emit_property_changed_signal(cur_default_ctx);
+
+ dbg("activation requeset in new ps (%p)", pscontext);
+OUT:
+ _ps_default_connection_hdlr(pscontext);
+ packet_service_context_complete_set_default_connection(obj_context, invocation, TRUE);
+ return TRUE;
+
+}
+
+static gboolean on_context_modify_profile(PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation,
+ GVariant *property, gpointer user_data)
+{
+ GVariantIter g_iter;
+ gchar *g_value;
+ gchar *g_key;
+
+ gboolean result = FALSE;
+ TcoreContextState context_state = 0;
+ PsContext *context = user_data;
+ GHashTable *profile_property = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+ dbg("modify context's profile properties");
+
+ tcore_context_get_state(context->co_context, &context_state);
+ if (context_state == TCORE_CONTEXT_STATE_ACTIVATING) {
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ /* Creating the profile property hash for for internal handling */
+ /* Create a hash table for the profile property as all fucntion already use ghash table */
+ g_variant_iter_init (&g_iter, property);
+ while (g_variant_iter_next (&g_iter, "{ss}", &g_key, &g_value)) {
+ g_hash_table_insert(profile_property, g_strdup(g_key), g_strdup(g_value));
+
+ /* must free data for ourselves */
+ g_free (g_value);
+ g_free (g_key);
+ }
+
+ result = __ps_context_update_profile(context, profile_property);
+ if (result != TRUE) {
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ _ps_service_deactivate_context(context->p_service, context);
+ if (context_state == TCORE_CONTEXT_STATE_DEACTIVATED) {
+ dbg("context is already disconnected");
+ _ps_context_set_connected(context, FALSE);
+ }
+
+ packet_service_context_complete_modify_profile(obj_context, invocation, TRUE);
+ return TRUE;
+}
+
+static gboolean on_context_remove_profile (PacketServiceContext *obj_context,
+ GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ PsContext *context = user_data;
+ gboolean result = FALSE;
+
+ dbg("Entered");
+
+ __ps_context_remove_database(context);
+ result = __ps_context_remove_context(context);
+ if (result) {
+ gchar *ctx_path = g_strdup(_ps_context_ref_path(context));
+
+ /* Remove context from HASH table */
+ g_hash_table_remove(contexts, ctx_path);
+ g_free(ctx_path);
+ }
+ else {
+ err("Failed to remove context [%p]", context);
+ }
+
+ packet_service_context_complete_remove_profile(obj_context, invocation, result);
+
+ return TRUE;
+}
+
+static void _ps_context_setup_interface(PacketServiceContext *context,
+ PsContext *context_data)
+{
+ dbg("Entered");
+
+ g_signal_connect (context,
+ "handle-get-properties",
+ G_CALLBACK (on_context_get_properties),
+ context_data);
+
+ g_signal_connect (context,
+ "handle-get-profile",
+ G_CALLBACK (on_context_get_profile),
+ context_data);
+
+ g_signal_connect (context,
+ "handle-activate",
+ G_CALLBACK (on_context_handle_activate),
+ context_data);
+
+ g_signal_connect (context,
+ "handle-deactivate",
+ G_CALLBACK (on_context_handle_deactivate),
+ context_data);
+
+ g_signal_connect (context,
+ "handle-set-default-connection",
+ G_CALLBACK (on_context_set_default_connection),
+ context_data);
+
+ g_signal_connect (context,
+ "handle-modify-profile",
+ G_CALLBACK (on_context_modify_profile),
+ context_data);
+
+ g_signal_connect (context,
+ "handle-remove-profile",
+ G_CALLBACK (on_context_remove_profile),
+ context_data);
+
+ dbg("Exiting");
+ return;
+}
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
+#include <glib.h>
+
#include "ps-error.h"
GQuark ps_error_quark(void)
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
#include <stdio.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
#include <tcore.h>
#include <plugin.h>
#include <ps.h>
-static enum tcore_hook_return __on_hook_modem_added(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data, void *user_data)
+PsCustom *ps_ctx = NULL;
+
+void _packet_service_cleanup()
+{
+ dbg("Entered");
+
+ /*Cleaning up the master list*/
+ g_slist_foreach(ps_ctx->master, __remove_master, NULL);
+
+ /*Unowning the Gdbus */
+ g_bus_unown_name(ps_ctx->bus_id);
+
+ /*Freeing the memory allocated to the custom data for Packet Service*/
+ g_free(ps_ctx);
+ ps_ctx = NULL;
+
+ dbg("Exiting");
+ return;
+}
+
+
+TcoreHookReturn __on_hook_modem_added(Server *server,
+ TcoreServerNotification command,
+ guint data_len, void *data, void *user_data)
{
gpointer *master = user_data;
- gboolean rv=FALSE;
+ gboolean rv = FALSE;
+ dbg("Entered");
rv = _ps_master_create_modems(master);
dbg("Modem Added hook operation: [%s]", (rv ? "SUCCESS" : "FAIL"));
- return TCORE_HOOK_RETURN_STOP_PROPAGATION;
+ return TCORE_HOOK_RETURN_CONTINUE;
}
static gboolean on_load()
return TRUE;
}
+static void on_bus_acquired(GDBusConnection *conn,
+ const gchar *name, gpointer user_data)
+{
+ gboolean rv=FALSE;
+ gpointer *master = NULL;
+
+ TcorePlugin *p = user_data;
+
+ dbg("Bus is acquired");
+
+ /*Storing the GDbus connection in custom data */
+ ps_ctx->conn = conn;
+
+ master = _ps_master_create_master(conn, p);
+ if (!master) {
+ err("Unable to Intialize the Packet Service");
+ _packet_service_cleanup();
+ return;
+ }
+
+ ps_ctx->master = g_slist_append(ps_ctx->master, master);
+
+ rv = _ps_master_create_modems(master);
+ if (!rv) {
+ dbg("_ps_master_create_modems failed");
+ _packet_service_cleanup();
+ }
+
+ dbg("initialized PacketService plugin!");
+ return ;
+}
+
static gboolean on_init(TcorePlugin *p)
{
- gpointer *master;
- DBusGConnection *conn;
- GError *error = NULL;
+ guint id;
gboolean rv=FALSE;
+ gchar *address = NULL;
+ GError *error = NULL;
+ GDBusConnection *conn = NULL;
- //get dbus connection
- conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (conn == NULL) {
- err("fail to get dbus(%s)", error->message);
+ if (!p)
return FALSE;
- }
- dbg("get dbus connection (%p)", conn);
- dbg("plugin pointer (%p)", p);
rv = _ps_context_initialize(p);
- if(rv != TRUE){
+ if (rv != TRUE) {
dbg("fail to initialize context global variable");
return FALSE;
}
- master = _ps_master_create_master(conn, p);
- rv = _ps_master_create_modems(master);
- if (rv == FALSE) {
- dbg("Modem NOT created... will wait for TNOTI_MODEM_ADDED notification");
+ ps_ctx = g_try_malloc0(sizeof(PsCustom));
+ if (!ps_ctx) {
+ err("Memory allocation failed for the custom data of PS");
+ return FALSE;
+ }
+
+ dbg("i'm init - PacketService!");
+ address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ g_assert_no_error(error);
+ dbg("address of the bus [%s]", address);
- tcore_server_add_notification_hook(tcore_plugin_ref_server(p),
- TNOTI_MODEM_ADDED, __on_hook_modem_added, master);
- } else {
- dbg("initialized PacketService plugin!");
+ conn = g_dbus_connection_new_for_address_sync(address,
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+ NULL, NULL, &error);
+ g_assert_no_error(error);
+ if (!conn) {
+ dbg("connection failed");
}
+ id = g_bus_own_name_on_connection(conn,
+ PS_DBUS_SERVICE,
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,
+ on_bus_acquired, NULL,
+ p, NULL);
+
+ dbg("id=[%d]", id);
+
+
+ /* Initializing the custom data for PacketService */
+ ps_ctx->bus_id = id;
+ ps_ctx->conn = NULL;
+ ps_ctx->master = NULL;
+ ps_ctx->p = p;
+
return TRUE;
}
static void on_unload(TcorePlugin *p)
{
dbg("i'm unload!");
- return;
+
+ _packet_service_cleanup();
}
-struct tcore_plugin_define_desc plugin_define_desc =
-{
+EXPORT_API struct tcore_plugin_define_desc plugin_define_desc = {
.name = "PACKETSERVICE",
.priority = TCORE_PLUGIN_PRIORITY_MID + 1,
.version = 1,
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
#include <unistd.h>
-#include "ps-master.h"
-
#include "ps.h"
-#include "ps-error.h"
+#include "generated-code.h"
#include <server.h>
#include <plugin.h>
#include <storage.h>
#include <hal.h>
-#define PS_MASTER_PATH "/"
+#define PS_MASTER_PATH "/"
#define PROP_DEFAULT FALSE
#define PROP_DEFAULT_STR NULL
#define BOOL2STRING(a) ((a==TRUE) ? ("TRUE"):("FALSE"))
-/*Properties*/
-enum {
- PROP_MASTER_O,
- PROP_MASTER_PLUGIN,
- PROP_MASTER_CONN,
- PROP_MASTER_PATH
-};
+static void __ps_master_emit_modem_added_signal(PsMaster *master, gpointer modem);
+/* static void __ps_master_emit_modem_removed_signal(PsMaster *master, gpointer modem); */
+static void _ps_master_setup_interface(PacketServiceMaster *master, PsMaster *master_data);
-enum {
- SIG_MASTER_MODEM_ADDED,
- SIG_MASTER_MODEM_REMOVED,
- SIG_MASTER_LAST
-};
+static void __ps_master_register_key_callback(gpointer master, TcoreStorageKey key);
+static void __ps_master_storage_key_callback(TcoreStorageKey key, void *value, void *user_data);
-static guint32 signals[SIG_MASTER_LAST] = {0,};
+#if 0
+static void __ps_master_handle_contexts(gchar *request)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ GHashTable *contexts = NULL;
-struct PsMasterClass {
- GObjectClass parent;
+ dbg("send dbus %s requeset", request);
- void (*modem_added)(PsMaster *master, gchar *modem_path);
- void (*modem_removed)(PsMaster *master, gchar *modem_path);
-};
+ contexts = _ps_context_ref_hashtable();
+ if (contexts == NULL) {
+ err("no profiles");
+ return;
+ }
-struct PsMaster {
- GObject parent;
+ g_hash_table_iter_init(&iter, contexts);
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ gchar *s_path = NULL;
+
+ s_path = _ps_context_ref_path(value);
+ dbg("key(%s), value(%p), path(%s)", (gchar *)key, value, s_path);
+ if (!g_strcmp0(request, "InterfaceDown")) {
+ _ps_context_handle_ifacedown(value);
+ } else if (!g_strcmp0(request, "InterfaceUp")) {
+ _ps_context_handle_ifaceup(value);
+ }
+ }
+ return;
+}
+#endif
- //member variable
- gchar *path;
- TcorePlugin *plg;
- DBusGConnection *conn;
- GHashTable *modems;
-};
+void __remove_master(gpointer data, gpointer user_data)
+{
+ PsMaster *master = data;
-G_DEFINE_TYPE(PsMaster, ps_master, G_TYPE_OBJECT);
+ dbg("Entered");
-/*Function Declaration*/
-static void __ps_master_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-static void __ps_master_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+ /* Need to remove the compelete hash table */
+ g_hash_table_remove_all(master->modems);
-gboolean ps_iface_master_get_modems(PsMaster *master, DBusGMethodInvocation *context);
-gboolean ps_iface_master_get_profile_list(PsMaster *master, DBusGMethodInvocation *context);
-gboolean ps_iface_master_add_profile(PsMaster *master, GHashTable *profile_property, gboolean *result, GError **error);
-gboolean ps_iface_master_reset_profile(PsMaster *master, gboolean *result, GError **error);
+ /* Need to UNexport and Unref the master Object */
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(master->if_obj));
-static void __ps_master_emit_modem_added_signal(PsMaster *master, gpointer modem);
-/*static void __ps_master_emit_modem_removed_signal(PsMaster *master, gpointer modem);*/
+ g_object_unref(master->if_obj);
-static void __remove_modem(gpointer data);
-static void __ps_master_register_key_callback(gpointer master, enum tcore_storage_key key);
-static void __ps_master_storage_key_callback(enum tcore_storage_key key, void *value, void *user_data);
+ /* Need to free the memory allocated for the members of the master */
+ g_free(master->path);
+ g_free(master);
-#include "ps-iface-master-glue.h"
+ dbg("Exiting");
+ return;
+}
-static void ps_master_init(PsMaster *master)
+static void __ps_master_emit_modem_added_signal(PsMaster *master, gpointer modem)
{
- dbg("ps master init");
- master->plg = NULL;
- master->conn = NULL;
- master->path = PROP_DEFAULT_STR;
- master->modems = g_hash_table_new_full(g_str_hash,g_str_equal, g_free, __remove_modem);
+ GVariant *gv = NULL;
+ GVariantBuilder properties;
+
+ dbg("get modem properties");
+
+ gv = _ps_modem_get_properties(modem, &properties);
+ packet_service_master_emit_modem_added(master->if_obj,gv);
+
+ dbg("Exiting");
return;
}
-static void ps_master_class_init(PsMasterClass *klass)
+/*
+static void __ps_master_emit_modem_removed_signal(PsMaster *master, gpointer modem)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ g_signal_emit(master, signals[SIG_MASTER_MODEM_REMOVED], 0, _ps_modem_ref_path(modem));
+ dbg("master (%p) emit the modem(%p) removed signal", master, modem);
+ return;
+}
+*/
- dbg("class_init");
+static void __ps_master_register_key_callback(gpointer object, TcoreStorageKey key)
+{
+ PsMaster *master = (PsMaster *) object;
+ Server *s = tcore_plugin_ref_server(master->plg);
+ TcoreStorage *strg = NULL;
- //set property
- object_class->get_property = __ps_master_get_property;
- object_class->set_property = __ps_master_set_property;
+ strg = tcore_server_find_storage(s, "vconf");
+ tcore_storage_set_key_callback(strg, key, __ps_master_storage_key_callback, object);
- //register class to dbus
- dbus_g_object_type_install_info(PS_TYPE_MASTER, &dbus_glib_ps_iface_master_object_info);
+ return;
+}
- //add properties
- g_object_class_install_property(
- object_class,
- PROP_MASTER_PLUGIN,
- g_param_spec_pointer("plg", "PLUGIN", "Plug in Object",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+static void __ps_master_storage_key_callback(TcoreStorageKey key, void *value, void *user_data)
+{
+ GVariant *tmp = NULL;
+ GHashTableIter iter;
+ gpointer h_key, h_value;
+ gboolean type_check = FALSE;
+ PsMaster *master = (PsMaster *)user_data;
- g_object_class_install_property(
- object_class,
- PROP_MASTER_CONN,
- g_param_spec_boxed("conn", "CONNECTION", "DBus connection", DBUS_TYPE_G_CONNECTION,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ dbg("storage key(%d) callback", key);
+ g_return_if_fail(master != NULL);
- g_object_class_install_property(
- object_class,
- PROP_MASTER_PATH,
- g_param_spec_string("path", "Path", "Object path", NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ tmp = (GVariant *)value;
+ if (!tmp) {
+ err("value is null");
+ return;
+ }
- //add signal handler
- signals[SIG_MASTER_MODEM_ADDED] = g_signal_new("modem-added", G_OBJECT_CLASS_TYPE(klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(PsMasterClass, modem_added), NULL, NULL,
- g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
+ type_check = g_variant_is_of_type(tmp, G_VARIANT_TYPE_BOOLEAN);
+ if (!type_check) {
+ err("wrong variant data type");
+ g_variant_unref(tmp);
+ return;
+ }
- signals[SIG_MASTER_MODEM_REMOVED] = g_signal_new("modem-removed", G_OBJECT_CLASS_TYPE(klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(PsMasterClass, modem_removed), NULL, NULL,
- g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, DBUS_TYPE_G_OBJECT_PATH);
+ g_hash_table_iter_init(&iter, master->modems);
+ while (g_hash_table_iter_next(&iter, &h_key, &h_value) == TRUE) {
+ if(key == STORAGE_KEY_DATA_ENABLE) {
+ gboolean data_allowed = g_variant_get_boolean(tmp);
+ _ps_modem_set_data_allowed(h_value, data_allowed);
+ } else if(key == STORAGE_KEY_SETAPPL_STATE_DATA_ROAMING) {
+ gboolean roaming_allowed = g_variant_get_boolean(tmp);
+ _ps_modem_set_data_roaming_allowed(h_value, roaming_allowed);
+ }
+ }
+ g_variant_unref(tmp);
return;
}
-static void __ps_master_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+gpointer _ps_master_create_master(GDBusConnection *conn, TcorePlugin *p)
{
- return;
+ PacketServiceMaster *master = NULL;
+ PsMaster *new_master = NULL;
+ GError *error = NULL;
+
+ dbg("master object create");
+ tcore_check_return_value(conn != NULL, NULL);
+
+ /* creating the master object for the interface com.tcore.ps.master */
+ master = packet_service_master_skeleton_new();
+ tcore_check_return_value(master != NULL, NULL);
+
+
+ /* Initializing the master list for internal referencing */
+ new_master = g_try_malloc0(sizeof(PsMaster));
+ if (NULL == new_master) {
+ err("Unable to allocate memory for master");
+ goto FAILURE;
+ }
+
+ new_master->conn = conn;
+ new_master->path = g_strdup(PS_MASTER_PATH);
+ new_master->plg = p;
+ new_master->if_obj = master;
+ new_master->modems =
+ g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, __remove_modem_handler);
+
+ /* Setting Up the call backs for the interface */
+ _ps_master_setup_interface(master, new_master);
+
+ /* exporting the interface object to the path mention for master */
+ g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(master),
+ conn, PS_MASTER_PATH, &error);
+ g_assert_no_error (error);
+
+ /* Registering the key callbacks for values in storage settings */
+ __ps_master_register_key_callback(new_master,
+ STORAGE_KEY_DATA_ENABLE);
+ __ps_master_register_key_callback(new_master,
+ STORAGE_KEY_SETAPPL_STATE_DATA_ROAMING);
+
+ /* Adding Hook for modem addition laters */
+ tcore_server_add_notification_hook(tcore_plugin_ref_server(p),
+ TCORE_SERVER_NOTIFICATION_ADDED_MODEM_PLUGIN,
+ __on_hook_modem_added, new_master);
+
+ dbg("Successfully created the master");
+ return new_master;
+
+FAILURE:
+ err("Unable to create master");
+ g_object_unref(master);
+ return NULL;
}
-static void __ps_master_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+gboolean _ps_master_create_modems(gpointer object)
{
- PsMaster *master = PS_MASTER(object);
+ Server *s = NULL;
+ GSList *plist = NULL;
+ PsMaster *master = NULL;
- switch (prop_id) {
- case PROP_MASTER_PLUGIN: {
- master->plg = g_value_get_pointer(value);
- msg(" master(%p) set plg(%p)", master, master->plg);
- }
- break;
- case PROP_MASTER_CONN: {
- master->conn = g_value_get_boxed(value);
- msg(" master(%p) set conn(%p)", master, master->conn);
+ TcorePlugin *plugin;
+ gchar *modem_name;
+ CoreObject *co_modem;
+ gpointer modem, modem_node;
+
+ dbg("create modem objects");
+ tcore_check_return_value(object != NULL, FALSE);
+
+ master = (PsMaster *)object;
+ s = tcore_plugin_ref_server(master->plg);
+ plist = tcore_server_get_modem_plugin_list(s);
+ for (; plist; plist = plist->next) {
+ plugin = plist->data;
+ co_modem = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM);
+ if (co_modem == NULL)
+ continue;
+
+ dbg("create modem objects %p", co_modem);
+ modem_name = g_strdup_printf("/%s",
+ tcore_server_get_cp_name_by_plugin(plugin));
+
+ modem_node = g_hash_table_lookup(master->modems, modem_name);
+ if (modem_node != NULL) {
+ dbg("modem '%s' already exists", modem_name);
+ g_free(modem_name);
+
+ continue;
}
- break;
- case PROP_MASTER_PATH: {
- if (master->path) g_free(master->path);
- master->path = g_value_dup_string(value);
- msg(" master(%p) set path(%s)", master, master->path);
+
+ /* Create Modem */
+ modem = _ps_modem_create_modem(master->conn,
+ master->plg, master, modem_name, co_modem);
+ if (modem == NULL) {
+ err("Failed to Create modem '%s'", modem_name);
+ g_free(modem_name);
+
+ return FALSE;
}
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- } //swtich end
- return;
+ g_hash_table_insert(master->modems, g_strdup(modem_name), modem);
+ dbg("Created modem '%s'", modem_name);
+
+ /* Emit signal: Modem added */
+ __ps_master_emit_modem_added_signal(master, modem);
+
+ g_free(modem_name);
+ }
+
+ return TRUE;
}
-gboolean ps_iface_master_get_modems(PsMaster *master, DBusGMethodInvocation *context)
+gboolean _ps_master_get_storage_value_bool(gpointer object, TcoreStorageKey key)
{
- GError *error = NULL;
+ Server *s = NULL;
+ TcoreStorage *strg = NULL;
+ PsMaster *master = object;
+
+ tcore_check_return_value(master != NULL, FALSE);
+ s = tcore_plugin_ref_server(master->plg);
+ strg = tcore_server_find_storage(s, "vconf");
+
+ return tcore_storage_get_bool(strg, key);
+}
+
+gint _ps_master_get_storage_value_int(gpointer object, TcoreStorageKey key)
+{
+ Server *s = NULL;
+ TcoreStorage *strg = NULL;
+ PsMaster *master = object;
+
+ tcore_check_return_value(master != NULL, FALSE);
+ s = tcore_plugin_ref_server(master->plg);
+ strg = tcore_server_find_storage(s, "vconf");
+
+ return tcore_storage_get_int(strg, key);
+}
+
+gboolean _ps_master_set_storage_value_bool(gpointer object,TcoreStorageKey key, gboolean value)
+{
+ Server *s = NULL;
+ TcoreStorage *strg = NULL;
+ PsMaster *master = object;
+
+ tcore_check_return_value(master != NULL, FALSE);
+ s = tcore_plugin_ref_server(master->plg);
+ strg = tcore_server_find_storage(s, "vconf");
+
+ return tcore_storage_set_bool(strg, key, value);
+}
+
+gboolean _ps_master_set_storage_value_int(gpointer object, TcoreStorageKey key, gint value)
+{
+ Server *s = NULL;
+ TcoreStorage *strg = NULL;
+ PsMaster *master = object;
+
+ tcore_check_return_value(master != NULL, FALSE);
+ s = tcore_plugin_ref_server(master->plg);
+ strg = tcore_server_find_storage(s, "vconf");
+
+ return tcore_storage_set_int(strg, key, value);
+}
+
+static gboolean on_master_get_modems (PacketServiceMaster *obj_master,
+ GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ GVariantBuilder b_modem;
+ GVariant *modems;
+
GHashTableIter iter;
gpointer key, value;
- GHashTable *modems;
-
- dbg("master get modems interface");
+ PsMaster *master = user_data;
+ dbg("Entered");
if (master->modems == NULL) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "master(%p) does not have modems", master);
- dbus_g_method_return_error(context, error);
- return FALSE;
+ err("No modem Present");
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
}
- modems = g_hash_table_new_full(g_direct_hash, g_str_equal, g_free,
- (GDestroyNotify) g_hash_table_destroy);
+ g_variant_builder_init(&b_modem,G_VARIANT_TYPE("a{sa{ss}}"));
g_hash_table_iter_init(&iter, master->modems);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
gchar *path = NULL;
- GHashTable *properties = NULL;
- gboolean rv = FALSE;
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- rv = _ps_modem_get_properties(value, properties);
- if (rv != TRUE) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "fail to get properties modem(%p)",
- value);
- dbus_g_method_return_error(context, error);
- g_hash_table_destroy(properties);
- g_hash_table_destroy(modems);
- return TRUE;
- }
path = _ps_modem_ref_path(value);
- g_hash_table_insert(modems, g_strdup(path), properties);
- dbg("modem (%p) inserted into hash", value);
+ dbg("modem path [%s]",path);
+
+ g_variant_builder_open(&b_modem, G_VARIANT_TYPE("{sa{ss}}"));
+ g_variant_builder_add(&b_modem, "s", g_strdup(path));
+ if (FALSE == _ps_modem_get_properties_handler(value, &b_modem)) {
+ err("Unable to get the modem properties");
+ g_variant_builder_close(&b_modem);
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
+ }
+ g_variant_builder_close(&b_modem);
}
+ modems = g_variant_builder_end(&b_modem);
- dbus_g_method_return(context, modems);
- g_hash_table_destroy(modems);
-
+ packet_service_master_complete_get_modems(obj_master, invocation, modems);
return TRUE;
}
-gboolean ps_iface_master_get_profile_list(PsMaster *master, DBusGMethodInvocation *context)
+static gboolean on_master_get_profile_list (PacketServiceMaster *obj_master,
+ GDBusMethodInvocation *invocation, gpointer user_data)
{
int index = 0;
- GError *error = NULL;
GHashTableIter iter;
gpointer key, value;
GHashTable *contexts = NULL;
GSList *profiles = NULL;
+ dbg("master get the profile list");
+
contexts = _ps_context_ref_hashtable();
if (contexts == NULL) {
err("no profiles");
- g_set_error(&error, PS_ERROR, PS_ERR_NO_PROFILE, "profile does not exists");
- dbus_g_method_return_error(context, error);
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
return TRUE;
}
s_path = _ps_context_ref_path(value);
dbg("key(%s), value(%p), path(%s)", (gchar *)key, value, s_path);
- if(s_path)
+ if (s_path)
profiles = g_slist_append(profiles, g_strdup((const gchar*)s_path));
}
if (profiles == NULL) {
err("no profiles");
- g_set_error(&error, PS_ERROR, PS_ERR_NO_PROFILE, "profile does not exists");
- dbus_g_method_return_error(context, error);
+ FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
return TRUE;
}
len = g_slist_length(profiles);
strv = g_new(gchar *, len+1);
- do{
+ while (profiles) {
strv[index] = g_strdup(profiles->data);
index++;
- }while( (profiles = g_slist_next(profiles)) );
+
+ profiles = profiles->next;
+ }
strv[index] = NULL;
- dbus_g_method_return(context, strv);
+ packet_service_master_complete_get_profile_list(obj_master,
+ invocation,(const gchar *const *)strv);
+
g_strfreev(strv);
profiles = g_slist_nth(profiles, 0);
g_slist_free_full(profiles, g_free);
return TRUE;
}
-gboolean ps_iface_master_add_profile(PsMaster *master, GHashTable *profile_property,
- gboolean *result, GError **error)
+static gboolean on_master_add_profile (PacketServiceMaster *obj_master,
+ GDBusMethodInvocation *invocation,
+ GVariant *property, gpointer user_data)
{
+ GVariantIter g_iter;
+ gchar *g_value;
+ gchar *g_key;
+
GHashTableIter iter;
gpointer key, value;
gboolean rv = FALSE;
gchar *operator = NULL;
+ PsMaster *master = user_data;
+ GHashTable *profile_property =
+ g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
dbg("add profile request");
g_hash_table_iter_init(&iter, master->modems);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
operator = _ps_modem_ref_operator(value);
- if(operator)
+ if (operator)
break;
}
- if(!operator){
- dbg("there is no active modem");
- g_set_error(error, PS_ERROR, PS_ERR_INTERNAL,"fail to add profile");
- *result = FALSE;
+ if (!operator) {
+ err("there is no active modem");
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
return TRUE;
}
+ /* Create a hash table for the profile property as all fucntion already use ghash table */
+ g_variant_iter_init (&g_iter, property);
+ while (g_variant_iter_next (&g_iter, "{ss}", &g_key, &g_value)) {
+ dbg(" '%s' value '%s'", g_key, g_value);
+
+ g_hash_table_insert(profile_property, g_strdup(g_key), g_strdup(g_value));
+
+ /* must free data for ourselves */
+ g_free (g_value);
+ g_free (g_key);
+ }
+
rv = _ps_context_add_context(value, operator, profile_property);
- if(rv != TRUE){
- g_set_error(error, PS_ERROR, PS_ERR_INTERNAL,"fail to add profile");
- *result = FALSE;
+ if (rv != TRUE) {
+ err("Failed to add the Profile");
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
return TRUE;
}
- dbg("success to add profile");
- *result = TRUE;
+ packet_service_master_complete_add_profile(obj_master, invocation, TRUE);
+ g_hash_table_destroy(profile_property);
return TRUE;
}
-gboolean ps_iface_master_reset_profile(PsMaster *master, gboolean *result, GError **error)
+static gboolean on_master_reset_profile (PacketServiceMaster *obj_master,
+ GDBusMethodInvocation *invocation,
+ gint type, gpointer user_data)
{
GHashTableIter iter;
gpointer key, value;
gboolean rv = FALSE;
int b_check = 0;
+ PsMaster *master = user_data;
- *result = TRUE;
-
- dbg("reset profile request");
+ dbg("reset profile request type(%d)", type);
if (master->modems == NULL) {
- dbg("modem does not exist");
- g_set_error(error, PS_ERROR, PS_ERR_INTERNAL, "fail to get modem");
- *result = FALSE;
+ err("modem does not exist");
+ FAIL_RESPONSE(invocation,PS_ERR_INTERNAL);
return TRUE;
}
- b_check = access("/opt/system/csc-default/data/csc-default-data-connection.ini", F_OK);
- if( b_check != 0 ){
- dbg("csc file was not there");
- g_set_error(error, PS_ERROR, PS_ERR_INTERNAL, "no csc data file");
- *result = FALSE;
- return TRUE;
+ if (type == 0) {
+ b_check = access("/opt/system/csc-default/data/csc-default-data-connection.ini", F_OK);
+ if (b_check != 0 ) {
+ err("csc file was not there");
+ FAIL_RESPONSE(invocation,PS_ERR_INTERNAL);
+ return TRUE;
+ }
}
g_hash_table_iter_init(&iter, master->modems);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- dbg("key(%s), value(%p) context", key, value);
+ err("key(%s), value(%p) context", key, value);
_ps_modem_processing_power_enable(value, FALSE);
_ps_modem_set_sim_enabled(value, FALSE);
}
+ dbg("Reseting the hash table");
_ps_context_reset_hashtable();
- _ps_context_reset_profile_table();
- rv = _ps_context_fill_profile_table_from_ini_file();
+
+ if (type == 0) {
+ _ps_context_reset_profile_table();
+ rv = _ps_context_fill_profile_table_from_ini_file();
+ }
g_hash_table_iter_init(&iter, master->modems);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
_ps_get_co_modem_values(value);
}
- if(!rv){
- dbg("csc data was wrong");
- g_set_error(error, PS_ERROR, PS_ERR_INTERNAL, "fail to load csc data");
- *result = FALSE;
+ if (type == 0 && !rv) {
+ err("csc data was wrong");
+ FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
+ return TRUE;
}
+ packet_service_master_complete_reset_profile(obj_master, invocation, TRUE);
return TRUE;
}
-static void __ps_master_emit_modem_added_signal(PsMaster *master, gpointer modem)
+static void _ps_master_setup_interface(PacketServiceMaster *master,
+ PsMaster *master_data)
{
- GHashTable *properties = NULL;
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_modem_get_properties(modem, properties);
- g_signal_emit(master, signals[SIG_MASTER_MODEM_ADDED], 0, properties);
- dbg("master (%p) emit the modem(%p) added signal", master, modem);
- g_hash_table_destroy(properties);
- return;
-}
-
-/*static void __ps_master_emit_modem_removed_signal(PsMaster *master, gpointer modem)
-{
- g_signal_emit(master, signals[SIG_MASTER_MODEM_REMOVED], 0, _ps_modem_ref_path(modem));
- dbg("master (%p) emit the modem(%p) removed signal", master, modem);
- return;
-}*/
-
-static void __remove_modem(gpointer data)
-{
- dbg("remove modem (%p)", data);
- return;
-}
-
-static void __ps_master_register_key_callback(gpointer object, enum tcore_storage_key key)
-{
- gpointer handle = NULL;
- PsMaster *master = (PsMaster *) object;
- Server *s = tcore_plugin_ref_server(master->plg);
- static Storage *strg;
-
- strg = tcore_server_find_storage(s, "vconf");
- handle = tcore_storage_create_handle(strg, "vconf");
- if (!handle)
- err("fail to create vconf handle");
-
- tcore_storage_set_key_callback(strg, key, __ps_master_storage_key_callback, object);
-
- return;
-}
-
-static void __ps_master_storage_key_callback(enum tcore_storage_key key, void *value, void *user_data)
-{
- GVariant *tmp = NULL;
- GHashTableIter iter;
- gpointer h_key, h_value;
- gboolean type_check = FALSE;
- PsMaster *master = (PsMaster *)user_data;
-
- dbg("storage key(%d) callback", key);
- g_return_if_fail(master != NULL);
-
- tmp = (GVariant *)value;
- if(!tmp){
- err("value is null");
- return;
- }
-
- type_check = g_variant_is_of_type(tmp, G_VARIANT_TYPE_BOOLEAN);
- if(!type_check){
- err("wrong variant data type");
- g_variant_unref(tmp);
- return;
- }
-
- g_hash_table_iter_init(&iter, master->modems);
- while (g_hash_table_iter_next(&iter, &h_key, &h_value) == TRUE) {
- if(key == KEY_3G_ENABLE){
- gboolean data_allowed = g_variant_get_boolean(tmp);
- _ps_modem_set_data_allowed(h_value, data_allowed);
- }
- else if(key == KEY_DATA_ROAMING_SETTING){
- gboolean roaming_allowed = g_variant_get_boolean(tmp);
- _ps_modem_set_data_roaming_allowed(h_value, roaming_allowed);
- }
- }
-
- g_variant_unref(tmp);
- return;
-}
-
-gpointer _ps_master_create_master(DBusGConnection *conn, TcorePlugin *p)
-{
- guint rv;
- GObject *object;
- DBusGProxy *proxy;
- GError *error = NULL;
-
- dbg("master object create");
- g_return_val_if_fail(conn != NULL, NULL);
-
- proxy = dbus_g_proxy_new_for_name(conn, "org.freedesktop.DBus", "/org/freedesktop/DBus",
- "org.freedesktop.DBus");
-
- if (!dbus_g_proxy_call(proxy, "RequestName", &error, G_TYPE_STRING, PS_DBUS_SERVICE,
- G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &rv, G_TYPE_INVALID)) {
- err("Failed to acquire service(%s) error(%s)", PS_DBUS_SERVICE, error->message);
- return NULL;
- }
-
- object = g_object_new(PS_TYPE_MASTER, "plg", p, "conn", conn, "path", PS_MASTER_PATH, NULL);
- dbus_g_connection_register_g_object(conn, PS_MASTER_PATH, object);
- msg(" master(%p) register dbus path(%s)", object, PS_MASTER_PATH);
-
- __ps_master_register_key_callback(object, KEY_3G_ENABLE);
- __ps_master_register_key_callback(object, KEY_DATA_ROAMING_SETTING);
-
- return object;
-}
-
-gboolean _ps_master_create_modems(gpointer object)
-{
- Server *s = NULL;
- GSList *plist = NULL;
- gpointer modem = NULL, tmp = NULL;
- PsMaster *master = NULL;
- gboolean ret = FALSE;
-
- dbg("create modem objects");
- g_return_val_if_fail(object != NULL, FALSE);
-
- master = (PsMaster *) object;
- s = tcore_plugin_ref_server(master->plg);
- plist = tcore_server_ref_plugins(s);
-
- if (NULL == plist) {
- dbg("fail to get plugin-in list.");
- return FALSE;
- }
-
- for (; plist != NULL; plist = g_slist_next(plist)) {
- TcorePlugin *p = NULL;
- CoreObject *co_modem = NULL;
- gchar *modem_name = NULL;
-
- p = plist->data;
-
- /* AT Standard Plug-in is not considered */
- if ((p == NULL)
- || (strcmp(tcore_plugin_ref_plugin_name(p), "AT") == 0))
- continue;
-
- co_modem = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM);
- if (!co_modem)
- continue;
-
- modem_name = g_strdup_printf("/%s", tcore_server_get_cp_name_by_plugin(p));
- tmp = g_hash_table_lookup(master->modems, modem_name);
- if (tmp != NULL) {
- dbg("modem (%p) already existed", tmp);
- continue;
- }
-
- modem = _ps_modem_create_modem(master->conn, master->plg, master, modem_name, co_modem);
- if (modem == NULL) {
- dbg("fail to create modem");
- return FALSE;
- }
-
- g_hash_table_insert(master->modems, g_strdup(modem_name), modem);
- dbg("modem (%p) created", modem);
-
- __ps_master_emit_modem_added_signal(master, modem);
-
- g_free(modem_name);
-
- ret = TRUE;
- }
-
- return ret;
-}
-
-gboolean _ps_master_get_storage_value(gpointer object, enum tcore_storage_key key)
-{
- Server *s = NULL;
- Storage *strg = NULL;
- PsMaster *master = object;
-
- g_return_val_if_fail(master != NULL, FALSE);
- s = tcore_plugin_ref_server(master->plg);
- strg = tcore_server_find_storage(s, "vconf");
-
- return tcore_storage_get_bool(strg, key);
-}
-
-gboolean _ps_master_set_storage_value(gpointer object, enum tcore_storage_key key, gboolean value)
-{
- Server *s = NULL;
- Storage *strg = NULL;
- PsMaster *master = object;
-
- g_return_val_if_fail(master != NULL, FALSE);
- s = tcore_plugin_ref_server(master->plg);
- strg = tcore_server_find_storage(s, "vconf");
-
- return tcore_storage_set_bool(strg, key, value);
+ dbg("Entered");
+
+ g_signal_connect (master,
+ "handle-get-modems",
+ G_CALLBACK (on_master_get_modems),
+ master_data);
+
+ g_signal_connect (master,
+ "handle-get-profile-list",
+ G_CALLBACK (on_master_get_profile_list),
+ master_data);
+
+ g_signal_connect (master,
+ "handle-add-profile",
+ G_CALLBACK (on_master_add_profile),
+ master_data);
+
+ g_signal_connect (master,
+ "handle-reset-profile",
+ G_CALLBACK (on_master_reset_profile),
+ master_data);
}
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
-#include "ps-modem.h"
-
#include "ps.h"
-#include "ps-error.h"
+#include "generated-code.h"
#include <server.h>
#include <plugin.h>
#include <core_object.h>
-#define PROP_DEFAULT FALSE
-#define PROP_DEFAULT_STR NULL
-#define BOOL2STRING(a) ((a==TRUE) ? ("TRUE"):("FALSE"))
-
-/*Properties*/
-
-enum {
- PROP_MODEM_O,
-
- PROP_MODEM_PATH,
- PROP_MODEM_MASTER,
- PROP_MODEM_PLUGIN,
- PROP_MODEM_COMODEM,
- PROP_MODEM_CONN,
-};
-
-enum {
- SIG_MODEM_SERVICE_ADDED,
- SIG_MODEM_SERVICE_REMOVED,
- SIG_MODEM_PROPERTY_CHANGED,
- SIG_MODEM_LAST
-};
-
-static guint32 signals[SIG_MODEM_LAST] = { 0, };
-
-struct PsModemClass {
- GObjectClass parent;
-
- //method and signals
- void (*service_added)(PsModem *modem, gchar *service_path);
- void (*service_removed)(PsModem *modem, gchar *service_path);
- void (*property_changed)(PsModem *modem, GHashTable *modem_property);
-};
-
-struct PsModem {
- GObject parent;
-
- gchar* path;
- gpointer p_master;
- TcorePlugin *plg;
- CoreObject *co_modem;
- DBusGConnection *conn;
-
- /*Value from modem*/
- gchar* operator;
- gboolean powered;
- gboolean sim_init;
- gboolean flight_mode;
- gboolean roaming_allowed;
- gboolean data_allowed;
-
- GHashTable *services;
-};
-
-G_DEFINE_TYPE(PsModem, ps_modem, G_TYPE_OBJECT);
-
-/*Function Declaration*/
-static void __ps_modem_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-static void __ps_modem_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-
-gboolean ps_iface_modem_get_properties(PsModem *modem, DBusGMethodInvocation *context);
-gboolean ps_iface_modem_get_services(PsModem *modem, DBusGMethodInvocation *context);
+#define PROP_DEFAULT FALSE
+#define PROP_DEFAULT_STR NULL
+#define BOOL2STRING(a) ((a==TRUE) ? ("TRUE"):("FALSE"))
static void __ps_modem_emit_property_changed_signal(PsModem *modem);
static void __ps_modem_emit_service_added_signal(PsModem *modem, gpointer service);
-/*static void __ps_modem_emit_service_removed_signal(PsModem *modem, gpointer service);*/
+/* static void __ps_modem_emit_service_removed_signal(PsModem *modem, gpointer service); */
+static void _ps_modem_setup_interface(PacketServiceModem *modem, PsModem *modem_data);
-static void __remove_service(gpointer data);
-static void __ps_modem_create_service(DBusGConnection *conn, TcorePlugin *p,
- gpointer modem, CoreObject *co_modem);
+static void __ps_modem_create_service(GDBusConnection *conn,
+ TcorePlugin *p, gpointer modem, CoreObject *co_modem);
static void __ps_modem_remove_service(PsModem *modem, gpointer service);
-static gboolean __ps_modem_set_powered(PsModem *modem, gboolean value);
-static gboolean __ps_modem_set_sim_complete(PsModem *modem, gboolean value, gchar *operator);
-static void __ps_modem_get_ps_setting_from_storage(GObject *object);
+static void __ps_modem_get_ps_setting_from_storage(PsModem *object);
static void __ps_modem_processing_modem_event(gpointer object);
-#include "ps-iface-modem-glue.h"
-
-static void ps_modem_init(PsModem *modem)
-{
- dbg("modem initialize");
-
- modem->path = PROP_DEFAULT_STR;
- modem->p_master = NULL;
- modem->plg = NULL;
- modem->co_modem = NULL;
- modem->conn = NULL;
-
- modem->operator = PROP_DEFAULT_STR;
- modem->powered = PROP_DEFAULT;
- modem->sim_init = PROP_DEFAULT;
- modem->flight_mode = PROP_DEFAULT;
- modem->roaming_allowed = PROP_DEFAULT;
- modem->data_allowed = PROP_DEFAULT;
-
- modem->services = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, __remove_service);
- return;
-}
-
-static void ps_modem_class_init(PsModemClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- //class init
- dbg("class init");
-
- object_class->get_property = __ps_modem_get_property;
- object_class->set_property = __ps_modem_set_property;
-
- //dbus register
- dbus_g_object_type_install_info(PS_TYPE_MODEM, &dbus_glib_ps_iface_modem_object_info);
-
- //add properties
- g_object_class_install_property(
- object_class,
- PROP_MODEM_PATH,
- g_param_spec_string("path", "PATH", "Modem Path", NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_MODEM_MASTER,
- g_param_spec_pointer("p_master", "MASTER", "Master Object",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_MODEM_PLUGIN,
- g_param_spec_pointer("plg", "PLUGIN", "Plug in Object",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_MODEM_COMODEM,
- g_param_spec_pointer("co_modem", "COREOBJECTMODEM", "CoreObject Modem",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_MODEM_CONN,
- g_param_spec_boxed("conn", "CONNECTION", "DBus connection", DBUS_TYPE_G_CONNECTION,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- //add signal handler
- signals[SIG_MODEM_SERVICE_ADDED] = g_signal_new("service-added", G_OBJECT_CLASS_TYPE(klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(PsModemClass, service_added), NULL, NULL,
- g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
-
- signals[SIG_MODEM_SERVICE_REMOVED] = g_signal_new("service-removed", G_OBJECT_CLASS_TYPE(klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(PsModemClass, service_removed), NULL, NULL,
- g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, DBUS_TYPE_G_OBJECT_PATH);
-
- signals[SIG_MODEM_PROPERTY_CHANGED] = g_signal_new("property-changed",
- G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(PsModemClass, property_changed), NULL, NULL,
- g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
-
- return;
-}
-
-static void __ps_modem_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
- return;
-}
-
-static void __ps_modem_set_property(GObject *object, guint prop_id, const GValue *value,
- GParamSpec *pspec)
-{
- PsModem *modem = PS_MODEM(object);
-
- switch (prop_id) {
- case PROP_MODEM_PATH: {
- if (modem->path) g_free(modem->path);
- modem->path = g_value_dup_string(value);
- msg(" modem(%p) set path(%s)", modem, modem->path);
- }
- break;
- case PROP_MODEM_MASTER: {
- modem->p_master = g_value_get_pointer(value);
- msg(" modem(%p) set master(%p)", modem, modem->p_master);
- }
- break;
- case PROP_MODEM_PLUGIN: {
- modem->plg = g_value_get_pointer(value);
- msg(" modem(%p) set plg(%p)", modem, modem->plg);
- }
- break;
- case PROP_MODEM_COMODEM: {
- modem->co_modem = g_value_get_pointer(value);
- msg(" modem(%p) set coreobject modem(%p)", modem, modem->co_modem);
- }
- break;
- case PROP_MODEM_CONN: {
- modem->conn = g_value_get_boxed(value);
- msg(" modem(%p) set conn(%p)", modem, modem->conn);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- } //swtich end
-
- return;
-}
-
-gboolean ps_iface_modem_get_properties(PsModem *modem, DBusGMethodInvocation *context)
-{
- GError *error = NULL;
- gboolean rv = FALSE;
- GHashTable *properties = NULL;
-
- dbg("get modem properties");
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- rv = _ps_modem_get_properties(modem, properties);
- if (rv != TRUE) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "fail to get properties modem(%p)", modem);
- dbus_g_method_return_error(context, error);
- g_hash_table_destroy(properties);
- return FALSE;
- }
-
- dbus_g_method_return(context, properties);
- g_hash_table_destroy(properties);
-
- return FALSE;
-}
+static gboolean __ps_modem_set_powered(PsModem *modem, gboolean value);
+static gboolean __ps_modem_set_sim_complete(PsModem *modem,
+ gboolean value, gchar *operator);
-gboolean ps_iface_modem_get_services(PsModem *modem, DBusGMethodInvocation *context)
+void __remove_modem_handler(gpointer data)
{
- GError *error = NULL;
- GHashTableIter iter;
- gpointer key, value;
- GHashTable *services;
-
- dbg("modem get service interface");
+ PsModem *modem = data;
- if (modem->services == NULL) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "modem(%p) does not have services",
- modem);
- dbus_g_method_return_error(context, error);
- return FALSE;
+ dbg("Entered");
+ if (!modem) {
+ dbg("Modem is NULL");
+ return;
}
- services = g_hash_table_new_full(g_direct_hash, g_str_equal, g_free,
- (GDestroyNotify) g_hash_table_destroy);
+ /* Need to remove the compelete hash table */
+ g_hash_table_remove_all(modem->services);
- g_hash_table_iter_init(&iter, modem->services);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- gboolean rv = FALSE;
- gchar *path = NULL;
- GHashTable *properties = NULL;
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- rv = _ps_service_get_properties(value, properties);
- if (rv != TRUE) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "fail to get properties service(%p)",
- value);
- dbus_g_method_return_error(context, error);
- g_hash_table_destroy(properties);
- g_hash_table_destroy(services);
- return FALSE;
- }
+ /* Need to UNexport and Unref the master Object */
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(modem->if_obj));
- path = _ps_service_ref_path(value);
- g_hash_table_insert(services, g_strdup(path), properties);
- dbg("service (%p) inserted into hash", value);
- }
+ g_object_unref(modem->if_obj);
- dbus_g_method_return(context, services);
- g_hash_table_destroy(services);
+ /* Need to free memory allocated for the internal structure */
+ g_free(modem->path);
+ g_free(modem->operator);
+ g_free(modem);
- return TRUE;
+ dbg("Exiting");
}
static void __ps_modem_emit_property_changed_signal(PsModem *modem)
{
- GHashTable *properties = NULL;
+ GVariant *gv = NULL;
+ GVariantBuilder properties;
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_modem_get_properties(modem, properties);
-
- dbg("Emit signal - 'PROPERTY CHANGED' - modem: [0x%x]", modem);
- g_signal_emit(modem, signals[SIG_MODEM_PROPERTY_CHANGED], 0, properties);
-
- g_hash_table_destroy(properties);
+ dbg("get modem properties");
- return;
+ gv = _ps_modem_get_properties(modem, &properties);
+ packet_service_modem_emit_property_changed(modem->if_obj, gv);
}
static void __ps_modem_emit_service_added_signal(PsModem *modem, gpointer service)
{
- GHashTable *properties = NULL;
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_service_get_properties(service, properties);
+ GVariant *gv = NULL;
+ GVariantBuilder property;
- dbg("Emit signal - MODEM SERVICE ADDED' - modem: [0x%x] service: [0x%x]", modem, service);
- g_signal_emit(modem, signals[SIG_MODEM_SERVICE_ADDED], 0, properties);
+ dbg("get service properties");
- g_hash_table_destroy(properties);
- return;
+ gv = _ps_service_get_properties(service, &property);
+ packet_service_modem_emit_service_added(modem->if_obj, gv);
}
-/*static void __ps_modem_emit_service_removed_signal(PsModem *modem, gpointer service)
-{
- g_signal_emit(modem, signals[SIG_MODEM_SERVICE_REMOVED], 0, _ps_service_ref_path(service));
- dbg("modem (%p) emit the service(%p) removed signal", modem, service);
- return;
-}*/
-
-static void __remove_service(gpointer data)
+/* blocked may be used later
+static void __ps_modem_emit_service_removed_signal(PsModem *modem, gpointer service)
{
+ PsService *psservice = service;
+ packet_service_modem_emit_service_removed(modem->if_obj,psservice->path);
return;
}
+*/
-static void __ps_modem_create_service(DBusGConnection *conn, TcorePlugin *p,
- gpointer modem, CoreObject *co_modem)
+static void __ps_modem_create_service(GDBusConnection *conn,
+ TcorePlugin *p, gpointer modem, CoreObject *co_modem)
{
gchar *t_path = NULL;
GObject *object = NULL;
CoreObject *co_network = NULL;
TcorePlugin *target_plg = NULL;
- dbg("Create Modem Service - Path: [%s]", _ps_modem_ref_path(modem));
-
target_plg = tcore_object_ref_plugin(co_modem);
+
co_ps = tcore_plugin_ref_core_object(target_plg, CORE_OBJECT_TYPE_PS);
- if (!co_ps) {
- err("No PS Core object");
- return;
- }
co_network = tcore_plugin_ref_core_object(target_plg, CORE_OBJECT_TYPE_NETWORK);
- if (!co_network) {
- err("No NETWORK Core object");
+
+ if (!co_ps || !co_network) {
+ err("Either ps or network core object not Present");
return;
}
t_path = g_strdup_printf("%s_ps", _ps_modem_ref_path(modem));
- dbg("Service Path: [%s]", t_path);
+ dbg("service path (%s)", t_path);
+ /* Create service object */
object = _ps_service_create_service(conn,p, modem, co_network, co_ps, t_path);
- dbg("Created Service: [0x%x]", object);
g_hash_table_insert( ((PsModem *) modem)->services, g_strdup(t_path), object);
+ dbg("service (%p) insert to hash", object);
- /* Emit Service signal */
+ /* Emit signal for service added */
__ps_modem_emit_service_added_signal((PsModem *) modem, object);
- /* Free memory */
g_free(t_path);
-
- return;
}
static void __ps_modem_remove_service(PsModem *modem, gpointer service)
{
- //unregister dbus
- dbus_g_connection_unregister_g_object(modem->conn, (GObject *)service);
- //remove object from hash table
+ PsService *psservice = service;
+
+ dbg("Entered");
+
+ /* Unexporting the interface for the modem */
+ if (psservice->if_obj) {
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(psservice->if_obj));
+ g_object_unref(psservice->if_obj);
+ psservice->if_obj = NULL;
+ }
+
g_hash_table_remove(modem->services, _ps_service_ref_path(service));
- g_object_unref(service);
- return;
+ dbg("Successfully removed the service from the modem");
}
static gboolean __ps_modem_set_powered(PsModem *modem, gboolean value)
{
- dbg("modem: [0x%x] Modem powered: [%s]", modem,(value ? "YES" : "NO"));
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
modem->powered = value;
- /* Emit Property change signal */
+ dbg("modem(%p) powered(%d)", modem, modem->powered);
__ps_modem_emit_property_changed_signal(modem);
return TRUE;
static gboolean __ps_modem_set_sim_complete(PsModem *modem, gboolean value, gchar *operator)
{
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
modem->sim_init = value;
if (value && operator != NULL && !modem->operator)
modem->operator = g_strdup(operator);
- dbg("modem: [0x%x] SIM init: '%s' operator: [%s]",
- modem, (modem->sim_init ? "TRUE" : "FALSE"), modem->operator);
-
- /* Emit Property change signal */
+ dbg("modem(%p) sim init(%d) operator(%s)", modem, modem->sim_init, modem->operator);
__ps_modem_emit_property_changed_signal(modem);
return TRUE;
}
-static gboolean __ps_modem_set_flight_mode(PsModem *modem, gboolean value)
+static gboolean __ps_modem_set_flght_mode(PsModem *modem, gboolean value)
{
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
modem->flight_mode = value;
- dbg("modem(%p) flight_mode(%d)", modem, modem->flight_mode);
- /* Emit Property change signal */
+ dbg("modem(%p) flight_mode(%d)", modem, modem->flight_mode);
__ps_modem_emit_property_changed_signal(modem);
-
- /* Process modem event */
__ps_modem_processing_modem_event(modem);
return TRUE;
}
-static void __ps_modem_get_ps_setting_from_storage(GObject *object)
+static void __ps_modem_get_ps_setting_from_storage(PsModem *object)
{
gboolean key_3g_enable = FALSE, key_roaming_allowed = FALSE;
PsModem *modem = NULL;
- dbg("Extract PS settings");
-
modem = (PsModem *) object;
- key_3g_enable = _ps_master_get_storage_value(modem->p_master, KEY_3G_ENABLE);
- key_roaming_allowed = _ps_master_get_storage_value(modem->p_master, KEY_DATA_ROAMING_SETTING);
- msg(" Data allowed: [%s]", key_3g_enable ? "YES" : "NO");
- msg(" Roaming allowed: [%s]", key_roaming_allowed ? "YES" : "NO");
+ key_3g_enable = _ps_master_get_storage_value_bool(modem->p_master, STORAGE_KEY_DATA_ENABLE);
+ key_roaming_allowed = _ps_master_get_storage_value_bool(modem->p_master, STORAGE_KEY_SVC_ROAM);
- /* Set Data allowed value */
_ps_modem_set_data_allowed(modem, key_3g_enable);
- /* Set Roaming allowed value */
_ps_modem_set_data_roaming_allowed(modem, key_roaming_allowed);
+
+ dbg("data allowed(%d) roaming allowed(%d) ", key_3g_enable, key_roaming_allowed);
}
static void __ps_modem_processing_modem_event(gpointer object)
g_return_if_fail(modem != NULL);
- if(!modem->services)
+ if (!modem->services) {
+ err("Null Service");
return;
+ }
g_hash_table_iter_init(&iter, modem->services);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
s_roaming = _ps_service_get_roaming(value);
_ps_update_cellular_state_key(value);
- if(!modem->powered){
- dbg("modem is not powered");
+ if (!modem->powered) {
_ps_service_remove_contexts(value);
_ps_free_co_ps_event(value);
_ps_free_co_network_event(value);
continue;
}
- if(modem->flight_mode
- || !modem->data_allowed
- || (s_roaming && !modem->roaming_allowed) ){
+ if (modem->flight_mode || !modem->data_allowed || (s_roaming && !modem->roaming_allowed)) {
_ps_service_disconnect_contexts(value);
continue;
}
- /* Only available case */
+ //only available case
_ps_service_connect_default_context(value);
}
-
- return;
}
-gpointer _ps_modem_create_modem(DBusGConnection *conn, TcorePlugin *p, gpointer master,
- gchar* modem_name, gpointer co_modem)
+gpointer _ps_modem_create_modem(GDBusConnection *conn,
+ TcorePlugin *p, gpointer master, gchar* modem_name, gpointer co_modem)
{
- guint rv = 0;
- GObject *object;
- DBusGProxy *proxy;
+ PacketServiceModem *modem;
+ PsModem *new_modem;
GError *error = NULL;
- dbg("Create modem object");
+ dbg("modem object create");
+ tcore_check_return_value(conn != NULL, NULL);
+ tcore_check_return_value(master != NULL, NULL);
- g_return_val_if_fail(conn != NULL, NULL);
- g_return_val_if_fail(master != NULL, NULL);
+ /* creating the master object for the interface com.tcore.ps.modem */
+ modem = packet_service_modem_skeleton_new();
- /* Creating new Proxy */
- proxy = dbus_g_proxy_new_for_name(conn, "org.freedesktop.DBus", "/org/freedesktop/DBus",
- "org.freedesktop.DBus");
-
- if (!dbus_g_proxy_call(proxy, "RequestName", &error, G_TYPE_STRING, PS_DBUS_SERVICE,
- G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &rv, G_TYPE_INVALID)) {
- err("Failed to acquire service(%s) error(%s)", PS_DBUS_SERVICE, error->message);
+ /* Initializing the modem list for internal referencing */
+ new_modem = g_try_malloc0(sizeof(PsModem));
+ if (NULL == new_modem) {
+ err("Unable to allocate memory for modem");
return NULL;
}
- dbg("Created Proxy - Path: [%s]", PS_DBUS_SERVICE);
- /* Creating new Object */
- object = g_object_new(PS_TYPE_MODEM, "path", modem_name, "p_master", master, "plg", p, "co_modem",
- co_modem, "conn", conn, NULL);
+ new_modem->conn = conn;
+ new_modem->p_master = master;
+ new_modem->plg = p;
+ new_modem->co_modem = co_modem;
+ new_modem->path = g_strdup(modem_name);
+ new_modem->if_obj = modem;
+ new_modem->services =
+ g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, __remove_service_handler);
- /* Extract PS setting */
- __ps_modem_get_ps_setting_from_storage(object);
+ dbg("core object of modem %p", co_modem);
- /* Hook modem & SIM events */
- _ps_hook_co_modem_event(object);
+ dbg("core object of modem %p", new_modem->co_modem);
+ __ps_modem_get_ps_setting_from_storage(new_modem);
+ _ps_hook_co_modem_event(new_modem);
+ _ps_get_co_modem_values(new_modem);
- /* Extract modem values */
- _ps_get_co_modem_values(object);
+ /* Setting the interface call backs functions */
+ _ps_modem_setup_interface(modem, new_modem);
- dbus_g_connection_register_g_object(conn, modem_name, object);
- msg(" modem(%p) register dbus path(%s)", object, modem_name);
+ /* exporting the interface object to the path mention for modem */
+ g_dbus_interface_skeleton_export((G_DBUS_INTERFACE_SKELETON(modem)),
+ conn, modem_name, &error);
+ g_assert_no_error (error);
- return object;
+ dbg("Successfully created the modem");
+ return new_modem;
}
gboolean _ps_modem_processing_flight_mode(gpointer object, gboolean enable)
{
PsModem * modem = object;
- dbg("Process Flight mode - Flight mode: [%s]", (enable ? "ON" : "OFF"));
-
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
- if (modem->flight_mode == enable) {
- dbg("No change in Flight mode: [%s]",
- (modem->flight_mode ? "ON" : "OFF"));
+ if (modem->flight_mode == enable)
return TRUE;
- }
- /* Set Flight mode */
- __ps_modem_set_flight_mode(modem, enable);
+ __ps_modem_set_flght_mode(modem, enable);
return TRUE;
}
{
PsModem * modem = object;
- dbg("Process Power - Enable: [%s]", (enable ? "ENABLE" : "DISABLE"));
+ tcore_check_return_value(modem != NULL, FALSE);
- g_return_val_if_fail(modem != NULL, FALSE);
-
- if (modem->powered == enable) {
- dbg("No change in Modem Power: [%s]",
- (modem->powered ? "ENABLE" : "DISABLE"));
+ if (modem->powered == enable)
return TRUE;
- }
- /* Set Modem Power */
__ps_modem_set_powered(modem, enable);
-
if (enable) {
- dbg("Create Service");
- __ps_modem_create_service(modem->conn, modem->plg, modem, modem->co_modem);
- } else {
- dbg("Process modem event");
+ __ps_modem_create_service(modem->conn,
+ modem->plg, modem, modem->co_modem);
+
+ if (modem->sim_init == TRUE && modem->operator != NULL) {
+ GHashTable *contexts = NULL;
+ contexts = _ps_context_ref_hashtable();
+
+ if (contexts != NULL) {
+ GHashTableIter iter;
+ gpointer key, value;
+ g_hash_table_iter_init(&iter, modem->services);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ _ps_service_ref_contexts(value, contexts, modem->operator);
+ }
+ }
+ }
+ }
+ else {
__ps_modem_processing_modem_event(modem);
+ _ps_modem_set_sim_enabled(modem, FALSE);
}
return TRUE;
}
-gboolean _ps_modem_processing_sim_complete(gpointer object, gboolean complete, gchar *operator)
+gboolean _ps_modem_processing_sim_complete(gpointer object,
+ gboolean complete, gchar *operator)
{
PsModem * modem = object;
GHashTable *contexts = NULL;
- dbg("SIM init: '%s' Operator: [%s]", (complete ? "YES" : "NO"), operator);
-
- g_return_val_if_fail(modem != NULL, FALSE);
- if (modem->sim_init == complete) {
- dbg("No change in SIM init state - SIM INIT COMPLETE: [%s]",
- (modem->sim_init ? "YES" : "NO"));
+ tcore_check_return_value(modem != NULL, FALSE);
+ dbg("Entered");
+ if (modem->sim_init == complete)
return TRUE;
- }
- /* Set SIM init */
__ps_modem_set_sim_complete(modem, complete, operator);
- if (modem->sim_init == TRUE && modem->operator != NULL)
- contexts = _ps_context_create_hashtable(modem->conn, modem->plg, modem->operator);
+ if (modem->sim_init == TRUE && modem->operator != NULL) {
+ contexts = _ps_context_create_hashtable(modem->conn,
+ modem->plg, modem->operator);
+ dbg("Hash table created");
+ }
if (contexts != NULL) {
GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init(&iter, modem->services);
-
+ dbg("context not null as created the hash");
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ //_ps_service_set_number_of_pdn_cnt(value, modem->operator);
_ps_service_ref_contexts(value, contexts, modem->operator);
}
}
+ dbg("Exiting");
return TRUE;
}
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
modem->sim_init = value;
dbg("modem(%p) sim_enabled(%d)", modem, modem->sim_init);
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
modem->data_allowed = value;
dbg("modem(%p) data allowed(%d)", modem, modem->data_allowed);
gboolean _ps_modem_get_data_allowed(gpointer object)
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
return modem->data_allowed;
}
-gboolean _ps_modem_set_data_roaming_allowed(gpointer object, gboolean roaming_allowed)
+gboolean _ps_modem_set_data_roaming_allowed(gpointer object,
+ gboolean roaming_allowed)
{
PsModem * modem = object;
- GHashTableIter iter;
- gpointer key, value;
- gboolean s_roaming = FALSE;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
modem->roaming_allowed = roaming_allowed;
dbg("modem(%p) roaming allowed(%d)", modem, modem->roaming_allowed);
__ps_modem_emit_property_changed_signal(modem);
- if(!modem->services)
+ if (!modem->services)
return TRUE;
- g_hash_table_iter_init(&iter, modem->services);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- s_roaming = _ps_service_get_roaming(value);
- break;
- }
-
- if(s_roaming)
+ if (modem->roaming)
__ps_modem_processing_modem_event(modem);
return TRUE;
}
+gboolean _ps_modem_get_roaming(gpointer object)
+{
+ PsModem * modem = object;
+ tcore_check_return_value(modem != NULL, FALSE);
+
+ return modem->roaming;
+}
+
+void _ps_modem_set_roaming(gpointer object, gboolean value)
+{
+ PsModem * modem = object;
+ g_return_if_fail(modem != NULL);
+
+ modem->roaming = value;
+ dbg("modem(%p) roaming(%d)", modem, modem->roaming);
+
+ return;
+}
+
gboolean _ps_modem_get_data_roaming_allowed(gpointer object)
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
return modem->roaming_allowed;
}
gboolean _ps_modem_get_flght_mode(gpointer object)
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
return modem->flight_mode;
}
gboolean _ps_modem_get_sim_init(gpointer object)
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
return modem->sim_init;
}
gboolean _ps_modem_get_power(gpointer object)
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
return modem->powered;
}
gchar* _ps_modem_ref_operator(gpointer object)
{
PsModem * modem = object;
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
return modem->operator;
}
-gboolean _ps_modem_get_properties(gpointer object, GHashTable *properties)
+gboolean _ps_modem_get_properties_handler(gpointer object,
+ GVariantBuilder *properties)
{
PsModem *modem = object;
- dbg("Get modem properties");
- g_return_val_if_fail(modem != NULL, FALSE);
- g_return_val_if_fail(properties != NULL, FALSE);
-
- g_hash_table_insert(properties, "path", g_strdup(modem->path));
- g_hash_table_insert(properties, "operator", g_strdup(modem->operator));
- g_hash_table_insert(properties, "powered", BOOL2STRING(modem->powered));
- g_hash_table_insert(properties, "sim_init", BOOL2STRING(modem->sim_init));
- g_hash_table_insert(properties, "flight_mode", BOOL2STRING(modem->flight_mode));
- g_hash_table_insert(properties, "roaming_allowed", BOOL2STRING(modem->roaming_allowed));
- g_hash_table_insert(properties, "data_allowed", BOOL2STRING(modem->data_allowed));
-
- msg(" Path: [%s]", modem->path);
- msg(" Operator: [%s]", modem->operator);
- msg(" Powered: [%s]", modem->powered ? "YES" : "NO");
- msg(" SIM Init: [%s]", modem->sim_init ? "YES" : "NO");
- msg(" Flight mode: [%s]", modem->flight_mode ? "ON" : "OFF");
- msg(" Roaming allowed: [%s]", modem->roaming_allowed ? "YES" : "NO");
- msg(" Data allowed: [%s]", modem->data_allowed ? "YES" : "NO");
+ dbg("get modem properties");
+ tcore_check_return_value(modem != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
+ g_variant_builder_open(properties,G_VARIANT_TYPE("a{ss}"));
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(modem->path));
+
+ if (modem->operator) {
+ g_variant_builder_add(properties, "{ss}", "operator", g_strdup(modem->operator));
+ }
+ g_variant_builder_add(properties, "{ss}", "powered", g_strdup(BOOL2STRING(modem->powered)));
+ g_variant_builder_add(properties, "{ss}", "sim_init", g_strdup(BOOL2STRING(modem->sim_init)));
+ g_variant_builder_add(properties, "{ss}", "flight_mode", g_strdup(BOOL2STRING(modem->flight_mode)));
+ g_variant_builder_add(properties, "{ss}", "roaming_allowed", g_strdup(BOOL2STRING(modem->roaming_allowed)));
+ g_variant_builder_add(properties, "{ss}", "data_allowed", g_strdup(BOOL2STRING(modem->data_allowed)));
+ g_variant_builder_close(properties);
+
+ dbg("Exiting");
return TRUE;
}
+GVariant *_ps_modem_get_properties(gpointer object, GVariantBuilder *properties)
+{
+ PsModem *modem = object;
+
+ dbg("get modem properties");
+ tcore_check_return_value(modem != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
+
+ g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
+
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(modem->path));
+
+ if (modem->operator) {
+ g_variant_builder_add(properties, "{ss}", "operator", g_strdup(modem->operator));
+ }
+ g_variant_builder_add(properties, "{ss}", "powered", g_strdup(BOOL2STRING(modem->powered)));
+ g_variant_builder_add(properties, "{ss}", "sim_init", g_strdup(BOOL2STRING(modem->sim_init)));
+ g_variant_builder_add(properties, "{ss}", "flight_mode", g_strdup(BOOL2STRING(modem->flight_mode)));
+ g_variant_builder_add(properties, "{ss}", "roaming_allowed", g_strdup(BOOL2STRING(modem->roaming_allowed)));
+ g_variant_builder_add(properties, "{ss}", "data_allowed", g_strdup(BOOL2STRING(modem->data_allowed)));
+
+ dbg("Path: [%s]", modem->path);
+ dbg("Operator: [%s]", modem->operator);
+ dbg("Powered: [%s]", modem->powered ? "YES" : "NO");
+ dbg("SIM Init: [%s]", modem->sim_init ? "YES" : "NO");
+ dbg("Flight mode: [%s]", modem->flight_mode ? "ON" : "OFF");
+ dbg("Roaming allowed: [%s]", modem->roaming_allowed ? "YES" : "NO");
+ dbg("Data allowed: [%s]", modem->data_allowed ? "YES" : "NO");
+
+ return g_variant_builder_end(properties);
+}
+
GHashTable* _ps_modem_ref_services(gpointer object)
{
PsModem *modem = object;
- g_return_val_if_fail(modem != NULL, NULL);
+ tcore_check_return_value(modem != NULL, NULL);
return modem->services;
}
gchar* _ps_modem_ref_path(gpointer object)
{
PsModem *modem = object;
- g_return_val_if_fail(modem != NULL, NULL);
+ tcore_check_return_value(modem != NULL, NULL);
return modem->path;
}
gpointer _ps_modem_ref_plugin(gpointer object)
{
PsModem *modem = object;
- g_return_val_if_fail(modem != NULL, NULL);
+ tcore_check_return_value(modem != NULL, NULL);
return modem->plg;
}
gpointer _ps_modem_ref_dbusconn(gpointer object)
{
PsModem *modem = object;
- g_return_val_if_fail(modem != NULL, NULL);
+ tcore_check_return_value(modem != NULL, NULL);
return modem->conn;
}
gpointer _ps_modem_ref_co_modem(gpointer object)
{
PsModem *modem = object;
- g_return_val_if_fail(modem != NULL, NULL);
+ tcore_check_return_value(modem != NULL, NULL);
return modem->co_modem;
}
+
+static gboolean on_modem_get_properties (PacketServiceModem *obj_modem,
+ GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ GVariant *gv = NULL;
+ GVariantBuilder properties;
+
+ dbg("get modem properties");
+
+ gv = _ps_modem_get_properties(user_data, &properties);
+ packet_service_modem_complete_get_properties(obj_modem, invocation, gv);
+ return TRUE;
+}
+
+static gboolean on_modem_get_services (PacketServiceModem *obj_modem,
+ GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ GVariantBuilder b_service;
+ GVariant *services;
+
+ GHashTableIter iter;
+ gpointer key, value;
+ PsModem *modem = user_data;
+
+ dbg("modem get service interface");
+
+ if (modem->services == NULL) {
+ FAIL_RESPONSE(invocation,PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ g_variant_builder_init(&b_service, G_VARIANT_TYPE("a{sa{ss}}"));
+ g_hash_table_iter_init(&iter,modem->services);
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ gchar *path = NULL;
+
+ g_variant_builder_open(&b_service,G_VARIANT_TYPE("{sa{ss}}"));
+ path = _ps_service_ref_path(value);
+ dbg("path added [%s]", path);
+ g_variant_builder_add(&b_service, "s", g_strdup(path));
+ if (FALSE == _ps_service_get_properties_handler(value, &b_service)) {
+ g_variant_builder_close(&b_service);
+ FAIL_RESPONSE(invocation,PS_ERR_INTERNAL);
+ return TRUE;
+ }
+ g_variant_builder_close(&b_service);
+ }
+
+ services = g_variant_builder_end(&b_service);
+ packet_service_modem_complete_get_services(obj_modem, invocation, services);
+ return TRUE;
+}
+
+static void _ps_modem_setup_interface(PacketServiceModem *modem,
+ PsModem *modem_data)
+{
+ dbg("Entered");
+
+ g_signal_connect (modem,
+ "handle-get-properties",
+ G_CALLBACK (on_modem_get_properties),
+ modem_data);
+
+ g_signal_connect (modem,
+ "handle-get-services",
+ G_CALLBACK (on_modem_get_services),
+ modem_data);
+}
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
-#include "ps-service.h"
-
#include "ps.h"
-#include "ps-error.h"
+#include "generated-code.h"
#include <core_object.h>
#include <co_ps.h>
+#include <co_context.h>
+
#define PROP_DEFAULT FALSE
#define PROP_DEFAULT_STR NULL
-#define BOOL2STRING(a) ((a==TRUE) ? ("TRUE"):("FALSE"))
+#define BOOL2STRING(a) ((a == TRUE) ? ("TRUE"):("FALSE"))
#define TIMEOUT_DEFAULT 5
#define TIMEOUT_MAX 1280
guint connection_timeout;
guint timer_src;
-/*Properties*/
-
-enum {
- PROP_SERVICE_O,
-
- PROP_SERVICE_PATH,
- PROP_SERVICE_PLUGIN,
- PROP_SERVICE_CONN,
- PROP_SERVICE_P_MODEM,
- PROP_SERVICE_CO_NETWORK,
- PROP_SERVICE_CO_PS
-};
-
-enum {
- SIG_SERVICE_CONTEXT_ADDED,
- SIG_SERVICE_CONTEXT_REMOVED,
- SIG_SERVICE_PROPERTY_CHANGED,
- SIG_SERVICE_LAST
-};
-
-static guint32 signals[SIG_SERVICE_LAST] = {0,};
-
-struct PsServiceClass {
- GObjectClass parent;
-
- //method and signals
- void (*context_added)(PsService *service, gchar *context_path);
- void (*context_removed)(PsService *service, gchar *context_path);
- void (*property_changed)(PsService *service, GHashTable *service_property);
-};
-
-struct PsService {
- GObject parent;
-
- gchar *path;
- TcorePlugin *plg;
- DBusGConnection *conn;
- gpointer p_modem;
- CoreObject *co_network;
- CoreObject *co_ps;
-
- gboolean ps_attached;
- gboolean roaming;
- enum telephony_network_access_technology act;
-
- GHashTable *contexts;
-};
-
-G_DEFINE_TYPE(PsService, ps_service, G_TYPE_OBJECT);
-
-/*Function Declaration*/
-static void __ps_service_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-static void __ps_service_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-
-gboolean ps_iface_service_get_properties(PsService *service, DBusGMethodInvocation *context);
-gboolean ps_iface_service_get_contexts(PsService *service, DBusGMethodInvocation *context);
-
static void __ps_service_emit_property_changed_signal(PsService *service);
static void __ps_service_emit_context_added_signal(PsService *service, gpointer context);
static void __ps_service_emit_context_removed_signal(PsService *service, gpointer context);
+static void _ps_service_setup_interface(PacketServiceService *service, PsService *service_data);
-static void __remove_context(gpointer data);
-static char *__ps_service_act2string(enum telephony_network_access_technology act);
-static gboolean __ps_service_check_connection_option(gpointer service);
+static char *__ps_service_act2string(TelNetworkAct act);
+static gboolean __ps_service_check_connection_option(gpointer service, gpointer context);
static gboolean __ps_service_connetion_timeout_handler(gpointer user_data);
-#include "ps-iface-service-glue.h"
-
-static void ps_service_init(PsService *service)
-{
- dbg("service initialize");
-
- service->path = PROP_DEFAULT_STR;
- service->plg = NULL;
- service->conn = NULL;
- service->p_modem = NULL;
- service->co_network = NULL;
- service->co_ps = NULL;
-
- service->ps_attached = PROP_DEFAULT;
- service->roaming = PROP_DEFAULT;
- service->act = NETWORK_ACT_UNKNOWN;
-
- service->contexts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, __remove_context);
- return;
-}
-
-static void ps_service_class_init(PsServiceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- //class init
- dbg("class init");
-
- object_class->get_property = __ps_service_get_property;
- object_class->set_property = __ps_service_set_property;
-
- //dbus register
- dbus_g_object_type_install_info(PS_TYPE_SERVICE, &dbus_glib_ps_iface_service_object_info);
-
- //add properties
- g_object_class_install_property(
- object_class,
- PROP_SERVICE_PATH,
- g_param_spec_string("path", "PATH", "Technology Path", NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_SERVICE_P_MODEM,
- g_param_spec_pointer("p_modem", "MODEM", "Parent Modem Object",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_SERVICE_PLUGIN,
- g_param_spec_pointer("plg", "PLUGIN", "Plug in Object",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_SERVICE_CO_NETWORK,
- g_param_spec_pointer("co_network", "COREOBJECT NETWORK", "CoreObject of Network",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_SERVICE_CO_PS,
- g_param_spec_pointer("co_ps", "COREOBJECTPS", "CoreObject of PS",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property(
- object_class,
- PROP_SERVICE_CONN,
- g_param_spec_boxed("conn", "CONNECTION", "DBus connection", DBUS_TYPE_G_CONNECTION,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- //add signal handler
- signals[SIG_SERVICE_CONTEXT_ADDED] = g_signal_new("context-added", G_OBJECT_CLASS_TYPE(klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(PsServiceClass, context_added), NULL, NULL,
- g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
-
- signals[SIG_SERVICE_CONTEXT_REMOVED] = g_signal_new("context-removed",
- G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(PsServiceClass, context_removed), NULL, NULL,
- g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, DBUS_TYPE_G_OBJECT_PATH);
-
- signals[SIG_SERVICE_PROPERTY_CHANGED] = g_signal_new("property-changed",
- G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(PsServiceClass, property_changed), NULL, NULL,
- g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
-
- return;
-}
-
-static void __ps_service_get_property(GObject *object, guint prop_id, GValue *value,
- GParamSpec *pspec)
-{
- return;
-}
-
-static void __ps_service_set_property(GObject *object, guint prop_id, const GValue *value,
- GParamSpec *pspec)
-{
- PsService *service = PS_SERVICE(object);
-
- switch (prop_id) {
- case PROP_SERVICE_PATH: {
- if (service->path) g_free(service->path);
- service->path = g_value_dup_string(value);
- msg("service(%p) set path(%s)", service, service->path);
- }
- break;
- case PROP_SERVICE_P_MODEM: {
- service->p_modem = g_value_get_pointer(value);
- msg("service(%p) set modem(%p)", service, service->p_modem);
- }
- break;
- case PROP_SERVICE_PLUGIN: {
- service->plg = g_value_get_pointer(value);
- msg("service(%p) set plg(%p)", service, service->plg);
- }
- break;
- case PROP_SERVICE_CO_NETWORK: {
- service->co_network = g_value_get_pointer(value);
- msg("service(%p) set co_network(%p)", service, service->co_network);
- }
- break;
- case PROP_SERVICE_CO_PS: {
- service->co_ps = g_value_get_pointer(value);
- msg("service(%p) set co_ps(%p)", service, service->co_ps);
- }
- break;
- case PROP_SERVICE_CONN: {
- service->conn = g_value_get_boxed(value);
- msg("service(%p) set conn(%p)", service, service->conn);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- } //swtich end
-
- return;
-}
-
-gboolean ps_iface_service_get_properties(PsService *service, DBusGMethodInvocation *context)
+void __remove_service_handler(gpointer data)
{
- GError *error = NULL;
- gboolean rv = FALSE;
- GHashTable *properties = NULL;
-
- dbg("get service properties");
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- rv = _ps_service_get_properties(service, properties);
- if (rv != TRUE) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "fail to get properties service(%p)",
- service);
- dbus_g_method_return_error(context, error);
- g_hash_table_destroy(properties);
- return FALSE;
- }
-
- dbus_g_method_return(context, properties);
- g_hash_table_destroy(properties);
- return TRUE;
-}
+ PsService *service = data;
-gboolean ps_iface_service_get_contexts(PsService *service, DBusGMethodInvocation *context)
-{
- GError *error = NULL;
- GHashTableIter iter;
- gpointer key, value;
- GHashTable *contexts;
-
- dbg("service get contexts interface");
-
- if (service->contexts == NULL) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "service(%p) does not have contexts",
- service);
- dbus_g_method_return_error(context, error);
- return FALSE;
+ dbg("Entered");
+ if (!service) {
+ dbg("Service is Null");
+ return;
}
- contexts = g_hash_table_new_full(g_direct_hash, g_str_equal, g_free,
- (GDestroyNotify) g_hash_table_destroy);
-
- g_hash_table_iter_init(&iter, service->contexts);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- gboolean rv = FALSE;
- gchar *path = NULL;
- GHashTable *properties = NULL;
-
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- rv = _ps_context_get_properties(value, properties);
- if (rv != TRUE) {
- g_set_error(&error, PS_ERROR, PS_ERR_INTERNAL, "fail to get properties context(%p)",
- value);
- dbus_g_method_return_error(context, error);
- g_hash_table_destroy(properties);
- g_hash_table_destroy(contexts);
- return FALSE;
- }
+ /*Need to remove the compelete hash table*/
+ g_hash_table_remove_all(service->contexts);
- path = _ps_context_ref_path(value);
- g_hash_table_insert(contexts, g_strdup(path), properties);
- dbg("service (%p) inserted into hash", value);
+ /*Need to UNexport and Unref the master Object */
+ if (service->if_obj) {
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(service->if_obj));
+ g_object_unref(service->if_obj);
+ service->if_obj = NULL;
}
- dbus_g_method_return(context, contexts);
- g_hash_table_destroy(contexts);
-
- return TRUE;
+ /*Need to free the memory of the internal structure*/
+ g_free(service->path);
+ g_free(service);
}
static void __ps_service_emit_property_changed_signal(PsService *service)
{
- GHashTable *properties = NULL;
+ GVariant *gv = NULL;
+ GVariantBuilder property;
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_service_get_properties(service, properties);
- g_signal_emit(service, signals[SIG_SERVICE_PROPERTY_CHANGED], 0, properties);
- dbg("service (%p) emit property changed signal", service);
- g_hash_table_destroy(properties);
+ dbg("get service properties");
- return;
+ gv = _ps_service_get_properties(service, &property);
+ packet_service_service_emit_property_changed(service->if_obj, gv);
+
+ dbg("Exiting");
}
static void __ps_service_emit_context_added_signal(PsService *service, gpointer context)
{
- GHashTable *properties = NULL;
+ GVariant *gv = NULL;
+ GVariantBuilder property;
+
+ dbg("get service properties");
- properties = g_hash_table_new(g_str_hash, g_str_equal);
- _ps_context_get_properties(context, properties);
- g_signal_emit(service, signals[SIG_SERVICE_CONTEXT_ADDED], 0, properties);
- dbg("service (%p) emit the context(%p) added signal", service, context);
- g_hash_table_destroy(properties);
- return;
+ gv = _ps_context_get_properties(context, &property);
+ packet_service_service_emit_context_added(service->if_obj, gv);
+
+ dbg("Exiting");
}
static void __ps_service_emit_context_removed_signal(PsService *service, gpointer context)
{
- g_signal_emit(service, signals[SIG_SERVICE_CONTEXT_REMOVED], 0, _ps_context_ref_path(context));
- dbg("service (%p) emit the context(%p) removed signal", service, context);
- return;
-}
+ PsContext *pscontext = context;
-static void __remove_context(gpointer data)
-{
- return;
+ dbg("Entered");
+ packet_service_service_emit_context_removed(service->if_obj, pscontext->path);
+
+ dbg("Exiting");
}
-static char *__ps_service_act2string(enum telephony_network_access_technology act)
+static char *__ps_service_act2string(TelNetworkAct act)
{
switch (act) {
- case NETWORK_ACT_GSM:
- case NETWORK_ACT_GPRS:
- case NETWORK_ACT_EGPRS:
- case NETWORK_ACT_UMTS:
- case NETWORK_ACT_GSM_UTRAN:
+ case TEL_NETWORK_ACT_GSM:
+ case TEL_NETWORK_ACT_GPRS:
+ case TEL_NETWORK_ACT_EGPRS:
+ case TEL_NETWORK_ACT_UMTS:
+ case TEL_NETWORK_ACT_GSM_AND_UMTS:
return "GSM";
- case NETWORK_ACT_IS95A:
- case NETWORK_ACT_IS95B:
- case NETWORK_ACT_CDMA_1X:
- case NETWORK_ACT_EVDO_REV0:
- case NETWORK_ACT_CDMA_1X_EVDO_REV0:
- case NETWORK_ACT_EVDO_REVA:
- case NETWORK_ACT_CDMA_1X_EVDO_REVA:
- case NETWORK_ACT_EVDV:
- return "CDMA";
- case NETWORK_ACT_LTE:
+ case TEL_NETWORK_ACT_LTE:
return "LTE";
- case NETWORK_ACT_UNKNOWN:
+ case TEL_NETWORK_ACT_UNKNOWN:
default:
return "unknown";
}
return NULL;
}
-static gboolean __ps_service_check_connection_option(gpointer object)
+static gboolean __ps_service_check_connection_option(gpointer object, gpointer context)
{
gboolean b_connect = TRUE;
gboolean power, sim, data, flight;
- PsService *service = object;
- if(service->roaming){
- b_connect &=_ps_modem_get_data_roaming_allowed(service->p_modem);
- }
+
+ PsService *service = object;
power = _ps_modem_get_power(service->p_modem);
sim = _ps_modem_get_sim_init(service->p_modem);
b_connect &= sim;
b_connect &= data;
b_connect &= !flight;
- dbg("power(%d), sim init(%d), data allowed(%d), flight mode(%d)", power, sim, data, flight);
+ b_connect &= !service->restricted;
+
+ dbg("power(%d), sim init(%d), data allowed(%d), flight mode(%d) ",
+ power, sim, data, flight);
return b_connect;
}
static gboolean __ps_service_connetion_timeout_handler(gpointer context)
{
- int rv = 0;
+ gint rv = 0;
PsService *service = NULL;
service = _ps_context_ref_service(context);
return FALSE;
}
-gpointer _ps_service_create_service(DBusGConnection *conn, TcorePlugin *p, gpointer p_modem,
+gpointer _ps_service_create_service(GDBusConnection *conn, TcorePlugin *p, gpointer p_modem,
CoreObject *co_network, CoreObject *co_ps, gchar* path)
{
- guint rv = 0;
- GObject *object;
- DBusGProxy *proxy;
+ PacketServiceService *service;
GError *error = NULL;
+ PsService *new_service;
- dbg("Create SERVICE object - Path: [%s]", path);
- g_return_val_if_fail(conn != NULL, NULL);
- g_return_val_if_fail(p_modem != NULL, NULL);
+ dbg("service object create");
+ tcore_check_return_value(conn != NULL, NULL);
+ tcore_check_return_value(p_modem != NULL, NULL);
- /* Create new Proxy */
- proxy = dbus_g_proxy_new_for_name(conn, "org.freedesktop.DBus", "/org/freedesktop/DBus",
- "org.freedesktop.DBus");
+ /*creating the master object for the interface com.tcore.ps.modem*/
+ service = packet_service_service_skeleton_new();
- if (!dbus_g_proxy_call(proxy, "RequestName", &error, G_TYPE_STRING, PS_DBUS_SERVICE,
- G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &rv, G_TYPE_INVALID)) {
- err("Failed to acquire context(%s) error(%s)", PS_DBUS_SERVICE, error->message);
- return NULL;
+ /*Initializing the modem list for internal referencing*/
+ new_service = g_try_malloc0(sizeof(PsService));
+ if (NULL == new_service) {
+ err("Unable to allocate memory for master");
+ goto FAILURE;
}
- dbg("Acquired context: [%s]", PS_DBUS_SERVICE);
- /* Creating new Service object */
- object = g_object_new(PS_TYPE_SERVICE, "conn", conn, "plg", p, "p_modem", p_modem, "co_network",
- co_network, "co_ps", co_ps, "path", path, NULL);
+ new_service->conn = conn;
+ new_service->plg = p;
+ new_service->p_modem = p_modem;
+ new_service->co_network = co_network;
+ new_service->co_ps = co_ps;
+ new_service->path = g_strdup(path);
+ new_service->if_obj = service;
+ new_service->contexts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+ _ps_hook_co_network_event(new_service);
+ _ps_get_co_network_values(new_service);
+ _ps_hook_co_ps_event(new_service);
- _ps_hook_co_network_event(object);
- _ps_get_co_network_values(object);
- _ps_hook_co_ps_event(object);
+ /*Setting up the interface for the service */
+ _ps_service_setup_interface(service, new_service);
- dbus_g_connection_register_g_object(conn, path, object);
- msg("service(%p) register dbus path(%s)", object, path);
+ /*exporting the interface object to the path mention for master*/
+ g_dbus_interface_skeleton_export((G_DBUS_INTERFACE_SKELETON(service)),
+ conn,
+ path,
+ &error);
+
+ g_assert_no_error (error);
+
+ connection_timeout = TIMEOUT_DEFAULT;
+ dbg("Successfully Created the service");
+ return new_service;
- return object;
+FAILURE:
+ /*To Do: Handle failure case*/
+ return NULL;
}
gboolean _ps_service_ref_context(gpointer object, gpointer context)
PsService *service = object;
dbg("service refer to context");
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
s_path = _ps_context_ref_path(context);
tmp = g_hash_table_lookup(service->contexts, s_path);
return FALSE;
}
+ /* Setting service */
_ps_context_set_service(context, service);
+
+ /* Add Context to PS Core object */
tcore_ps_add_context(service->co_ps, (CoreObject *) _ps_context_ref_co_context(context));
+
+ /* Insert conetxt to Hash Table */
g_hash_table_insert(service->contexts, g_strdup(s_path), context);
dbg("context(%p) insert to hash", context);
+
+ /* Emit Context added signal */
__ps_service_emit_context_added_signal(service, context);
//_ps_service_connect_default_context(service);
gpointer key, value;
PsService *service = object;
gboolean ret = TRUE;
- int rv;
+ gint rv;
- dbg("Service refer to Contexts");
-
- g_return_val_if_fail(service != NULL, FALSE);
+ dbg("service refer to contexts");
+ tcore_check_return_value(service != NULL, FALSE);
g_hash_table_iter_init(&iter, contexts);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
/* Hash lookup */
tmp = g_hash_table_lookup(service->contexts, s_path);
if (tmp != NULL) {
- dbg("context [0x%x] already existed", tmp);
+ dbg("context(%p) already existed", tmp);
continue;
}
_ps_context_set_service(value, service);
/* Add Context to PS Core object */
- tcore_ps_add_context(service->co_ps, (CoreObject *)_ps_context_ref_co_context(value));
+ tcore_ps_add_context(service->co_ps, (CoreObject *) _ps_context_ref_co_context(value));
- /* Insert conetxt to Hash Table */
+ /* Insert context to Service Hash Table */
g_hash_table_insert(service->contexts, g_strdup(s_path), value);
- dbg("Inserted context to Hash table - context [0x%x]", value);
+ dbg("Inserted context to Hash table - context [%p]", value);
/* Emit Context added signal */
__ps_service_emit_context_added_signal(service, value);
f_awo = _ps_context_get_alwayson_enable(value);
- dbg("Always ON: [%s]", (f_awo ? "YES" : "NO"));
- if(f_awo) {
- dbg("Define Context");
+ if (f_awo) {
rv = _ps_service_define_context(service, value);
dbg("return rv(%d)", rv);
}
/* Update cellular state key */
_ps_update_cellular_state_key(service);
- //_ps_service_connect_default_context(service);
return ret;
}
PsService *service = object;
dbg("service unref contexts");
- g_return_val_if_fail(service != NULL, FALSE);
- g_return_val_if_fail(context != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
+ tcore_check_return_value(context != NULL, FALSE);
dbg("remove context(%p) from service(%p)", context, service);
+
+ /* Remove Context from PS Core object */
tcore_ps_remove_context(service->co_ps, (CoreObject *) _ps_context_ref_co_context(context));
+
+ /* Remove context to Hash Table */
g_hash_table_remove(service->contexts, _ps_context_ref_path(context));
+
+ /* Emit Context Remove signal */
__ps_service_emit_context_removed_signal(service, context);
return TRUE;
}
-gboolean _ps_service_get_properties(gpointer object, GHashTable *properties)
+gboolean _ps_service_get_properties_handler(gpointer object, GVariantBuilder *properties)
{
PsService *service = object;
dbg("get service properties");
- g_return_val_if_fail(service != NULL, FALSE);
- g_return_val_if_fail(properties != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
- g_hash_table_insert(properties, "path", g_strdup(service->path));
- g_hash_table_insert(properties, "ps_attached", BOOL2STRING(service->ps_attached));
- g_hash_table_insert(properties, "roaming", BOOL2STRING(service->roaming));
- g_hash_table_insert(properties, "act", __ps_service_act2string(service->act));
+ g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(service->path));
+ g_variant_builder_add(properties, "{ss}", "ps_attached", g_strdup(BOOL2STRING(service->ps_attached)));
+ g_variant_builder_add(properties, "{ss}", "roaming", g_strdup(BOOL2STRING(service->roaming)));
+ g_variant_builder_add(properties, "{ss}", "act", g_strdup(__ps_service_act2string(service->act)));
+ g_variant_builder_close(properties);
return TRUE;
}
+GVariant * _ps_service_get_properties(gpointer object, GVariantBuilder *properties)
+{
+ PsService *service = object;
+
+ dbg("get service properties");
+ tcore_check_return_value(service != NULL, FALSE);
+ tcore_check_return_value(properties != NULL, FALSE);
+
+ g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
+
+ g_variant_builder_add(properties, "{ss}", "path", g_strdup(service->path));
+ g_variant_builder_add(properties, "{ss}", "ps_attached", g_strdup(BOOL2STRING(service->ps_attached)));
+ g_variant_builder_add(properties, "{ss}", "roaming", g_strdup(BOOL2STRING(service->roaming)));
+ g_variant_builder_add(properties, "{ss}", "act", g_strdup(__ps_service_act2string(service->act)));
+
+ return g_variant_builder_end(properties);
+}
+
gchar* _ps_service_ref_path(gpointer object)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, NULL);
+ tcore_check_return_value(service != NULL, NULL);
return service->path;
}
gpointer _ps_service_ref_plugin(gpointer object)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, NULL);
+ tcore_check_return_value(service != NULL, NULL);
return service->plg;
}
gpointer _ps_service_ref_co_network(gpointer object)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, NULL);
+ tcore_check_return_value(service != NULL, NULL);
return service->co_network;
}
gpointer _ps_service_ref_co_ps(gpointer object)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, NULL);
+ tcore_check_return_value(service != NULL, NULL);
return service->co_ps;
}
-gboolean _ps_service_set_context_info(gpointer object, struct tnoti_ps_pdp_ipconfiguration *devinfo)
+gpointer _ps_service_ref_modem(gpointer object)
+{
+ PsService *service = object;
+ tcore_check_return_value(service != NULL, NULL);
+
+ return service->p_modem;
+}
+
+gboolean _ps_service_set_context_info(gpointer object, TcorePsPdpIpConf *devinfo)
{
GSList* contexts = NULL;
PsService *service = object;
dbg("Set context information");
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
/* Refer context */
dbg("Context ID: [%d]", devinfo->context_id);
- contexts = tcore_ps_ref_context_by_id(service->co_ps, devinfo->context_id);
+ tcore_ps_ref_context_by_id(service->co_ps, devinfo->context_id, &contexts);
if (NULL == contexts) {
- dbg("Failed to refer context");
+ err("Failed to refer context");
return FALSE;
}
co_context = contexts->data;
if (NULL == co_context) {
- dbg("Context is NULL");
+ err("Context is NULL");
continue;
}
return TRUE;
}
-int _ps_service_define_context(gpointer object, gpointer context)
+gint _ps_service_define_context(gpointer object, gpointer context)
{
PsService *service = object;
CoreObject *co_context = NULL;
gboolean b_connect = TRUE;
+ TelReturn ret;
dbg("define context(%p)", context);
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, TEL_RETURN_FAILURE);
co_context = (CoreObject *)_ps_context_ref_co_context(context);
- b_connect = __ps_service_check_connection_option(service);
- if(!b_connect)
- return TCORE_RETURN_EPERM;
+ b_connect = __ps_service_check_connection_option(service, co_context);
+ if (!b_connect) {
+ return TEL_RETURN_FAILURE;
+
+ }
+
+ ret = tcore_plugin_dispatch_request(tcore_object_ref_plugin(service->co_ps), TRUE,
+ TCORE_COMMAND_PS_DEFINE_CONTEXT,
+ &co_context, sizeof(CoreObject *),
+ NULL, NULL);
- return tcore_ps_define_context(service->co_ps, co_context, NULL);
+ return ret;
}
-int _ps_service_activate_context(gpointer object, gpointer context)
+gint _ps_service_activate_context(gpointer object, gpointer context)
{
PsService *service = object;
CoreObject *co_context = NULL;
gboolean b_connect = TRUE;
gboolean ps_defined;
- int ret = TCORE_RETURN_FAILURE;
+ gint ret = TEL_RETURN_FAILURE;
dbg("Activate context [0x%x]", context);
- g_return_val_if_fail(service != NULL, TCORE_RETURN_EINVAL);
+ tcore_check_return_value(service != NULL, TEL_RETURN_INVALID_PARAMETER);
co_context = (CoreObject *)_ps_context_ref_co_context(context);
- /* Check for connection option */
- b_connect = __ps_service_check_connection_option(service);
- dbg("Service option - PS Attached: [%s]", (service->ps_attached ? "YES" : "NO"));
-
- b_connect &= service->ps_attached;
- dbg("Connect: [%s]", (b_connect ? "YES" : "NO"));
- if(!b_connect)
- return TCORE_RETURN_EPERM;
+ b_connect = __ps_service_check_connection_option(service, co_context);
+ if (!b_connect) {
+ err("Connection option failed");
+ return TEL_RETURN_FAILURE;
+ }
ps_defined = _ps_context_get_ps_defined(context);
- if(!ps_defined) {
- dbg("PDP profile is NOT defined!!! Need to define it first...");
- ret = tcore_ps_define_context(service->co_ps, co_context, NULL);
- }
- else {
+ if (!ps_defined) {
+ dbg("PDP profile is NOT defined!!! Need to define it first... co_context: [%p]");
+ ret = tcore_plugin_dispatch_request(tcore_object_ref_plugin(service->co_ps), TRUE,
+ TCORE_COMMAND_PS_DEFINE_CONTEXT,
+ &co_context, sizeof(CoreObject *),
+ NULL, NULL);
+ } else {
dbg("PDP profile is defined!!! Activate context...");
- ret = tcore_ps_activate_context(service->co_ps, co_context, NULL);
+ ret = tcore_plugin_dispatch_request(tcore_object_ref_plugin(service->co_ps), TRUE,
+ TCORE_COMMAND_PS_ACTIVATE_CONTEXT,
+ &co_context, sizeof(CoreObject *),
+ NULL, NULL);
}
return ret;
}
-gboolean _ps_service_deactivate_context(gpointer object, gpointer context)
+gint _ps_service_deactivate_context(gpointer object, gpointer context)
{
PsService *service = object;
CoreObject *co_context = NULL;
+ TelReturn ret = TEL_RETURN_FAILURE ;
dbg("deactivate context(%p)", context);
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, TEL_RETURN_INVALID_PARAMETER);
co_context = (CoreObject *)_ps_context_ref_co_context(context);
+ ret = tcore_plugin_dispatch_request(tcore_object_ref_plugin(service->co_ps), TRUE,
+ TCORE_COMMAND_PS_DEACTIVATE_CONTEXT,
+ &co_context, sizeof(CoreObject *),
+ NULL, NULL);
- return tcore_ps_deactivate_context(service->co_ps, co_context, NULL);
+ return ret;
+}
+
+void _ps_service_set_retry_timeout_value(int value)
+{
+ connection_timeout = value;
+ dbg("current timeout (%d)", connection_timeout);
}
void _ps_service_connection_timer(gpointer object, gpointer context)
gboolean f_awo = FALSE;
f_awo = _ps_context_get_alwayson_enable(context);
- if(!f_awo)
+ if (!f_awo)
return;
+ if (timer_src != 0) {
+ dbg("remove connection retry timer (%d)", timer_src);
+ g_source_remove(timer_src);
+ timer_src = 0;
+ }
+
timer_src = g_timeout_add_seconds(connection_timeout, __ps_service_connetion_timeout_handler, context);
dbg("cellular service timer started timer src(%d), timeout(%d)", timer_src, connection_timeout);
connection_timeout = connection_timeout*2;
- if(connection_timeout > TIMEOUT_MAX)
- connection_timeout = TIMEOUT_MAX;
-
- return;
+ if (connection_timeout >= TIMEOUT_MAX)
+ connection_timeout = TIMEOUT_DEFAULT;
}
void _ps_service_reset_connection_timer(gpointer context)
PsService *service = object;
dbg("service remove all contexts");
- g_return_if_fail(service != NULL);
+ tcore_check_return(service != NULL);
g_hash_table_iter_init(&iter, service->contexts);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
}
g_hash_table_remove_all(service->contexts);
- return;
}
void _ps_service_disconnect_contexts(gpointer object)
PsService *service = object;
dbg("service disconnect all contexts");
- g_return_if_fail(service != NULL);
+ tcore_check_return(service != NULL);
g_hash_table_iter_init(&iter, service->contexts);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
_ps_service_reset_connection_timer(value);
_ps_service_deactivate_context(service, value);
}
-
- return;
}
-void _ps_service_connect_default_context(gpointer object)
+gint _ps_service_connect_default_context(gpointer object)
{
+ gint rv = TEL_RETURN_FAILURE;
GHashTableIter iter;
gpointer key, value;
PsService *service = object;
- dbg("Connect to 'default' context");
- g_return_if_fail(service != NULL);
+ dbg("service connect default context");
+ tcore_check_return_value(service != NULL, TEL_RETURN_INVALID_PARAMETER);
g_hash_table_iter_init(&iter, service->contexts);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
gboolean f_awo = FALSE;
-
f_awo = _ps_context_get_alwayson_enable(value);
- dbg("Always ON: [%s]", (f_awo ? "YES" : "NO"));
- if(f_awo){
- int rv = 0;
+ if (f_awo) {
_ps_service_reset_connection_timer(value);
- /* Activate context */
+ /* Activate Context */
rv = _ps_service_activate_context(service, value);
dbg("return rv(%d)", rv);
break;
}
}
- return;
+ return rv;
}
gpointer _ps_service_return_default_context(gpointer object)
gpointer key, value;
PsService *service = object;
- g_return_val_if_fail(service != NULL, NULL);
+ tcore_check_return_value(service != NULL, NULL);
g_hash_table_iter_init(&iter, service->contexts);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
gboolean b_default = FALSE;
b_default = _ps_context_get_default_internet(value);
- if(b_default){
+ if (b_default) {
return value;
}
}
gboolean _ps_service_processing_network_event(gpointer object, gboolean ps_attached, gboolean roaming)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, FALSE);
-
- if(service->ps_attached == ps_attached && service->roaming == roaming)
- return TRUE;
+ tcore_check_return_value(service != NULL, FALSE);
_ps_service_set_ps_attached(service, ps_attached);
- _ps_service_set_roaming(service, roaming);
_ps_update_cellular_state_key(service);
+ if (service->roaming != roaming) {
+ gboolean roaming_allowed = FALSE;
+ _ps_service_set_roaming(service, roaming);
+ roaming_allowed = _ps_modem_get_data_roaming_allowed(service->p_modem);
+ if (!roaming_allowed && roaming) {
+ dbg("Roaming allowed (%d), Roaming status (%d)", roaming_allowed, roaming);
+ _ps_service_disconnect_contexts(service);
+ return TRUE;
+ }
+ }
- if(service->ps_attached)
+ if (service->ps_attached)
_ps_service_connect_default_context(service);
return TRUE;
}
-gboolean _ps_service_set_connected(gpointer object, int context_id, gboolean enabled)
+gboolean _ps_service_set_connected(gpointer object, gint context_id, gboolean enabled)
{
GHashTableIter iter;
gpointer key, value;
- PsService *service = NULL;
- dbg("Set service - Context ID: [%d] State: [%s]",
- context_id, (enabled ? "CONNECTED" : "NOT CONNECTED"));
+ PsService *service = NULL;
service = (PsService *) object;
g_hash_table_iter_init(&iter, service->contexts);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ guint tmp_cid;
CoreObject *context = NULL;
- int tmp_cid;
context = _ps_context_ref_co_context(value);
- tmp_cid = tcore_context_get_id(context);
+ tcore_context_get_id(context, &tmp_cid);
- if (tmp_cid != context_id) continue;
+ if (tmp_cid != (guint)context_id) continue;
- if(!enabled) {
- dbg("Clear teh context ID");
+ if (!enabled) {
+ dbg("Reset socket connections.");
tcore_ps_clear_context_id(service->co_ps, context);
}
- /* Set the state */
_ps_context_set_connected(value, enabled);
}
GHashTableIter iter;
gpointer key, out;
- dbg("PS Defined - Context ID: [%d] Value: [%d]", cid, value);
-
- g_return_if_fail(service != NULL);
+ tcore_check_return(service != NULL);
g_hash_table_iter_init(&iter, service->contexts);
while (g_hash_table_iter_next(&iter, &key, &out) == TRUE) {
- gboolean r_activate = 0;
-
- /* Set Context */
- r_activate = _ps_context_set_ps_defined(out, value, cid);
- r_activate &= value;
-
- dbg("Activate context: [%s]", (r_activate ? "YES" : "NO"));
- if(r_activate) {
+ gboolean r_actvate = 0;
+ r_actvate = _ps_context_set_ps_defined(out, value, cid);
+ r_actvate &= value;
+ if (r_actvate) {
int rv;
-
- dbg("Activate context - Context ID: [%d]", cid);
+ dbg("define is complete, activate context for cid(%d)", cid);
rv = _ps_service_activate_context(service, out);
- dbg("Activate context request - %s", (rv == TCORE_RETURN_SUCCESS ? "SUCCESS" : "FAIL"));
+ dbg("rv(%d)", rv);
break;
}
}
-
- return;
}
gboolean _ps_service_set_ps_attached(gpointer object, gboolean value)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
service->ps_attached = value;
dbg("service(%p) ps_attached(%d)", service, service->ps_attached);
return TRUE;
}
+gboolean _ps_service_get_restricted(gpointer object)
+{
+ PsService *service = object;
+ tcore_check_return_value(service != NULL, FALSE);
+
+ return service->restricted;
+}
+
+gboolean _ps_service_set_restricted(gpointer object, gboolean value)
+{
+ PsService *service = object;
+ tcore_check_return_value(service != NULL, FALSE);
+
+ service->restricted = value;
+ dbg("service(%p) restricted(%d)", service, service->restricted);
+
+ _ps_update_cellular_state_key(service);
+ return TRUE;
+}
+
+#if 0
+gboolean _ps_service_set_number_of_pdn_cnt(gpointer object, gchar *operator)
+{
+ int rv = 0;
+ int num_of_pdn = 0;
+ PsService *service = object;
+ tcore_check_return_value(service != NULL, FALSE);
+ dbg("Entered");
+ num_of_pdn = _ps_context_get_number_of_pdn(operator);
+ rv = tcore_ps_set_num_of_pdn(service->co_ps, num_of_pdn);
+
+ if (rv != TEL_RETURN_SUCCESS) {
+ dbg("error to get maximum number of pdn");
+ }
+ dbg("Exiting");
+ return TRUE;
+}
+#endif
+
gboolean _ps_service_get_roaming(gpointer object)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
return service->roaming;
}
gboolean _ps_service_set_roaming(gpointer object, gboolean value)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
service->roaming = value;
dbg("service(%p) roaming(%d)", service, service->roaming);
return TRUE;
}
+static void _indicator_cb_dns_reply(GObject *src, GAsyncResult *res, gpointer user_data)
+{
+ GList *list, *cur;
+ GInetAddress *addr;
+ gchar *str_addr;
+ GError *error = NULL;
+
+ list = g_resolver_lookup_by_name_finish((GResolver *)src, res, &error);
+ if (!list) {
+ dbg("fail to get dns resolving");
+ if (error) {
+ dbg ("error:%d, %s", error->code, error->message);
+ g_error_free (error);
+ }
+ return;
+ }
+
+ for (cur = list; cur; cur = cur->next) {
+ addr = cur->data;
+ str_addr = g_inet_address_to_string(addr);
+ if (!str_addr)
+ continue;
+ dbg("addr(%s)", str_addr);
+
+ g_free(str_addr);
+ g_object_unref(cur->data);
+ break;
+ }
+
+ g_object_unref(src);
+ g_list_free(list);
+}
+
gboolean _ps_service_set_access_technology(gpointer object,
- enum telephony_network_access_technology value)
+ TelNetworkAct value)
{
PsService *service = object;
- g_return_val_if_fail(service != NULL, FALSE);
+ TelNetworkAct p_act = 0;
+ tcore_check_return_value(service != NULL, FALSE);
+ p_act = service->act;
service->act = value;
- dbg("service(%p) Access Technology(%d)", service, service->act);
+ dbg("service(%p) P ACT(%d) Access Technology(%d)", service, p_act, service->act);
+
+ if (p_act == TEL_NETWORK_ACT_LTE
+ && (service->act >= TEL_NETWORK_ACT_GSM
+ && service->act < TEL_NETWORK_ACT_LTE)) {
+ GResolver *r = NULL;
- if(service->act > NETWORK_ACT_UNKNOWN && service->act < NETWORK_ACT_NOT_SPECIFIED){
+ dbg("send the dns pkt for keeping connection");
+
+ r = g_resolver_get_default();
+ g_resolver_lookup_by_name_async(r, "www.google.com", NULL, _indicator_cb_dns_reply, NULL);
+ }
+
+ if (service->act > TEL_NETWORK_ACT_UNKNOWN) {
_ps_update_cellular_state_key(service);
_ps_service_connect_default_context(service);
}
return TRUE;
}
-enum telephony_ps_state _ps_service_check_cellular_state(gpointer object)
+TcorePsState _ps_service_check_cellular_state(gpointer object)
{
gboolean state = FALSE;
PsService *service = object;
- g_return_val_if_fail(service != NULL, TELEPHONY_PS_NO_SERVICE);
+ tcore_check_return_value(service != NULL, TCORE_PS_STATE_NO_SERVICE);
state = _ps_modem_get_power(service->p_modem);
- if(!state){
- return TELEPHONY_PS_NO_SERVICE;
+ if (!state) {
+ dbg("NO SERVICE");
+ return TCORE_PS_STATE_NO_SERVICE;
}
state = _ps_modem_get_sim_init(service->p_modem);
- if(!state){
- return TELEPHONY_PS_NO_SERVICE;
+ if (!state) {
+ dbg("NO SERVICE");
+ return TCORE_PS_STATE_NO_SERVICE;
}
state = _ps_modem_get_flght_mode(service->p_modem);
- if(state){
- return TELEPHONY_PS_FLIGHT_MODE;
+ if (state) {
+ dbg("FLIGHT MODE ON");
+ return TCORE_PS_STATE_FLIGHT_MODE;
}
- if(!service->ps_attached){
- return TELEPHONY_PS_NO_SERVICE;
+ if (!service->ps_attached) {
+ dbg("NO SERVICE");
+ return TCORE_PS_STATE_NO_SERVICE;
}
state = _ps_modem_get_data_allowed(service->p_modem);
- if(!state){
- return TELEPHONY_PS_3G_OFF;
+ if (!state) {
+ dbg("DATA OFF");
+ return TCORE_PS_STATE_3G_OFF;
}
state = _ps_modem_get_data_roaming_allowed(service->p_modem);
- if(service->roaming && !state){
- return TELEPHONY_PS_ROAMING_OFF;
+ if (service->roaming && !state) {
+ dbg("DATA ROAMING OFF");
+ return TCORE_PS_STATE_ROAMING_OFF;
}
- return TELEPHONY_PS_ON;
+ return TCORE_PS_STATE_ON;
+}
+static gboolean on_service_get_properties (PacketServiceService *obj_service,
+ GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ GVariant *gv = NULL;
+ GVariantBuilder property;
+ dbg("get service properties");
+
+ gv = _ps_service_get_properties(user_data, &property);
+ packet_service_service_complete_get_properties(obj_service, invocation, gv);
+ return TRUE;
+}
+
+static gboolean on_service_get_context (PacketServiceService *obj_service,
+ GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ GVariantBuilder b_context;
+ GVariant *contexts;
+
+ GHashTableIter iter;
+ gpointer key, value;
+ PsService *service = user_data;
+
+ dbg("modem get contexts interface");
+
+ if (service->contexts == NULL) {
+ err("No context present for service");
+ FAIL_RESPONSE(invocation,PS_ERR_INTERNAL);
+ return TRUE;
+ }
+
+ g_variant_builder_init(&b_context, G_VARIANT_TYPE("a{sa{ss}}"));
+ g_hash_table_iter_init(&iter, service->contexts);
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ gchar *path = NULL;
+ g_variant_builder_open(&b_context,G_VARIANT_TYPE("{sa{ss}}"));
+ path = _ps_service_ref_path(value);
+
+ g_variant_builder_add(&b_context, "s",g_strdup(path));
+ if (FALSE == _ps_context_get_properties_handler(value, &b_context)) {
+ err("Failed to get property");
+ g_variant_builder_close(&b_context);
+ FAIL_RESPONSE(invocation,PS_ERR_INTERNAL);
+ return TRUE;
+ }
+ g_variant_builder_close(&b_context);
+
+ }
+
+ contexts = g_variant_builder_end(&b_context);
+ packet_service_service_complete_get_contexts(obj_service, invocation,contexts);
+ return TRUE;
+}
+
+static void _ps_service_setup_interface(PacketServiceService *service,
+ PsService *service_data)
+{
+ dbg("Entered");
+ g_signal_connect (service,
+ "handle-get-properties",
+ G_CALLBACK (on_service_get_properties),
+ service_data);
+
+ g_signal_connect (service,
+ "handle-get-contexts",
+ G_CALLBACK (on_service_get_context),
+ service_data);
+
+ dbg("Exiting");
}
/*
* tel-plugin-packetservice
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
#include "ps.h"
+#include <tcore.h>
#include <server.h>
#include <plugin.h>
#include <storage.h>
-#include <util.h>
#include <co_ps.h>
+#include <co_context.h>
#include <co_modem.h>
#include <co_sim.h>
#include <co_network.h>
-#include <util.h>
-
-static enum tcore_hook_return __on_hook_call_status(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data,
- void *user_data)
+static TcoreHookReturn __on_hook_call_status(TcorePlugin *plugin,
+ TcoreNotification command, guint data_len, void *data, void *user_data)
{
gpointer service = user_data;
- struct tnoti_ps_call_status *cstatus = NULL;
- char *ifname;
+ TcorePsCallStatusInfo *cstatus = NULL;
gboolean netif_updown = FALSE;
+ gchar *ifname = NULL;
GSList *contexts;
CoreObject *co_context;
+ CoreObject *co;
- dbg("CALL Status event");
+ dbg("Call Status event");
+ tcore_check_return_value(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ co = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
- g_return_val_if_fail(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
-
- cstatus = (struct tnoti_ps_call_status *)data;
- g_return_val_if_fail(cstatus != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ cstatus = (TcorePsCallStatusInfo *)data;
+ tcore_check_return_value(cstatus != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
dbg("Context ID: [%d] Call State: [%s]", cstatus->context_id,
- ((cstatus->state == PS_DATA_CALL_CTX_DEFINED) ? "DEFINED"
- : (cstatus->state == PS_DATA_CALL_CONNECTED) ? "CONNECTED"
- : "NOT CONNECTED"));
+ ((cstatus->state == TCORE_PS_CALL_STATE_CTX_DEFINED) ? "DEFINED"
+ : (cstatus->state == TCORE_PS_CALL_STATE_CONNECTED) ? "CONNECTED"
+ : "NOT CONNECTED"));
- if (cstatus->state == PS_DATA_CALL_CTX_DEFINED)
+ if (cstatus->state == TCORE_PS_CALL_STATE_CTX_DEFINED)
goto out;
- else if (cstatus->state == PS_DATA_CALL_CONNECTED)
+ else if (cstatus->state == TCORE_PS_CALL_STATE_CONNECTED)
netif_updown = TRUE;
- else if (cstatus->state == PS_DATA_CALL_NOT_CONNECTED)
+ else if (cstatus->state == TCORE_PS_CALL_STATE_NOT_CONNECTED)
netif_updown = FALSE;
/* Refer to context */
- contexts = tcore_ps_ref_context_by_id(source, cstatus->context_id);
+ tcore_ps_ref_context_by_id(co, cstatus->context_id, &contexts);
for (; contexts != NULL; contexts = g_slist_next(contexts)) {
co_context = contexts->data;
if (co_context == NULL) {
}
/* Get Interface name */
- ifname = tcore_context_get_ipv4_devname(co_context);
+ tcore_context_get_ipv4_devname(co_context, &ifname);
if (ifname == NULL) {
dbg("Interface name is NULL");
continue;
/* Setup network interface */
if (tcore_util_netif(ifname, netif_updown)
- != TCORE_RETURN_SUCCESS) {
+ != TEL_RETURN_SUCCESS) {
g_slist_free(contexts);
- g_free(ifname);
err("Failed to setup interface - Interface name: [%s] Interface Status: [%s]",
- ifname, (netif_updown ? "UP" : "DOWN"));
+ ifname, (netif_updown ? "UP" : "DOWN"));
}
dbg("Successfully setup interface - Interface name: [%s] Interface Status: [%s]",
- ifname, (netif_updown ? "UP" : "DOWN"));
+ ifname, (netif_updown ? "UP" : "DOWN"));
}
-
out:
//send activation event / deactivation event
- if (cstatus->state == PS_DATA_CALL_CTX_DEFINED) { /* OK: PDP define is complete. */
+ if (cstatus->state == TCORE_PS_CALL_STATE_CTX_DEFINED) {
+ /* OK: PDP define is complete. */
dbg("Service - [READY TO ACTIVATE]");
_ps_service_set_ps_defined(service, TRUE, cstatus->context_id);
//_ps_service_connect_default_context(service);
- }
- else if (cstatus->state == PS_DATA_CALL_CONNECTED) { /* CONNECTED */
+ } else if (cstatus->state == TCORE_PS_CALL_STATE_CONNECTED) {
+ /* CONNECTED */
dbg("Service - [ACTIVATED]");
_ps_service_set_connected(service, cstatus->context_id, TRUE);
- }
- else if (cstatus->state == PS_DATA_CALL_NOT_CONNECTED) { /* NO CARRIER */
- dbg("Service - [DEACTIVATED]");
+ } else if (cstatus->state == TCORE_PS_CALL_STATE_NOT_CONNECTED) {
+ /* NO CARRIER */
_ps_service_set_ps_defined(service, FALSE, cstatus->context_id);
_ps_service_set_connected(service, cstatus->context_id, FALSE);
}
-
return TCORE_HOOK_RETURN_CONTINUE;
}
-static enum tcore_hook_return __on_hook_session_data_counter(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data,
- void *user_data)
-{
- g_return_val_if_fail(user_data != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
-
- dbg("session data counter event");
-
- return TCORE_HOOK_RETURN_CONTINUE;
-}
-
-static enum tcore_hook_return __on_hook_ipconfiguration(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data,
- void *user_data)
+static TcoreHookReturn __on_hook_ipconfiguration(TcorePlugin *plugin,
+ TcoreNotification command, guint data_len, void *data, void *user_data)
{
gpointer service = user_data;
- CoreObject *co_ps = NULL;
- struct tnoti_ps_pdp_ipconfiguration *devinfo = NULL;
+ TcorePsPdpIpConf *devinfo = NULL;
- g_return_val_if_fail(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ tcore_check_return_value(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
- devinfo = (struct tnoti_ps_pdp_ipconfiguration *) data;
- co_ps = (CoreObject *) _ps_service_ref_co_ps(service);
-
- if (co_ps != source) {
- dbg("Mismatching PS object");
- return TCORE_HOOK_RETURN_CONTINUE;
- }
+ devinfo = (TcorePsPdpIpConf *) data;
dbg("IP Configuration event");
_ps_service_set_context_info(service, devinfo);
return TCORE_HOOK_RETURN_CONTINUE;
}
-static enum tcore_hook_return __on_hook_powered(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data, void *user_data)
+static TcoreHookReturn __on_hook_powered(TcorePlugin *plugin,
+ TcoreNotification command, guint data_len, void *data, void *user_data)
{
gpointer modem = user_data;
- struct tnoti_modem_power *modem_power = NULL;
+ TelModemPowerStatus *modem_power = NULL;
gboolean power = FALSE;
dbg("Powered event");
- g_return_val_if_fail(modem != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ tcore_check_return_value(modem != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
- modem_power = (struct tnoti_modem_power *)data;
+ modem_power = (TelModemPowerStatus *)data;
dbg("Modem Power state: [%s]",
- ((modem_power->state == MODEM_STATE_ONLINE) ? "ONLINE"
- : (modem_power->state == MODEM_STATE_OFFLINE) ? "OFFLINE" : "ERROR"));
+ ((*modem_power == TEL_MODEM_POWER_ON) ? "ONLINE"
+ : (*modem_power == TEL_MODEM_POWER_OFF) ? "OFFLINE" : "ERROR"));
- if ( modem_power->state == MODEM_STATE_ONLINE )
+ if ( *modem_power == TEL_MODEM_POWER_ON )
power = TRUE;
else
power = FALSE;
return TCORE_HOOK_RETURN_CONTINUE;
}
-static enum tcore_hook_return __on_hook_flight(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data, void *user_data)
+static TcoreHookReturn __on_hook_flight(TcorePlugin *plugin,
+ TcoreNotification command, guint data_len, void *data, void *user_data)
{
gpointer modem = user_data;
- struct tnoti_modem_flight_mode *modem_flight = NULL;
+ gboolean *flight_mode = NULL;
dbg("Flight mode event");
- g_return_val_if_fail(modem != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ tcore_check_return_value(modem != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
- modem_flight = (struct tnoti_modem_flight_mode *)data;
- dbg("Flight mode: [%s]", (modem_flight->enable ? "ON" : "OFF"));
+ flight_mode = (gboolean *)data;
+ dbg("Flight mode: [%s]", (*flight_mode ? "ON" : "OFF"));
/* Process Flight mode event */
- _ps_modem_processing_flight_mode(modem, modem_flight->enable);
+ _ps_modem_processing_flight_mode(modem, *flight_mode);
return TCORE_HOOK_RETURN_CONTINUE;
}
-static enum tcore_hook_return __on_hook_net_register(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data,
- void *user_data)
+static TcoreHookReturn __on_hook_net_register(TcorePlugin *plugin,
+ TcoreNotification command, guint data_len, void *data, void *user_data)
{
gpointer service = user_data;
gboolean ps_attached = FALSE;
- struct tnoti_network_registration_status *regist_status;
+ TelNetworkRegStatusInfo *registration_status;
dbg("network register event called");
- g_return_val_if_fail(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ tcore_check_return_value(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
- regist_status = (struct tnoti_network_registration_status *) data;
- if (regist_status->ps_domain_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL)
+ registration_status = (TelNetworkRegStatusInfo *)data;
+ if (registration_status->ps_status == TEL_NETWORK_REG_STATUS_REGISTERED ||
+ registration_status->ps_status == TEL_NETWORK_REG_STATUS_ROAMING)
ps_attached = TRUE;
- _ps_service_processing_network_event(service, ps_attached, regist_status->roaming_status);
+ _ps_service_processing_network_event(service, ps_attached, registration_status->ps_status);
+
+ dbg("act(%d)", registration_status->act);
+ _ps_service_set_access_technology(service, registration_status->act);
return TCORE_HOOK_RETURN_CONTINUE;
}
-static enum tcore_hook_return __on_hook_net_change(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data,
- void *user_data)
+static TcoreHookReturn __on_hook_sim_init(TcorePlugin *plugin,
+ TcoreNotification command, guint data_len, void *data, void *user_data)
{
- gpointer service = user_data;
- struct tnoti_network_change *network_change;
+ TelSimCardStatusInfo *sim_data;
+ CoreObject *co_sim;
- dbg("network change event called");
- g_return_val_if_fail(service != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
- network_change = (struct tnoti_network_change *) data;
- dbg("plmn(%s) act(%d)", network_change->plmn, network_change->act);
- _ps_service_set_access_technology(service, network_change->act);
+ dbg("sim init event called");
+ tcore_check_return_value(user_data != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
- return TCORE_HOOK_RETURN_CONTINUE;
-}
+ co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
-static enum tcore_hook_return __on_hook_sim_init(Server *s, CoreObject *source,
- enum tcore_notification_command command, unsigned int data_len, void *data, void *user_data)
-{
- struct tnoti_sim_status *sim_data;
+ sim_data = (TelSimCardStatusInfo *)data;
+ dbg("SIM status: [0x%02x]", sim_data->status);
- dbg("SIM INIT event");
- g_return_val_if_fail(user_data != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+ if( sim_data->status == TEL_SIM_STATUS_SIM_INIT_COMPLETED){
+ TelSimImsiInfo *imsi = NULL;
+ char plmn[(TEL_SIM_MCC_MNC_LEN_MAX * 2) + 1] = {0,}; //mcc+mnc
- sim_data = (struct tnoti_sim_status *)data;
- dbg("SIM status: [0x%02x]", sim_data->sim_status);
+ tcore_sim_get_imsi(co_sim, &imsi);
+ strncpy(plmn, imsi->mcc,strlen( imsi->mcc));
+ strcat(plmn, imsi->mnc);
- if( sim_data->sim_status == SIM_STATUS_INIT_COMPLETED){
- struct tel_sim_imsi *sim_imsi = NULL;
- sim_imsi = tcore_sim_get_imsi(source);
- _ps_modem_processing_sim_complete((gpointer)user_data, TRUE, (gchar *)sim_imsi->plmn);
- g_free(sim_imsi);
+ _ps_modem_processing_sim_complete((gpointer)user_data, TRUE, plmn);
+ g_free(imsi);
}
return TCORE_HOOK_RETURN_CONTINUE;
gboolean _ps_hook_co_modem_event(gpointer modem)
{
- Server *s = NULL;
- TcorePlugin *p;
- g_return_val_if_fail(modem != NULL, FALSE);
+ CoreObject *co_modem;
+ tcore_check_return_value(modem != NULL, FALSE);
- dbg("Hook Modem & SIM events");
-
- p = _ps_modem_ref_plugin(modem);
- s = tcore_plugin_ref_server(p);
+ dbg("Hooking modem and sim events");
+ co_modem = _ps_modem_ref_co_modem(modem);
- tcore_server_add_notification_hook(s, TNOTI_MODEM_POWER, __on_hook_powered, modem);
- tcore_server_add_notification_hook(s, TNOTI_MODEM_FLIGHT_MODE, __on_hook_flight, modem);
- tcore_server_add_notification_hook(s, TNOTI_SIM_STATUS, __on_hook_sim_init, modem);
+ tcore_plugin_add_notification_hook(tcore_object_ref_plugin(co_modem),
+ TCORE_NOTIFICATION_MODEM_POWER, __on_hook_powered, modem);
+ tcore_plugin_add_notification_hook(tcore_object_ref_plugin(co_modem),
+ TCORE_NOTIFICATION_MODEM_FLIGHT_MODE, __on_hook_flight, modem);
+ tcore_plugin_add_notification_hook(tcore_object_ref_plugin(co_modem),
+ TCORE_NOTIFICATION_SIM_STATUS, __on_hook_sim_init, modem);
return TRUE;
}
CoreObject *co_sim = NULL;
gboolean sim_init = FALSE, modem_powered = FALSE, flight_mode = FALSE;
- int sim_status = 0;
- struct tel_sim_imsi *sim_imsi = NULL;
-
- dbg("Extract modem values");
+ TelSimCardStatus sim_status;
+ TelSimImsiInfo *sim_imsi = NULL;
+ gchar plmn[(TEL_SIM_MCC_MNC_LEN_MAX * 2) + 1] = {0,}; //mcc+mnc
- g_return_val_if_fail(modem != NULL, FALSE);
+ tcore_check_return_value(modem != NULL, FALSE);
co_modem = _ps_modem_ref_co_modem(modem);
- if (!co_modem)
+ if (!co_modem){
+ err("invalid PsModem ");
return FALSE;
+ }
plg = tcore_object_ref_plugin(co_modem);
- if (!plg)
+ if (!plg){
+ err("invalid plugin");
return FALSE;
+ }
co_sim = tcore_plugin_ref_core_object(plg, CORE_OBJECT_TYPE_SIM);
- if (!co_sim)
+ if (!co_sim) {
+ err("invalid co sim");
return FALSE;
+ }
/* SIM State */
- sim_status = tcore_sim_get_status(co_sim);
- if(sim_status == SIM_STATUS_INIT_COMPLETED) {
+ tcore_sim_get_status(co_sim, &sim_status);
+ if(sim_status == TEL_SIM_STATUS_SIM_INIT_COMPLETED){
sim_init = TRUE;
/*
- * If SIM State is initialized then fetch the Modem Power,
- * else wait for Modem Power Notification.
+ * If sim is intialized then only fetch modem state
*/
- modem_powered = tcore_modem_get_powered(co_modem);
+ tcore_modem_get_powered(co_modem, &modem_powered);
}
/* IMSI */
- sim_imsi = tcore_sim_get_imsi(co_sim);
+ tcore_sim_get_imsi(co_sim, &sim_imsi);
+ strncpy(plmn, sim_imsi->mcc, strlen( sim_imsi->mcc));
+ strcat(plmn, sim_imsi->mnc);
/* Flight mode */
- flight_mode = tcore_modem_get_flight_mode_state(co_modem);
+ tcore_modem_get_flight_mode_state(co_modem, &flight_mode);
- msg(" SIM init: [%s]", sim_init ? "YES" : "NO");
- msg(" Modem powered: [%s]", modem_powered ? "YES" : "ON");
- msg(" Flight mode: [%s]", flight_mode ? "ON" : "OFF");
+ dbg("SIM init: [%s], Modem powered: [%s], Flight mode: [%s]",
+ sim_init ? "YES" : "NO",
+ modem_powered ? "YES" : "ON",
+ flight_mode ? "ON" : "OFF");
/* Set Flight mode */
_ps_modem_processing_flight_mode(modem, flight_mode);
_ps_modem_processing_power_enable(modem, modem_powered);
/* Process SIM state */
- _ps_modem_processing_sim_complete(modem, sim_init, (gchar *)sim_imsi->plmn);
+ _ps_modem_processing_sim_complete(modem, sim_init, plmn);
g_free(sim_imsi);
return TRUE;
gboolean _ps_hook_co_network_event(gpointer service)
{
- Server *s = NULL;
- TcorePlugin *p;
+ CoreObject *co_network;
+ tcore_check_return_value(service != NULL, FALSE);
- g_return_val_if_fail(service != NULL, FALSE);
- p = _ps_service_ref_plugin(service);
- s = tcore_plugin_ref_server(p);
+ dbg("Hook for network event");
+ co_network = _ps_service_ref_co_network(service);
- tcore_server_add_notification_hook(s, TNOTI_NETWORK_REGISTRATION_STATUS, __on_hook_net_register, service);
- tcore_server_add_notification_hook(s, TNOTI_NETWORK_CHANGE, __on_hook_net_change, service);
+ tcore_plugin_add_notification_hook(tcore_object_ref_plugin(co_network),
+ TCORE_NOTIFICATION_NETWORK_REGISTRATION_STATUS,
+ __on_hook_net_register, service);
return TRUE;
}
{
CoreObject *co_network = NULL;
gboolean ps_attached = FALSE;
+ gboolean roam ;
- enum telephony_network_service_domain_status ps_status;
- enum telephony_network_access_technology act;
+ TelNetworkRegStatus ps_status;
+ TelNetworkAct act;
- g_return_val_if_fail(service != NULL, FALSE);
+ tcore_check_return_value(service != NULL, FALSE);
co_network = _ps_service_ref_co_network(service);
- tcore_network_get_service_status(co_network, TCORE_NETWORK_SERVICE_DOMAIN_TYPE_PACKET, &ps_status);
+ tcore_network_get_ps_reg_status(co_network, &ps_status);
tcore_network_get_access_technology(co_network, &act);
+ tcore_network_get_roam_state(co_network, &roam);
- if (ps_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL)
+ if (ps_status == TEL_NETWORK_REG_STATUS_REGISTERED)
ps_attached = TRUE;
- _ps_service_set_roaming(service, tcore_network_get_roaming_state(co_network));
+ _ps_service_set_roaming(service, roam );
_ps_service_set_ps_attached(service, ps_attached);
_ps_service_set_access_technology(service, act);
gboolean _ps_hook_co_ps_event(gpointer service)
{
- Server *s = NULL;
- TcorePlugin *p;
- g_return_val_if_fail(service != NULL, FALSE);
+ CoreObject *co_ps;
+ tcore_check_return_value(service != NULL, FALSE);
+
+ co_ps = _ps_service_ref_co_ps(service);
- p = _ps_service_ref_plugin(service);
- s = tcore_plugin_ref_server(p);
+ tcore_plugin_add_notification_hook(tcore_object_ref_plugin(co_ps),
+ TCORE_NOTIFICATION_PS_CALL_STATUS,
+ __on_hook_call_status, service);
- tcore_server_add_notification_hook(s, TNOTI_PS_CALL_STATUS, __on_hook_call_status, service);
- tcore_server_add_notification_hook(s, TNOTI_PS_CURRENT_SESSION_DATA_COUNTER, __on_hook_session_data_counter, service);
- tcore_server_add_notification_hook(s, TNOTI_PS_PDP_IPCONFIGURATION, __on_hook_ipconfiguration, service);
+ tcore_plugin_add_notification_hook(tcore_object_ref_plugin(co_ps),
+ TCORE_NOTIFICATION_PS_IPCONFIG,
+ __on_hook_ipconfiguration, service);
return TRUE;
}
gboolean _ps_free_co_ps_event(gpointer service)
{
- Server *s = NULL;
- TcorePlugin *p;
- g_return_val_if_fail(service != NULL, FALSE);
+ CoreObject *co_ps;
+ tcore_check_return_value(service != NULL, FALSE);
- p = _ps_service_ref_plugin(service);
- s = tcore_plugin_ref_server(p);
+ co_ps = _ps_service_ref_co_ps(service);
- tcore_server_remove_notification_hook(s, __on_hook_call_status);
- tcore_server_remove_notification_hook(s, __on_hook_session_data_counter);
- tcore_server_remove_notification_hook(s, __on_hook_ipconfiguration);
+ tcore_plugin_remove_notification_hook(tcore_object_ref_plugin(co_ps),
+ TCORE_NOTIFICATION_PS_CALL_STATUS,
+ __on_hook_call_status);
+
+ tcore_plugin_remove_notification_hook(tcore_object_ref_plugin(co_ps),
+ TCORE_NOTIFICATION_PS_IPCONFIG,
+ __on_hook_ipconfiguration);
return TRUE;
}
gboolean _ps_free_co_network_event(gpointer service)
{
- Server *s = NULL;
- TcorePlugin *p;
- g_return_val_if_fail(service != NULL, FALSE);
+ CoreObject *co_network;
+ tcore_check_return_value(service != NULL, FALSE);
- p = _ps_service_ref_plugin(service);
- s = tcore_plugin_ref_server(p);
+ co_network = _ps_service_ref_co_network(service);
- tcore_server_remove_notification_hook(s, __on_hook_net_register);
- tcore_server_remove_notification_hook(s, __on_hook_net_change);
+ tcore_plugin_remove_notification_hook(tcore_object_ref_plugin(co_network),
+ TCORE_NOTIFICATION_NETWORK_REGISTRATION_STATUS,
+ __on_hook_net_register);
return TRUE;
}
gboolean _ps_update_cellular_state_key(gpointer service)
{
Server *s = NULL;
- gpointer handle = NULL;
- static Storage *strg;
- int cur_cell_state = 0;
- int stored_cell_state = 0;
+ TcoreStorage *strg;
+ TcorePsState cur_cell_state;
+ gint stored_cell_state = 0;
- s = tcore_plugin_ref_server( (TcorePlugin *)_ps_service_ref_plugin(service) );
+ s = tcore_plugin_ref_server((TcorePlugin *)_ps_service_ref_plugin(service));
strg = tcore_server_find_storage(s, "vconf");
- handle = tcore_storage_create_handle(strg, "vconf");
- if (!handle){
- err("fail to create vconf handle");
- return FALSE;
- }
cur_cell_state = _ps_service_check_cellular_state(service);
- stored_cell_state = tcore_storage_get_int(strg,STORAGE_KEY_CELLULAR_STATE);
+ stored_cell_state = tcore_storage_get_int(strg, STORAGE_KEY_CELLULAR_STATE);
+
dbg("cellular state, current (%d), cur_cell_state (%d)", stored_cell_state, cur_cell_state);
- if(stored_cell_state != cur_cell_state)
- tcore_storage_set_int(strg,STORAGE_KEY_CELLULAR_STATE, cur_cell_state);
+
+ if (stored_cell_state != (gint)cur_cell_state)
+ tcore_storage_set_int(strg, STORAGE_KEY_CELLULAR_STATE, cur_cell_state);
return TRUE;
}