Skip to content

Commit f80f923

Browse files
committed
Create plat.c that implements platform specific functions
1 parent abc5724 commit f80f923

File tree

3 files changed

+102
-53
lines changed

3 files changed

+102
-53
lines changed

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(FUDGE_CORE
1616
object.c
1717
fuji_lua.c
1818
lua_runtime.c
19+
plat.c
1920
)
2021

2122
add_library(libfudge STATIC ${FUDGE_CORE})

lib/cli.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,6 @@
1111
#include <unistd.h>
1212
#include <sys/wait.h>
1313

14-
void plat_dbg(char *fmt, ...) {
15-
printf("DBG: ");
16-
va_list args;
17-
va_start(args, fmt);
18-
vprintf(fmt, args);
19-
va_end(args);
20-
}
21-
char *app_get_client_name(void) {
22-
return strdup("app");
23-
}
24-
void app_print(char *fmt, ...) {
25-
printf("APP: ");
26-
va_list args;
27-
va_start(args, fmt);
28-
vprintf(fmt, args);
29-
va_end(args);
30-
}
31-
void app_send_cam_name(const char *name) {}
32-
int app_get_os_network_handle(struct NetworkHandle *h) {
33-
return 0;
34-
}
35-
int app_get_wifi_network_handle(struct NetworkHandle *h) {
36-
return -1;
37-
}
38-
int app_bind_socket_to_network(int fd, struct NetworkHandle *h) {
39-
return 0;
40-
}
41-
void tester_log(char *fmt, ...) {
42-
printf("LOG: ");
43-
va_list args;
44-
va_start(args, fmt);
45-
vprintf(fmt, args);
46-
va_end(args);
47-
}
48-
void tester_fail(char *fmt, ...) {
49-
printf("FAIL: ");
50-
va_list args;
51-
va_start(args, fmt);
52-
vprintf(fmt, args);
53-
va_end(args);
54-
}
55-
int fuji_discovery_check_cancel(void *arg) {
56-
return 0;
57-
}
58-
void fuji_discovery_update_progress(void *arg, enum DiscoverUpdateMessages progress) {}
59-
void app_increment_progress_bar(int read) {}
60-
void app_report_download_speed(long time, size_t size) {}
61-
void app_downloaded_file(const struct PtpObjectInfo *oi, const char *path) {}
62-
void app_get_file_path(char buffer[256], const char *filename) {abort();}
63-
void app_downloading_file(const struct PtpObjectInfo *oi) {}
64-
int app_check_thread_cancel(void) {return 0;}
65-
void app_get_tether_file_path(char buffer[256]) {abort();}
66-
6714
int fuji_test_discovery(struct PtpRuntime *r);
6815

6916
void nothing(int x) {}

lib/plat.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Default weak functions that implement platform specific functions
2+
#include <stdio.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
#include <stdarg.h>
7+
#include <libpict.h>
8+
#include <fuji.h>
9+
#include <app.h>
10+
11+
__attribute__((weak))
12+
void plat_dbg(char *fmt, ...) {
13+
printf("DBG: ");
14+
va_list args;
15+
va_start(args, fmt);
16+
vprintf(fmt, args);
17+
va_end(args);
18+
}
19+
20+
__attribute__((weak))
21+
char *app_get_client_name(void) {
22+
return strdup("app");
23+
}
24+
25+
__attribute__((weak))
26+
void app_print(char *fmt, ...) {
27+
printf("APP: ");
28+
va_list args;
29+
va_start(args, fmt);
30+
vprintf(fmt, args);
31+
va_end(args);
32+
}
33+
34+
__attribute__((weak))
35+
void app_send_cam_name(const char *name) {
36+
printf("Got camera name '%s'\n", name);
37+
}
38+
39+
__attribute__((weak))
40+
int app_get_os_network_handle(struct NetworkHandle *h) {
41+
return 0;
42+
}
43+
44+
__attribute__((weak))
45+
int app_get_wifi_network_handle(struct NetworkHandle *h) {
46+
return -1;
47+
}
48+
49+
__attribute__((weak))
50+
int app_bind_socket_to_network(int fd, struct NetworkHandle *h) {
51+
return 0;
52+
}
53+
54+
__attribute__((weak))
55+
void tester_log(char *fmt, ...) {
56+
printf("LOG: ");
57+
va_list args;
58+
va_start(args, fmt);
59+
vprintf(fmt, args);
60+
va_end(args);
61+
}
62+
63+
__attribute__((weak))
64+
void tester_fail(char *fmt, ...) {
65+
printf("FAIL: ");
66+
va_list args;
67+
va_start(args, fmt);
68+
vprintf(fmt, args);
69+
va_end(args);
70+
}
71+
72+
__attribute__((weak))
73+
int fuji_discovery_check_cancel(void *arg) {
74+
return 0;
75+
}
76+
77+
__attribute__((weak))
78+
void fuji_discovery_update_progress(void *arg, enum DiscoverUpdateMessages progress) {
79+
printf("Discovery progress '%d'\n", progress);
80+
}
81+
__attribute__((weak))
82+
void app_increment_progress_bar(int read) {
83+
printf("%d\n", read);
84+
}
85+
__attribute__((weak))
86+
void app_report_download_speed(long time, size_t size) {
87+
int mbps = (int)((size * 8) / (time));
88+
printf("Download speed: %dmbps\n", mbps);
89+
}
90+
__attribute__((weak))
91+
void app_downloaded_file(const struct PtpObjectInfo *oi, const char *path) {
92+
printf("File has been downloaded to '%s'\n", path);
93+
}
94+
__attribute__((weak))
95+
void app_get_file_path(char buffer[256], const char *filename) {abort();}
96+
__attribute__((weak))
97+
void app_downloading_file(const struct PtpObjectInfo *oi) {}
98+
__attribute__((weak))
99+
int app_check_thread_cancel(void) {return 0;}
100+
__attribute__((weak))
101+
void app_get_tether_file_path(char buffer[256]) {abort();}

0 commit comments

Comments
 (0)