3 #include <minix/sysutil.h>
5 /* SEF Live update variables. */
6 PRIVATE
int sef_lu_state
= SEF_LU_STATE_NULL
;
8 /* SEF Live update callbacks. */
9 PRIVATE
struct sef_cbs
{
10 sef_cb_lu_prepare_t sef_cb_lu_prepare
;
11 sef_cb_lu_state_isvalid_t sef_cb_lu_state_isvalid
;
12 sef_cb_lu_state_changed_t sef_cb_lu_state_changed
;
13 sef_cb_lu_state_dump_t sef_cb_lu_state_dump
;
14 sef_cb_lu_ready_pre_t sef_cb_lu_ready_pre
;
16 SEF_CB_LU_PREPARE_DEFAULT
,
17 SEF_CB_LU_STATE_ISVALID_DEFAULT
,
18 SEF_CB_LU_STATE_CHANGED_DEFAULT
,
19 SEF_CB_LU_STATE_DUMP_DEFAULT
,
20 SEF_CB_LU_READY_PRE_DEFAULT
,
23 /* SEF Live update prototypes for sef_receive(). */
24 PUBLIC
_PROTOTYPE( void do_sef_lu_before_receive
, (void) );
25 PUBLIC
_PROTOTYPE( int do_sef_lu_request
, (message
*m_ptr
) );
28 EXTERN
_PROTOTYPE( char* sef_debug_header
, (void) );
29 PRIVATE
int sef_lu_debug_cycle
= 0;
31 /*===========================================================================*
32 * do_sef_lu_before_receive *
33 *===========================================================================*/
34 PUBLIC
void do_sef_lu_before_receive()
36 /* Handle SEF Live update before receive events. */
38 /* Nothing to do if we are not preparing for a live update. */
39 if(sef_lu_state
== SEF_LU_STATE_NULL
) {
47 sef_lu_dprint("%s, cycle=%d. Dumping state variables:\n",
48 sef_debug_header(), sef_lu_debug_cycle
);
49 sef_cbs
.sef_cb_lu_state_dump(sef_lu_state
);
53 /* Let the callback code handle the event.
54 * For SEF_LU_STATE_WORK_FREE, we're always ready, tell immediately.
56 if(sef_lu_state
== SEF_LU_STATE_WORK_FREE
) {
60 sef_cbs
.sef_cb_lu_prepare(sef_lu_state
);
64 /*===========================================================================*
66 *===========================================================================*/
67 PUBLIC
int do_sef_lu_request(message
*m_ptr
)
69 /* Handle a SEF Live update request. */
70 int old_state
, is_valid_state
;
72 sef_lu_debug_cycle
= 0;
73 old_state
= sef_lu_state
;
75 /* Only accept live update requests with a valid state. */
76 is_valid_state
= sef_cbs
.sef_cb_lu_state_isvalid(m_ptr
->RS_LU_STATE
);
81 /* Set the new live update state. */
82 sef_lu_state
= m_ptr
->RS_LU_STATE
;
84 /* If the live update state changed, let the callback code
87 if(old_state
!= sef_lu_state
) {
88 sef_cbs
.sef_cb_lu_state_changed(old_state
, sef_lu_state
);
92 /* Return OK not to let anybody else intercept the request. */
96 /*===========================================================================*
98 *===========================================================================*/
99 PUBLIC
void sef_lu_ready(int result
)
105 sef_lu_debug_begin();
106 sef_lu_dprint("%s, cycle=%d. Ready to update with result: %d%s\n",
107 sef_debug_header(), sef_lu_debug_cycle
,
108 result
, (result
== OK
? "(OK)" : ""));
112 /* Let the callback code perform any pre-ready operations. */
113 r
= sef_cbs
.sef_cb_lu_ready_pre(result
);
115 /* Abort update if callback returned error. */
119 /* Inform RS that we're ready with the given result. */
120 m
.m_type
= RS_LU_PREPARE
;
121 m
.RS_LU_STATE
= sef_lu_state
;
122 m
.RS_LU_RESULT
= result
;
123 r
= sendrec(RS_PROC_NR
, &m
);
125 panic("sendrec failed: %d", r
);
130 sef_lu_debug_begin();
131 sef_lu_dprint("%s, cycle=%d. The %s aborted the update!\n",
132 sef_debug_header(), sef_lu_debug_cycle
,
133 (result
== OK
? "server" : "client"));
137 /* Something went wrong. Update was aborted and we didn't get updated.
138 * Restore things back to normal and continue executing.
140 old_state
= sef_lu_state
;
141 sef_lu_state
= SEF_LU_STATE_NULL
;
142 if(old_state
!= sef_lu_state
) {
143 sef_cbs
.sef_cb_lu_state_changed(old_state
, sef_lu_state
);
147 /*===========================================================================*
148 * sef_setcb_lu_prepare *
149 *===========================================================================*/
150 PUBLIC
void sef_setcb_lu_prepare(sef_cb_lu_prepare_t cb
)
153 sef_cbs
.sef_cb_lu_prepare
= cb
;
156 /*===========================================================================*
157 * sef_setcb_lu_state_isvalid *
158 *===========================================================================*/
159 PUBLIC
void sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_t cb
)
162 sef_cbs
.sef_cb_lu_state_isvalid
= cb
;
165 /*===========================================================================*
166 * sef_setcb_lu_state_changed *
167 *===========================================================================*/
168 PUBLIC
void sef_setcb_lu_state_changed(sef_cb_lu_state_changed_t cb
)
171 sef_cbs
.sef_cb_lu_state_changed
= cb
;
174 /*===========================================================================*
175 * sef_setcb_lu_state_dump *
176 *===========================================================================*/
177 PUBLIC
void sef_setcb_lu_state_dump(sef_cb_lu_state_dump_t cb
)
180 sef_cbs
.sef_cb_lu_state_dump
= cb
;
183 /*===========================================================================*
184 * sef_setcb_lu_ready_pre *
185 *===========================================================================*/
186 PUBLIC
void sef_setcb_lu_ready_pre(sef_cb_lu_ready_pre_t cb
)
189 sef_cbs
.sef_cb_lu_ready_pre
= cb
;
192 /*===========================================================================*
193 * sef_cb_lu_prepare_null *
194 *===========================================================================*/
195 PUBLIC
void sef_cb_lu_prepare_null(int state
)
199 /*===========================================================================*
200 * sef_cb_lu_state_isvalid_null *
201 *===========================================================================*/
202 PUBLIC
int sef_cb_lu_state_isvalid_null(int state
)
207 /*===========================================================================*
208 * sef_cb_lu_state_changed_null *
209 *===========================================================================*/
210 PUBLIC
void sef_cb_lu_state_changed_null(int old_state
, int state
)
214 /*===========================================================================*
215 * sef_cb_lu_state_dump_null *
216 *===========================================================================*/
217 PUBLIC
void sef_cb_lu_state_dump_null(int state
)
219 sef_lu_dprint("NULL\n");
222 /*===========================================================================*
223 * sef_cb_lu_ready_pre_null *
224 *===========================================================================*/
225 PUBLIC
int sef_cb_lu_ready_pre_null(int result
)
230 /*===========================================================================*
231 * sef_cb_lu_prepare_always_ready *
232 *===========================================================================*/
233 PUBLIC
void sef_cb_lu_prepare_always_ready(int state
)
238 /*===========================================================================*
239 * sef_cb_lu_state_isvalid_standard *
240 *===========================================================================*/
241 PUBLIC
int sef_cb_lu_state_isvalid_standard(int state
)
243 return SEF_LU_STATE_IS_STANDARD(state
);