Merge pull request #19 from tripzero/master
[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)
30 {
31         setTimeout();
32 }
33
34 AsyncPropertyReply::AsyncPropertyReply(const AsyncPropertyRequest &request)
35         :AsyncPropertyRequest(request), value(NULL), success(false), timeoutSource(nullptr)
36 {
37         setTimeout();
38 }
39
40 AsyncPropertyReply::AsyncPropertyReply(const AsyncSetPropertyRequest &request)
41         :AsyncPropertyRequest(request), value(request.value), success(false), timeoutSource(nullptr)
42 {
43         setTimeout();
44         if(value)
45                 value->zone = request.zoneFilter;
46 }
47
48 void AsyncPropertyReply::setTimeout()
49 {
50         auto timeoutfunc = [](gpointer userData) {
51                 AsyncPropertyReply* thisReply = static_cast<AsyncPropertyReply*>(userData);
52                 if(thisReply->success == false)
53                 {
54                         thisReply->error = Timeout;
55                         thisReply->completed(thisReply);
56                 }
57                 return 0;
58         };
59
60         if(timeout)
61         {
62                 timeoutSource = g_timeout_source_new(timeout);
63                 g_source_set_callback(timeoutSource,(GSourceFunc) timeoutfunc, this, nullptr);
64                 g_source_attach(timeoutSource, nullptr);
65         }
66 }