~phablet-team/ofono/ofono-bug-updates

« back to all changes in this revision

Viewing changes to examples/nettime.c

  • Committer: Marcel Holtmann
  • Date: 2010-10-01 05:44:09 UTC
  • Revision ID: git-v1:88f1b3c85e746f6e5c4e3828d59a92f4a548c0d4
build: Move example plugins to its own directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2010  Nokia Corporation and/or its subsidiary(-ies).
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License version 2 as
 
9
 *  published by the Free Software Foundation.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <string.h>
 
27
#include <glib.h>
 
28
 
 
29
#define OFONO_API_SUBJECT_TO_CHANGE
 
30
#include <ofono/plugin.h>
 
31
#include <ofono/log.h>
 
32
#include <ofono/nettime.h>
 
33
#include <ofono/types.h>
 
34
 
 
35
#include "common.h"
 
36
 
 
37
static int example_nettime_probe(struct ofono_nettime_context *context)
 
38
{
 
39
        ofono_debug("Example Network Time Probe for modem: %p",
 
40
                        context->modem);
 
41
        return 0;
 
42
}
 
43
 
 
44
static void example_nettime_remove(struct ofono_nettime_context *context)
 
45
{
 
46
        ofono_debug("Example Network Time Remove for modem: %p",
 
47
                        context->modem);
 
48
}
 
49
 
 
50
static void example_nettime_info_received(struct ofono_nettime_context *context,
 
51
                                                struct ofono_network_time *info)
 
52
{
 
53
        if (!info)
 
54
                return;
 
55
 
 
56
        ofono_debug("Received a network time notification on modem: %p",
 
57
                        context->modem);
 
58
        ofono_debug("Time: %04d-%02d-%02d %02d:%02d:%02d%c%02d:%02d (DST=%d)",
 
59
                        info->year, info->mon, info->mday, info->hour,
 
60
                        info->min, info->sec, info->utcoff > 0 ? '+' : '-',
 
61
                        info->utcoff / 3600, (info->utcoff % 3600) / 60,
 
62
                        info->dst / 3600);
 
63
}
 
64
 
 
65
static struct ofono_nettime_driver example_driver = {
 
66
        .name           = "Example Network Time",
 
67
        .probe          = example_nettime_probe,
 
68
        .remove         = example_nettime_remove,
 
69
        .info_received  = example_nettime_info_received,
 
70
};
 
71
 
 
72
static int example_nettime_init(void)
 
73
{
 
74
        return ofono_nettime_driver_register(&example_driver);
 
75
}
 
76
 
 
77
static void example_nettime_exit(void)
 
78
{
 
79
        ofono_nettime_driver_unregister(&example_driver);
 
80
}
 
81
 
 
82
OFONO_PLUGIN_DEFINE(example_nettime, "Example Network Time Plugin",
 
83
                        VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
 
84
                        example_nettime_init, example_nettime_exit)