Skip to content

Commit

Permalink
Define a central EMCallback type
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Oct 30, 2009
1 parent 812c800 commit b61b7a6
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ext/cmain.cpp
Expand Up @@ -49,7 +49,7 @@ extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
evma_initialize_library
***********************/

extern "C" void evma_initialize_library (void(*cb)(const unsigned long, int, const char*, const unsigned long))
extern "C" void evma_initialize_library (EMCallback cb)
{
// Probably a bad idea to mess with the signal mask of a process
// we're just being linked into.
Expand Down
2 changes: 1 addition & 1 deletion ext/cplusplus.cpp
Expand Up @@ -34,7 +34,7 @@ EM::Run
void EM::Run (void (*start_func)())
{
evma_set_epoll (1);
evma_initialize_library (EM::Callback);
evma_initialize_library ((EMCallback)EM::Callback);
if (start_func)
AddTimer (0, start_func);
evma_run_machine();
Expand Down
2 changes: 1 addition & 1 deletion ext/ed.cpp
Expand Up @@ -118,7 +118,7 @@ EventableDescriptor::~EventableDescriptor()
EventableDescriptor::SetEventCallback
*************************************/

void EventableDescriptor::SetEventCallback (void(*cb)(const unsigned long, int, const char*, const unsigned long))
void EventableDescriptor::SetEventCallback (EMCallback cb)
{
EventCallback = cb;
}
Expand Down
4 changes: 2 additions & 2 deletions ext/ed.h
Expand Up @@ -62,7 +62,7 @@ class EventableDescriptor: public Bindable_t
bool IsCloseScheduled();
virtual void HandleError(){ ScheduleClose (false); }

void SetEventCallback (void (*cb)(const unsigned long, int, const char*, const unsigned long));
void SetEventCallback (EMCallback);

virtual bool GetPeername (struct sockaddr*) {return false;}
virtual bool GetSockname (struct sockaddr*) {return false;}
Expand Down Expand Up @@ -99,7 +99,7 @@ class EventableDescriptor: public Bindable_t
protected:
int MySocket;

void (*EventCallback)(const unsigned long, int, const char*, const unsigned long);
EMCallback EventCallback;
void _GenericInboundDispatch(const char*, int);

Int64 CreatedAt;
Expand Down
3 changes: 1 addition & 2 deletions ext/em.cpp
Expand Up @@ -20,7 +20,6 @@ See the file COPYING for complete licensing information.
// THIS ENTIRE FILE WILL EVENTUALLY BE FOR UNIX BUILDS ONLY.
//#ifdef OS_UNIX


#include "project.h"

// Keep a global variable floating around
Expand Down Expand Up @@ -79,7 +78,7 @@ void EventMachine_t::SetMaxTimerCount (int count)
EventMachine_t::EventMachine_t
******************************/

EventMachine_t::EventMachine_t (void (*event_callback)(const unsigned long, int, const char*, const unsigned long)):
EventMachine_t::EventMachine_t (EMCallback event_callback):
HeartbeatInterval(2000000),
EventCallback (event_callback),
NextHeartbeatTime (0),
Expand Down
7 changes: 2 additions & 5 deletions ext/em.h
Expand Up @@ -57,7 +57,6 @@ See the file COPYING for complete licensing information.
#define EmSelect select
#endif


#ifdef OS_UNIX
typedef long long Int64;
#endif
Expand All @@ -82,7 +81,7 @@ class EventMachine_t
static void SetMaxTimerCount (int);

public:
EventMachine_t (void(*event_callback)(const unsigned long, int, const char*, const unsigned long));
EventMachine_t (EMCallback);
virtual ~EventMachine_t();

void Run();
Expand Down Expand Up @@ -168,7 +167,7 @@ class EventMachine_t
MaxEvents = 4096
};
int HeartbeatInterval;
void (*EventCallback)(const unsigned long, int, const char*, const unsigned long);
EMCallback EventCallback;

class Timer_t: public Bindable_t {
};
Expand Down Expand Up @@ -225,8 +224,6 @@ struct SelectData_t
int nSockets;
};



#endif // __EventMachine__H_

//#endif // OS_UNIX
2 changes: 1 addition & 1 deletion ext/eventmachine.h
Expand Up @@ -39,7 +39,7 @@ extern "C" {

};

void evma_initialize_library (void(*)(const unsigned long, int, const char*, const unsigned long));
void evma_initialize_library (EMCallback);
void evma_run_machine();
void evma_release_library();
const unsigned long evma_install_oneshot_timer (int seconds);
Expand Down
11 changes: 8 additions & 3 deletions ext/project.h
Expand Up @@ -134,6 +134,14 @@ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_ino
#include <sys/uio.h>
#endif

#if __cplusplus
extern "C" {
#endif
typedef void (*EMCallback)(const unsigned long, int, const char*, const unsigned long);
#if __cplusplus
}
#endif

#include "binder.h"
#include "em.h"
#include "epoll.h"
Expand All @@ -145,7 +153,4 @@ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_ino
#include "eventmachine.h"
#include "eventmachine_cpp.h"




#endif // __Project__H_
2 changes: 1 addition & 1 deletion ext/rubymain.cpp
Expand Up @@ -170,7 +170,7 @@ t_initialize_event_machine

static VALUE t_initialize_event_machine (VALUE self)
{
evma_initialize_library (event_callback_wrapper);
evma_initialize_library ((EMCallback)event_callback_wrapper);
return Qnil;
}

Expand Down

0 comments on commit b61b7a6

Please sign in to comment.