Added initial code for Gtest
[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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <pthread.h>
21
22 #include <systemd/sd-daemon.h>
23 #include <glib-object.h>
24 #include <curl/curl.h>
25
26 #include "download-provider-config.h"
27 #include "download-provider-log.h"
28 #include "download-provider-client-manager.h"
29 #include "download-provider-network.h"
30
31 pthread_t g_client_manager_tid;
32 void *dp_client_manager(void *arg);
33
34 #if (BUILD_GCOV != 0)
35 extern void __gcov_flush(void);
36 #endif
37
38 int main(int argc, char **argv)
39 {
40         GMainLoop *event_loop;
41         TRACE_INFO("download-provider's working is started");
42
43         event_loop = g_main_loop_new(NULL, FALSE);
44         if (!event_loop) {
45                 TRACE_ERROR("Failed to create g main loop handle");
46                 return 0;
47         }
48         // check network status
49         if (dp_network_connection_init() < 0) {
50                 TRACE_ERROR("failed to init network-manager");
51                 return 0;
52         }
53         //Requested By platform team, It should be in main thread.
54         curl_global_init(CURL_GLOBAL_ALL);
55
56 #if (BUILD_GCOV != 0)
57         setenv("GCOV_PREFIX", "/tmp/", 1);
58 #endif
59
60         // create a thread for main thread
61         if (pthread_create(&g_client_manager_tid, NULL, dp_client_manager, (void *)event_loop) != 0) {
62                 TRACE_ERROR("failed to create main thread");
63                 curl_global_cleanup();
64                 return 0;
65         } else {
66                 pthread_detach(g_client_manager_tid);
67                 TRACE_INFO("download main thread is created[%lu]", g_client_manager_tid);
68         }
69
70         TRACE_INFO("g main loop is started");
71         g_main_loop_run(event_loop);
72         curl_global_cleanup();
73         dp_network_connection_destroy();
74         g_main_loop_unref(event_loop);
75
76 #if (BUILD_GCOV != 0)
77         __gcov_flush();
78 #endif
79         TRACE_INFO("download-provider's working is done");
80         return 0;
81 }