opkg: add internal state framework
[oweals/opkg-lede.git] / opkg_state.c
1 /* opkg_state.c - the opkg package management system
2
3    Thomas Wood <thomas@openedhand.com>
4
5    Copyright (C) 2008 by OpenMoko Inc
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 */
17
18 #include "libopkg.h"
19
20 opkg_state_changed_callback opkg_cb_state;
21
22 static opkg_state_t opkg_state = 0;
23 static char *opkg_state_data = NULL;
24
25 void
26 opkg_set_current_state (opkg_state_t state, const char *data)
27 {
28   if (opkg_state_data)
29     free (opkg_state_data);
30   opkg_state_data = malloc (strlen (data));
31   strcpy (opkg_state_data, data);
32
33   opkg_state = state;
34 }
35
36 void
37 opkg_get_current_state (opkg_state_t *state, const char **data)
38 {
39   *state = opkg_state;
40   *data = opkg_state_data;
41 }