00001 #ifndef _EVENT_TIMED_H_ 00002 #define _EVENT_TIMED_H_ 00003 /* Copyright (C) 2004-2006 MySQL AB 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00018 00019 00020 #define EVEX_OK 0 00021 #define EVEX_KEY_NOT_FOUND -1 00022 #define EVEX_OPEN_TABLE_FAILED -2 00023 #define EVEX_WRITE_ROW_FAILED -3 00024 #define EVEX_DELETE_ROW_FAILED -4 00025 #define EVEX_GET_FIELD_FAILED -5 00026 #define EVEX_PARSE_ERROR -6 00027 #define EVEX_INTERNAL_ERROR -7 00028 #define EVEX_NO_DB_ERROR -8 00029 #define EVEX_COMPILE_ERROR -19 00030 #define EVEX_GENERAL_ERROR -20 00031 #define EVEX_BAD_IDENTIFIER -21 00032 #define EVEX_BODY_TOO_LONG -22 00033 #define EVEX_BAD_PARAMS -23 00034 #define EVEX_NOT_RUNNING -24 00035 #define EVEX_MICROSECOND_UNSUP -25 00036 #define EVEX_CANT_KILL -26 00037 00038 #define EVENT_EXEC_NO_MORE (1L << 0) 00039 #define EVENT_NOT_USED (1L << 1) 00040 #define EVENT_FREE_WHEN_FINISHED (1L << 2) 00041 00042 00043 class sp_head; 00044 00045 class Event_timed 00046 { 00047 Event_timed(const Event_timed &); /* Prevent use of these */ 00048 void operator=(Event_timed &); 00049 my_bool in_spawned_thread; 00050 ulong locked_by_thread_id; 00051 my_bool running; 00052 ulong thread_id; 00053 pthread_mutex_t LOCK_running; 00054 pthread_cond_t COND_finished; 00055 00056 bool status_changed; 00057 bool last_executed_changed; 00058 00059 public: 00060 enum enum_status 00061 { 00062 ENABLED = 1, 00063 DISABLED 00064 }; 00065 00066 enum enum_on_completion 00067 { 00068 ON_COMPLETION_DROP = 1, 00069 ON_COMPLETION_PRESERVE 00070 }; 00071 00072 TIME last_executed; 00073 00074 LEX_STRING dbname; 00075 LEX_STRING name; 00076 LEX_STRING body; 00077 00078 LEX_STRING definer_user; 00079 LEX_STRING definer_host; 00080 LEX_STRING definer;// combination of user and host 00081 00082 LEX_STRING comment; 00083 TIME starts; 00084 TIME ends; 00085 TIME execute_at; 00086 my_bool starts_null; 00087 my_bool ends_null; 00088 my_bool execute_at_null; 00089 00090 longlong expression; 00091 interval_type interval; 00092 00093 ulonglong created; 00094 ulonglong modified; 00095 enum enum_on_completion on_completion; 00096 enum enum_status status; 00097 sp_head *sphead; 00098 ulong sql_mode; 00099 const uchar *body_begin; 00100 00101 bool dropped; 00102 bool free_sphead_on_delete; 00103 uint flags;//all kind of purposes 00104 00105 static void *operator new(size_t size) 00106 { 00107 void *p; 00108 DBUG_ENTER("Event_timed::new(size)"); 00109 p= my_malloc(size, MYF(0)); 00110 DBUG_PRINT("info", ("alloc_ptr=0x%lx", p)); 00111 DBUG_RETURN(p); 00112 } 00113 00114 static void *operator new(size_t size, MEM_ROOT *mem_root) 00115 { return (void*) alloc_root(mem_root, (uint) size); } 00116 00117 static void operator delete(void *ptr, size_t size) 00118 { 00119 DBUG_ENTER("Event_timed::delete(ptr,size)"); 00120 DBUG_PRINT("enter", ("free_ptr=0x%lx", ptr)); 00121 TRASH(ptr, size); 00122 my_free((gptr) ptr, MYF(0)); 00123 DBUG_VOID_RETURN; 00124 } 00125 00126 static void operator delete(void *ptr, MEM_ROOT *mem_root) 00127 { 00128 /* 00129 Don't free the memory it will be done by the mem_root but 00130 we need to call the destructor because we free other resources 00131 which are not allocated on the root but on the heap, or we 00132 deinit mutexes. 00133 */ 00134 DBUG_ASSERT(0); 00135 } 00136 00137 Event_timed(); 00138 00139 ~Event_timed(); 00140 00141 void 00142 init(); 00143 00144 void 00145 deinit_mutexes(); 00146 00147 int 00148 init_definer(THD *thd); 00149 00150 int 00151 init_execute_at(THD *thd, Item *expr); 00152 00153 int 00154 init_interval(THD *thd, Item *expr, interval_type new_interval); 00155 00156 void 00157 init_name(THD *thd, sp_name *spn); 00158 00159 int 00160 init_starts(THD *thd, Item *starts); 00161 00162 int 00163 init_ends(THD *thd, Item *ends); 00164 00165 void 00166 init_body(THD *thd); 00167 00168 void 00169 init_comment(THD *thd, LEX_STRING *set_comment); 00170 00171 int 00172 load_from_row(MEM_ROOT *mem_root, TABLE *table); 00173 00174 bool 00175 compute_next_execution_time(); 00176 00177 int 00178 drop(THD *thd); 00179 00180 void 00181 mark_last_executed(THD *thd); 00182 00183 bool 00184 update_fields(THD *thd); 00185 00186 int 00187 get_create_event(THD *thd, String *buf); 00188 00189 int 00190 execute(THD *thd, MEM_ROOT *mem_root); 00191 00192 int 00193 compile(THD *thd, MEM_ROOT *mem_root); 00194 00195 bool 00196 is_running(); 00197 00198 int 00199 spawn_now(void * (*thread_func)(void*), void *arg); 00200 00201 bool 00202 spawn_thread_finish(THD *thd); 00203 00204 void 00205 free_sp(); 00206 00207 bool 00208 has_equal_db(Event_timed *etn); 00209 00210 int 00211 kill_thread(THD *thd); 00212 00213 void 00214 set_thread_id(ulong tid) { thread_id= tid; } 00215 }; 00216 00217 #endif /* _EVENT_H_ */
1.4.7

