Merge pull request #67 from tripzero/trip
[profile/ivi/automotive-message-broker.git] / lib / abstractroutingengine.cpp
1 /*
2   Copyright (C) 2012  Intel Corporation
3
4   This library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Lesser General Public
6   License as published by the Free Software Foundation; either
7   version 2.1 of the License, or (at your option) any later version.
8
9   This library is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this library; if not, write to the Free Software
16   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19
20 #include "abstractroutingengine.h"
21
22
23
24 AbstractRoutingEngine::~AbstractRoutingEngine()
25 {
26 }
27
28 AsyncPropertyReply::AsyncPropertyReply()
29         :AsyncPropertyRequest(), value(nullptr), success(false), timeoutSource(nullptr), timedout(nullptr)
30 {
31         setTimeout();
32 }
33
34 AsyncPropertyReply::AsyncPropertyReply(const AsyncPropertyRequest &request)
35         :AsyncPropertyRequest(request), value(NULL), success(false), timeoutSource(nullptr), timedout(nullptr)
36 {
37         setTimeout();
38 }
39
40 AsyncPropertyReply::AsyncPropertyReply(const AsyncSetPropertyRequest &request)
41         :AsyncPropertyRequest(request), value(request.value), success(false), timeoutSource(nullptr), timedout(nullptr)
42 {
43         setTimeout();
44         if(value)
45                 value->zone = request.zoneFilter;
46 }
47
48 AsyncPropertyReply::~AsyncPropertyReply()
49 {
50         if(timeoutSource)
51         {
52                 g_source_destroy(timeoutSource);
53                 g_source_unref(timeoutSource);
54         }
55 }
56
57 void AsyncPropertyReply::setTimeout()
58 {
59         auto timeoutfunc = [](gpointer userData) {
60                 AsyncPropertyReply* thisReply = static_cast<AsyncPropertyReply*>(userData);
61                 if(thisReply->success == false)
62                 {
63                         thisReply->error = Timeout;
64                         if(thisReply->timedout)
65                                 thisReply->timedout(thisReply);
66                         if(thisReply->completed)
67                                 thisReply->completed(thisReply);
68                 }
69                 return 0;
70         };
71
72         if(timeout)
73         {
74                 timeoutSource = g_timeout_source_new(timeout);
75                 g_source_set_callback(timeoutSource,(GSourceFunc) timeoutfunc, this, nullptr);
76                 g_source_attach(timeoutSource, nullptr);
77         }
78 }