/
camera.c
193 lines (164 loc) · 5.22 KB
1
2
3
4
/**
* @file camera.c
* Camera module -- this handles the camera LED-indicator for MCE
* <p>
5
* Copyright © 2007-2011 Nokia Corporation and/or its subsidiary(-ies).
6
* Copyright (C) 2013-2019 Jolla Ltd.
7
8
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
9
10
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
*
* mce 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.
*
* mce 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 mce. If not, see <http://www.gnu.org/licenses/>.
*/
#include "camera.h"
27
#include "../mce-log.h"
28
29
#include "../mce-io.h"
#include "../mce-conf.h"
30
#include "../tklock.h"
31
32
33
34
#include <string.h>
#include <gmodule.h>
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
/** Unlock the tklock if the camera is popped out? */
static gboolean popout_unlock = DEFAULT_CAMERA_POPOUT_UNLOCK;
/** Module name */
#define MODULE_NAME "camera"
/** Functionality provided by this module */
static const gchar *const provides[] = { MODULE_NAME, NULL };
/** Functionality that this module depends on */
static const gchar *const depends[] = { "tklock", NULL };
/** Functionality that this module recommends */
static const gchar *const recommends[] = { "led", NULL };
/** Module information */
G_MODULE_EXPORT module_info_struct module_info = {
/** Name of the module */
.name = MODULE_NAME,
/** Module dependencies */
.depends = depends,
/** Module recommends */
.recommends = recommends,
/** Module provides */
.provides = provides,
/** Module priority */
.priority = 250
};
/** ID for the camera active state I/O monitor */
66
static mce_io_mon_t *camera_active_state_iomon_id = NULL;
67
68
/** ID for the camera pop-out state I/O monitor */
69
static mce_io_mon_t *camera_popout_state_iomon_id = NULL;
70
71
72
73
74
/** Camera pop-out state I/O monitor deleted callback
*
* @param iomon io monitor that is about to get deleted
*/
75
static void camera_popout_state_iomon_delete_cb(mce_io_mon_t *iomon)
76
77
78
79
80
81
82
83
84
{
if( iomon == camera_popout_state_iomon_id )
camera_popout_state_iomon_id = 0;
}
/** Camera active state I/O monitor deleted callback
*
* @param iomon io monitor that is about to get deleted
*/
85
static void camera_active_state_iomon_delete_cb(mce_io_mon_t *iomon)
86
87
88
89
90
{
if( iomon == camera_active_state_iomon_id )
camera_active_state_iomon_id = 0;
}
91
92
93
94
95
/**
* I/O monitor callback for the camera active state
*
* @param data The new data
* @param bytes_read Unused
96
* @return Always returns FALSE to return remaining chunks (if any)
97
*/
98
static gboolean camera_active_state_iomon_input_cb(mce_io_mon_t *iomon, gpointer data, gsize bytes_read)
99
{
100
(void)iomon;
101
102
103
(void)bytes_read;
if (!strncmp(data, MCE_CAMERA_ACTIVE, strlen(MCE_CAMERA_ACTIVE))) {
104
105
datapipe_exec_full(&led_pattern_activate_pipe,
MCE_LED_PATTERN_CAMERA);
106
} else {
107
108
datapipe_exec_full(&led_pattern_deactivate_pipe,
MCE_LED_PATTERN_CAMERA);
109
}
110
111
return FALSE;
112
113
114
115
116
117
118
}
/**
* I/O monitor callback for the camera pop-out state
*
* @param data The new data
* @param bytes_read Unused
119
* @return Always returns FALSE to return remaining chunks (if any)
120
*/
121
static gboolean camera_popout_state_iomon_input_cb(mce_io_mon_t *iomon, gpointer data, gsize bytes_read)
122
{
123
(void)iomon;
124
125
126
(void)bytes_read;
/* Generate activity */
127
mce_datapipe_generate_activity();
128
129
130
131
132
133
134
135
if (popout_unlock == FALSE)
goto EXIT;
/* Unlock tklock if camera is popped out */
if (!strncmp(data, MCE_CAMERA_POPPED_OUT,
strlen(MCE_CAMERA_POPPED_OUT))) {
/* Request delayed unlock of touchscreen/keypad lock */
136
mce_datapipe_request_tklock(TKLOCK_REQUEST_OFF_DELAYED);
137
138
139
}
EXIT:
140
return FALSE;
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
}
/**
* Init function for the camera module
*
* @todo XXX status needs to be set on error!
*
* @param module Unused
* @return NULL on success, a string with an error message on failure
*/
G_MODULE_EXPORT const gchar *g_module_check_init(GModule *module);
const gchar *g_module_check_init(GModule *module)
{
(void)module;
/* Get configuration options */
popout_unlock = mce_conf_get_bool(MCE_CONF_TKLOCK_GROUP,
MCE_CONF_CAMERA_POPOUT_UNLOCK,
159
DEFAULT_CAMERA_POPOUT_UNLOCK);
160
161
162
/* Register I/O monitors */
camera_active_state_iomon_id =
163
164
165
166
167
mce_io_mon_register_string(-1, CAMERA_ACTIVE_STATE_PATH,
MCE_IO_ERROR_POLICY_IGNORE,
TRUE,
camera_active_state_iomon_input_cb,
camera_active_state_iomon_delete_cb);
168
169
camera_popout_state_iomon_id =
170
171
172
173
174
mce_io_mon_register_string(-1, CAMERA_POPOUT_STATE_PATH,
MCE_IO_ERROR_POLICY_IGNORE,
TRUE,
camera_popout_state_iomon_input_cb,
camera_popout_state_iomon_delete_cb);
175
176
177
178
179
180
181
182
183
184
185
186
187
188
return NULL;
}
/**
* Exit function for the camera module
*
* @param module Unused
*/
G_MODULE_EXPORT void g_module_unload(GModule *module);
void g_module_unload(GModule *module)
{
(void)module;
/* Unregister I/O monitors */
189
190
mce_io_mon_unregister(camera_popout_state_iomon_id);
mce_io_mon_unregister(camera_active_state_iomon_id);
191
192
193
return;
}