ext/asyncengine/asyncengine_ruby.h in asyncengine-0.0.1.testing1 vs ext/asyncengine/asyncengine_ruby.h in asyncengine-0.0.2.alpha1
- old
+ new
@@ -1,22 +1,60 @@
#ifndef ASYNCENGINE_RUBY_H
#define ASYNCENGINE_RUBY_H
#include <ruby.h>
-#include <libuv/include/uv.h> // NOTE: Not needed if dir_config() line is enabled in extconf.rb.
-//#include <uv.h> // so this line becomes enough.
+#include "libuv/include/uv.h"
+#include "rb_utilities.h"
+#include "debug.h"
-// Uncomment this line for enabling TRACE() function.
-//#define AE_DEBUG
-#ifdef AE_DEBUG
-#define AE_TRACE() fprintf(stderr, "AE_TRACE: %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
-#else
-#define AE_TRACE()
-#endif
+/*
+ * This macro behaves as follows:
+ * - Returns false if AE is releasing.
+ * - Raises a AE::NotRunningError exception if stopped.
+ * - Does nothing if AE is running.
+ */
+#define AE_CHECK_STATUS() \
+ switch(AE_status) { \
+ case AE_RUNNING: \
+ AE_DEBUG("AsyncEngine status: RUNNING => let's go"); \
+ break; \
+ case AE_RELEASING: \
+ AE_DEBUG("AsyncEngine status: RELEASING => return Qfalse"); \
+ return Qfalse; \
+ break; \
+ case AE_STOPPED: \
+ AE_DEBUG("AsyncEngine status: STOPPED => raise error"); \
+ rb_raise(eAsyncEngineNotRunningError, "AsyncEngine is not running"); \
+ break; \
+ default: \
+ AE_ABORT("AsyncEngine status: unknown => abort!"); \
+ break; \
+ }
VALUE mAsyncEngine;
+VALUE cAsyncEngineHandle;
+VALUE eAsyncEngineError;
+VALUE eAsyncEngineUvError;
+VALUE eAsyncEngineNotRunningError;
+VALUE AE_handles;
+VALUE AE_procs;
+VALUE AE_UV_ERRORS;
-#endif /* #ifndef ASYNCENGINE_RUBY_H */
+enum ae_status {
+ AE_RUNNING = 1,
+ AE_RELEASING = 2,
+ AE_STOPPED = 3
+};
+
+enum ae_status AE_status;
+
+uv_loop_t *AE_uv_loop;
+
+
+void ae_handle_error(VALUE error);
+
+
+#endif /* ASYNCENGINE_RUBY_H */
\ No newline at end of file