gam-resource-manager: adjust to updated proxied call callback signature.
[profile/ivi/murphy.git] / src / breedline / breedline.h
1 /*
2  * Copyright (c) 2012, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *   * Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *   * Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *   * Neither the name of Intel Corporation nor the names of its contributors
14  *     may be used to endorse or promote products derived from this software
15  *     without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __BREEDLINE_H__
31 #define __BREEDLINE_H__
32
33 #include <breedline/macros.h>
34
35 BRL_CDECL_BEGIN
36
37 /** Default history buffer size (in number of items). */
38 #define BRL_DEFAULT_HISTORY 64
39
40 /** Type for opaque breedline context. */
41 struct brl_s;
42 typedef struct brl_s brl_t;
43
44 /** Create a new breedline context for the given file descriptor. */
45 brl_t *brl_create(int fd, const char *prompt);
46
47 /** Destroy the given context. */
48 void brl_destroy(brl_t *brl);
49
50 /** Set breedline prompt. */
51 int brl_set_prompt(brl_t *brl, const char *prompt);
52
53 /** Hide breedline prompt. */
54 void brl_hide_prompt(brl_t *brl);
55
56 /** Show breedline prompt. */
57 void brl_show_prompt(brl_t *brl);
58
59 /** Limit the size of history to the given number of entries. */
60 int brl_limit_history(brl_t *brl, size_t size);
61
62 /** Read a single line of input and put it to the given buffer. */
63 int brl_read_line(brl_t *brl, char *buf, size_t size);
64
65 /** Add an entry to history. Replaces oldest entry if history buffer is full. */
66 int brl_add_history(brl_t *brl, const char *entry);
67
68 /** In put delivery callback type, used when running in mainloop mode. */
69 typedef void (*brl_line_cb_t)(brl_t *brl, const char *line, void *user_data);
70
71 /** Breedline mainloop subset abstraction. */
72 typedef struct {
73     void *(*add_watch)(void *ml, int fd,
74                        void (*cb)(int fd, int events, void *user_data),
75                        void *user_data);
76     void  (*del_watch)(void *w);
77 } brl_mainloop_ops_t;
78
79 /** Set up the given context to be pumped by the given mainloop. */
80 int brl_use_mainloop(brl_t *brl, void *ml, brl_mainloop_ops_t *ops,
81                      brl_line_cb_t cb, void *user_data);
82
83 /** Memory allocation operations. */
84 typedef struct {
85     void *(*allocfn)(size_t size, const char *file, int line, const char *func);
86     void *(*reallocfn)(void *ptr, size_t size, const char *file, int line,
87                        const char *func);
88     char *(*strdupfn)(const char *str, const char *file, int line,
89                       const char *func);
90     void  (*freefn)(void *ptr, const char *file, int line, const char *func);
91 } brl_allocator_t;
92
93 /** Override the default memory allocator. */
94 int brl_set_allocator(brl_allocator_t *allocator);
95
96 BRL_CDECL_END
97
98 #endif /* __BREEDLINE_H__ */