Libtrap: Internal development docs  1.16.1
ifc_file.h
Go to the documentation of this file.
1 /**
2  * \file ifc_file.h
3  * \brief TRAP file interfaces
4  * \author Tomas Jansky <janskto1@fit.cvut.cz>
5  * \date 2015
6  */
7 /*
8  * Copyright (C) 2015, 2016 CESNET
9  *
10  * LICENSE TERMS
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in
19  * the documentation and/or other materials provided with the
20  * distribution.
21  * 3. Neither the name of the Company nor the names of its contributors
22  * may be used to endorse or promote products derived from this
23  * software without specific prior written permission.
24  *
25  * ALTERNATIVELY, provided that this notice is retained in full, this
26  * product may be distributed under the terms of the GNU General Public
27  * License (GPL) version 2 or later, in which case the provisions
28  * of the GPL apply INSTEAD OF those given above.
29  *
30  * This software is provided ``as is'', and any express or implied
31  * warranties, including, but not limited to, the implied warranties of
32  * merchantability and fitness for a particular purpose are disclaimed.
33  * In no event shall the company or contributors be liable for any
34  * direct, indirect, incidental, special, exemplary, or consequential
35  * damages (including, but not limited to, procurement of substitute
36  * goods or services; loss of use, data, or profits; or business
37  * interruption) however caused and on any theory of liability, whether
38  * in contract, strict liability, or tort (including negligence or
39  * otherwise) arising in any way out of the use of this software, even
40  * if advised of the possibility of such damage.
41  *
42  */
43 #ifndef _TRAP_IFC_FILE_H_
44 #define _TRAP_IFC_FILE_H_
45 
46 #include <limits.h>
47 #include "trap_ifc.h"
48 
49 #define TIME_PARAM "time="
50 #define TIME_PARAM_LEN strlen(TIME_PARAM)
51 #define SIZE_PARAM "size="
52 #define SIZE_PARAM_LEN strlen(SIZE_PARAM)
53 #define TIME_FORMAT_STRING ".%Y%m%d%H%M"
54 #define TIME_FORMAT_STRING_LEN strlen(TIME_FORMAT_STRING)
55 #define FILE_SIZE_SUFFIX_LEN 6
56 #define FILENAME_TEMPLATE_LEN PATH_MAX + 256
57 
58 typedef struct file_buffer_s {
59  uint32_t wr_index; /**< Pointer to first free byte in buffer payload */
60  uint8_t *header; /**< Pointer to first byte in buffer */
61  uint8_t *data; /**< Pointer to first byte of buffer payload */
62  uint8_t finished; /**< Flag indicating whether buffer is full and ready to be sent */
64 
65 typedef struct file_private_s {
67  FILE *fd;
68  time_t create_time;
69  char **files;
71  char filename[PATH_MAX];
72  char mode[3];
74  uint8_t neg_initialized;
75  uint16_t file_index;
76  uint16_t file_cnt;
77  uint32_t file_change_size;
78  uint32_t file_change_time;
79  uint32_t buffer_size; /**< Buffer size [bytes] */
80  uint32_t ifc_idx; /**< Index of interface in 'ctx->out_ifc_list' array */
81 
84 
85 /** Create file receive interface (input ifc).
86  * Receive function of this interface reads data from defined file.
87  * @param[in] ctx Pointer to the private libtrap context data (#trap_ctx_init()).
88  * @param[in] params <filename> expected.
89  * @param[out] ifc Created interface.
90  * @return Error code (0 on success). Generated interface is returned in ifc.
91  */
92 int create_file_recv_ifc(trap_ctx_priv_t *ctx, const char *params, trap_input_ifc_t *ifc, uint32_t idx);
93 
94 
95 /** Create file send interface (output ifc).
96  * Send function of this interface stores data into defined file.
97  * @param[in] ctx Pointer to the private libtrap context data (#trap_ctx_init()).
98  * @param[in] params <filename>:<mode>:<time>:<size>
99  * <mode> is optional, w - write, a - append. Write is set as default mode.
100  * <time> is optional, periodically rotates file in which the data is being written.
101  * <size> is optional, rotates file in which the data is being written once it reaches specified size.
102  * @param[out] ifc Created interface.
103  * @return Error code (0 on success). Generated interface is returned in ifc.
104  */
105 int create_file_send_ifc(trap_ctx_priv_t *ctx, const char *params, trap_output_ifc_t *ifc, uint32_t idx);
106 
107 #endif
uint32_t ifc_idx
Definition: ifc_file.h:80
trap_ctx_priv_t * ctx
Definition: ifc_file.h:66
char is_terminated
Definition: ifc_file.h:73
struct file_buffer_s file_buffer_t
#define FILENAME_TEMPLATE_LEN
Definition: ifc_file.h:56
uint8_t neg_initialized
Definition: ifc_file.h:74
file_buffer_t buffer
Definition: ifc_file.h:82
uint32_t file_change_time
Definition: ifc_file.h:78
uint16_t file_cnt
Definition: ifc_file.h:76
int create_file_send_ifc(trap_ctx_priv_t *ctx, const char *params, trap_output_ifc_t *ifc, uint32_t idx)
Allocate and initiate file output interface. This function is called by TRAP library to initialize on...
Definition: ifc_file.c:765
uint8_t * data
Definition: ifc_file.h:61
char filename_tmplt[FILENAME_TEMPLATE_LEN]
Definition: ifc_file.h:70
uint8_t * header
Definition: ifc_file.h:60
struct file_private_s file_private_t
int create_file_recv_ifc(trap_ctx_priv_t *ctx, const char *params, trap_input_ifc_t *ifc, uint32_t idx)
Allocate and initiate file input interface. This function is called by TRAP library to initialize one...
Definition: ifc_file.c:432
uint32_t file_change_size
Definition: ifc_file.h:77
uint16_t file_index
Definition: ifc_file.h:75
char mode[3]
Definition: ifc_file.h:72
char filename[PATH_MAX]
Definition: ifc_file.h:71
time_t create_time
Definition: ifc_file.h:68
uint8_t finished
Definition: ifc_file.h:62
uint32_t buffer_size
Definition: ifc_file.h:79
char ** files
Definition: ifc_file.h:69
uint32_t wr_index
Definition: ifc_file.h:59
FILE * fd
Definition: ifc_file.h:67
Interface of TRAP interfaces.