Skip to content

Commit

Permalink
use enums instead of bare #defines
Browse files Browse the repository at this point in the history
  • Loading branch information
ghedo committed Jan 3, 2012
1 parent ff78a5f commit c3e2c93
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
8 changes: 5 additions & 3 deletions include/tofu.h
Expand Up @@ -45,9 +45,11 @@
extern "C" {
#endif

#define TOFU_FCGI 0
#define TOFU_ZMQ 1
#define TOFU_EVHTTP 2
typedef enum {
TOFU_FCGI,
TOFU_ZMQ,
TOFU_EVHTTP
} tofu_enum_backend_t;

void tofu_loop(tofu_ctx_t *ctx);

Expand Down
10 changes: 6 additions & 4 deletions include/tofu/req.h
Expand Up @@ -40,10 +40,12 @@
extern "C" {
#endif

#define GET 0
#define POST 1
#define PUT 2
#define DELETE 3
typedef enum {
GET,
POST,
PUT,
DELETE,
} tofu_enum_method_t;

typedef void tofu_req_t;

Expand Down
10 changes: 5 additions & 5 deletions src/backend.h
Expand Up @@ -33,15 +33,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define BACKEND_FCGI 0
#define BACKEND_ZMQ 1
#define BACKEND_EVHTTP 2

typedef struct {
int id;
char *name;

void (*loop)(tofu_ctx_t *ctx);
} tofu_backend_t;

tofu_backend_t backend;
typedef enum {
TOFU_FCGI,
TOFU_ZMQ,
TOFU_EVHTTP
} tofu_enum_backend_t;
2 changes: 1 addition & 1 deletion src/backend/evhttp.c
Expand Up @@ -54,7 +54,7 @@ void tofu_backend_evhttp_loop(tofu_ctx_t *ctx);
static void tofu_backend_evhttp_cb(struct evhttp_request *req, void *arg);

tofu_backend_t tofu_backend_evhttp = {
.id = BACKEND_EVHTTP,
.id = TOFU_EVHTTP,
.name = "evhttp",

.loop = tofu_backend_evhttp_loop,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/fcgi.c
Expand Up @@ -52,7 +52,7 @@ void tofu_backend_fcgi_loop(tofu_ctx_t *ctx);
static void tofu_backend_fcgi_send(tofu_rep_t *rep);

tofu_backend_t tofu_backend_fcgi = {
.id = BACKEND_FCGI,
.id = TOFU_FCGI,
.name = "fcgi",

.loop = tofu_backend_fcgi_loop,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/zmq.c
Expand Up @@ -57,7 +57,7 @@
void tofu_backend_zmq_loop(tofu_ctx_t *ctx);

tofu_backend_t tofu_backend_zmq = {
.id = BACKEND_ZMQ,
.id = TOFU_ZMQ,
.name = "zmq",

.loop = tofu_backend_zmq_loop,
Expand Down
6 changes: 3 additions & 3 deletions src/tofu.c
Expand Up @@ -58,19 +58,19 @@ void tofu_loop(tofu_ctx_t *ctx) {

switch (ctx -> backend) {
#ifdef HAVE_FCGI_STDIO_H
case BACKEND_FCGI:
case TOFU_FCGI:
backend = tofu_backend_fcgi;
break;
#endif

#ifdef HAVE_ZMQ_H
case BACKEND_ZMQ:
case TOFU_ZMQ:
backend = tofu_backend_zmq;
break;
#endif

#ifdef HAVE_EVHTTP_H
case BACKEND_EVHTTP:
case TOFU_EVHTTP:
backend = tofu_backend_evhttp;
break;
#endif
Expand Down

0 comments on commit c3e2c93

Please sign in to comment.