summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbustico2011-01-25 16:27:07 +0000
committerbustico2011-01-25 16:27:07 +0000
commit018db51fa49c2761516f4377a4958a2ce5b91fe3 (patch)
tree5c6624c3f88148bc1c9941c7aa5d0eedd7bef320
parentc55fdd5c11903b4a7f8d706f7065997410c154c7 (diff)
downloadivy-cplusplus-018db51fa49c2761516f4377a4958a2ce5b91fe3.zip
ivy-cplusplus-018db51fa49c2761516f4377a4958a2ce5b91fe3.tar.gz
ivy-cplusplus-018db51fa49c2761516f4377a4958a2ce5b91fe3.tar.bz2
ivy-cplusplus-018db51fa49c2761516f4377a4958a2ce5b91fe3.tar.xz
-add a Qt flavor of ivy c++ library
-add testIvyQt to show how to use ivy-c++ with Qt -fix testIvyXt --Cette ligne, et les suivantes ci-dessous, seront ignorees-- D ivyprobe.c A + testIvyXt.cxx AM ivyqtloop.h M Ivycpp.h A ivyqtloop.cxx D testIvy.cxx M Ivy.cxx A ivy-c++.readme A testIvyQt.cxx M Makefile
-rw-r--r--Ivy.cxx9
-rw-r--r--Ivycpp.h14
-rw-r--r--Makefile71
-rw-r--r--ivy-c++.readme30
-rw-r--r--ivyprobe.c199
-rw-r--r--ivyqtloop.cxx170
-rw-r--r--ivyqtloop.h67
-rw-r--r--testIvyQt.cxx194
-rw-r--r--testIvyXt.cxx (renamed from testIvy.cxx)45
9 files changed, 585 insertions, 214 deletions
diff --git a/Ivy.cxx b/Ivy.cxx
index bc40715..f737c4a 100644
--- a/Ivy.cxx
+++ b/Ivy.cxx
@@ -34,8 +34,14 @@ GLFWmutex Ivy::ivyCbmutex = NULL;
*/
Ivy::Ivy()
{
+}
+#ifdef USE_XT
+void Ivy::setXtAppContext(XtAppContext cntx )
+{
+ IvyC::IvyXtChannelAppContext (cntx);
}
+#endif
#ifndef USE_GLFW
Ivy::Ivy(const char* name, const char * ready, IvyApplicationCallback *callback,
@@ -99,12 +105,13 @@ void Ivy::start(const char *domain)
void Ivy::ivyMainLoop (void)
{
// DEBUG
-
+#ifndef USE_XT
#if (IVYMAJOR_VERSION == 3) && (IVYMINOR_VERSION < 9)
IvyC::IvyMainLoop(NULL, NULL);
#else
IvyC::IvyMainLoop();
#endif
+#endif // USE_XT
}
#else
void GLFWCALL Ivy::ivyMainLoopInSeparateThread (void *arg)
diff --git a/Ivycpp.h b/Ivycpp.h
index 5d6f1b6..c78f19e 100644
--- a/Ivycpp.h
+++ b/Ivycpp.h
@@ -9,9 +9,19 @@
#include <GL/glfw.h>
#endif
+#ifdef USE_XT
+#include <X11/Intrinsic.h>
+#endif
+
+
namespace IvyC
{
+#ifdef USE_XT
+ #include "ivyxtloop.h"
+#else
#include <Ivy/ivyloop.h>
+#endif
+
#include <Ivy/ivysocket.h>
#include <Ivy/ivy.h>
}
@@ -53,7 +63,9 @@ public:
#ifndef USE_GLFW
static void ivyMainLoop ();
#endif
-
+#ifdef USE_XT
+ static void setXtAppContext(XtAppContext cntx);
+#endif
protected:
static void ApplicationCb( IvyC::IvyClientPtr app, void *user_data,
diff --git a/Makefile b/Makefile
index a8fe677..644f0f4 100644
--- a/Makefile
+++ b/Makefile
@@ -12,8 +12,13 @@ ifeq ($(os),Darwin)
else
PERHAPS64 := $(shell uname --machine | perl -ne "print /64/ ? '64' : '';")
LIB:= lib$(PERHAPS64)
- XTLIB = -L/usr/$(LIB) -L/usr/X11R6/$(LIB)
- CPPFLAGS = -MMD -I/usr/X11R6/include
+ XTLIB= -L/usr/$(LIB) -L/usr/X11R6/$(LIB)
+ XTOPT= -DUSE_XT
+ QTINC= -I/usr/lib/qt4/include -I/usr/lib/qt4/include/QtCore -I/usr/lib/qt4/include/QtGui
+ QTOPT= -D_REENTRANT -DQT_SHARED
+ QTLIB= -lQtGui -lQtCore -lpthread
+
+ CPPFLAGS = -MMD -I/usr/X11R6/include -I/usr/local/include/Ivy
DSO_EXT = .so
LD = g++ -shared -fPIC
#PREFIX=/usr/local
@@ -25,6 +30,17 @@ else
endif
endif
+CASESENSITIVE = "yes"
+ifeq ($(CASESENSITIVE), "no")
+ PCRE_OPT=PCRE_CASELESS
+ REGCOMP_OPT=REG_ICASE
+else
+ PCRE_OPT=0
+ REGCOMP_OPT=REG_EXTENDED
+endif
+REGEXP= -DUSE_PCRE_REGEX -DPCRE_OPT=$(PCRE_OPT)
+PCREINC = $(shell pcre-config --cflags)
+
CXXFILES := Ivy.cxx IvyApplication.cxx
OBJECTS := $(CXXFILES:.cxx=.o)
@@ -34,12 +50,22 @@ CXXFILES_GLFW := Ivy_glfw.cxx IvyApplication.cxx
OBJECTS_GLFW := $(CXXFILES_GLFW:.cxx=.o)
DEPS_GLFW := $(CXXFILES_GLFW:.cxx=.d)
+CXXFILES_QT := Ivy.cxx IvyApplication.cxx ivyqtloop.cxx
+OBJECTS_QT := $(CXXFILES_QT:.cxx=.o)
+DEPS_QT := $(CXXFILES_QT:.cxx=.d)
+
+CXXFILES_XT := Ivy.cxx IvyApplication.cxx
+OBJECTS_XT := Ivy_Xt.o IvyApplication.o
+DEPS_XT := $(CXXFILES_XT:.cxx=.d)
+
LD_QUICKSTART_INFO=
GCXXINCS=
LIBIVY = libIvy
LIBIVY_GLFW = $(LIBIVY)_glfw
+LIBIVY_QT = $(LIBIVY)_Qt
+LIBIVY_XT = $(LIBIVY)_Xt
LIBIVY_STATIC = $(LIBIVY).a
LIBIVY_GLFW_STATIC = $(LIBIVY_GLFW).a
@@ -50,6 +76,13 @@ LIBIVY_DEPLIBS = -livy
LIBIVY_GLFW_SHARED = $(LIBIVY_GLFW)$(DSO_EXT)
LIBIVY_GLFW_DEPLIBS = -lglfw -livy -lX11 -lXext -lXxf86vm -lGL -lpthread
+LIBIVY_QT_SHARED = $(LIBIVY_QT)$(DSO_EXT)
+LIBIVY_QT_DEPLIBS = -lX11 -lXext -lQtCore -lpthread
+
+LIBIVY_XT_SHARED = $(LIBIVY_XT)$(DSO_EXT)
+LIBIVY_XT_DEPLIBS = -lX11 -lXext -lXt -lpthread
+
+
#a mettre dans les makefiles generant les executables
#LLDLIBS= -rpath. -L. -lTextureLabel -lInventor -lInventorXt -lXm -lXt -lttf -lGL -lGLU -lm
@@ -63,11 +96,25 @@ else
DBG=
endif
-default: $(LIBIVY_STATIC) $(LIBIVY_GLFW_STATIC) $(LIBIVY_SHARED) $(LIBIVY_GLFW_SHARED)
+default: $(LIBIVY_STATIC) $(LIBIVY_GLFW_STATIC) $(LIBIVY_SHARED) \
+ $(LIBIVY_GLFW_SHARED) $(LIBIVY_QT_SHARED) $(LIBIVY_XT_SHARED) \
+ testIvyQt testIvyXt
%.o: %.cxx
$(CC) -c $<
+
+Ivy_Xt.o: Ivy.cxx
+ $(CC) $(XTOPT) $< -c -o Ivy_Xt.o
+
+ivyqtloop.o: ivyqtloop.moc
+
+ivyqtloop.moc: ivyqtloop.h
+ /usr/lib/qt4/bin/moc $(QTOPT) $(QTINC) -i $< -o $@
+
+ivyqtloop.o: ivyqtloop.cxx
+ $(CC) $(QTINC) $(QTOPT) -c $<
+
$(LIBIVY_STATIC) : $(OBJECTS)
ar rv $(LIBIVY_STATIC) $(OBJECTS)
ranlib $(LIBIVY_STATIC)
@@ -82,6 +129,14 @@ $(LIBIVY_SHARED) : $(OBJECTS)
$(LIBIVY_GLFW_SHARED) : $(OBJECTS_GLFW)
$(LD) -o $(LIBIVY_GLFW_SHARED) $(OBJECTS_GLFW) $(LDFLAGS) $(LIBIVY_GLFW_DEPLIBS)
+$(LIBIVY_QT_SHARED) : $(OBJECTS_QT)
+ $(LD) -o $(LIBIVY_QT_SHARED) $(OBJECTS_QT) \
+ $(LDFLAGS) $(LIBIVY_QT_DEPLIBS)
+
+$(LIBIVY_XT_SHARED) : $(OBJECTS_XT)
+ $(LD) -o $(LIBIVY_XT_SHARED) $(OBJECTS_XT) \
+ $(LDFLAGS) $(LIBIVY_XT_DEPLIBS)
+
install: default
# headers
mkdir -p $(DESTDIR)$(PREFIX)/include/Ivy
@@ -109,8 +164,14 @@ install_mandriva64: default
LLDLIBS = -L $(XTLIB) -Wl,-rpath,$(XTLIB) -L. -Wl,-rpath,. -L$(IVY_PATH)/src
-testIvy : testIvy.cxx
- g++ -g $(XTLIB) $(LLDLIBS) -o $@ testIvy.cxx -lIvy -lxtivy -lXt -lX11
+testIvyXt : testIvyXt.cxx
+ g++ -g $(CPPFLAGS) $(XTLIB) $(LLDLIBS) -o $@ testIvyXt.cxx -lIvy -lxtivy -lXt -lX11 -lIvy_Xt
+
+testIvyQt.moc: testIvyQt.cxx
+ /usr/lib/qt4/bin/moc $(QTOPT) $(QTINC) -i $< -o $@
+
+testIvyQt : testIvyQt.cxx testIvyQt.moc
+ g++ -g $(QTOPT) $(QTINC) $(QTLIB) $(LLDLIBS) -o $@ testIvyQt.cxx -lIvy_Qt -livy
distclean clean :
diff --git a/ivy-c++.readme b/ivy-c++.readme
new file mode 100644
index 0000000..31a80a9
--- /dev/null
+++ b/ivy-c++.readme
@@ -0,0 +1,30 @@
+this is the c++ api for ivy.
+
+It's a wrapper over ivy-c, so ivy-c should be installed prior this.
+
+It is api compatible with the native ivy c++ implementation for windows.
+
+make all produce :
+
+° libIvy.so
+ a shared lib whith his own mainloop for console app.
+
+° libIvy_Qt.so
+ a shared lib which integrate in the Qt framework.
+
+
+° libIvy_Xt.so
+ a shared lib which integrate in the X toolkit mainloop
+
+° libIvy_glfw.so
+ a shared lib which integrate with glfw framework, in this case, there is a local
+ ivy mainloop in a thread, and another gl thread which does the drawing, beware that
+ you cannot directly call openGl within callback called by the ivy thread !!
+
+° testIvyQt
+ a test which demonstrate how to use Ivy and Qt
+
+° testIvyXt
+ a test which demonstrate how to use Ivy and Xt
+
+
diff --git a/ivyprobe.c b/ivyprobe.c
deleted file mode 100644
index f41f310..0000000
--- a/ivyprobe.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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/ivyqtloop.cxx b/ivyqtloop.cxx
new file mode 100644
index 0000000..17dfdae
--- /dev/null
+++ b/ivyqtloop.cxx
@@ -0,0 +1,170 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-2000
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Main loop based on the Qt trolltech Toolkit
+ *
+ * Authors: Alexandre Bustico
+ *
+ * $Id: ivyqtloop.c 3243 2008-03-21 09:03:34Z bustico $
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#ifdef WIN32
+#else
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <signal.h>
+#endif
+
+
+#include "ivyqtloop.h"
+#include "Ivy/ivydebug.h"
+
+IvyQt::IvyQt (struct _channel *chan, QObject *parent): QObject(parent),
+ channel (chan)
+{
+ id_read = new QSocketNotifier(channel->fd, QSocketNotifier::Read, this);
+ id_read->setEnabled(false);
+ connect(id_read, SIGNAL(activated(int)), SLOT(ivyRead(int)));
+
+ id_delete = new QSocketNotifier(channel->fd, QSocketNotifier::Exception, this);
+ id_delete->setEnabled(false);
+ connect(id_delete, SIGNAL(activated(int)), SLOT(ivyDelete(int)));
+
+ id_write = new QSocketNotifier(channel->fd, QSocketNotifier::Write, this);
+ id_write->setEnabled(false);
+ connect(id_write, SIGNAL(activated(int)), SLOT(ivyWrite(int)));
+}
+
+IvyQt::~IvyQt()
+{
+ //pas besoin de detruire les objets enfants, qt s'en charge
+}
+
+
+void IvyQt::startNotifiersRead()
+{
+ id_read->setEnabled(true);
+ id_delete->setEnabled(true);
+}
+
+void IvyQt::startNotifiersWrite()
+{
+ printf ("DEBUG> IvyQt::startNotifiersWrite\n");
+ id_write->setEnabled(true);
+}
+
+void IvyQt::removeNotifiersWrite()
+{
+ id_write->setEnabled(false);
+}
+
+void IvyQt::removeNotifiersRead()
+{
+ id_read->setEnabled(false);
+ id_delete->setEnabled(false);
+}
+
+
+void IvyQt::ivyRead (int fd)
+{
+ // TRACE("Handle Channel read %d\n",fd );
+ (*channel->handle_read)(channel,fd,channel->data);
+}
+
+void IvyQt::ivyWrite (int fd)
+{
+ printf ("DEBUG> IvyQt::ivyWrite\n");
+ // TRACE("Handle Channel write %d\n",fd );
+ (*channel->handle_write)(channel,fd,channel->data);
+}
+
+void IvyQt::ivyDelete (int fd)
+{
+ // TRACE("Handle Channel delete %d\n",*source );
+ (*channel->handle_delete)(channel->data);
+}
+
+
+
+void IvyChannelInit(void)
+{
+}
+
+void IvyChannelRemove( Channel channel )
+{
+
+ if ( channel->handle_delete )
+ (*channel->handle_delete)( channel->data );
+ channel->ivyQt->removeNotifiersRead();
+}
+
+
+
+Channel IvyChannelAdd(IVY_HANDLE fd, void *data,
+ ChannelHandleDelete handle_delete,
+ ChannelHandleRead handle_read,
+ ChannelHandleWrite handle_write
+ )
+{
+ Channel channel;
+
+ channel = (Channel) malloc (sizeof (struct _channel));
+ if ( !channel ) {
+ fprintf(stderr,"NOK Memory Alloc Error\n");
+ exit(0);
+ }
+
+ channel->handle_delete = handle_delete;
+ channel->handle_read = handle_read;
+ channel->handle_write = handle_write;
+ channel->data = data;
+ channel->fd = fd;
+ channel->ivyQt = new IvyQt(channel);
+ channel->ivyQt->startNotifiersRead();
+
+ return channel;
+}
+
+
+
+
+void IvyChannelAddWritableEvent(Channel channel)
+{
+ channel->ivyQt->startNotifiersWrite ();
+}
+
+void IvyChannelClearWritableEvent(Channel channel)
+{
+ channel->ivyQt->removeNotifiersWrite ();
+}
+
+
+void
+IvyChannelStop ()
+{
+ // not yet implemented
+}
+
+
+#include "ivyqtloop.moc"
diff --git a/ivyqtloop.h b/ivyqtloop.h
new file mode 100644
index 0000000..360efc6
--- /dev/null
+++ b/ivyqtloop.h
@@ -0,0 +1,67 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-2000
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Main loop based on the QT Toolkit (troltech)
+ *
+ * Authors: Alexandre Bustico
+ *
+ *
+ * $Id: ivyqtloop.h 1231 2011-01-11 16:34:15Z bustico $
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+
+#ifndef IVYQTLOOP_H
+#define IVYQTLOOP_H
+
+using namespace std;
+
+#include <Qt/qsocketnotifier.h>
+#include "Ivy/ivychannel.h"
+
+
+
+class IvyQt;
+
+struct _channel {
+ IvyQt *ivyQt;
+
+ int fd;
+ void *data;
+ ChannelHandleDelete handle_delete;
+ ChannelHandleRead handle_read;
+ ChannelHandleWrite handle_write;
+};
+
+class IvyQt : public QObject {
+ Q_OBJECT
+public:
+ IvyQt(struct _channel *chan, QObject *parent=0);
+ ~IvyQt();
+
+private slots:
+ void ivyRead (int);
+ void ivyWrite (int);
+ void ivyDelete (int);
+
+
+private:
+ struct _channel *channel;
+ QSocketNotifier* id_read;
+ QSocketNotifier* id_write;
+ QSocketNotifier* id_delete;
+
+public:
+ void startNotifiersRead ();
+ void startNotifiersWrite ();
+ void removeNotifiersRead ();
+ void removeNotifiersWrite ();
+};
+
+#endif // IVYQTLOOP_H
+
+
diff --git a/testIvyQt.cxx b/testIvyQt.cxx
new file mode 100644
index 0000000..ad5094d
--- /dev/null
+++ b/testIvyQt.cxx
@@ -0,0 +1,194 @@
+/*
+ * Ivy probe
+ *
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Main and only file
+ *
+ * Authors: Alexandre Bustico <alexandre.bustico@cena.fr>
+ *
+ * $Id: testIvyQt.cxx 1253 2006-05-24 13:02:58Z fourdan $
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/time.h>
+#include <unistd.h>
+#include <QApplication>
+
+#include <QFont>
+#include <QLCDNumber>
+#include <QPushButton>
+#include <QSlider>
+#include <QVBoxLayout>
+#include <QWidget>
+
+#include "Ivycpp.h"
+#include "IvyApplication.h"
+
+
+
+
+
+
+
+
+
+// int main(int argc, char *argv[])
+// {
+
+// IvyTest test;
+// test.bus->setXtAppContext(cntx);
+
+// test.Start();
+
+// XtAppMainLoop (cntx);
+
+// return 0;
+// }
+
+
+
+class MyWidget : public QWidget, public IvyApplicationCallback, public IvyMessageCallback
+ {
+ Q_OBJECT
+ public:
+ MyWidget(QWidget *parent = 0);
+
+ Ivy *bus;
+ void IvyStart();
+ void OnApplicationConnected(IvyApplication *app);
+ void OnApplicationDisconnected(IvyApplication *app);
+ void OnApplicationCongestion(IvyApplication *app);
+ void OnApplicationDecongestion(IvyApplication *app);
+ void OnApplicationFifoFull(IvyApplication *app);
+ void OnMessage(IvyApplication *app, int argc, const char **argv);
+
+ private:
+ QSlider *slider;
+ QLCDNumber *lcd;
+ QPushButton *quit;
+ static void ivyAppConnCb( IvyApplication *app ) {};
+ static void ivyAppDiscConnCb( IvyApplication *app ) {};
+
+private slots:
+ void sliderChange (int value);
+};
+
+
+
+ MyWidget::MyWidget(QWidget *parent)
+ : QWidget(parent)
+ {
+ quit = new QPushButton(tr("Quit"));
+ quit->setFont(QFont("Times", 18, QFont::Bold));
+
+ lcd = new QLCDNumber(2);
+ lcd->setSegmentStyle(QLCDNumber::Filled);
+
+ slider = new QSlider(Qt::Horizontal);
+ slider->setRange(0, 99);
+ slider->setValue(0);
+
+ connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
+ connect(slider, SIGNAL(valueChanged(int)),
+ lcd, SLOT(display(int)));
+ connect(slider, SIGNAL(valueChanged(int)),
+ this, SLOT(sliderChange(int)));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(quit);
+ layout->addWidget(lcd);
+ layout->addWidget(slider);
+ setLayout(layout);
+ }
+
+
+
+
+
+void MyWidget::IvyStart()
+{
+ bus = new Ivy( "TestIvyQt", "TestIvyQt READY",
+ BUS_APPLICATION_CALLBACK( ivyAppConnCb, ivyAppDiscConnCb ),false);
+ bus->BindMsg( "(\\d+)", this );
+ bus->start(NULL);
+}
+
+void MyWidget::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]);
+ int j = atoi (argv[i]);
+ slider->setValue(j);
+ }
+ printf("\n");
+}
+void MyWidget::OnApplicationConnected (IvyApplication *app)
+{
+ const char *appname;
+ const char *host;
+ appname = app->GetName();
+ host = app->GetHost();
+
+ printf("%s connected from %s\n", appname, host);
+
+}
+void MyWidget::OnApplicationDisconnected (IvyApplication *app)
+{
+ const char *appname;
+ const char *host;
+ appname = app->GetName ();
+ host = app->GetHost();
+
+ printf("%s disconnected from %s\n", appname, host);
+}
+
+void MyWidget::sliderChange (int val)
+{
+ char msg[256];
+
+ snprintf (msg, sizeof(msg), "TestIvyQt slider=%d", val);
+ bus->SendMsg (msg);
+}
+
+
+
+void MyWidget::OnApplicationCongestion(IvyApplication *app)
+{
+ std::cerr << "Ivy Congestion notififation\n";
+}
+void MyWidget::OnApplicationDecongestion(IvyApplication *app)
+{
+ std::cerr << "Ivy Decongestion notififation\n";
+}
+void MyWidget::OnApplicationFifoFull(IvyApplication *app)
+{
+ std::cerr << "Ivy FIFO Full notififation : MESSAGE WILL BE LOST\n";
+}
+
+
+
+ int main(int argc, char *argv[])
+ {
+ QApplication app(argc, argv);
+ MyWidget widget;
+ widget.IvyStart();
+
+ widget.show();
+ return app.exec();
+ }
+
+
+#include "testIvyQt.moc"
diff --git a/testIvy.cxx b/testIvyXt.cxx
index 53d83d8..4b51847 100644
--- a/testIvy.cxx
+++ b/testIvyXt.cxx
@@ -14,6 +14,9 @@
* copyright notice regarding this software
*/
+#include <iostream>
+#include <fstream>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -21,25 +24,38 @@
#include <sys/time.h>
#include <unistd.h>
#include <X11/Intrinsic.h>
-#include "Ivy.h"
+
+#define USE_XT
+
+#include "Ivycpp.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();
+ Ivy *bus;
+ void Start();
+ void OnApplicationConnected(IvyApplication *app);
+ void OnApplicationDisconnected(IvyApplication *app);
+ void OnApplicationCongestion(IvyApplication *app);
+ void OnApplicationDecongestion(IvyApplication *app);
+ void OnApplicationFifoFull(IvyApplication *app);
+ void OnMessage(IvyApplication *app, int argc, const char **argv);
+ IvyTest();
+
+private:
+
+ static void ivyAppConnCb( IvyApplication *app ) {};
+ static void ivyAppDiscConnCb( IvyApplication *app ) {};
};
+
IvyTest :: IvyTest()
{
}
void IvyTest :: Start()
{
- bus = new Ivy( "TestIvy", "TestIvy READY", this );
+ bus = new Ivy( "TestIvy", "TestIvy READY",
+ BUS_APPLICATION_CALLBACK( ivyAppConnCb, ivyAppDiscConnCb ),false);
bus->BindMsg( "(.*)", this );
bus->start(NULL);
}
@@ -71,6 +87,19 @@ void IvyTest :: OnApplicationDisconnected (IvyApplication *app)
printf("%s disconnected from %s\n", appname, host);
}
+void IvyTest::OnApplicationCongestion(IvyApplication *app)
+{
+ std::cerr << "Ivy Congestion notififation\n";
+}
+void IvyTest::OnApplicationDecongestion(IvyApplication *app)
+{
+ std::cerr << "Ivy Decongestion notififation\n";
+}
+void IvyTest::OnApplicationFifoFull(IvyApplication *app)
+{
+ std::cerr << "Ivy FIFO Full notififation : MESSAGE WILL BE LOST\n";
+}
+
int main(int argc, char *argv[])
{
XtAppContext cntx = XtCreateApplicationContext();