2cc85949374ca01e03b11b0c814eb662d5125026
[project/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 #include "opkg_state.h"
20
21
22 static char *state_strings[] =
23 {
24 "None",
25 "Downloading Package",
26 "Installing Package",
27 "Configuring Package",
28 "Upgrading Package",
29 "Removing Package",
30 "Downloading Repository",
31 "Verifying Repository Signature"
32 };
33
34
35
36 opkg_state_changed_callback opkg_cb_state_changed = NULL;
37
38 static opkg_state_t opkg_state = 0;
39 static char *opkg_state_data = NULL;
40
41 void
42 opkg_set_current_state (opkg_state_t state, const char *data)
43 {
44 if (opkg_state_data)
45 free (opkg_state_data);
46 if (data)
47 {
48 opkg_state_data = malloc (strlen (data));
49 strcpy (opkg_state_data, data);
50 }
51 else
52 {
53 opkg_state_data = NULL;
54 }
55
56 opkg_state = state;
57
58 if (opkg_cb_state_changed)
59 {
60 opkg_cb_state_changed (opkg_state, opkg_state_data);
61 }
62
63
64 printf ("opkg state set to %s: %s\n", state_strings[state], data);
65 }
66
67 void
68 opkg_get_current_state (opkg_state_t *state, const char **data)
69 {
70 *state = opkg_state;
71 *data = opkg_state_data;
72 }