2 Unix SMB/CIFS implementation.
4 helper functions for task based servers (nbtd, winbind etc)
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "process_model.h"
25 #include "lib/events/events.h"
26 #include "smbd/service.h"
27 #include "smbd/service_task.h"
28 #include "lib/messaging/irpc.h"
31 terminate a task service
33 void task_server_terminate(struct task_server
*task
, const char *reason
)
35 struct event_context
*event_ctx
= task
->event_ctx
;
36 const struct model_ops
*model_ops
= task
->model_ops
;
37 DEBUG(0,("task_server_terminate: [%s]\n", reason
));
39 model_ops
->terminate(event_ctx
, reason
);
42 /* used for the callback from the process model code */
44 void (*task_init
)(struct task_server
*);
45 const struct model_ops
*model_ops
;
50 called by the process model code when the new task starts up. This then calls
51 the server specific startup code
53 static void task_server_callback(struct event_context
*event_ctx
,
54 struct server_id server_id
, void *private)
56 struct task_state
*state
= talloc_get_type(private, struct task_state
);
57 struct task_server
*task
;
59 task
= talloc(event_ctx
, struct task_server
);
60 if (task
== NULL
) return;
62 task
->event_ctx
= event_ctx
;
63 task
->model_ops
= state
->model_ops
;
64 task
->server_id
= server_id
;
66 task
->msg_ctx
= messaging_init(task
, task
->server_id
, task
->event_ctx
);
68 task_server_terminate(task
, "messaging_init() failed");
72 state
->task_init(task
);
76 startup a task based server
78 NTSTATUS
task_server_startup(struct event_context
*event_ctx
,
79 const struct model_ops
*model_ops
,
80 void (*task_init
)(struct task_server
*))
82 struct task_state
*state
;
84 state
= talloc(event_ctx
, struct task_state
);
85 NT_STATUS_HAVE_NO_MEMORY(state
);
87 state
->task_init
= task_init
;
88 state
->model_ops
= model_ops
;
90 model_ops
->new_task(event_ctx
, task_server_callback
, state
);
98 void task_server_set_title(struct task_server
*task
, const char *title
)
100 task
->model_ops
->set_title(task
->event_ctx
, title
);