summaryrefslogtreecommitdiff
path: root/src/mcd-controller.c
blob: 1286cfdae991733da961cfb03054cd2d5956d90d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 8 -*- */
/*
 * This file is part of mission-control
 *
 * Copyright (C) 2007 Nokia Corporation. 
 *
 * Contact: Naba Kumar  <naba.kumar@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**
 * SECTION:mcd-controller
 * @title: McdController
 * @short_description: Server controller class
 * @see_also: 
 * @stability: Unstable
 * @include: mcd-controller.h
 * 
 * This class implements the logic to control mission-control based on all
 * external device events and states. It also controls mission-control
 * life-cycle based on such events.
 */

#include "mcd-controller.h"

/* Milliseconds to wait for Connectivity coming back up before exiting MC */
#define EXIT_COUNTDOWN_TIME 5000

#define MCD_CONTROLLER_PRIV(controller) \
    (G_TYPE_INSTANCE_GET_PRIVATE ((controller), \
				  MCD_TYPE_CONTROLLER, \
				  McdControllerPrivate))

G_DEFINE_TYPE (McdController, mcd_controller, MCD_TYPE_OPERATION);

/* Private */
typedef struct _McdControllerPrivate
{
    /* Current pending sleep timer */
    gint shutdown_timeout_id;

    gboolean is_disposed;
} McdControllerPrivate;

static void
mcd_controller_class_init (McdControllerClass * klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    g_type_class_add_private (object_class, sizeof (McdControllerPrivate));
}

static void
mcd_controller_init (McdController * obj)
{
}

/* Public */

McdController *
mcd_controller_new ()
{
    McdController *obj;
    obj = MCD_CONTROLLER (g_object_new (MCD_TYPE_CONTROLLER, NULL));
    return obj;
}

static gboolean
_mcd_controller_exit_by_timeout (gpointer data)
{
    McdController *controller;
    McdControllerPrivate *priv;
    
    controller = MCD_CONTROLLER (data);
    priv = MCD_CONTROLLER_PRIV (controller);
    
    priv->shutdown_timeout_id = 0;
    
    /* Notify sucide */
    mcd_mission_abort (MCD_MISSION (controller));
    
    return FALSE;
}

void
mcd_controller_shutdown (McdController *controller, const gchar *reason)
{
    g_return_if_fail (MCD_IS_CONTROLLER (controller));
    
    McdControllerPrivate *priv = MCD_CONTROLLER_PRIV (controller);
    
    if(!priv->shutdown_timeout_id)	
    {
	g_debug ("MC will bail out because of \"%s\" out exit after %i",
		 reason ? reason : "No reason specified",
		 EXIT_COUNTDOWN_TIME);
	
	priv->shutdown_timeout_id = g_timeout_add (EXIT_COUNTDOWN_TIME,
						   _mcd_controller_exit_by_timeout,
						   controller);
    }
    else
    {
	g_debug ("Already shutting down. This one has the reason %s",
		 reason ? reason:"No reason specified");
    }
    mcd_debug_print_tree (controller);
}

void
mcd_controller_cancel_shutdown (McdController *controller)
{
    g_return_if_fail (MCD_IS_CONTROLLER (controller));
    
    McdControllerPrivate *priv = MCD_CONTROLLER_PRIV (controller);
    
    if (priv->shutdown_timeout_id)
    {
	g_debug ("Cancelling exit timeout");
	g_source_remove (priv->shutdown_timeout_id);
	priv->shutdown_timeout_id = 0;
    }
}