From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e25bef67663eb0b1 X-Google-Attributes: gid103376,public X-Google-Thread: 10baf0,e25bef67663eb0b1 X-Google-Attributes: gid10baf0,public X-Google-ArrivalTime: 2001-05-09 16:33:41 PST Path: newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!chnws02.mediaone.net!chnws06.ne.mediaone.net!24.91.0.34!typhoon.ne.mediaone.net.POSTED!not-for-mail From: "Jeff Creem" Newsgroups: comp.windows.x.kde,comp.lang.ada References: <3AF9985D.63B5E511@uundz.de> Subject: Re: Glueing ADA to C++: Process sharing X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Wed, 09 May 2001 23:33:09 GMT NNTP-Posting-Host: 24.147.67.93 X-Complaints-To: abuse@mediaone.net X-Trace: typhoon.ne.mediaone.net 989451189 24.147.67.93 (Wed, 09 May 2001 19:33:09 EDT) NNTP-Posting-Date: Wed, 09 May 2001 19:33:09 EDT Organization: Road Runner Xref: newsfeed.google.com comp.windows.x.kde:8931 comp.lang.ada:7419 Date: 2001-05-09T23:33:09+00:00 List-Id: It is just a guess but if you are using the default Linux thread model of GNAT (meaning that you are not using Linux threads but fsu threads). Check the docs and readme file to figure out how to change the threading model to use Linux threads for Ada tasks. Also you realize that your Ada task as written is a processor hog (I assume this is just an example). Also there is probably no reason that the task spec should be in the package spec in this case. (Not the problem here just a style issue) "Tilman Gloetzner" wrote in message news:3AF9985D.63B5E511@uundz.de... > Hello, > > In the test program below, I am glueing an ADA package to a KDE > application. > The main loop is in the KDE application, while the ADA package contains > an independent > task which is to be rendezvoued by the KDE application. That all works. > > Process switching somehow represents a problem: Once the ADA task is > started, it > should be running continously. Instead, the ADA task blocks, and only > continues when > the window of the application is moved or an entry point of the Ada task > is rendezvoued. > > I am not sure if this is related to ADA (I am using gnat) or to KDE, > so I posted it to both newsgroups. > > > Help is very much appriciated (I really have no idea on how to tackle > this). > > > Thanks, > > Tilman > > > > =================== Makefile ================================== > CXXFLAGS = -Wall > INCLUDES= -I/opt/kde/include -I/usr/lib/qt/include -I/usr/local/include > -I. > QT_INCLUDES = -I/usr/lib/qt/include > > LDFLAGS = -L/opt/kde/lib -L/usr/X11/lib -L/usr/local/lib > LIB_X11 = -lX11 $(LIBSOCKET) > LIB_QT = -lqt $(LIB_X11) > LIB_KDECORE = -lkdecore -lXext $(LIB_QT) > LIB_KDEUI = -lkdeui $(LIB_KDECORE) > LIB_KFM = -lkfm $(LIB_KDEUI) > LIB_KFILE = -lkfile $(LIB_KFM) > > > ada_2_c.ali: ada_2_c.adb ada_2_c.ads > gnatmake -c ada_2_c.adb -o ada_2_c.o > gnatbind -n ada_2_c > > > c_main.moc: c_main.h > moc $< > $@ > > c_main.o: c_main.c c_main.h c_main.moc > $(CXX) -c $(CXXFLAGS) $(INCLUDES) $< -o $@ > > atask_n_kde: c_main.o ada_2_c.ali > gnatlink -v ada_2_c.ali c_main.o $ $(LIB_KFILE) $(LDFLAGS) -o $@ > > clean: > rm -f *.o *~ *.ali *.moc atask_n_kde > > ================== c_main.h =================================== > #ifndef __KTESTAPP_H > #define __KTESTAPP_H > #include > #include > #include > #include > #include > > #define VERSION 0.1 > > > > class KTestWindow:public KTMainWindow { > Q_OBJECT > > public: > KTestWindow(); > ~KTestWindow(); > > protected: > void paintEvent(QPaintEvent *); > > protected slots: > void Start(void); > void Stop(void); > void Register(void); > /* void openWidget(); */ > > private: > int paintEventCounter; > > }; > #endif > > ================== c_main.c =================================== > #include > #include > #include > #include > #include "c_main.moc" > #include "c_main.h" > #include > > #define SUCCESS 0 > > extern "C" { > void adainit (void); > void adafinal (void); > void Ada_TaskStart(void); > void Ada_TaskStop(void); > void Ada_TaskQuit(void); > void Ada_TaskRegister(int a,int b); > } > > > > > KTestWindow::KTestWindow() : KTMainWindow () { > > this->setFixedSize(400,50); > KMenuBar* mb = menuBar (); > mb->insertItem(i18n("&Quit"),kapp, SLOT(quit()),CTRL+Key_Q); > mb->insertItem(i18n("&TaskStart"),this, SLOT(Start()),CTRL+Key_S); > mb->insertItem(i18n("TaskSt&op"),this, SLOT(Stop()),CTRL+Key_O); > mb->insertItem(i18n("Task&Multiply"),this, > SLOT(Register()),CTRL+Key_M); > paintEventCounter = 0; > } > > > KTestWindow::~KTestWindow() { > Ada_TaskQuit(); > } > > void KTestWindow::Start() { > Ada_TaskStart(); > } > > void KTestWindow::Stop() { > Ada_TaskStop(); > } > > void KTestWindow::Register() { > Ada_TaskRegister(paintEventCounter,2); > } > > void KTestWindow::paintEvent(QPaintEvent *) { > char buf[20]; > QPainter > qp; > > cout<<"KTestWindow::paintEvent"< paintEventCounter++; > if (qp.begin(this)) { > sprintf(buf,"#paintEvents = %d",paintEventCounter); > qp.eraseRect(0,35,200,15); > qp.drawText(0,35,200,15,AlignBottom | AlignLeft,buf); > qp.end(); > } > } > > int main(int argc,char **argv) { > KApplication* a; > KTestWindow *t; > > printf("Start main\n"); > adainit(); > a = new KApplication(argc, argv, "ktest"); > a->enableSessionManagement(); > t = new KTestWindow(); > a->setTopWidget(t); > t->show(); > > return a->exec(); > adafinal(); > printf("End main\n"); > return(SUCCESS); > } > > ======================== ada_2_c.ads (package definition) > =========================== > with INTERFACES.C;use INTERFACES.C; > with INTERFACES.C.STRINGS; use INTERFACES.C.STRINGS; > use INTERFACES; > > > > package Ada_2_C is > > procedure TaskStart; > procedure TaskStop; > procedure TaskQuit; > procedure TaskRegister(A:Int;B:Int); > > pragma Export(CPP,TaskStart,"Ada_TaskStart"); > pragma Export(CPP,TaskStop,"Ada_TaskStop"); > pragma Export(CPP,TaskQuit,"Ada_TaskQuit"); > pragma Export(CPP,TaskRegister,"Ada_TaskRegister"); > > task type MULTIPLY_TASK_T is > entry Register(A:Integer;B:Integer); > entry Start; > entry Stop; > entry Quit; > end MULTIPLY_TASK_T; > > type MULTIPLY_TASK_REF is access MULTIPLY_TASK_T; > end Ada_2_C; > > ==================== ada_2_C.adb(package body) > ============================ > with TEXT_IO;use TEXT_IO; > package body Ada_2_C is > Multiply: Multiply_Task_Ref; > package Int_IO is new INTEGER_IO(INTEGER); > > procedure TaskStart is > begin > Multiply := new Multiply_Task_T; > Multiply.Start; > end TaskStart; > > procedure TaskStop is > begin > Multiply.Stop; > end TaskStop; > > procedure TaskQuit is > begin > Multiply.Quit; > end TaskQuit; > > procedure TaskRegister(A:Int;B:Int) is > begin > Multiply.Register(Integer(A),Integer(B)); > end TaskRegister; > > > task body MULTIPLY_TASK_T is > C,D : Integer := 0; > Counter: Integer := 0; > Run_Flag: Boolean := False; > Quit_Flag: Boolean := False; > begin > while (Quit_Flag = False) loop > select > accept Register(A:Integer;B:Integer) do > if (Run_Flag = True) then > C := A; > D := B; > end if; > end Register; > or > accept Start do > Put_Line("Multiply_Task.Start"); > Counter := 0; > Run_Flag := True; > end Start; > or > accept Stop do > Put_Line("Multiply_Task.Stop"); > Run_Flag := False; > end Stop; > or > accept Quit do > Put_Line("Multiply_Task.Quit"); > Run_Flag := False; > Quit_Flag := True; > end Quit; > or > delay(0.0); > if (Run_Flag = True) then > Put("Multiply_Task("); > Int_IO.Put(Counter); > Put("): "); > Int_IO.Put(C); > Put(" * "); > Int_IO.Put(D); > Put(" = "); > Int_IO.Put(C*D); > New_Line; > Counter := Counter + 1; > end if; > end select; > end loop; > end MULTIPLY_TASK_T; > > > end Ada_2_C;