Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

bg.h

Go to the documentation of this file.
00001 /*
00002  * $Id: bg.h 13296 2007-04-13 23:53:33Z cbiere $
00003  *
00004  * Copyright (c) 2002-2003, Raphael Manfredi
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00036 #ifndef _bg_h_
00037 #define _bg_h_
00038 
00039 #include "common.h"
00040 
00044 typedef enum {
00045     BGR_NEXT = 0,                   
00046     BGR_MORE,                       
00047     BGR_DONE,                       
00048     BGR_ERROR                       
00049 } bgret_t;
00050 
00054 typedef enum {
00055     BGS_OK = 0,                     
00056     BGS_ERROR,                      
00057     BGS_KILLED                      
00058 } bgstatus_t;
00059 
00060 /*
00061  * Signals that a task can receive.
00062  */
00063 
00064 typedef enum {
00065     BG_SIG_ZERO = 0,                
00066     BG_SIG_KILL,                    
00067     BG_SIG_TERM,                    
00068     BG_SIG_USR,                     
00069     BG_SIG_COUNT
00070 } bgsig_t;
00071 
00072 struct bgtask;
00073 
00074 /*
00075  * Signatures.
00076  *
00077  * `bgstep_cb_t' is a processing step callback.
00078  * `bgsig_cb_t' is a signal processing handler.
00079  * `bgclean_cb_t' is the context cleanup handler, called upon task destruction.
00080  * `bgdone_cb_t' is the final callback called when task is finished.
00081  * `bgstart_cb_t' is the initial callback when daemon starts working.
00082  * `bgend_cb_t' is the final callback when daemon ends working.
00083  * `bgnotify_cb_t' is the start/stop callback when daemon starts/stops working.
00084  */
00085 
00086 typedef bgret_t (*bgstep_cb_t)(struct bgtask *h, gpointer ctx, gint ticks);
00087 typedef void (*bgsig_cb_t)(struct bgtask *h, gpointer ctx, bgsig_t sig);
00088 typedef void (*bgclean_cb_t)(gpointer ctx);
00089 typedef void (*bgdone_cb_t)(struct bgtask *h, gpointer ctx,
00090     bgstatus_t status, gpointer arg);
00091 typedef void (*bgstart_cb_t)(struct bgtask *h, gpointer ctx, gpointer item);
00092 typedef void (*bgend_cb_t)(struct bgtask *h, gpointer ctx, gpointer item);
00093 typedef void (*bgnotify_cb_t)(struct bgtask *h, gboolean on);
00094 
00095 /*
00096  * Public interface.
00097  */
00098 
00099 void bg_close(void);
00100 void bg_sched_timer(gboolean overloaded);
00101 
00102 struct bgtask *bg_task_create(
00103     const gchar *name,
00104     const bgstep_cb_t *steps, gint stepcnt,
00105     gpointer ucontext,
00106     bgclean_cb_t ucontext_free,
00107     bgdone_cb_t done_cb,
00108     gpointer done_arg);
00109 
00110 struct bgtask *bg_daemon_create(
00111     const gchar *name,
00112     const bgstep_cb_t *steps, gint stepcnt,
00113     gpointer ucontext,
00114     bgclean_cb_t ucontext_free,
00115     bgstart_cb_t start_cb,
00116     bgend_cb_t end_cb,
00117     bgclean_cb_t item_free,
00118     bgnotify_cb_t notify);
00119 
00120 void bg_daemon_enqueue(struct bgtask *h, gpointer item);
00121 
00122 void bg_task_cancel(struct bgtask *h);
00123 void bg_task_exit(struct bgtask *h, gint code) G_GNUC_NORETURN;
00124 void bg_task_ticks_used(struct bgtask *h, gint used);
00125 bgsig_cb_t bg_task_signal(struct bgtask *h, bgsig_t sig, bgsig_cb_t handler);
00126 
00127 gint bg_task_seqno(const struct bgtask *h);
00128 gpointer bg_task_context(const struct bgtask *h);
00129 
00130 #endif  /* _bg_h_ */
00131 
00132 /* vi: set ts=4 sw=4 cindent: */

Generated on Sat Jun 30 17:53:22 2007 for gtk-gnutella by  doxygen 1.3.9.1