1 /*
2  *
3   ***** BEGIN LICENSE BLOCK *****
4 
5   Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
6   Copyright (C) 2017-2019 Olof Hagsand
7   Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC(Netgate)
8 
9   This file is part of CLIXON.
10 
11   Licensed under the Apache License, Version 2.0 (the "License");
12   you may not use this file except in compliance with the License.
13   You may obtain a copy of the License at
14 
15     http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22 
23   Alternatively, the contents of this file may be used under the terms of
24   the GNU General Public License Version 3 or later (the "GPL"),
25   in which case the provisions of the GPL are applicable instead
26   of those above. If you wish to allow use of your version of this file only
27   under the terms of the GPL, and not to allow others to
28   use your version of this file under the terms of Apache License version 2,
29   indicate your decision by deleting the provisions above and replace them with
30   the  notice and other provisions required by the GPL. If you do not delete
31   the provisions above, a recipient may use your version of this file under
32   the terms of any one of the Apache License version 2 or the GPL.
33 
34   ***** END LICENSE BLOCK *****
35 
36   */
37 
38 #ifndef _BACKEND_PLUGIN_H_
39 #define _BACKEND_PLUGIN_H_
40 
41 /*
42  * Types
43  */
44 
45 /*! Transaction data describing a system transition from a src to target state
46  * Clicon internal, presented as void* to app's callback in the 'transaction_data'
47  * type in clicon_backend_api.h
48  * The struct contains source and target XML tree (e.g. candidate/running)
49  * But primarily a set of XML tree vectors (dvec, avec, cvec) and associated lengths
50  * These contain the difference between src and target XML, ie "what has changed".
51  * It is up to the validate callbacks to ensure that these changes are OK
52  * It is up to the commit callbacks to enforce these changes in the "state" of
53  *the system.
54  */
55 typedef struct {
56     uint64_t   td_id;       /* Transaction id */
57     void      *td_arg;      /* Callback argument */
58     cxobj     *td_src;      /* Source database xml tree */
59     cxobj     *td_target;   /* Target database xml tree */
60     cxobj    **td_dvec;     /* Delete xml vector */
61     int        td_dlen;     /* Delete xml vector length */
62     cxobj    **td_avec;     /* Add xml vector */
63     int        td_alen;     /* Add xml vector length */
64     cxobj    **td_scvec;    /* Source changed xml vector */
65     cxobj    **td_tcvec;    /* Target changed xml vector */
66     int        td_clen;     /* Changed xml vector length */
67 } transaction_data_t;
68 
69 /*
70  * Prototypes
71  */
72 int clixon_plugin_reset_one(clixon_plugin *cp, clicon_handle h, char *db);
73 int clixon_plugin_reset_all(clicon_handle h, char *db);
74 
75 int clixon_plugin_daemon_one(clixon_plugin *cp, clicon_handle h);
76 int clixon_plugin_daemon_all(clicon_handle h);
77 
78 int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath, cxobj **xtop);
79 
80 transaction_data_t * transaction_new(void);
81 int transaction_free(transaction_data_t *);
82 
83 int plugin_transaction_begin_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
84 int plugin_transaction_begin_all(clicon_handle h, transaction_data_t *td);
85 
86 int plugin_transaction_validate_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
87 int plugin_transaction_validate_all(clicon_handle h, transaction_data_t *td);
88 
89 int plugin_transaction_complete_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
90 int plugin_transaction_complete_all(clicon_handle h, transaction_data_t *td);
91 
92 int plugin_transaction_commit_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
93 int plugin_transaction_commit_all(clicon_handle h, transaction_data_t *td);
94 
95 int plugin_transaction_commit_done_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
96 int plugin_transaction_commit_done_all(clicon_handle h, transaction_data_t *td);
97 
98 int plugin_transaction_end_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
99 int plugin_transaction_end_all(clicon_handle h, transaction_data_t *td);
100 
101 int plugin_transaction_abort_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
102 int plugin_transaction_abort_all(clicon_handle h, transaction_data_t *td);
103 
104 #endif  /* _BACKEND_PLUGIN_H_ */
105