aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbeber <beber>2005-12-09 22:28:13 +0000
committerbeber <beber>2005-12-09 22:28:13 +0000
commit1bd7932bef84af9a3ab6125b2ae5ff9d1aaeff6a (patch)
tree642e7925378e5707dfb5a750b19cab19497fcf66 /src
parentiadd a macro for ecore (diff)
downloadespik-1bd7932bef84af9a3ab6125b2ae5ff9d1aaeff6a.tar.xz
Add a profiler in code
Diffstat (limited to 'src')
-rw-r--r--src/espik.c9
-rw-r--r--src/espik_common_handler.c7
-rw-r--r--src/espik_config.c15
-rw-r--r--src/espik_debug.c2
-rw-r--r--src/espik_debug.h40
-rw-r--r--src/espik_irc.c33
-rw-r--r--src/espik_net.c8
7 files changed, 104 insertions, 10 deletions
diff --git a/src/espik.c b/src/espik.c
index ab0c640..852d0b0 100644
--- a/src/espik.c
+++ b/src/espik.c
@@ -10,12 +10,12 @@
/*#include <Ecore_Con.h> */ /* Socket lib */
/* Espik Stuff */
+#include "espik.h"
#include "espik_global.h"
#include "espik_config.h"
#include "espik_irc.h"
#include "espik_common_handler.h"
#include "espik_net.h"
-#include "espik.h"
#include "espik_debug.h"
typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
@@ -26,7 +26,8 @@ typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
int del_backslash (char *msg)
{
- int i, count;
+ int i, count;
+ espik_enter();
for (i = 0, count = 0; msg[i]; i++)
{
@@ -37,12 +38,15 @@ int del_backslash (char *msg)
}
}
+ espik_leave();
return (count);
}
int main (int argc, char **argv)
{
Ecore_Fd_Handler *fd_kb;
+ __indent_level = 0;
+ espik_enter();
printf ("Welcome to %s %s\n", APPS_NAME, ESPIK_VERSION);
@@ -123,5 +127,6 @@ int main (int argc, char **argv)
/* ecore_con_shutdown (); */
ecore_shutdown ();
+ espik_leave();
return (0);
}
diff --git a/src/espik_common_handler.c b/src/espik_common_handler.c
index ba9483f..2e91757 100644
--- a/src/espik_common_handler.c
+++ b/src/espik_common_handler.c
@@ -15,10 +15,11 @@
#include "espik_debug.h"
int server_data (void* data __UNUSED__, int ev_type __UNUSED__,
- Ecore_Con_Event_Server_Data* ev)
+ Ecore_Con_Event_Server_Data* ev)
{
unsigned int i;
char* msg;
+ espik_enter();
msg = strdup((char*)ev->data);
@@ -37,6 +38,7 @@ int server_data (void* data __UNUSED__, int ev_type __UNUSED__,
free (msg);
+ espik_leave();
return (0);
}
@@ -45,6 +47,7 @@ int kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
char* kb;
char* tmp;
int count;
+ espik_enter();
kb = malloc (sizeof (char) * 200);
@@ -84,8 +87,10 @@ int kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
ecore_main_loop_quit ();
free (tmp);
+ espik_leave();
return (0);
}
+ espik_leave();
return (1);
}
diff --git a/src/espik_config.c b/src/espik_config.c
index c739052..3964902 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -17,12 +17,14 @@ static int ret; /* For debug */
t_servinfo* espik_server_config_set (char* server, unsigned short port)
{
t_servinfo* s_info;
+ espik_enter();
s_info = malloc (sizeof (t_servinfo));
s_info->host = server;
s_info->port = port;
+ espik_leave();
return (s_info);
}
@@ -30,6 +32,7 @@ t_userinfo* espik_user_sysinfo_get ()
{
struct passwd* pw;
t_userinfo* u_info;
+ espik_enter();
pw = getpwuid (getuid ());
@@ -45,12 +48,14 @@ t_userinfo* espik_user_sysinfo_get ()
/*free (pw);*/ /*FIXME: segv */
+ espik_leave();
return (u_info);
}
void espik_config_default_set ()
{
t_userinfo* user_sysinfo;
+ espik_enter();
ecore_config_string_default ("/config/server/0/host", "beber.melee");
ecore_config_int_default ("/config/server/0/port", 6667);
@@ -64,10 +69,13 @@ void espik_config_default_set ()
ecore_config_string_default ("/espik/version", ESPIK_VERSION);
free (user_sysinfo);
+ espik_leave();
}
void espik_config_init ()
{
+ espik_enter();
+
if ((ret = ecore_config_init (APPS_NAME)) != ECORE_CONFIG_ERR_SUCC)
{
espik_debug_print ("Init ecore_config failed (%d)", ret);
@@ -83,10 +91,13 @@ void espik_config_init ()
/*kill_me (2);*/
/*exit (ret);*/
}
+ espik_leave();
}
void espik_config_get (t_info *s_info)
{
+ espik_enter();
+
s_info->server = malloc (sizeof (t_servinfo));
s_info->client = malloc (sizeof (t_userinfo));
@@ -102,10 +113,13 @@ void espik_config_get (t_info *s_info)
espik_debug_print ("Save ecore_config failed");
exit (-1);
}
+ espik_leave();
}
void espik_config_set (t_info config)
{
+ espik_enter();
+
ecore_config_int_set ("/config/server/len", 1);
ecore_config_string_set ("/config/server/0/host", config.server->host);
ecore_config_int_set ("/config/server/0/port", (int)config.server->port);
@@ -120,4 +134,5 @@ void espik_config_set (t_info config)
espik_debug_print ("Save ecore_config failed");
exit (-1);
}
+ espik_leave();
}
diff --git a/src/espik_debug.c b/src/espik_debug.c
index 74910c6..7d2aee1 100644
--- a/src/espik_debug.c
+++ b/src/espik_debug.c
@@ -12,8 +12,6 @@
#include <signal.h>
#endif /* _ESPIK_DEBUG_ */
-/*static int indent_level = 0;*/
-
inline void espik_debug_bt (int num)
{
#ifdef __GLIBC__
diff --git a/src/espik_debug.h b/src/espik_debug.h
index dca4f5f..75c65a1 100644
--- a/src/espik_debug.h
+++ b/src/espik_debug.h
@@ -3,14 +3,15 @@
#include "espik_global.h"
-#define DEBUG_FILENO stderr
+#define DEBUG_PRINT_FILENO stdout
+#define DEBUG_ENTLEV_FILENO stderr
#if defined (_ESPIK_DEBUG_) && defined (__GNUC__)
#define espik_debug_print(fmt, ...) \
{ \
- fprintf (DEBUG_FILENO, "%s+%i @%s: '", __FILE__, __LINE__, __func__); \
- fprintf (DEBUG_FILENO, fmt, ##__VA_ARGS__); \
- fprintf (DEBUG_FILENO, "'\n"); \
+ fprintf (DEBUG_PRINT_FILENO, "%s +%i @%s: '", __FILE__, __LINE__, __func__); \
+ fprintf (DEBUG_PRINT_FILENO, fmt, ##__VA_ARGS__); \
+ fprintf (DEBUG_PRINT_FILENO, "'\n"); \
}
#else
#define espik_debug_print(fmt, ...) \
@@ -18,6 +19,37 @@
}
#endif /* _ESPIK_DEBUG_ && __GNUC__ */
+#ifdef _ESPIK_DEBUG_
+#ifndef _ESPIK_DEBIG_INDENT_LEVEL
+#define _ESPIK_DEBIG_INDENT_LEVEL
+int __indent_level;
+#endif /* _ESPIK_DEBIG_INDENT_LEVEL */
+
+
+#define espik_enter() \
+{ \
+ __indent_level++; \
+ fprintf (DEBUG_ENTLEV_FILENO, ">(%d)%*c%s +%i @%s\n", __indent_level, __indent_level, ' ', __FILE__, __LINE__, __func__); \
+}
+
+#define espik_leave() \
+{ \
+ fprintf (DEBUG_ENTLEV_FILENO, "<(%d)%*c%s +%i @%s\n", __indent_level, __indent_level, ' ', __FILE__, __LINE__, __func__); \
+ __indent_level--; \
+}
+
+#else
+
+#define espik_enter() \
+{ \
+}
+
+#define espik_leave() \
+{ \
+}
+
+#endif /* _ESPIK_DEBUG_ */
+
inline void espik_bt (void);
void espik_debug_init();
void kill_me (short num);
diff --git a/src/espik_irc.c b/src/espik_irc.c
index 731d7ad..cd3a572 100644
--- a/src/espik_irc.c
+++ b/src/espik_irc.c
@@ -9,9 +9,9 @@
#include "espik_irc.h"
#include "espik_error.h"
/*#include "espik_common_handler.h"*/
-#include "espik.h"
#include "espik_net.h"
#include "espik_debug.h"
+#include "espik.h"
char* current_chan;
@@ -46,6 +46,7 @@ char** separate_commandline (char *msg)
{
unsigned int len;
char** two_words;
+ espik_enter();
/* Yes, do nothing, just get len ! */
for (len = 0 ; msg[len] != ' ' && msg[len] != '\t' ; len++);
@@ -61,6 +62,7 @@ char** separate_commandline (char *msg)
}
while (*two_words[1] == ' ' || *two_words[1] == '\t');
+ espik_leave();
return (two_words);
}
@@ -68,6 +70,7 @@ char** separate_commandline (char *msg)
void string_upper (char *str)
{
unsigned int len, i;
+ espik_enter();
len = strlen (str);
@@ -77,27 +80,33 @@ void string_upper (char *str)
str[i] -= 0x20;
}
espik_debug_print ("string_upper: %s", str);
+ espik_leave();
}
#endif
unsigned short sendmsg_len (char* msg)
{
+ espik_enter();
+ espik_leave();
return (strlen (msg) + 2);
}
static buf_t make_buffer(int len)
{
buf_t buf;
+ espik_enter();
buf.buf = malloc (sizeof(char) * len);
buf.len = len;
+ espik_leave();
return (buf);
}
char* irc_privmsg (char* chan, char* msg)
{
buf_t out;
+ espik_enter();
out = make_buffer (strlen ("PRIVMSG") + 1 /* "PRIVMSG " */
+ strlen (chan) + 2 /* ":<channel> " */
@@ -105,12 +114,14 @@ char* irc_privmsg (char* chan, char* msg)
snprintf (out.buf, out.len, "PRIVMSG %s :%s", chan, msg);
+ espik_leave();
return (out.buf);
}
char* irc_join (char* chan __UNUSED__, char* msg)
{
buf_t out;
+ espik_enter();
/* Could also by '&' and so one ...
* have to look on RFC, dev will be done with # only */
@@ -118,6 +129,7 @@ char* irc_join (char* chan __UNUSED__, char* msg)
{
espik_debug_print ("%s is not a channel", msg);
espik_debug_print ("Usage: /JOIN #channel");
+ espik_leave();
return (0);
}
@@ -126,12 +138,14 @@ char* irc_join (char* chan __UNUSED__, char* msg)
snprintf (out.buf, out.len, "JOIN %s", msg);
+ espik_leave();
return (out.buf);
}
char* irc_part (char* chan, char* msg)
{
buf_t out;
+ espik_enter();
if (msg[0] != '#')
{
@@ -154,12 +168,14 @@ char* irc_part (char* chan, char* msg)
snprintf (out.buf, out.len, "PART %s :%s", sep[0], sep[1]);
}
+ espik_leave();
return (out.buf);
}
char* irc_quit (char* chan __UNUSED__, char* msg)
{
buf_t out;
+ espik_enter();
out = make_buffer (strlen ("QUIT") + 2 /* "QUIT :" */
+ strlen (msg) + 1); /* "<msg>EOF" */
@@ -175,16 +191,20 @@ char* irc_quit (char* chan __UNUSED__, char* msg)
irc_disconnect(sock);
*/
+ espik_leave();
return (out.buf);
}
char* irc_raw (char* chan __UNUSED__, char* msg)
{
+ espik_enter();
+ espik_leave();
return (msg);
}
char* irc_nick (char* chan __UNUSED__, char* nick)
{
+ espik_enter();
buf_t out;
out = make_buffer (strlen ("NICK") + 1 /* "NICK " */
@@ -194,26 +214,32 @@ char* irc_nick (char* chan __UNUSED__, char* nick)
espik_debug_print ("NICK CHANGED REQUEST: %s", nick);
+ espik_leave();
return (out.buf);
}
#if 0
Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__)
{
+ espik_enter();
+ espik_leave();
return (NULL);
}
void irc_disconnect (Ecore_Con_Server *sock)
{
+ espik_enter();
espik_debug_print ("> irc_disconnect");
ecore_main_loop_quit ();
espik_debug_print ("< irc_disconnect");
+ espik_leave();
}
#endif
char* irc_send (char* msg)
{
char* out;
+ espik_enter();
out = NULL;
@@ -242,6 +268,7 @@ char* irc_send (char* msg)
if (!out)
{
espik_debug_print ("%s is not a know command", cmd_and_message[0]);
+ espik_leave();
return (0);
}
}
@@ -251,9 +278,13 @@ char* irc_send (char* msg)
}
if (!out)
+ {
+ espik_leave();
return (0);
+ }
espik_debug_print ("%sn", out);
+ espik_leave();
return (out);
}
diff --git a/src/espik_net.c b/src/espik_net.c
index 460009c..219e262 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -23,6 +23,7 @@ Ecore_Con_Server* con_sock;
void espik_con_init (t_info serv_info)
{
int nb_launch;
+ espik_enter();
nb_launch = ecore_con_init ();
@@ -56,10 +57,12 @@ void espik_con_init (t_info serv_info)
espik_debug_print ("ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL)");
exit (-1);
}
+ espik_leave();
}
void espik_con_up()
{
+ espik_enter();
printf ("Connected\n");
espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>");
@@ -79,10 +82,12 @@ void espik_con_up()
espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>");
connected++;
+ espik_leave();
}
void espik_con_shutdown ()
{
+ espik_enter();
/* espik_debug_print ("> espik_con_shutdown"); */
if (!connected)
@@ -93,12 +98,14 @@ void espik_con_shutdown ()
/* espik_debug_print ("< espik_con_shutdown"); */
ecore_main_loop_quit ();
+ espik_leave();
}
void espik_raw_send (char *msg)
{
int len;
char* out;
+ espik_enter();
len = strlen (msg) + 3;
@@ -118,4 +125,5 @@ void espik_raw_send (char *msg)
/* espik_debug_print ("%d", ret); */
free (out);
+ espik_leave();
}