BRL-CAD
fbserv.h
Go to the documentation of this file.
1 /* F B S E R V . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup libdm */
21 /** @{ */
22 /** @file fbserv.h
23  *
24  * @brief
25  * This header holds generic routines and data structures used for TCP based
26  * communication between a framebuffer and a remote process. Variations on
27  * this logic, based originally on the stand-alone fbserv program, are at the
28  * core of MGED and Archer's ability to display incoming image data from a
29  * separate rt process.
30  *
31  * Asynchronous interprocess communication and event monitoring is (as of 2021)
32  * still very much platform and toolkit specific. Hence, these data structures
33  * contain some void pointers which are used by individual applications to
34  * connect their own specific methods (for example, Tcl_Channel) to handle this
35  * problem. Improving this to be more generic and less dependent on specific
36  * toolkits and/or platform mechanisms would be a laudable goal, if practical.
37  *
38  */
39 
40 #ifndef DM_FBSERV_H
41 #define DM_FBSERV_H
42 
43 #include "common.h"
44 #include "pkg.h"
45 #include "dm/defines.h"
46 
47 __BEGIN_DECLS
48 
49 /* Framebuffer server object */
50 
51 #define NET_LONG_LEN 4 /**< @brief # bytes to network long */
52 #define MAX_CLIENTS 32
53 #define MAX_PORT_TRIES 100
54 #define FBS_CALLBACK_NULL (void (*)(void))NULL
55 #define FBSERV_OBJ_NULL (struct fbserv_obj *)NULL
56 
57 struct fbserv_obj;
58 
60  int fbsl_fd; /**< @brief socket to listen for connections */
61  void *fbsl_chan; /**< @brief platform/toolkit specific channel */
62  int fbsl_port; /**< @brief port number to listen on */
63  int fbsl_listen; /**< @brief !0 means listen for connections */
64  struct fbserv_obj *fbsl_fbsp; /**< @brief points to its fbserv object */
65 };
66 
67 
68 struct fbserv_client {
69  int fbsc_fd; /**< @brief socket to send data down */
70  void *fbsc_chan; /**< @brief platform/toolkit specific channel */
71  void *fbsc_handler; /**< @brief platform/toolkit specific handler */
72  struct pkg_conn *fbsc_pkg;
73  struct fbserv_obj *fbsc_fbsp; /**< @brief points to its fbserv object */
74 };
75 
76 
77 struct fbserv_obj {
78  struct fb *fbs_fbp; /**< @brief framebuffer pointer */
79  void *fbs_interp; /**< @brief interpreter */
80  struct fbserv_listener fbs_listener; /**< @brief data for listening */
81  struct fbserv_client fbs_clients[MAX_CLIENTS]; /**< @brief connected clients */
82 
83  int (*fbs_is_listening)(struct fbserv_obj *); /**< @brief return 1 if listening, else 0 */
84  int (*fbs_listen_on_port)(struct fbserv_obj *, int); /**< @brief return 1 on success, 0 on failure */
85  void (*fbs_open_server_handler)(struct fbserv_obj *); /**< @brief platform/toolkit method to open listener handler */
86  void (*fbs_close_server_handler)(struct fbserv_obj *); /**< @brief platform/toolkit method to close handler listener */
87  void (*fbs_open_client_handler)(struct fbserv_obj *, int, void *); /**< @brief platform/toolkit specific client handler setup (called by fbs_new_client) */
88  void (*fbs_close_client_handler)(struct fbserv_obj *, int); /**< @brief platform/toolkit method to close handler for client at index client_id */
89 
90  void (*fbs_callback)(void *); /**< @brief callback function */
92  struct bu_vls *msgs;
93  int fbs_mode; /**< @brief 0-off, 1-underlay, 2-interlay, 3-overlay */
94 };
95 
96 DM_EXPORT extern int fbs_open(struct fbserv_obj *fbsp, int port);
97 DM_EXPORT extern int fbs_close(struct fbserv_obj *fbsp);
98 DM_EXPORT extern struct pkg_switch *fbs_pkg_switch(void);
99 DM_EXPORT extern void fbs_setup_socket(int fd);
100 DM_EXPORT extern int fbs_new_client(struct fbserv_obj *fbsp, struct pkg_conn *pcp, void *data);
101 DM_EXPORT extern void fbs_existing_client_handler(void *clientData, int mask);
102 
103 
104 __END_DECLS
105 
106 #endif /* DM_FBSERV_H */
107 /** @} */
108 /*
109  * Local Variables:
110  * mode: C
111  * tab-width: 8
112  * indent-tabs-mode: t
113  * c-file-style: "stroustrup"
114  * End:
115  * ex: shiftwidth=4 tabstop=8
116  */
Header file for the BRL-CAD common definitions.
#define MAX_CLIENTS
Definition: fbserv.h:52
int fbs_new_client(struct fbserv_obj *fbsp, struct pkg_conn *pcp, void *data)
int fbs_close(struct fbserv_obj *fbsp)
void fbs_setup_socket(int fd)
void fbs_existing_client_handler(void *clientData, int mask)
struct pkg_switch * fbs_pkg_switch(void)
int fbs_open(struct fbserv_obj *fbsp, int port)
Definition: vls.h:53
Definition: defines.h:70
struct fbserv_obj * fbsc_fbsp
points to its fbserv object
Definition: fbserv.h:73
struct pkg_conn * fbsc_pkg
Definition: fbserv.h:72
void * fbsc_chan
platform/toolkit specific channel
Definition: fbserv.h:70
int fbsc_fd
socket to send data down
Definition: fbserv.h:69
void * fbsc_handler
platform/toolkit specific handler
Definition: fbserv.h:71
struct fbserv_obj * fbsl_fbsp
points to its fbserv object
Definition: fbserv.h:64
int fbsl_port
port number to listen on
Definition: fbserv.h:62
void * fbsl_chan
platform/toolkit specific channel
Definition: fbserv.h:61
int fbsl_fd
socket to listen for connections
Definition: fbserv.h:60
int fbsl_listen
!0 means listen for connections
Definition: fbserv.h:63
void(* fbs_open_server_handler)(struct fbserv_obj *)
platform/toolkit method to open listener handler
Definition: fbserv.h:85
struct fbserv_client fbs_clients[MAX_CLIENTS]
connected clients
Definition: fbserv.h:81
void(* fbs_callback)(void *)
callback function
Definition: fbserv.h:90
int(* fbs_listen_on_port)(struct fbserv_obj *, int)
return 1 on success, 0 on failure
Definition: fbserv.h:84
struct bu_vls * msgs
Definition: fbserv.h:92
void(* fbs_close_server_handler)(struct fbserv_obj *)
platform/toolkit method to close handler listener
Definition: fbserv.h:86
void * fbs_clientData
Definition: fbserv.h:91
struct fbserv_listener fbs_listener
data for listening
Definition: fbserv.h:80
int fbs_mode
0-off, 1-underlay, 2-interlay, 3-overlay
Definition: fbserv.h:93
void(* fbs_close_client_handler)(struct fbserv_obj *, int)
platform/toolkit method to close handler for client at index client_id
Definition: fbserv.h:88
struct fb * fbs_fbp
framebuffer pointer
Definition: fbserv.h:78
void * fbs_interp
interpreter
Definition: fbserv.h:79
void(* fbs_open_client_handler)(struct fbserv_obj *, int, void *)
platform/toolkit specific client handler setup (called by fbs_new_client)
Definition: fbserv.h:87
int(* fbs_is_listening)(struct fbserv_obj *)
return 1 if listening, else 0
Definition: fbserv.h:83
Definition: pkg.h:86
Definition: pkg.h:64