void CionOndemandServer::AddOndemandServiceList(std::string service_name,
std::string appid, std::string display_name) {
- for (auto peer : ondemand_peer_list_) {
+ for (auto const& peer : ondemand_peer_list_) {
if (peer->GetServiceName() == service_name &&
peer->GetAppID() == appid) {
_W("%s is already exist", appid.c_str());
void CionOndemandServer::RemoveOndemandServiceList(std::string service_name,
std::string appid) {
for (auto peer = ondemand_peer_list_.begin();
- peer != ondemand_peer_list_.end(); peer++) {
+ peer != ondemand_peer_list_.end(); peer++) {
if (peer->get()->GetServiceName() == service_name &&
peer->get()->GetAppID() == appid) {
ondemand_peer_list_.erase(peer);
return ret;
}
+static void __cion_service_info_destroy(cion_service_info_s *info)
+{
+ if (info == NULL)
+ return;
+
+ free(info->service_name);
+ free(info->appid);
+ free(info->display_name);
+ free(info);
+}
+
+static cion_service_info_s *__cion_service_info_create(sqlite3_stmt *stmt)
+{
+ cion_service_info_s *info;
+ const char* value;
+ int index = 0;
+
+ info = calloc(1, sizeof(cion_service_info_s));
+ if (info == NULL) {
+ _E("malloc() is failed");
+ return NULL;
+ }
+
+ value = (const char *)sqlite3_column_text(stmt, index++);
+ if (value == NULL) {
+ _E("sqlite3_column_text() is failed. index: %d", index - 1);
+ __cion_service_info_destroy(info);
+ return NULL;
+ }
+
+ info->service_name = strdup(value);
+ if (info->service_name == NULL) {
+ _E("strdup() is failed");
+ __cion_service_info_destroy(info);
+ return NULL;
+ }
+
+ value = (const char *)sqlite3_column_text(stmt, index++);
+ if (value == NULL) {
+ _E("sqlite3_column_text() is failed. index: %d", index - 1);
+ __cion_service_info_destroy(info);
+ return NULL;
+ }
+
+ info->appid = strdup(value);
+ if (info->appid == NULL) {
+ _E("strdup() is failed");
+ __cion_service_info_destroy(info);
+ return NULL;
+ }
+
+ value = (const char *)sqlite3_column_text(stmt, index++);
+ if (value != NULL)
+ info->display_name = strdup(value);
+ else
+ info->display_name = strdup("");
+
+ if (info->display_name == NULL) {
+ _E("strdup() is failed");
+ __cion_service_info_destroy(info);
+ return NULL;
+ }
+
+ return info;
+}
+
int esd_cion_get_enabled_service_list(GList **list)
{
int ret = -1;
sqlite3 *db;
char *query = NULL;
sqlite3_stmt *stmt = NULL;
+ cion_service_info_s *cion_info;
db = esd_cion_db_open();
if (!db) {
if (ret != SQLITE_OK)
goto out;
- while(sqlite3_step(stmt) == SQLITE_ROW) {
- cion_service_info_s *cion_info = malloc(sizeof(cion_service_info_s));
- cion_info->service_name = strdup((char*)sqlite3_column_text(stmt, 0));
- cion_info->appid = strdup((char*)sqlite3_column_text(stmt, 1));
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ cion_info = __cion_service_info_create(stmt);
+ if (cion_info == NULL) {
+ ret = -1;
+ goto out;
+ }
- char *display_name = (char*)sqlite3_column_text(stmt, 2);
- if (display_name)
- cion_info->display_name = strdup(display_name);
- else
- cion_info->display_name = strdup("");
_D("get list : [%s:%s:%s]",
- cion_info->service_name, cion_info->appid, cion_info->display_name);
-
+ cion_info->service_name, cion_info->appid,
+ cion_info->display_name);
*list = g_list_append(*list, cion_info);
}