diff options
-rw-r--r-- | Ivy.cxx | 357 | ||||
-rw-r--r-- | Ivy.d | 1 | ||||
-rw-r--r-- | IvyApplication.cxx | 34 | ||||
-rw-r--r-- | IvyApplication.d | 2 | ||||
-rw-r--r-- | IvyApplication.h | 41 | ||||
-rw-r--r-- | IvyCallback.h | 132 | ||||
-rw-r--r-- | Ivy_glfw.cxx | 2 | ||||
-rw-r--r-- | Ivy_glfw.d | 3 | ||||
-rw-r--r-- | Ivycpp.h | 71 | ||||
-rw-r--r-- | Makefile | 73 | ||||
-rw-r--r-- | Makefile.options | 2 | ||||
-rw-r--r-- | ivyprobe.c | 199 | ||||
-rw-r--r-- | testIvy.cxx | 87 |
13 files changed, 1004 insertions, 0 deletions
@@ -0,0 +1,357 @@ +// Ivy.cpp: implementation of the Ivy class. +// +////////////////////////////////////////////////////////////////////// + + +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> + +// DEBUG +#include <sys/types.h> +#include <unistd.h> +// END DEBUG + +#include "Ivycpp.h" +#include "IvyApplication.h" + +#ifdef USE_GLFW +GLFWmutex Ivy::ivyCbmutex = NULL; +#endif + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +/* +# _ +# | | +# ___ | |_ ___ _ _ _ __ +# / __| | __| / _ \ | | | | | '__| +# | (__ _ \ |_ | __/ | |_| | | | +# \___| (_) \__| \___| \__,_| |_| +*/ +Ivy::Ivy() +{ + +} + +#ifndef USE_GLFW +Ivy::Ivy(const char* name, const char * ready, IvyApplicationCallback *callback, + bool argaFrc) +{ + IvyC::IvyInit( name, ready, ApplicationCb, callback, DieCb, callback ); +} +#else +Ivy::Ivy(const char* name, const char * ready, IvyApplicationCallback *callback, + bool argaFrc, GLFWmutex _ivyCbmutex) +{ + IvyC::IvyInit( name, ready, ApplicationCb, callback, DieCb, callback ); + ivyCbmutex= _ivyCbmutex; +} +#endif +/* +# _____ _ +# | __ \ | | +# | | | | | |_ ___ _ _ _ __ +# | | | | | __| / _ \ | | | | | '__| +# | |__| | _ \ |_ | __/ | |_| | | | +# |_____/ (_) \__| \___| \__,_| |_| +*/ +Ivy::~Ivy() +{ + +} + + + + +/* +# _ _ +# | | | | +# ___ | |_ __ _ _ __ | |_ +# / __| | __| / _` | | '__| | __| +# \__ \ \ |_ | (_| | | | \ |_ +# |___/ \__| \__,_| |_| \__| + */ +void Ivy::start(const char *domain) +{ + IvyC::IvyStart( domain ); + +#ifdef USE_GLFW + GLFWthread threadId = glfwCreateThread (ivyMainLoopInSeparateThread, NULL); + if (threadId <= 0) { + printf ("Erreur : glfwCreateThread\n"); + exit (-1); + } +#endif +} + + + +#ifndef USE_GLFW +void Ivy::ivyMainLoop (void) +{ + // DEBUG + + IvyC::IvyMainLoop (NULL,NULL); +} +#else +void GLFWCALL Ivy::ivyMainLoopInSeparateThread (void *arg) +{ + // DEBUG + + if (getenv ("DEBUG") != NULL) { + char commande[256]; + sprintf (commande, "/usr/bin/X11/xterm -e /usr/bin/gdb -pid %d", getpid()); + printf ("DBG> launching %s\n", commande); + if (fork () == 0) { + system (commande); + exit (0); + } + printf ("DBG> Sortie de sleep\n"); + sleep (5); + } + // END DEBUG + + IvyC::IvyMainLoop (NULL,NULL); +} +#endif + + + + + + +/* +# _ _ __ +# | | | '_ \ +# ___ | |_ ___ | |_) | +# / __| | __| / _ \ | .__/ +# \__ \ \ |_ | (_) | | | +# |___/ \__| \___/ |_| + */ +void Ivy::stop() +{ + IvyC::IvyStop( ); +} + + + +/* +# _ _ _ __ __ __ _ +# | | (_) | | | \/ | / _` | +# | |__ _ _ __ __| | | \ / | ___ | (_| | +# | '_ \ | | | '_ \ / _` | | |\/| | / __| \__, | +# | |_) | | | | | | | | (_| | | | | | \__ \ __/ | +# |_.__/ |_| |_| |_| \__,_| |_| |_| |___/ |___/ + */ +long Ivy::BindMsg(const char *regexp, IvyMessageCallback *cb) +{ + return (long)IvyC::IvyBindMsg( MsgCb , cb, regexp ); +} + + +long Ivy::BindMsg (IvyMessageCallback *cb, const char *regexp, ... ) +{ + char buffer[4096]; + va_list args; + + va_start( args, regexp ); /* Initialize variable arguments. */ + vsprintf( buffer, regexp, args ); + va_end( args); + return (long)IvyC::IvyBindMsg( MsgCb , cb, buffer ); +} + + +/* +# _ _ _ _ _ __ __ __ _ +# | | | | | | (_) | | | \/ | / _` | +# | | | | _ __ | |__ _ _ __ __| | | \ / | ___ | (_| | +# | | | | | '_ \ | '_ \ | | | '_ \ / _` | | |\/| | / __| \__, | +# | |__| | | | | | | |_) | | | | | | | | (_| | | | | | \__ \ __/ | +# \____/ |_| |_| |_.__/ |_| |_| |_| \__,_| |_| |_| |___/ |___/ + */ +void Ivy::UnbindMsg(int id) +{ + IvyC::IvyUnbindMsg( (IvyC::MsgRcvPtr)id ); +} + + + + +/* +# ____ _ _ _____ _ _ +# | _ \ (_) | | | __ \ (_) | | +# | |_) | _ _ __ __| | | | | | _ _ __ ___ ___ | |_ +# | _ < | | | '_ \ / _` | | | | | | | | '__| / _ \ / __| | __| +# | |_) | | | | | | | | (_| | | |__| | | | | | | __/ | (__ \ |_ +# |____/ |_| |_| |_| \__,_| |_____/ |_| |_| \___| \___| \__| +# __ __ __ _ +# | \/ | / _` | +# | \ / | ___ | (_| | +# | |\/| | / __| \__, | +# | | | | \__ \ __/ | +# |_| |_| |___/ |___/ + */ +void Ivy::BindDirectMsg(IvyDirectMessageCallback *callback) +{ + IvyC::IvyBindDirectMsg( MsgDirectCb , callback); +} + + + + +/* +# ______ _ __ __ __ _ +# / ____| | | | \/ | / _` | +# | (___ ___ _ __ __| | | \ / | ___ | (_| | +# \___ \ / _ \ | '_ \ / _` | | |\/| | / __| \__, | +# .____) | | __/ | | | | | (_| | | | | | \__ \ __/ | +# \_____/ \___| |_| |_| \__,_| |_| |_| |___/ |___/ + */ +int Ivy::SendMsg(const char * message, ... ) +{ + char buffer[4096]; + va_list args; + + va_start( args, message ); /* Initialize variable arguments. */ + vsnprintf( buffer, sizeof (buffer), message, args ); + va_end( args); + return IvyC::IvySendMsg (buffer); +} + + +/* +# ______ _ _____ _ _ +# / ____| | | | __ \ (_) | | +# | (___ ___ _ __ __| | | | | | _ _ __ ___ ___ | |_ +# \___ \ / _ \ | '_ \ / _` | | | | | | | | '__| / _ \ / __| | __| +# .____) | | __/ | | | | | (_| | | |__| | | | | | | __/ | (__ \ |_ +# \_____/ \___| |_| |_| \__,_| |_____/ |_| |_| \___| \___| \__| +# __ __ __ _ +# | \/ | / _` | +# | \ / | ___ | (_| | +# | |\/| | / __| \__, | +# | | | | \__ \ __/ | +# |_| |_| |___/ |___/ + */ +void Ivy::SendDirectMsg(IvyApplication * app, int id, const char *message) +{ + IvyC::IvySendDirectMsg( app->appptr, id, (char *)message ); +} + + + +/* +# _____ _ +# / ____| | | +# | | | | __ _ ___ ___ ___ ___ +# | | | | / _` | / __| / __| / _ \ / __| +# | |____ | | | (_| | \__ \ \__ \ | __/ \__ \ +# \_____| |_| \__,_| |___/ |___/ \___| |___/ + */ +void Ivy::Classes(int argc, const char **argv ) +{ + IvyC::IvySetFilter( argc, argv); +} + + + +/* +# ___ _ __ _ __ _ _ _ _ +# / _ \ | '_ \ | '_ \ | | (_) | | (_) +# | |_| | | |_) | | |_) | | | _ ___ __ _ | |_ _ ___ _ __ +# | _ | | .__/ | .__/ | | | | / __| / _` | | __| | | / _ \ | '_ \ +# | | | | | | | | | | | | | (__ | (_| | \ |_ | | | (_) | | | | | +# |_| |_| |_| |_| |_| |_| \___| \__,_| \__| |_| \___/ |_| |_| +# _____ _ +# / ____| | | +# | | | |__ +# | | | '_ \ +# | |____ | |_) | +# \_____| |_.__/ + */ +void Ivy::ApplicationCb( IvyC::IvyClientPtr app, void *user_data, IvyC::IvyApplicationEvent event ) +{ +IvyApplicationCallback *callback = (IvyApplicationCallback *)user_data; +IvyApplication *appObj = new IvyApplication( app ); + switch ( event ) + { + case IvyC::IvyApplicationConnected: + callback->OnApplicationConnected( appObj ); + break; + case IvyC::IvyApplicationDisconnected: + callback->OnApplicationDisconnected( appObj ); + break; + } +delete appObj; +} + + + +/* +# _____ _ _____ _ +# | __ \ (_) / ____| | | +# | | | | _ ___ | | | |__ +# | | | | | | / _ \ | | | '_ \ +# | |__| | | | | __/ | |____ | |_) | +# |_____/ |_| \___| \_____| |_.__/ + */ +void Ivy::DieCb( IvyC::IvyClientPtr app, void *user_data, int id ) +{ +} + + + +/* +# __ __ __ _ _____ _ _ +# | \/ | / _` | | __ \ (_) | | +# | \ / | ___ | (_| | | | | | _ _ __ ___ ___ | |_ +# | |\/| | / __| \__, | | | | | | | | '__| / _ \ / __| | __| +# | | | | \__ \ __/ | | |__| | | | | | | __/ | (__ \ |_ +# |_| |_| |___/ |___/ |_____/ |_| |_| \___| \___| \__| +# _____ _ +# / ____| | | +# | | | |__ +# | | | '_ \ +# | |____ | |_) | +# \_____| |_.__/ + */ +void Ivy::MsgDirectCb( IvyC::IvyClientPtr app, void *user_data, int id, char *msg ) +{ +IvyDirectMessageCallback *cb = (IvyDirectMessageCallback *)user_data; +IvyApplication *appObj = new IvyApplication( app ); + cb->OnDirectMessage( appObj, id, msg ); +delete appObj; +} + + + + +/* +# __ __ __ _ _____ _ +# | \/ | / _` | / ____| | | +# | \ / | ___ | (_| | | | | |__ +# | |\/| | / __| \__, | | | | '_ \ +# | | | | \__ \ __/ | | |____ | |_) | +# |_| |_| |___/ |___/ \_____| |_.__/ + */ +void Ivy::MsgCb( IvyC::IvyClientPtr app, void *user_data, int argc, char **argv ) +{ +#ifdef USE_GLFW + if (ivyCbmutex) + glfwLockMutex (ivyCbmutex); +#endif + + IvyMessageCallback *cb = (IvyMessageCallback *)user_data; + IvyApplication *appObj = new IvyApplication( app ); + + cb->OnMessage( appObj, argc, (const char **)argv ); + delete appObj; + +#ifdef USE_GLFW + if (ivyCbmutex) + glfwUnlockMutex (ivyCbmutex); +#endif +} @@ -0,0 +1 @@ +Ivy.o: Ivy.cxx Ivycpp.h IvyCallback.h IvyApplication.h diff --git a/IvyApplication.cxx b/IvyApplication.cxx new file mode 100644 index 0000000..b4df2cf --- /dev/null +++ b/IvyApplication.cxx @@ -0,0 +1,34 @@ +// IvyApplication.cpp : implementation file +// + +#include "IvyApplication.h" + +///////////////////////////////////////////////////////////////////////////// +// IvyApplication + +IvyApplication::IvyApplication(IvyC::IvyClientPtr ptr) +{ +appptr = ptr; +} + +IvyApplication::~IvyApplication() +{ + +} + + +const char *IvyApplication::GetName(void) +{ +return IvyC::IvyGetApplicationName( appptr ); +} + + +const char *IvyApplication::GetHost(void) +{ +return IvyC::IvyGetApplicationHost( appptr ); +} + + + + + diff --git a/IvyApplication.d b/IvyApplication.d new file mode 100644 index 0000000..aaecda3 --- /dev/null +++ b/IvyApplication.d @@ -0,0 +1,2 @@ +IvyApplication.o: IvyApplication.cxx IvyApplication.h Ivycpp.h \ + IvyCallback.h diff --git a/IvyApplication.h b/IvyApplication.h new file mode 100644 index 0000000..0a66763 --- /dev/null +++ b/IvyApplication.h @@ -0,0 +1,41 @@ +#if !defined(IVYAPPLICATION_H) +#define IVYAPPLICATION_H + + +// IvyApplication.h : header file +// + + +#include "Ivycpp.h" + + +///////////////////////////////////////////////////////////////////////////// +// IvyApplication command target + +class IvyApplication +{ +// Attributes +public: + +IvyC::IvyClientPtr appptr; + +// Operations +public: + IvyApplication(IvyC::IvyClientPtr ptr ); + virtual ~IvyApplication(); + +// Overrides +public: + const char *GetName(void); + const char *GetHost(void); + + + +}; + +///////////////////////////////////////////////////////////////////////////// + +#endif // !defined(IVYAPPLICATION_H) + + + diff --git a/IvyCallback.h b/IvyCallback.h new file mode 100644 index 0000000..1d47dc4 --- /dev/null +++ b/IvyCallback.h @@ -0,0 +1,132 @@ +// IvyCallback.h : Interface for the IvyMessageCallback Class +// : Interface for the IvyDirectMessageCallback Class +// : Interface for the IvyApplicationCallback Class +// + + +#ifndef __IVYXTLOOP_H__ +#define __IVYXTLOOP_H__ + +class IvyApplication; + +/* Callback for the normal bus Message */ + +class IvyMessageCallback { +public: + virtual void OnMessage (IvyApplication *app, int argc, const char **argv )=0; + virtual ~IvyMessageCallback() + { + } +}; + + +class IvyMessageCallbackFunction: public IvyMessageCallback { +public: + typedef void ( *IvyMessageCallback_fun )( IvyApplication *app, void *user_data, int argc, const char **argv ); + IvyMessageCallback_fun MessageCb; + void *data; + +public: + IvyMessageCallbackFunction ( IvyMessageCallback_fun m_cb, void *udata = NULL ) : MessageCb( m_cb ) + { + data = udata; + } + ~IvyMessageCallbackFunction () + { + } + void OnMessage (IvyApplication *app, int argc, const char **argv) + { + (*MessageCb) (app, data, argc, argv); + } + +/* raccourci d'ecriture */ +#define BUS_CALLBACK( m , d ) new IvyMessageCallbackFunction( m, d ) +}; +/* template Class Callback for the normal bus Message */ +template <class T> class IvyMessageCallbackOf : public IvyMessageCallback { + +protected: + T* Object; + typedef void ( T::*IvyMessageCallback_fun )( IvyApplication *app, int argc, const char **argv ); + IvyMessageCallback_fun MessageCb; + +public: + IvyMessageCallbackOf ( T* o, IvyMessageCallback_fun m_cb ) : Object (o), MessageCb( m_cb ) + { + } + ~IvyMessageCallbackOf () + { + } + void OnMessage (IvyApplication *app, int argc, const char **argv) + { + (Object->*MessageCb) (app, argc, argv); + } + +/* raccourci d'ecriture */ +#define BUS_CALLBACK_OF( cl, m ) new IvyMessageCallbackOf<cl>( this, m ) +}; +/* Callback for the direct Message */ +class IvyDirectMessageCallback { +public: + virtual void OnDirectMessage (IvyApplication *app, int id, const char *arg ) = 0; + virtual ~IvyDirectMessageCallback () {}; +}; + +/* Application Callback */ + +class IvyApplicationCallback { +public: + virtual void OnApplicationConnected (IvyApplication *app) = 0; + virtual void OnApplicationDisconnected (IvyApplication *app) = 0; + virtual ~IvyApplicationCallback() + { + } +}; +class IvyApplicationNullCallback : public IvyApplicationCallback { +public: + virtual void OnApplicationConnected (IvyApplication *app) + {}; + virtual void OnApplicationDisconnected (IvyApplication *app) + {}; + virtual ~IvyApplicationNullCallback() + { + } +}; + +// Static function CB +class IvyApplicationCallbackFunction: public IvyApplicationCallback { +public: + typedef void ( *IvyApplicationCallback_fun )( IvyApplication *app ); + IvyApplicationCallback_fun ApplicationConnectedCb; + IvyApplicationCallback_fun ApplicationDisconnectedCb; + +public: + IvyApplicationCallbackFunction ( IvyApplicationCallback_fun con_cb, IvyApplicationCallback_fun disc_cb) + : ApplicationConnectedCb( con_cb ), ApplicationDisconnectedCb( disc_cb ) + { + } + ~IvyApplicationCallbackFunction () + { + } + virtual void OnApplicationConnected (IvyApplication *app) + { + (*ApplicationConnectedCb) (app); + }; + virtual void OnApplicationDisconnected (IvyApplication *app) + { + (*ApplicationDisconnectedCb) (app); + }; + +/* raccourci d'ecriture */ +#define BUS_APPLICATION_CALLBACK( conn, disconn ) new IvyApplicationCallbackFunction( conn, disconn ) +}; +/* Callback for the die Message */ +class IvyDieCallback { +public: + virtual bool OnDie (IvyApplication *app, int id, const char *arg ) = 0; + virtual ~IvyDieCallback() + { + } +}; +#endif // __IVYXTLOOP_H__ + diff --git a/Ivy_glfw.cxx b/Ivy_glfw.cxx new file mode 100644 index 0000000..d74dcd9 --- /dev/null +++ b/Ivy_glfw.cxx @@ -0,0 +1,2 @@ +#define USE_GLFW 1 +#include "Ivy.cxx" diff --git a/Ivy_glfw.d b/Ivy_glfw.d new file mode 100644 index 0000000..b828482 --- /dev/null +++ b/Ivy_glfw.d @@ -0,0 +1,3 @@ +Ivy_glfw.o: Ivy_glfw.cxx Ivy.cxx Ivycpp.h /usr/X11R6/include/GL/glfw.h \ + /usr/X11R6/include/GL/gl.h /usr/X11R6/include/GL/glext.h \ + /usr/X11R6/include/GL/glu.h IvyCallback.h IvyApplication.h diff --git a/Ivycpp.h b/Ivycpp.h new file mode 100644 index 0000000..f55c5c7 --- /dev/null +++ b/Ivycpp.h @@ -0,0 +1,71 @@ +// Ivy.h: interface for the Ivy class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(__IVY_H) +#define __IVY_H + +#ifdef USE_GLFW +#include <GL/glfw.h> +#endif + +namespace IvyC +{ + #include <Ivy/ivyloop.h> + #include <Ivy/ivysocket.h> + #include <Ivy/ivy.h> +} +#include "IvyCallback.h" + +class IvyApplication; + +class Ivy +{ + +public: + + Ivy(); +#ifdef USE_GLFW + Ivy( const char *name, const char* ready, IvyApplicationCallback *callback, + bool argaFrc, GLFWmutex _ivyCbmutex = NULL); +#else + Ivy( const char *name, const char* ready, IvyApplicationCallback *callback, + bool argaFrc); +#endif + virtual ~Ivy(); + + static long BindMsg (const char *regexp, IvyMessageCallback *cb ); + static long BindMsg (IvyMessageCallback *cb, const char *regexp, ... ); + static void UnbindMsg( int id ); + static void Classes( int argc, const char **argv ); + + static int SendMsg(const char * message, ... ); + static void SendDirectMsg( IvyApplication *app, int id, + const char *message); + static void BindDirectMsg( IvyDirectMessageCallback *callback ); + + + + static void start(const char *domain); + static void stop(); +#ifndef USE_GLFW +static void ivyMainLoop (); +#endif + +protected: + + static void ApplicationCb( IvyC::IvyClientPtr app, void *user_data, + IvyC::IvyApplicationEvent event ) ; + static void DieCb( IvyC::IvyClientPtr app, void *user_data, int id ) ; + static void MsgCb( IvyC::IvyClientPtr app, void *user_data, int argc, char **argv ) ; + static void MsgDirectCb( IvyC::IvyClientPtr app, void *user_data, int id, char *msg ) ; +#ifdef USE_GLFW + static void GLFWCALL ivyMainLoopInSeparateThread (void *arg); + +private: + static GLFWmutex ivyCbmutex; + +#endif +}; + +#endif // !defined(__IVY_H) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a2af1cc --- /dev/null +++ b/Makefile @@ -0,0 +1,73 @@ +os=$(shell uname -s) + +ifeq ($(os),Darwin) +IVY_PATH := $(HOME)/src-ext/ivy-c-3.6/src +CPPFLAGS= -MMD -I$(IVY_PATH) +DSO_EXT=.dylib +LD=g++ -dynamiclib -single_module +LDFLAGS=-L$(IVY_PATH) -L/sw/lib -framework OpenGL -framework AGL -framework Carbon +else +CPPFLAGS= -MMD -I/usr/X11R6/include +DSO_EXT=.so +LD=g++ -shared +LDFLAGS= +endif + + +CXXFILES := Ivy.cxx IvyApplication.cxx +OBJECTS := $(CXXFILES:.cxx=.o) +DEPS := $(CXXFILES:.cxx=.d) + +CXXFILES_GLFW := Ivy_glfw.cxx IvyApplication.cxx +OBJECTS_GLFW := $(CXXFILES_GLFW:.cxx=.o) +DEPS_GLFW := $(CXXFILES_GLFW:.cxx=.d) + + +LD_QUICKSTART_INFO= +GCXXINCS= +LIBIVY = libIvy.a +LIBIVY_GLFW = libIvy_glfw.a +PERHAPS64= `uname -m | perl -ne "print /64/ ? '64' : '';"` + +ifeq ($(PERHAPS64), '64') + XTLIB = -L/usr/X11R6/lib/ +else + XTLIB = -L/usr/X11R6/lib64/ +endif + +#a mettre dans les makefiles generant les executables +#LLDLIBS= -rpath. -L. -lTextureLabel -lInventor -lInventorXt -lXm -lXt -lttf -lGL -lGLU -lm + + +ifdef DEBUG +CC= g++ -fPIC -g -Wall -pg $(CPPFLAGS) +else +CC= g++ -fPIC -O2 -Wall $(CPPFLAGS) +endif + +default: $(LIBIVY) $(LIBIVY_GLFW) + +%.o: %.cxx + $(CC) -c $< + +$(LIBIVY) : $(OBJECTS) + ar rv $(LIBIVY) $(OBJECTS) + ranlib $(LIBIVY) + +$(LIBIVY_GLFW) : $(OBJECTS_GLFW) + ar rv $(LIBIVY_GLFW) $(OBJECTS_GLFW) + ranlib $(LIBIVY_GLFW) + + + +LLDLIBS = -L $(XTLIB) -Wl,-rpath,$(XTLIB) -L. -Wl,-rpath,. -L$(IVY_PATH)/src + +testIvy : testIvy.cxx + g++ -g $(LDFLAGS) $(LLDLIBS) -o $@ testIvy.cxx -lIvy -lxtivy -lXt -lX11 + + +clean : + /bin/rm -f *$(DSO_EXT) $(OBJECTS) $(LIBIVY) $(DEPS) \ + $(OBJECTS_GLFW) $(LIBIVY_GLFW) $(DEPS_GLFW) core *.o *.d *~ + +-include *.d diff --git a/Makefile.options b/Makefile.options new file mode 100644 index 0000000..44f8431 --- /dev/null +++ b/Makefile.options @@ -0,0 +1,2 @@ +OPTIMIZER= -pch -n32 -g -r4000 + diff --git a/ivyprobe.c b/ivyprobe.c new file mode 100644 index 0000000..f41f310 --- /dev/null +++ b/ivyprobe.c @@ -0,0 +1,199 @@ +/* + * Ivy probe + * + * Copyright (C) 1997-2000 + * Centre d'Études de la Navigation Aérienne + * + * Main and only file + * + * Authors: François-Régis Colin <fcolin@cena.fr> + * + * $Id$ + * + * Please refer to file version.h for the + * copyright notice regarding this software + */ + + +#define IVYMAINLOOP + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> + +#include "ivyloop.h" +#include "ivysocket.h" +#include "ivy.h" +#include "timer.h" + +int app_count = 0; +int wait_count = 0; + +void Callback (IvyClientPtr app, void *user_data, int argc, char *argv[]) +{ + int i; + printf ("%s sent ",IvyGetApplicationName(app)); + for (i = 0; i < argc; i++) + printf(" '%s'",argv[i]); + printf("\n"); +} + +void HandleStdin (Channel channel, HANDLE fd, void *data) +{ + char buf[4096]; + char *line; + char *cmd; + char *arg; + int id; + IvyClientPtr app; + int err; + line = fgets(buf, 4096, stdin); + if (!line) { + IvyChannelClose (channel); + IvyStop(); + + return; + } + if (*line == '.') { + cmd = strtok (line, ".: \n"); + + if (strcmp (cmd, "die") == 0) { + arg = strtok (NULL, " \n"); + if (arg) { + app = IvyGetApplication (arg); + if (app) + IvySendDieMsg (app); + else printf ("No Application %s!!!\n",arg); + } + + } else if (strcmp(cmd, "dieall-yes-i-am-sure") == 0) { + arg = IvyGetApplicationList(); + arg = strtok (arg, " \n"); + while (arg) { + app = IvyGetApplication (arg); + if (app) + IvySendDieMsg (app); + else + printf ("No Application %s!!!\n",arg); + arg = strtok (NULL, " "); + } + + } else if (strcmp(cmd, "bind") == 0) { + arg = strtok (NULL, "'"); + if (arg) { + IvyBindMsg (Callback, NULL, arg); + } + + } else if (strcmp(cmd, "where") == 0) { + arg = strtok (NULL, " \n"); + if (arg) { + app = IvyGetApplication (arg); + if (app) + printf ("Application %s on %s\n",arg, IvyGetApplicationHost (app)); + else printf ("No Application %s!!!\n",arg); + } + } else if (strcmp(cmd, "direct") == 0) { + arg = strtok (NULL, " \n"); + if (arg) { + app = IvyGetApplication (arg); + if (app) { + arg = strtok (NULL, " "); + id = atoi (arg) ; + arg = strtok (NULL, "'"); + IvySendDirectMsg (app, id, arg); + } else + printf ("No Application %s!!!\n",arg); + } + + } else if (strcmp(cmd, "who") == 0) { + printf("Apps: %s\n", IvyGetApplicationList()); + + } else if (strcmp(cmd, "help") == 0) { + fprintf(stderr,"Commands list:\n"); + printf(" .help - this help\n"); + printf(" .quit - terminate this application\n"); + printf(" .die appname - send die msg to appname\n"); + printf(" .dieall-yes-i-am-sure - send die msg to all applis\n"); + printf(" .direct appname id 'arg' - send direct msg to appname\n"); + printf(" .where appname - on which host is appname\n"); + printf(" .bind 'regexp' - add a msg to receive\n"); + printf(" .who - who is on the bus\n"); + } else if (strcmp(cmd, "quit") == 0) { + exit(0); + } + } else { + cmd = strtok (buf, "\n"); + err = IvySendMsg (cmd); + printf("-> Sent to %d peer%s\n", err, err == 1 ? "" : "s"); + } +} + +void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent event) +{ + char *appname; + char *host; + char **msgList; + appname = IvyGetApplicationName (app); + host = IvyGetApplicationHost (app); + switch (event) { + + case IvyApplicationConnected: + app_count++; + printf("%s connected from %s\n", appname, host); +/* printf("Application(%s): Begin Messages\n", appname);*/ + msgList = IvyGetApplicationMessages (app); + while (*msgList ) + printf("%s subscribes to '%s'\n",appname,*msgList++); +/* printf("Application(%s): End Messages\n",appname);*/ + if (app_count == wait_count) + IvyChannelSetUp (0, NULL, NULL, HandleStdin); + break; + + case IvyApplicationDisconnected: + app_count--; + printf("%s disconnected from %s\n", appname, host); + break; + + default: + printf("%s: unkown event %d\n", appname, event); + break; + } +} + + +int main(int argc, char *argv[]) +{ + int c; + int timer_test = 0; + char busbuf [1024] = ""; + const char* bus = 0; + while ((c = getopt(argc, argv, "d:b:w:t")) != EOF) + switch (c) { + case 'b': + strcpy (busbuf, optarg); + bus = busbuf; + break; + case 'w': + wait_count = atoi(optarg) ; + break; + case 't': + timer_test = 1; + break; + } + + /* Mainloop management */ + + IvyInit ("IVYPROBE", "IVYPROBE READY", ApplicationCallback,NULL,NULL,NULL); + for (; optind < argc; optind++) + IvyBindMsg (Callback, NULL, argv[optind]); + + if (wait_count == 0) + IvyChannelSetUp (0, NULL, NULL, HandleStdin); + + IvyStart (bus); + + IvyMainLoop (0); + return 0; +} diff --git a/testIvy.cxx b/testIvy.cxx new file mode 100644 index 0000000..53d83d8 --- /dev/null +++ b/testIvy.cxx @@ -0,0 +1,87 @@ +/* + * Ivy probe + * + * Copyright (C) 1997-1999 + * Centre d'Études de la Navigation Aérienne + * + * Main and only file + * + * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr> + * + * $Id$ + * + * Please refer to file version.h for the + * copyright notice regarding this software + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/time.h> +#include <unistd.h> +#include <X11/Intrinsic.h> +#include "Ivy.h" +#include "IvyApplication.h" + + +class IvyTest : public IvyApplicationCallback, public IvyMessageCallback { +public: + Ivy *bus; + void Start(); + void OnApplicationConnected(IvyApplication *app); + void OnApplicationDisconnected(IvyApplication *app); + void OnMessage(IvyApplication *app, int argc, const char **argv); + IvyTest(); +}; +IvyTest :: IvyTest() +{ +} +void IvyTest :: Start() +{ + bus = new Ivy( "TestIvy", "TestIvy READY", this ); + bus->BindMsg( "(.*)", this ); + bus->start(NULL); +} +void IvyTest :: OnMessage(IvyApplication *app, int argc, const char **argv) +{ + int i; + printf ("%s sent ",app->GetName()); + for (i = 0; i < argc; i++) + printf(" '%s'",argv[i]); + printf("\n"); +} +void IvyTest :: OnApplicationConnected (IvyApplication *app) +{ + const char *appname; + const char *host; + appname = app->GetName(); + host = app->GetHost(); + + printf("%s connected from %s\n", appname, host); + +} +void IvyTest :: OnApplicationDisconnected (IvyApplication *app) +{ + const char *appname; + const char *host; + appname = app->GetName (); + host = app->GetHost(); + + printf("%s disconnected from %s\n", appname, host); +} + +int main(int argc, char *argv[]) +{ + XtAppContext cntx = XtCreateApplicationContext(); + IvyTest test; + test.bus->setXtAppContext(cntx); + + test.Start(); + + XtAppMainLoop (cntx); + + return 0; +} + + |