Use the same type to compare values
[platform/framework/web/download-provider.git] / provider / download-provider-main.c
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define _GNU_SOURCE
18 #include <pthread.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include <systemd/sd-daemon.h>
24 #include <glib-object.h>
25 #include <curl/curl.h>
26
27 #include "download-provider-config.h"
28 #include "download-provider-log.h"
29 #include "download-provider-client-manager.h"
30 #include "download-provider-network.h"
31
32 pthread_t g_client_manager_tid;
33 void *dp_client_manager(void *arg);
34
35 #if (BUILD_GCOV != 0)
36 extern void __gcov_flush(void);
37 #endif
38
39 int main(int argc, char **argv)
40 {
41         GMainLoop *event_loop;
42         TRACE_INFO("download-provider's working is started");
43
44         event_loop = g_main_loop_new(NULL, FALSE);
45         if (!event_loop) {
46                 TRACE_ERROR("Failed to create g main loop handle");
47                 return 0;
48         }
49         // check network status
50         if (dp_network_connection_init() < 0) {
51                 TRACE_ERROR("failed to init network-manager");
52                 return 0;
53         }
54         //Requested By platform team, It should be in main thread.
55         curl_global_init(CURL_GLOBAL_ALL);
56
57 #if (BUILD_GCOV != 0)
58         setenv("GCOV_PREFIX", "/tmp/", 1);
59 #endif
60
61         // create a thread for main thread
62         if (pthread_create(&g_client_manager_tid, NULL, dp_client_manager, (void *)event_loop) != 0) {
63                 TRACE_ERROR("failed to create main thread");
64                 curl_global_cleanup();
65                 return 0;
66         } else {
67                 pthread_setname_np(g_client_manager_tid, "dp-client-mgr");
68                 pthread_detach(g_client_manager_tid);
69                 TRACE_INFO("download main thread is created[%lu]", g_client_manager_tid);
70         }
71
72         TRACE_INFO("g main loop is started");
73         g_main_loop_run(event_loop);
74         curl_global_cleanup();
75         dp_network_connection_destroy();
76         g_main_loop_unref(event_loop);
77
78 #if (BUILD_GCOV != 0)
79         __gcov_flush();
80 #endif
81         TRACE_INFO("download-provider's working is done");
82         return 0;
83 }