summaryrefslogtreecommitdiff
path: root/utils/wpseditor/libwps/src/proxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/wpseditor/libwps/src/proxy.c')
-rw-r--r--utils/wpseditor/libwps/src/proxy.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/utils/wpseditor/libwps/src/proxy.c b/utils/wpseditor/libwps/src/proxy.c
new file mode 100644
index 0000000000..3a3b8ce4d9
--- /dev/null
+++ b/utils/wpseditor/libwps/src/proxy.c
@@ -0,0 +1,132 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "dummies.h"
4#include "proxy.h"
5#include "api.h"
6#include "gwps.h"
7#include "gwps-common.h"
8#include <string.h>
9
10struct screen screens[NB_SCREENS];
11struct wps_data wpsdata;
12struct gui_wps gwps;
13struct mp3entry id3;
14struct mp3entry nid3;
15
16extern void test_api(struct proxy_api *api);
17
18bool debug_wps = true;
19int wps_verbose_level = 0;
20int errno_;
21pfdebugf dbgf = 0;
22
23static char pluginbuf[PLUGIN_BUFFER_SIZE];
24
25const char* get_model_name(){
26#ifdef TARGET_MODEL
27 return TARGET_MODEL;
28#else
29 return "unknown";
30#endif
31}
32
33int read_line(int fd, char* buffer, int buffer_size)
34{
35 int count = 0;
36 int num_read = 0;
37
38 errno_ = 0;
39
40 while (count < buffer_size)
41 {
42 unsigned char c;
43
44 if (1 != read(fd, &c, 1))
45 break;
46
47 num_read++;
48
49 if ( c == '\n' )
50 break;
51
52 if ( c == '\r' )
53 continue;
54
55 buffer[count++] = c;
56 }
57
58 buffer[MIN(count, buffer_size - 1)] = 0;
59
60 return errno_ ? -1 : num_read;
61}
62
63void* plugin_get_buffer(size_t *buffer_size)
64{
65 *buffer_size = PLUGIN_BUFFER_SIZE;
66 return pluginbuf;
67}
68
69int checkwps(const char *filename, int verbose){
70 int res;
71 int fd;
72
73 struct wps_data wps;
74 wps_verbose_level = verbose;
75
76 fd = open(filename, O_RDONLY);
77 if (fd < 0) {
78 DEBUGF1("Failed to open %s\n",filename);
79 return 2;
80 }
81 close(fd);
82
83 res = wps_data_load(&wps, &screens[0], filename, true);
84
85 if (!res) {
86 DEBUGF1("WPS parsing failure\n");
87 return 3;
88 }
89
90 DEBUGF1("WPS parsed OK\n");
91 return 0;
92}
93
94int wps_init(const char* filename,struct proxy_api *api, bool isfile){
95 int res;
96 if (!api)
97 return 4;
98 dummies_init();
99 test_api(api);
100 set_api(api);
101 wps_data_init(&wpsdata);
102 wps_verbose_level = api->verbose;
103 res = wps_data_load(&wpsdata, &screens[0], filename, isfile);
104 if (!res)
105 {
106 DEBUGF1("ERR: WPS parsing failure\n");
107 return 3;
108 }
109 DEBUGF1("WPS parsed OK\n");
110 DEBUGF1("\n-------------------------------------------------\n");
111 wps_state.paused = true;
112 gwps.data = &wpsdata;
113 gwps.display = &screens[0];
114 gwps.state = &wps_state;
115 gwps.state->id3 = &id3;
116 gwps.state->nid3 = &nid3;
117 gui_wps[0] = gwps;
118 return res;
119}
120
121int wps_display(){
122 DEBUGF3("wps_display(): begin\n");
123 int res = gui_wps_display();
124 DEBUGF3("\nWPS %sdisplayed\n", (res ? "" : "not "));
125 return res;
126}
127int wps_refresh(){
128 DEBUGF3("-----------------<wps_refresh(): begin>-----------------\n");
129 int res = gui_wps_refresh(&gwps, 0, WPS_REFRESH_ALL);
130 DEBUGF3("\nWPS %srefreshed\n", (res ? "" : "not "));
131 return res;
132}