GUAC-236: Allocate and pass display to all instruction handlers.
This commit is contained in:
parent
f286bd92c7
commit
4634ce391a
@ -25,8 +25,19 @@
|
||||
|
||||
#include <guacamole/timestamp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp) {
|
||||
/* STUB */
|
||||
return 0;
|
||||
}
|
||||
|
||||
guacenc_display* guacenc_display_alloc() {
|
||||
return (guacenc_display*) calloc(1, sizeof(guacenc_display));
|
||||
}
|
||||
|
||||
int guacenc_display_free(guacenc_display* display) {
|
||||
free(display);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -101,5 +101,28 @@ typedef struct guacenc_display {
|
||||
*/
|
||||
int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp);
|
||||
|
||||
/**
|
||||
* Allocates a new Guacamole video encoder display. This display serves as the
|
||||
* representation of encoding state, as well as the state of the Guacamole
|
||||
* display as instructions are read and handled.
|
||||
*
|
||||
* @return
|
||||
* The newly-allocated Guacamole video encoder display, or NULL if the
|
||||
* display could not be allocated.
|
||||
*/
|
||||
guacenc_display* guacenc_display_alloc();
|
||||
|
||||
/**
|
||||
* Frees all memory associated with the given Guacamole video encoder display,
|
||||
* and finishes any underlying encoding process.
|
||||
*
|
||||
* @param display
|
||||
* The Guacamole video encoder display to free.
|
||||
*
|
||||
* @return
|
||||
* Zero if the encoding process completed successfully, non-zero otherwise.
|
||||
*/
|
||||
int guacenc_display_free(guacenc_display* display);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "instructions.h"
|
||||
#include "log.h"
|
||||
|
||||
@ -40,6 +41,9 @@
|
||||
* Reads and handles all Guacamole instructions from the given guac_socket
|
||||
* until end-of-stream is reached.
|
||||
*
|
||||
* @param display
|
||||
* The current internal display of the Guacamole video encoder.
|
||||
*
|
||||
* @param path
|
||||
* The name of the file being parsed (for logging purposes). This file
|
||||
* must already be open and available through the given socket.
|
||||
@ -51,7 +55,8 @@
|
||||
* Zero on success, non-zero if parsing of Guacamole protocol data through
|
||||
* the given socket fails.
|
||||
*/
|
||||
static int guacenc_read_instructions(const char* path, guac_socket* socket) {
|
||||
static int guacenc_read_instructions(guacenc_display* display,
|
||||
const char* path, guac_socket* socket) {
|
||||
|
||||
/* Obtain Guacamole protocol parser */
|
||||
guac_parser* parser = guac_parser_alloc();
|
||||
@ -60,7 +65,8 @@ static int guacenc_read_instructions(const char* path, guac_socket* socket) {
|
||||
|
||||
/* Continuously read and handle all instructions */
|
||||
while (!guac_parser_read(parser, socket, -1)) {
|
||||
guacenc_handle_instruction(parser->opcode, parser->argc, parser->argv);
|
||||
guacenc_handle_instruction(display, parser->opcode,
|
||||
parser->argc, parser->argv);
|
||||
}
|
||||
|
||||
/* Fail on read/parse error */
|
||||
@ -79,10 +85,16 @@ static int guacenc_read_instructions(const char* path, guac_socket* socket) {
|
||||
|
||||
int guacenc_encode(const char* path) {
|
||||
|
||||
/* Allocate display for encoding process */
|
||||
guacenc_display* display = guacenc_display_alloc();
|
||||
if (display == NULL)
|
||||
return 1;
|
||||
|
||||
/* Open input file */
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
guacenc_log(GUAC_LOG_ERROR, "%s: %s", path, strerror(errno));
|
||||
guacenc_display_free(display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -92,20 +104,22 @@ int guacenc_encode(const char* path) {
|
||||
guacenc_log(GUAC_LOG_ERROR, "%s: %s", path,
|
||||
guac_status_string(guac_error));
|
||||
close(fd);
|
||||
guacenc_display_free(display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
guacenc_log(GUAC_LOG_INFO, "Encoding \"%s\" ...", path);
|
||||
|
||||
/* Attempt to read all instructions in the file */
|
||||
if (guacenc_read_instructions(path, socket)) {
|
||||
if (guacenc_read_instructions(display, path, socket)) {
|
||||
guac_socket_free(socket);
|
||||
guacenc_display_free(display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Parsing/encoding was successful */
|
||||
/* Close input and finish encoding process */
|
||||
guac_socket_free(socket);
|
||||
return 0;
|
||||
return guacenc_display_free(display);
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
@ -28,7 +29,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_blob(int argc, char** argv) {
|
||||
int guacenc_handle_blob(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 2) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_cfill(int argc, char** argv) {
|
||||
int guacenc_handle_cfill(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 6) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_copy(int argc, char** argv) {
|
||||
int guacenc_handle_copy(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 9) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_cursor(int argc, char** argv) {
|
||||
int guacenc_handle_cursor(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 7) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_dispose(int argc, char** argv) {
|
||||
int guacenc_handle_dispose(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 1) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_end(int argc, char** argv) {
|
||||
int guacenc_handle_end(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 1) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_img(int argc, char** argv) {
|
||||
int guacenc_handle_img(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 6) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_move(int argc, char** argv) {
|
||||
int guacenc_handle_move(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 5) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_rect(int argc, char** argv) {
|
||||
int guacenc_handle_rect(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 5) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_shade(int argc, char** argv) {
|
||||
int guacenc_handle_shade(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 2) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_size(int argc, char** argv) {
|
||||
int guacenc_handle_size(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 3) {
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
@ -63,7 +64,7 @@ static guac_timestamp guacenc_parse_timestamp(const char* str) {
|
||||
|
||||
}
|
||||
|
||||
int guacenc_handle_sync(int argc, char** argv) {
|
||||
int guacenc_handle_sync(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 1) {
|
||||
|
@ -21,13 +21,14 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int guacenc_handle_transfer(int argc, char** argv) {
|
||||
int guacenc_handle_transfer(guacenc_display* display, int argc, char** argv) {
|
||||
|
||||
/* Verify argument count */
|
||||
if (argc < 9) {
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "instructions.h"
|
||||
#include "log.h"
|
||||
|
||||
@ -45,7 +46,7 @@ guacenc_instruction_handler_mapping guacenc_instruction_handler_map[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
int guacenc_handle_instruction(const char* opcode,
|
||||
int guacenc_handle_instruction(guacenc_display* display, const char* opcode,
|
||||
int argc, char** argv) {
|
||||
|
||||
/* Search through mapping for instruction handler having given opcode */
|
||||
@ -58,7 +59,7 @@ int guacenc_handle_instruction(const char* opcode,
|
||||
/* Invoke defined handler */
|
||||
guacenc_instruction_handler* handler = current->handler;
|
||||
if (handler != NULL)
|
||||
return handler(argc, argv);
|
||||
return handler(display, argc, argv);
|
||||
|
||||
/* Log defined but unimplemented instructions */
|
||||
guacenc_log(GUAC_LOG_DEBUG, "\"%s\" not implemented", opcode);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define GUACENC_INSTRUCTIONS_H
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
|
||||
/**
|
||||
* A callback function which, when invoked, handles a particular Guacamole
|
||||
@ -32,6 +33,9 @@
|
||||
* arguments for that instruction are included in the parameters given to the
|
||||
* callback.
|
||||
*
|
||||
* @param display
|
||||
* The current internal display of the Guacamole video encoder.
|
||||
*
|
||||
* @param argc
|
||||
* The number of arguments (excluding opcode) passed to the instruction
|
||||
* being handled by the callback.
|
||||
@ -44,7 +48,8 @@
|
||||
* Zero if the instruction was handled successfully, non-zero if an error
|
||||
* occurs.
|
||||
*/
|
||||
typedef int guacenc_instruction_handler(int argc, char** argv);
|
||||
typedef int guacenc_instruction_handler(guacenc_display* display,
|
||||
int argc, char** argv);
|
||||
|
||||
/**
|
||||
* Mapping of instruction opcode to corresponding handler function.
|
||||
@ -76,6 +81,9 @@ extern guacenc_instruction_handler_mapping guacenc_instruction_handler_map[];
|
||||
* Handles the instruction having the given opcode and arguments, encoding the
|
||||
* result to the in-progress video.
|
||||
*
|
||||
* @param display
|
||||
* The current internal display of the Guacamole video encoder.
|
||||
*
|
||||
* @param opcode
|
||||
* The opcode of the instruction being handled.
|
||||
*
|
||||
@ -91,7 +99,8 @@ extern guacenc_instruction_handler_mapping guacenc_instruction_handler_map[];
|
||||
* Zero if the instruction was handled successfully, non-zero if an error
|
||||
* occurs.
|
||||
*/
|
||||
int guacenc_handle_instruction(const char* opcode, int argc, char** argv);
|
||||
int guacenc_handle_instruction(guacenc_display* display,
|
||||
const char* opcode, int argc, char** argv);
|
||||
|
||||
/**
|
||||
* Handler for the Guacamole "blob" instruction.
|
||||
|
Loading…
Reference in New Issue
Block a user