Debian Codegraph @

src/data_log.cc

raw
1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3
4 /* libticables2 - link cable library, a part of the TiLP project
5 * Copyright (C) 1999-2005 Romain Lievin
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 This unit allows to trace bytes which are transferred between PC
24 and TI calculator.
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <glib.h>
32 #include <glib/gstdio.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <string.h>
37
38 #include <stdint.h>
39 #include "gettext.h"
40 #include "logging.h"
41 #include "data_log.h"
42
43 #include "log_hex.h"
44 #include "log_dbus.h"
45 #include "log_dusb.h"
46 #include "log_nsp.h"
47
48 int log_start(CableHandle *h)
49 {
50 gchar *tmp;
51 int ret;
52
53 tmp = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_DIR, NULL);
54 if (!g_mkdir_with_parents(tmp, 0750))
55 {
56 ret = log_hex_start();
57 if (!ret)
58 {
59 if (h->model == CABLE_USB)
60 {
61 ret = log_dusb_start();
62 if (!ret)
63 {
64 ret = log_nsp_start();
65 }
66 }
67 else
68 {
69 ret = log_dbus_start();
70 }
71 }
72 }
73 else
74 {
75 ticables_critical("Failed to create folder for logs");
76 ret = 1;
77 }
78 g_free(tmp);
79
80 return ret;
81 }
82
83 int log_N(CableHandle *h, int dir, const uint8_t *data, uint32_t len)
84 {
85 log_hex_N(dir, data, len);
86
87 if (h->model == CABLE_USB)
88 {
89 log_dusb_N(dir, data, len);
90 log_nsp_N(dir, data, len);
91 }
92 else
93 {
94 log_dbus_N(dir, data, len);
95 }
96
97 return 0;
98 }
99
100 int log_stop(CableHandle *h)
101 {
102 log_hex_stop();
103
104 if (h->model == CABLE_USB)
105 {
106 log_dusb_stop();
107 log_nsp_stop();
108 }
109 else
110 {
111 log_dbus_stop();
112 }
113
114 return 0;
115 }