From 247750abcbf6760bbc52aa5d64fc375d6fbee8a3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 6 Dec 2020 19:28:06 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit 00d4f92b717fbcbed6f9eee361975d6ee5380d59) --- examples/catfile.cc | 55 --------------- examples/catfile.cpp | 55 +++++++++++++++ examples/dcasttest.cc | 72 -------------------- examples/dcasttest.cpp | 72 ++++++++++++++++++++ examples/flow.cc | 56 ---------------- examples/flow.cpp | 56 ++++++++++++++++ examples/hello_impl.cc | 76 --------------------- examples/hello_impl.cpp | 76 +++++++++++++++++++++ examples/helloclient.cc | 76 --------------------- examples/helloclient.cpp | 76 +++++++++++++++++++++ examples/hellodynamic.cc | 94 -------------------------- examples/hellodynamic.cpp | 94 ++++++++++++++++++++++++++ examples/hellodynamic2.cc | 124 ---------------------------------- examples/hellodynamic2.cpp | 124 ++++++++++++++++++++++++++++++++++ examples/hellomain.cc | 77 --------------------- examples/hellomain.cpp | 77 +++++++++++++++++++++ examples/helloserver.cc | 52 --------------- examples/helloserver.cpp | 52 +++++++++++++++ examples/irdemo.cc | 155 ------------------------------------------- examples/irdemo.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++ examples/playtofile_impl.cc | 99 --------------------------- examples/playtofile_impl.cpp | 99 +++++++++++++++++++++++++++ examples/playtofile_main.cc | 147 ---------------------------------------- examples/playtofile_main.cpp | 147 ++++++++++++++++++++++++++++++++++++++++ examples/referenceinfo.cc | 57 ---------------- examples/referenceinfo.cpp | 57 ++++++++++++++++ examples/streamsound.cc | 106 ----------------------------- examples/streamsound.cpp | 106 +++++++++++++++++++++++++++++ examples/testaggregation.cc | 73 -------------------- examples/testaggregation.cpp | 73 ++++++++++++++++++++ examples/testasubsys.cc | 142 --------------------------------------- examples/testasubsys.cpp | 142 +++++++++++++++++++++++++++++++++++++++ examples/testdhandle.cc | 115 -------------------------------- examples/testdhandle.cpp | 115 ++++++++++++++++++++++++++++++++ examples/testthreads.cc | 64 ------------------ examples/testthreads.cpp | 64 ++++++++++++++++++ examples/x11commtest.cc | 76 --------------------- examples/x11commtest.cpp | 76 +++++++++++++++++++++ 38 files changed, 1716 insertions(+), 1716 deletions(-) delete mode 100644 examples/catfile.cc create mode 100644 examples/catfile.cpp delete mode 100644 examples/dcasttest.cc create mode 100644 examples/dcasttest.cpp delete mode 100644 examples/flow.cc create mode 100644 examples/flow.cpp delete mode 100644 examples/hello_impl.cc create mode 100644 examples/hello_impl.cpp delete mode 100644 examples/helloclient.cc create mode 100644 examples/helloclient.cpp delete mode 100644 examples/hellodynamic.cc create mode 100644 examples/hellodynamic.cpp delete mode 100644 examples/hellodynamic2.cc create mode 100644 examples/hellodynamic2.cpp delete mode 100644 examples/hellomain.cc create mode 100644 examples/hellomain.cpp delete mode 100644 examples/helloserver.cc create mode 100644 examples/helloserver.cpp delete mode 100644 examples/irdemo.cc create mode 100644 examples/irdemo.cpp delete mode 100644 examples/playtofile_impl.cc create mode 100644 examples/playtofile_impl.cpp delete mode 100644 examples/playtofile_main.cc create mode 100644 examples/playtofile_main.cpp delete mode 100644 examples/referenceinfo.cc create mode 100644 examples/referenceinfo.cpp delete mode 100644 examples/streamsound.cc create mode 100644 examples/streamsound.cpp delete mode 100644 examples/testaggregation.cc create mode 100644 examples/testaggregation.cpp delete mode 100644 examples/testasubsys.cc create mode 100644 examples/testasubsys.cpp delete mode 100644 examples/testdhandle.cc create mode 100644 examples/testdhandle.cpp delete mode 100644 examples/testthreads.cc create mode 100644 examples/testthreads.cpp delete mode 100644 examples/x11commtest.cc create mode 100644 examples/x11commtest.cpp (limited to 'examples') diff --git a/examples/catfile.cc b/examples/catfile.cc deleted file mode 100644 index 3da8f75..0000000 --- a/examples/catfile.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include -#include -#include - -using namespace std; -using namespace Arts; - -int main(int argc, char **argv) -{ - if(argc != 2) - { - fprintf(stderr, "usage: catfile \n"); - exit(1); - } - - Dispatcher dispatcher; - FileInputStream file; - StdoutWriter writer; - - if(!file.open(argv[1])) - { - printf("can't open file %s\n",argv[1]); - exit(1); - } - - connect(file, writer); - - file.start(); - writer.start(); - - while(!file.eof()) - dispatcher.ioManager()->processOneEvent(false); -} diff --git a/examples/catfile.cpp b/examples/catfile.cpp new file mode 100644 index 0000000..3da8f75 --- /dev/null +++ b/examples/catfile.cpp @@ -0,0 +1,55 @@ +/* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ + +#include +#include +#include + +using namespace std; +using namespace Arts; + +int main(int argc, char **argv) +{ + if(argc != 2) + { + fprintf(stderr, "usage: catfile \n"); + exit(1); + } + + Dispatcher dispatcher; + FileInputStream file; + StdoutWriter writer; + + if(!file.open(argv[1])) + { + printf("can't open file %s\n",argv[1]); + exit(1); + } + + connect(file, writer); + + file.start(); + writer.start(); + + while(!file.eof()) + dispatcher.ioManager()->processOneEvent(false); +} diff --git a/examples/dcasttest.cc b/examples/dcasttest.cc deleted file mode 100644 index 5066cd7..0000000 --- a/examples/dcasttest.cc +++ /dev/null @@ -1,72 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include -#include -#include - -using namespace std; -using namespace Arts; - -/* - * This is a little test program that illustrates remote dynamic casting. - * Arts_SimpleSoundServer is a global object that is a SimpleSoundServer, - * so the first dynamic cast should succeed, while it is no Synth_PLAY, - * so the second dynamic cast should fail. - */ - -int main() -{ - Dispatcher dispatcher; - Object obj = Reference("global:Arts_SimpleSoundServer"); - - if(obj.isNull()) - { - cerr << "this test will only work if artsd is running" << endl; - exit(1); - } - - /* - * TODO: fix this. This fails currently as in the first line only an - * Object_stub will get created, no SimpleSoundServer_stub, and _cast - * which is used by DynamicCast wil only try to cast the _stub object, - * not do any further tricks. - */ - SimpleSoundServer server = DynamicCast(obj); - if(server.isNull()) - { - cerr << "remote dynamic casting is too restrictive" << endl; - exit(1); - } - - Synth_PLAY play = DynamicCast(obj); - if(!play.isNull()) - { - cerr << "remote dynamic casting doesn't do proper checks" << endl; - exit(1); - } - - cout << "remote dynamic casting seems to be fine" << endl; - return 0; -} diff --git a/examples/dcasttest.cpp b/examples/dcasttest.cpp new file mode 100644 index 0000000..5066cd7 --- /dev/null +++ b/examples/dcasttest.cpp @@ -0,0 +1,72 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include +#include +#include + +using namespace std; +using namespace Arts; + +/* + * This is a little test program that illustrates remote dynamic casting. + * Arts_SimpleSoundServer is a global object that is a SimpleSoundServer, + * so the first dynamic cast should succeed, while it is no Synth_PLAY, + * so the second dynamic cast should fail. + */ + +int main() +{ + Dispatcher dispatcher; + Object obj = Reference("global:Arts_SimpleSoundServer"); + + if(obj.isNull()) + { + cerr << "this test will only work if artsd is running" << endl; + exit(1); + } + + /* + * TODO: fix this. This fails currently as in the first line only an + * Object_stub will get created, no SimpleSoundServer_stub, and _cast + * which is used by DynamicCast wil only try to cast the _stub object, + * not do any further tricks. + */ + SimpleSoundServer server = DynamicCast(obj); + if(server.isNull()) + { + cerr << "remote dynamic casting is too restrictive" << endl; + exit(1); + } + + Synth_PLAY play = DynamicCast(obj); + if(!play.isNull()) + { + cerr << "remote dynamic casting doesn't do proper checks" << endl; + exit(1); + } + + cout << "remote dynamic casting seems to be fine" << endl; + return 0; +} diff --git a/examples/flow.cc b/examples/flow.cc deleted file mode 100644 index eaddf32..0000000 --- a/examples/flow.cc +++ /dev/null @@ -1,56 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld, stefan@space.twc.de - Nicolas Brodu, nicolas.brodu@free.fr - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "artsflow.h" -#include "connect.h" - -using namespace Arts; - -int main() -{ - Dispatcher dispatcher; - - // object creation - Synth_FREQUENCY freq; - Synth_WAVE_SIN sin; - Synth_PLAY play; - - // object initialization - setValue(freq, 440.0); - - // object connection - connect(freq, sin); - connect(sin, play, "invalue_left"); - connect(sin, play, "invalue_right"); - - // start all objects (maybe we should group objects like with QWidget - // parents and such?) - freq.start(); - sin.start(); - play.start(); - - // go - dispatcher.run(); -} diff --git a/examples/flow.cpp b/examples/flow.cpp new file mode 100644 index 0000000..eaddf32 --- /dev/null +++ b/examples/flow.cpp @@ -0,0 +1,56 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld, stefan@space.twc.de + Nicolas Brodu, nicolas.brodu@free.fr + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "artsflow.h" +#include "connect.h" + +using namespace Arts; + +int main() +{ + Dispatcher dispatcher; + + // object creation + Synth_FREQUENCY freq; + Synth_WAVE_SIN sin; + Synth_PLAY play; + + // object initialization + setValue(freq, 440.0); + + // object connection + connect(freq, sin); + connect(sin, play, "invalue_left"); + connect(sin, play, "invalue_right"); + + // start all objects (maybe we should group objects like with QWidget + // parents and such?) + freq.start(); + sin.start(); + play.start(); + + // go + dispatcher.run(); +} diff --git a/examples/hello_impl.cc b/examples/hello_impl.cc deleted file mode 100644 index 5f7bb68..0000000 --- a/examples/hello_impl.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - Modified by Nicolas Brodu, nicolas.brodu@free.fr - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. -*/ - -#include "hello_impl.h" -#include - -using namespace std; - -void Hello_impl::hellobase(const string& s) -{ - printf("Hellobase '%s'!\n",s.c_str()); -} - -void Hello_impl::hello(const string& s) -{ - printf("Hello '%s'!\n",s.c_str()); -} - -void Hello_impl::constructor(long i) -{ - myvalue=i; -} - -long Hello_impl::myValue() -{ - return myvalue; -} - -void Hello_impl::myValue(long newValue) -{ - myvalue=newValue; -} - -void Hello_impl::add(long a) -{ - myvalue += a; -} - -void Hello_impl::printTotal() -{ - printf("Total=%ld\n",myvalue); -} - -long Hello_impl::sum(long a, long b) -{ - return a+b; -} - -string Hello_impl::concat(const string& s1, const string& s2) -{ - return s1+s2; -} - -REGISTER_IMPLEMENTATION(Hello_impl); diff --git a/examples/hello_impl.cpp b/examples/hello_impl.cpp new file mode 100644 index 0000000..5f7bb68 --- /dev/null +++ b/examples/hello_impl.cpp @@ -0,0 +1,76 @@ +/* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + Modified by Nicolas Brodu, nicolas.brodu@free.fr + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. +*/ + +#include "hello_impl.h" +#include + +using namespace std; + +void Hello_impl::hellobase(const string& s) +{ + printf("Hellobase '%s'!\n",s.c_str()); +} + +void Hello_impl::hello(const string& s) +{ + printf("Hello '%s'!\n",s.c_str()); +} + +void Hello_impl::constructor(long i) +{ + myvalue=i; +} + +long Hello_impl::myValue() +{ + return myvalue; +} + +void Hello_impl::myValue(long newValue) +{ + myvalue=newValue; +} + +void Hello_impl::add(long a) +{ + myvalue += a; +} + +void Hello_impl::printTotal() +{ + printf("Total=%ld\n",myvalue); +} + +long Hello_impl::sum(long a, long b) +{ + return a+b; +} + +string Hello_impl::concat(const string& s1, const string& s2) +{ + return s1+s2; +} + +REGISTER_IMPLEMENTATION(Hello_impl); diff --git a/examples/helloclient.cc b/examples/helloclient.cc deleted file mode 100644 index f5f3410..0000000 --- a/examples/helloclient.cc +++ /dev/null @@ -1,76 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "hello.h" - -#include -#include - -using namespace Arts; - -int main(int argc, char **argv) -{ - if(argc != 2) - { - fprintf(stderr,"usage: %s \n",argv[0]); - exit(1); - } - - Dispatcher dispatcher; - - Hello h = Reference(argv[1]); - if(h.isNull()) - { - fprintf(stderr,"can't connect to the object\n"); - exit(1); - } - - const char *who = getenv("LOGNAME"); - if(!who) who = "stefan"; - - printf("calling h.hello(\"%s\")\n", who); - h.hello(who); -/* - printf("h->sum(2,4) is %ld\n", - h->sum2(2,4)); - - printf("h->sum(2,4,6) is %ld\n", - h->sum3(2,4,6)); -*/ - h.myValue(6); - printf("h.myValue(6), h.myValue() is %ld\n", - h.myValue()); - - printf("h.concat(\"MCOP \",\"is great!\") is \"%s\"\n", - h.concat("MCOP ","is great!").c_str()); - - /* - int i,j = 0; - for(i=0;i<100000;i++) - j += h->sum2(2,4); - printf("%d\n",j); - */ - return 0; -} diff --git a/examples/helloclient.cpp b/examples/helloclient.cpp new file mode 100644 index 0000000..f5f3410 --- /dev/null +++ b/examples/helloclient.cpp @@ -0,0 +1,76 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "hello.h" + +#include +#include + +using namespace Arts; + +int main(int argc, char **argv) +{ + if(argc != 2) + { + fprintf(stderr,"usage: %s \n",argv[0]); + exit(1); + } + + Dispatcher dispatcher; + + Hello h = Reference(argv[1]); + if(h.isNull()) + { + fprintf(stderr,"can't connect to the object\n"); + exit(1); + } + + const char *who = getenv("LOGNAME"); + if(!who) who = "stefan"; + + printf("calling h.hello(\"%s\")\n", who); + h.hello(who); +/* + printf("h->sum(2,4) is %ld\n", + h->sum2(2,4)); + + printf("h->sum(2,4,6) is %ld\n", + h->sum3(2,4,6)); +*/ + h.myValue(6); + printf("h.myValue(6), h.myValue() is %ld\n", + h.myValue()); + + printf("h.concat(\"MCOP \",\"is great!\") is \"%s\"\n", + h.concat("MCOP ","is great!").c_str()); + + /* + int i,j = 0; + for(i=0;i<100000;i++) + j += h->sum2(2,4); + printf("%d\n",j); + */ + return 0; +} diff --git a/examples/hellodynamic.cc b/examples/hellodynamic.cc deleted file mode 100644 index b55cbf4..0000000 --- a/examples/hellodynamic.cc +++ /dev/null @@ -1,94 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "hello.h" -#include "dynamicrequest.h" - -#include -#include -#include - -using namespace std; -using namespace Arts; - -/* - * Hellodynamic illustrates the usage of the DynamicRequest class to perform - * dynamic requests. There are two things you can try - * - * hellodynamic - * - * which will use a local implementation of a hello object, and - * - * hellodynamic - * - * which will use a remote implementation of a hello object. - */ -int main(int argc, char **argv) -{ - Dispatcher dispatcher; - Hello h; - - // Check if we should connect to a remote server: - if(argc == 2) - { - h = Reference(argv[1]); - if(h.isNull()) - { - fprintf(stderr,"can't connect to the object\n"); - exit(1); - } - } - - // find out logname - const char *who = getenv("LOGNAME"); - if(!who) who = "stefan"; - - printf("calling h.hello(\"%s\")\n", who); - - // the dynamic equivalent to h.hello(who) - DynamicRequest hellorequest(h); - - if(!hellorequest.method("hello").param(who).invoke()) - cout << "dynamic invocation to h.hello(...) failed" << endl; - - /* - Note: you could reuse hellorequest here, and indeed, if you - call the _same_ method over and over again, you'll get quite - some speed gain as the signature is only looked up once. - */ - - // set a value (no error checking here, I am lazy ;) - DynamicRequest(h).method("_set_myValue").param(42).invoke(); - - // get a value via "normal" interface - printf("h.myValue() is %ld (after setting it to 42)\n", h.myValue()); - - // call h.concat("MCOP ","rules.") dynamically - string s; - DynamicRequest(h).method("concat").param("MCOP ").param("rules.").invoke(s); - cout << "Conclusion of this test: " << s << endl; - - return 0; -} diff --git a/examples/hellodynamic.cpp b/examples/hellodynamic.cpp new file mode 100644 index 0000000..b55cbf4 --- /dev/null +++ b/examples/hellodynamic.cpp @@ -0,0 +1,94 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "hello.h" +#include "dynamicrequest.h" + +#include +#include +#include + +using namespace std; +using namespace Arts; + +/* + * Hellodynamic illustrates the usage of the DynamicRequest class to perform + * dynamic requests. There are two things you can try + * + * hellodynamic + * + * which will use a local implementation of a hello object, and + * + * hellodynamic + * + * which will use a remote implementation of a hello object. + */ +int main(int argc, char **argv) +{ + Dispatcher dispatcher; + Hello h; + + // Check if we should connect to a remote server: + if(argc == 2) + { + h = Reference(argv[1]); + if(h.isNull()) + { + fprintf(stderr,"can't connect to the object\n"); + exit(1); + } + } + + // find out logname + const char *who = getenv("LOGNAME"); + if(!who) who = "stefan"; + + printf("calling h.hello(\"%s\")\n", who); + + // the dynamic equivalent to h.hello(who) + DynamicRequest hellorequest(h); + + if(!hellorequest.method("hello").param(who).invoke()) + cout << "dynamic invocation to h.hello(...) failed" << endl; + + /* + Note: you could reuse hellorequest here, and indeed, if you + call the _same_ method over and over again, you'll get quite + some speed gain as the signature is only looked up once. + */ + + // set a value (no error checking here, I am lazy ;) + DynamicRequest(h).method("_set_myValue").param(42).invoke(); + + // get a value via "normal" interface + printf("h.myValue() is %ld (after setting it to 42)\n", h.myValue()); + + // call h.concat("MCOP ","rules.") dynamically + string s; + DynamicRequest(h).method("concat").param("MCOP ").param("rules.").invoke(s); + cout << "Conclusion of this test: " << s << endl; + + return 0; +} diff --git a/examples/hellodynamic2.cc b/examples/hellodynamic2.cc deleted file mode 100644 index 0647564..0000000 --- a/examples/hellodynamic2.cc +++ /dev/null @@ -1,124 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "hello.h" -#include "dynamicskeleton.h" -#include "debug.h" -#include "stdio.h" - -using namespace Arts; -using namespace std; - -namespace Arts { typedef DynamicSkeleton Object_dskel; } - -class HelloDynamic : public Arts::Object_dskel { -protected: - long myValue; - -public: - HelloDynamic() : Arts::Object_dskel("Hello") { - } - void process(long methodID, Arts::Buffer *request, Arts::Buffer *result) - { - const Arts::MethodDef& methodDef = getMethodDef(methodID); - - if(methodDef.name == "hello") // void hello(string); - { - string s; request->readString(s); - printf("Hello '%s'!\n",s.c_str()); - } - else if(methodDef.name == "_set_myValue") // attribute long myValue; - { - myValue = request->readLong(); - } - else if(methodDef.name == "_get_myValue") - { - result->writeLong(myValue); - } - else if(methodDef.name == "concat") - { - string s1; request->readString(s1); - string s2; request->readString(s2); - result->writeString(s1+s2); - } - else if(methodDef.name == "sum") - { - long a = request->readLong(); - long b = request->readLong(); - result->writeLong(a+b); - } - else - { - arts_fatal("method %s unimplemented", methodDef.name.c_str()); - } - } -}; - -/* - * this program illustrates that you /can/ implement an interface without - * using the IDL compiler skeleton do to so - this is useful if you want - * to create a language or object system binding, where you don't know - * all interfaces that are present at compile time - * - * however, it's definitely advanced stuff, and not for daily use ;) - */ -int main() -{ - Dispatcher dispatcher; - - Object obj = Object::_from_base(new HelloDynamic()); - if(obj.isNull()) - arts_fatal("dimpl is no object?"); - - HelloBase b = DynamicCast(obj); - if(b.isNull()) - arts_fatal("can't cast the object to HelloBase"); - - - Hello h = DynamicCast(obj); - /*arts_info("%d",obj.isCompatibleWith("Hello"));*/ - - if(h.isNull()) - arts_fatal("can't destringify to the object"); - - const char *who = getenv("LOGNAME"); - if(!who) who = "stefan"; - - arts_info("calling h.hello(\"%s\")", who); - h.hello(who); - - h.myValue(6); - arts_info("h.myValue(6), h.myValue() is %ld", - h.myValue()); - - arts_info("h.concat(\"MCOP \",\"is great!\") is \"%s\"", - h.concat("MCOP ","is great!").c_str()); - - /* - int i,j = 0; - for(i=0;i<100000;i++) - j += h.sum(2,4); - printf("%d\n",j); - */ - - return 0; -} diff --git a/examples/hellodynamic2.cpp b/examples/hellodynamic2.cpp new file mode 100644 index 0000000..0647564 --- /dev/null +++ b/examples/hellodynamic2.cpp @@ -0,0 +1,124 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "hello.h" +#include "dynamicskeleton.h" +#include "debug.h" +#include "stdio.h" + +using namespace Arts; +using namespace std; + +namespace Arts { typedef DynamicSkeleton Object_dskel; } + +class HelloDynamic : public Arts::Object_dskel { +protected: + long myValue; + +public: + HelloDynamic() : Arts::Object_dskel("Hello") { + } + void process(long methodID, Arts::Buffer *request, Arts::Buffer *result) + { + const Arts::MethodDef& methodDef = getMethodDef(methodID); + + if(methodDef.name == "hello") // void hello(string); + { + string s; request->readString(s); + printf("Hello '%s'!\n",s.c_str()); + } + else if(methodDef.name == "_set_myValue") // attribute long myValue; + { + myValue = request->readLong(); + } + else if(methodDef.name == "_get_myValue") + { + result->writeLong(myValue); + } + else if(methodDef.name == "concat") + { + string s1; request->readString(s1); + string s2; request->readString(s2); + result->writeString(s1+s2); + } + else if(methodDef.name == "sum") + { + long a = request->readLong(); + long b = request->readLong(); + result->writeLong(a+b); + } + else + { + arts_fatal("method %s unimplemented", methodDef.name.c_str()); + } + } +}; + +/* + * this program illustrates that you /can/ implement an interface without + * using the IDL compiler skeleton do to so - this is useful if you want + * to create a language or object system binding, where you don't know + * all interfaces that are present at compile time + * + * however, it's definitely advanced stuff, and not for daily use ;) + */ +int main() +{ + Dispatcher dispatcher; + + Object obj = Object::_from_base(new HelloDynamic()); + if(obj.isNull()) + arts_fatal("dimpl is no object?"); + + HelloBase b = DynamicCast(obj); + if(b.isNull()) + arts_fatal("can't cast the object to HelloBase"); + + + Hello h = DynamicCast(obj); + /*arts_info("%d",obj.isCompatibleWith("Hello"));*/ + + if(h.isNull()) + arts_fatal("can't destringify to the object"); + + const char *who = getenv("LOGNAME"); + if(!who) who = "stefan"; + + arts_info("calling h.hello(\"%s\")", who); + h.hello(who); + + h.myValue(6); + arts_info("h.myValue(6), h.myValue() is %ld", + h.myValue()); + + arts_info("h.concat(\"MCOP \",\"is great!\") is \"%s\"", + h.concat("MCOP ","is great!").c_str()); + + /* + int i,j = 0; + for(i=0;i<100000;i++) + j += h.sum(2,4); + printf("%d\n",j); + */ + + return 0; +} diff --git a/examples/hellomain.cc b/examples/hellomain.cc deleted file mode 100644 index 024f97a..0000000 --- a/examples/hellomain.cc +++ /dev/null @@ -1,77 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld stefan@space.twc.de - Nicolas Brodu, brodu@kde.org - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "hello.h" -#include - -using namespace std; -using namespace Arts; - -int main() -{ - Dispatcher dispatcher; - - // Just use plain C++! - Hello server; - server.hello("server"); - - // creation from MCOP reference - Hello client( Reference( server.toString() ) ); - if (!client.isNull()) client.hello("local test"); - else cout << "fatal: a valid reference can't be decoded" << endl; - - // creation from wrong reference - Hello xclient( Reference("fdshjkhdsf") ); - - // check result => should be null - if (xclient.isNull()) cout << "passed invalid reference test" << endl; - else cout << "fatal: an invalid reference can be decoded" << endl; - - // using a constructor - Hello hint(3); - cout << hint.myValue() << endl; - - - Hello castsrc; - HelloBase casthint = castsrc; - casthint.hellobase("cast test passed"); - if(castsrc.isNull()) cout << "cast problem with auto creation" << endl; - castsrc.hello("second cast test passed"); - - // Can copy (or here copy constructor) the objects - Hello hcopy = hint; - hcopy.add(5); - hcopy.printTotal(); - - // dynamic creation is OK - Hello* dyn = new Hello; - cout << dyn->concat("I am"," a dynamic hello") << endl; - dyn->hellobase("dynamic hellobase hello"); - delete dyn; - -// dispatcher.run(); - return 0; - -} diff --git a/examples/hellomain.cpp b/examples/hellomain.cpp new file mode 100644 index 0000000..024f97a --- /dev/null +++ b/examples/hellomain.cpp @@ -0,0 +1,77 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld stefan@space.twc.de + Nicolas Brodu, brodu@kde.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "hello.h" +#include + +using namespace std; +using namespace Arts; + +int main() +{ + Dispatcher dispatcher; + + // Just use plain C++! + Hello server; + server.hello("server"); + + // creation from MCOP reference + Hello client( Reference( server.toString() ) ); + if (!client.isNull()) client.hello("local test"); + else cout << "fatal: a valid reference can't be decoded" << endl; + + // creation from wrong reference + Hello xclient( Reference("fdshjkhdsf") ); + + // check result => should be null + if (xclient.isNull()) cout << "passed invalid reference test" << endl; + else cout << "fatal: an invalid reference can be decoded" << endl; + + // using a constructor + Hello hint(3); + cout << hint.myValue() << endl; + + + Hello castsrc; + HelloBase casthint = castsrc; + casthint.hellobase("cast test passed"); + if(castsrc.isNull()) cout << "cast problem with auto creation" << endl; + castsrc.hello("second cast test passed"); + + // Can copy (or here copy constructor) the objects + Hello hcopy = hint; + hcopy.add(5); + hcopy.printTotal(); + + // dynamic creation is OK + Hello* dyn = new Hello; + cout << dyn->concat("I am"," a dynamic hello") << endl; + dyn->hellobase("dynamic hellobase hello"); + delete dyn; + +// dispatcher.run(); + return 0; + +} diff --git a/examples/helloserver.cc b/examples/helloserver.cc deleted file mode 100644 index 01ffa41..0000000 --- a/examples/helloserver.cc +++ /dev/null @@ -1,52 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "common.h" -#include "hello_impl.h" - -#include -#include -#include - -using namespace std; -using namespace Arts; - -int main() -{ - Dispatcher dispatcher(0,Dispatcher::startUnixServer); - Hello server; - - string reference = server.toString(); - printf("%s\n",reference.c_str()); - - Hello h = Reference(reference); - if(!h.isNull()) - h.hello("local test"); - else - printf("Local access to the Hello_impl object failed?\n"); - - dispatcher.run(); - return 0; -} diff --git a/examples/helloserver.cpp b/examples/helloserver.cpp new file mode 100644 index 0000000..01ffa41 --- /dev/null +++ b/examples/helloserver.cpp @@ -0,0 +1,52 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "common.h" +#include "hello_impl.h" + +#include +#include +#include + +using namespace std; +using namespace Arts; + +int main() +{ + Dispatcher dispatcher(0,Dispatcher::startUnixServer); + Hello server; + + string reference = server.toString(); + printf("%s\n",reference.c_str()); + + Hello h = Reference(reference); + if(!h.isNull()) + h.hello("local test"); + else + printf("Local access to the Hello_impl object failed?\n"); + + dispatcher.run(); + return 0; +} diff --git a/examples/irdemo.cc b/examples/irdemo.cc deleted file mode 100644 index aedd832..0000000 --- a/examples/irdemo.cc +++ /dev/null @@ -1,155 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "common.h" - -#include -#include -#include -#include - -using namespace std; -using namespace Arts; - -static void printInterface(InterfaceDef id) -{ - string inherit; - if(id.inheritedInterfaces.size()) - { - vector::iterator ii; - bool first = true; - inherit = ": "; - for(ii = id.inheritedInterfaces.begin(); ii != id.inheritedInterfaces.end(); ii++) - { - if(!first) inherit +=","; - first = false; - inherit += (*ii)+" "; - } - } - printf("interface %s %s{\n",id.name.c_str(),inherit.c_str()); - // attributes, streams - vector::iterator ai; - for(ai = id.attributes.begin(); ai != id.attributes.end(); ai++) - { - const AttributeDef& ad = *ai; - if(ad.flags & attributeAttribute) - { - /* readwrite */ - if(ad.flags & (streamOut|streamIn) == (streamOut|streamIn)) - { - printf(" attribute %s %s;\n",ad.type.c_str(), ad.name.c_str()); - } - else - { - if(ad.flags & streamOut) /* readable from outside */ - { - printf(" readonly attribute %s %s;\n", - ad.type.c_str(), ad.name.c_str()); - } - if(ad.flags & streamIn) /* writeable from outside */ - { - printf(" ?writeonly? attribute %s %s;\n", - ad.type.c_str(), ad.name.c_str()); - } - } - } - if(ad.flags & attributeStream) - { - const char *dir = (ad.flags & streamOut)?"out":"in"; - const char *async = (ad.flags & streamAsync)?"async ":""; - string type = ad.type; - if(type == "float" && !(ad.flags & streamAsync)) type = "audio"; - - printf(" %s%s %s stream %s;\n",async,dir, - type.c_str(),ad.name.c_str()); - } - } - - // methods - vector::iterator mi; - for(mi = id.methods.begin();mi != id.methods.end(); mi++) - { - MethodDef& md = *mi; - printf(" %s %s(",md.type.c_str(),md.name.c_str()); - - bool first = true; - vector::iterator pi; - for(pi = md.signature.begin(); pi != md.signature.end(); pi++) - { - ParamDef& pd = *pi; - if(!first) printf(", "); - printf("%s %s",pd.type.c_str(),pd.name.c_str()); - first = false; - } - printf(");\n"); - } - printf("}\n"); -} - -/* - * This demo shows that you can find out what interface an object has and - * what types it needs to work without knowing anything but the object - * reference. - * - * The reason for that is that every object offers the _interfaceName - * _queryInterface and _queryType methods, which you can use to find out - * anything you need to know to talk to that object. - * - * Just pass this programm an MCOP object reference, and it will print out - * the corresponding interface. - * - * (TODO: one could make it print out all inherited interfaces and the - * types that are used in the interface, too. Ports, etc could be shown - * as well). - */ - -/** - * Interface repository demo - reasonable testcase: - * - * - make sure artsd is running - * - irdemo global:Arts_SimpleSoundServer - */ -int main(int argc, char **argv) -{ - if(argc != 2) - { - fprintf(stderr,"usage: %s \n",argv[0]); - exit(1); - } - - Dispatcher dispatcher; - Object o = Reference(argv[1]); - if(o.isNull()) - { - fprintf(stderr,"can't connect to the object\n"); - exit(1); - } - - string iname = o._interfaceName(); - InterfaceDef idef = o._queryInterface(iname); - printInterface(idef); - - return 0; -} diff --git a/examples/irdemo.cpp b/examples/irdemo.cpp new file mode 100644 index 0000000..aedd832 --- /dev/null +++ b/examples/irdemo.cpp @@ -0,0 +1,155 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "common.h" + +#include +#include +#include +#include + +using namespace std; +using namespace Arts; + +static void printInterface(InterfaceDef id) +{ + string inherit; + if(id.inheritedInterfaces.size()) + { + vector::iterator ii; + bool first = true; + inherit = ": "; + for(ii = id.inheritedInterfaces.begin(); ii != id.inheritedInterfaces.end(); ii++) + { + if(!first) inherit +=","; + first = false; + inherit += (*ii)+" "; + } + } + printf("interface %s %s{\n",id.name.c_str(),inherit.c_str()); + // attributes, streams + vector::iterator ai; + for(ai = id.attributes.begin(); ai != id.attributes.end(); ai++) + { + const AttributeDef& ad = *ai; + if(ad.flags & attributeAttribute) + { + /* readwrite */ + if(ad.flags & (streamOut|streamIn) == (streamOut|streamIn)) + { + printf(" attribute %s %s;\n",ad.type.c_str(), ad.name.c_str()); + } + else + { + if(ad.flags & streamOut) /* readable from outside */ + { + printf(" readonly attribute %s %s;\n", + ad.type.c_str(), ad.name.c_str()); + } + if(ad.flags & streamIn) /* writeable from outside */ + { + printf(" ?writeonly? attribute %s %s;\n", + ad.type.c_str(), ad.name.c_str()); + } + } + } + if(ad.flags & attributeStream) + { + const char *dir = (ad.flags & streamOut)?"out":"in"; + const char *async = (ad.flags & streamAsync)?"async ":""; + string type = ad.type; + if(type == "float" && !(ad.flags & streamAsync)) type = "audio"; + + printf(" %s%s %s stream %s;\n",async,dir, + type.c_str(),ad.name.c_str()); + } + } + + // methods + vector::iterator mi; + for(mi = id.methods.begin();mi != id.methods.end(); mi++) + { + MethodDef& md = *mi; + printf(" %s %s(",md.type.c_str(),md.name.c_str()); + + bool first = true; + vector::iterator pi; + for(pi = md.signature.begin(); pi != md.signature.end(); pi++) + { + ParamDef& pd = *pi; + if(!first) printf(", "); + printf("%s %s",pd.type.c_str(),pd.name.c_str()); + first = false; + } + printf(");\n"); + } + printf("}\n"); +} + +/* + * This demo shows that you can find out what interface an object has and + * what types it needs to work without knowing anything but the object + * reference. + * + * The reason for that is that every object offers the _interfaceName + * _queryInterface and _queryType methods, which you can use to find out + * anything you need to know to talk to that object. + * + * Just pass this programm an MCOP object reference, and it will print out + * the corresponding interface. + * + * (TODO: one could make it print out all inherited interfaces and the + * types that are used in the interface, too. Ports, etc could be shown + * as well). + */ + +/** + * Interface repository demo - reasonable testcase: + * + * - make sure artsd is running + * - irdemo global:Arts_SimpleSoundServer + */ +int main(int argc, char **argv) +{ + if(argc != 2) + { + fprintf(stderr,"usage: %s \n",argv[0]); + exit(1); + } + + Dispatcher dispatcher; + Object o = Reference(argv[1]); + if(o.isNull()) + { + fprintf(stderr,"can't connect to the object\n"); + exit(1); + } + + string iname = o._interfaceName(); + InterfaceDef idef = o._queryInterface(iname); + printInterface(idef); + + return 0; +} diff --git a/examples/playtofile_impl.cc b/examples/playtofile_impl.cc deleted file mode 100644 index ff7602a..0000000 --- a/examples/playtofile_impl.cc +++ /dev/null @@ -1,99 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "playtofile.h" -#include "flowsystem.h" -#include "stdsynthmodule.h" -#include "convert.h" -#include "stdio.h" - -using namespace Arts; -using namespace std; - -namespace Arts { - class PlayToFile_impl : virtual public PlayToFile_skel, - virtual public StdSynthModule - { - typedef unsigned char uchar; - unsigned char *outblock; - unsigned long maxsamples; - string _filename; - FILE *out; - public: - PlayToFile_impl() : _filename("-") - { - } - void filename(const string& newfilename) { - _filename = newfilename; - filename_changed(_filename); - } - - string filename() { return _filename; } - - void streamInit() { - maxsamples = 0; - outblock = 0; - if(_filename == "-") - out = stdout; - else - out = fopen(_filename.c_str(),"w"); - } - void streamEnd() { - if(outblock) - { - delete[] outblock; - outblock = 0; - } - if(out != stdout) - { - fclose(out); - } - } - - void calculateBlock(unsigned long samples) - { - if(samples > maxsamples) - { - maxsamples = samples; - - if(outblock) delete[] outblock; - outblock = new uchar[maxsamples * 4]; // 2 channels, 16 bit - } - - convert_stereo_2float_i16le(samples,left,right, outblock); - fwrite(outblock, 1, 4 * samples,out); - } - - /* - * this is the most tricky part here - since we will run in a context - * where no audio hardware will play the "give me more data role", - * we'll have to request things ourselves (requireFlow() tells the - * flowsystem that more signal flow should happen, so that - * calculateBlock will get called - */ - void goOn() - { - _node()->requireFlow(); - } - }; - REGISTER_IMPLEMENTATION(PlayToFile_impl); -}; diff --git a/examples/playtofile_impl.cpp b/examples/playtofile_impl.cpp new file mode 100644 index 0000000..ff7602a --- /dev/null +++ b/examples/playtofile_impl.cpp @@ -0,0 +1,99 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "playtofile.h" +#include "flowsystem.h" +#include "stdsynthmodule.h" +#include "convert.h" +#include "stdio.h" + +using namespace Arts; +using namespace std; + +namespace Arts { + class PlayToFile_impl : virtual public PlayToFile_skel, + virtual public StdSynthModule + { + typedef unsigned char uchar; + unsigned char *outblock; + unsigned long maxsamples; + string _filename; + FILE *out; + public: + PlayToFile_impl() : _filename("-") + { + } + void filename(const string& newfilename) { + _filename = newfilename; + filename_changed(_filename); + } + + string filename() { return _filename; } + + void streamInit() { + maxsamples = 0; + outblock = 0; + if(_filename == "-") + out = stdout; + else + out = fopen(_filename.c_str(),"w"); + } + void streamEnd() { + if(outblock) + { + delete[] outblock; + outblock = 0; + } + if(out != stdout) + { + fclose(out); + } + } + + void calculateBlock(unsigned long samples) + { + if(samples > maxsamples) + { + maxsamples = samples; + + if(outblock) delete[] outblock; + outblock = new uchar[maxsamples * 4]; // 2 channels, 16 bit + } + + convert_stereo_2float_i16le(samples,left,right, outblock); + fwrite(outblock, 1, 4 * samples,out); + } + + /* + * this is the most tricky part here - since we will run in a context + * where no audio hardware will play the "give me more data role", + * we'll have to request things ourselves (requireFlow() tells the + * flowsystem that more signal flow should happen, so that + * calculateBlock will get called + */ + void goOn() + { + _node()->requireFlow(); + } + }; + REGISTER_IMPLEMENTATION(PlayToFile_impl); +}; diff --git a/examples/playtofile_main.cc b/examples/playtofile_main.cc deleted file mode 100644 index ba049da..0000000 --- a/examples/playtofile_main.cc +++ /dev/null @@ -1,147 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "playtofile.h" -#include "kmedia2.h" -#include "debug.h" -#include "dynamicrequest.h" -#include "connect.h" -#include "flowsystem.h" -#include -#include - -using namespace Arts; -using namespace std; - -/* copypasted from simplesoundserver_impl.cc */ -PlayObject createPlayObject(const string& filename) -{ - string objectType = ""; - - /* - * figure out extension (as lowercased letters) - */ - string extension = ""; - bool extensionok = false; - string::const_reverse_iterator i; - for(i = filename.rbegin(); i != filename.rend() && !extensionok; i++) - { - if(*i == '.') - extensionok = true; - else - extension = (char)tolower(*i) + extension; - } - - /* - * query trader for PlayObjects which support this - */ - if(extensionok) - { - arts_debug("search playobject, extension = %s",extension.c_str()); - - TraderQuery query; - query.supports("Interface","Arts::PlayObject"); - query.supports("Extension",extension); - - vector *offers = query.query(); - if(!offers->empty()) - objectType = offers->front().interfaceName(); // first offer - - delete offers; - } - - /* - * create a PlayObject and connect it - */ - if(!objectType.empty()) - { - arts_debug("creating %s to play file", objectType.c_str()); - - PlayObject result = SubClass(objectType); - if(result.loadMedia(filename)) - { - result._node()->start(); - return result; - } - else arts_warning("couldn't load file %s", filename.c_str()); - } - else arts_warning("file format extension %s unsupported",extension.c_str()); - - return PlayObject::null(); -} - -/* - * This is an example for dumping things to a file. It demonstates, that - * - * a) you can use all aRts objects in a non-realtime environment (i.e. - * the time in the PlayObject will pass much faster than the outside - * time when dumping things to a file) - * - * b) complayObjectnents will be dynamically loaded as needed - * - * c) you need to do small tricks to get the signal flow going when you are - * not having audio modules around - * - * d) by implementing aRts modules, you can easily grab and insert data from/to - * arbitary non-aRts sources - for instance, a wave editor might implement - * own modules to get the wave from/to memory - */ -int main(int argc, char **argv) -{ - Dispatcher d; - - if(argc != 2 && argc != 3) - { - cerr << "usage: playtofile [ ]" << endl; - exit(1); - } - PlayObject playObject = createPlayObject(argv[1]); - if(playObject.isNull()) - { - cerr << "can't read inputfile " << argv[1] << endl; - exit(1); - } - - playObject.play(); - - PlayToFile playToFile; - if(argc == 3) playToFile.filename(argv[2]); - - connect(playObject, "left", playToFile,"left"); - connect(playObject, "right", playToFile,"right"); - - // - // special case when using mpeglib, do tell it not to block (internal - // interface) - we also put an usleep here to ensure that the threads - // and everything is fully initialized as soon as we start - usleep(100000); - if(playObject._base()->_isCompatibleWith("DecoderBaseObject")) - if(!DynamicRequest(playObject).method("_set_blocking").param(true).invoke()) - cerr << "mpeglib, and blocking attribute can't be changed?" << endl; - // - - playToFile.start(); - while(playObject.state() != posIdle) - playToFile.goOn(); - - return 0; -} diff --git a/examples/playtofile_main.cpp b/examples/playtofile_main.cpp new file mode 100644 index 0000000..bd47185 --- /dev/null +++ b/examples/playtofile_main.cpp @@ -0,0 +1,147 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "playtofile.h" +#include "kmedia2.h" +#include "debug.h" +#include "dynamicrequest.h" +#include "connect.h" +#include "flowsystem.h" +#include +#include + +using namespace Arts; +using namespace std; + +/* copypasted from simplesoundserver_impl.cpp */ +PlayObject createPlayObject(const string& filename) +{ + string objectType = ""; + + /* + * figure out extension (as lowercased letters) + */ + string extension = ""; + bool extensionok = false; + string::const_reverse_iterator i; + for(i = filename.rbegin(); i != filename.rend() && !extensionok; i++) + { + if(*i == '.') + extensionok = true; + else + extension = (char)tolower(*i) + extension; + } + + /* + * query trader for PlayObjects which support this + */ + if(extensionok) + { + arts_debug("search playobject, extension = %s",extension.c_str()); + + TraderQuery query; + query.supports("Interface","Arts::PlayObject"); + query.supports("Extension",extension); + + vector *offers = query.query(); + if(!offers->empty()) + objectType = offers->front().interfaceName(); // first offer + + delete offers; + } + + /* + * create a PlayObject and connect it + */ + if(!objectType.empty()) + { + arts_debug("creating %s to play file", objectType.c_str()); + + PlayObject result = SubClass(objectType); + if(result.loadMedia(filename)) + { + result._node()->start(); + return result; + } + else arts_warning("couldn't load file %s", filename.c_str()); + } + else arts_warning("file format extension %s unsupported",extension.c_str()); + + return PlayObject::null(); +} + +/* + * This is an example for dumping things to a file. It demonstates, that + * + * a) you can use all aRts objects in a non-realtime environment (i.e. + * the time in the PlayObject will pass much faster than the outside + * time when dumping things to a file) + * + * b) complayObjectnents will be dynamically loaded as needed + * + * c) you need to do small tricks to get the signal flow going when you are + * not having audio modules around + * + * d) by implementing aRts modules, you can easily grab and insert data from/to + * arbitary non-aRts sources - for instance, a wave editor might implement + * own modules to get the wave from/to memory + */ +int main(int argc, char **argv) +{ + Dispatcher d; + + if(argc != 2 && argc != 3) + { + cerr << "usage: playtofile [ ]" << endl; + exit(1); + } + PlayObject playObject = createPlayObject(argv[1]); + if(playObject.isNull()) + { + cerr << "can't read inputfile " << argv[1] << endl; + exit(1); + } + + playObject.play(); + + PlayToFile playToFile; + if(argc == 3) playToFile.filename(argv[2]); + + connect(playObject, "left", playToFile,"left"); + connect(playObject, "right", playToFile,"right"); + + // + // special case when using mpeglib, do tell it not to block (internal + // interface) - we also put an usleep here to ensure that the threads + // and everything is fully initialized as soon as we start + usleep(100000); + if(playObject._base()->_isCompatibleWith("DecoderBaseObject")) + if(!DynamicRequest(playObject).method("_set_blocking").param(true).invoke()) + cerr << "mpeglib, and blocking attribute can't be changed?" << endl; + // + + playToFile.start(); + while(playObject.state() != posIdle) + playToFile.goOn(); + + return 0; +} diff --git a/examples/referenceinfo.cc b/examples/referenceinfo.cc deleted file mode 100644 index b980378..0000000 --- a/examples/referenceinfo.cc +++ /dev/null @@ -1,57 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "common.h" -#include - -using namespace Arts; - -int main(int argc, char **argv) -{ - Dispatcher dispatcher; - ObjectReference r; - - if(argc != 2) - { - fprintf(stderr,"usage: %s \n",argv[0]); - exit(1); - } - - if(!dispatcher.stringToObjectReference(r,argv[1])) - { - fprintf(stderr, - "Can't read this object reference (invalid?)\n"); - exit(1); - } - printf("serverID: %s\n",r.serverID.c_str()); - printf("objectID: %ld\n\n",r.objectID); - - printf("URLs:\n"); - std::vector::iterator ui; - for(ui = r.urls.begin(); ui != r.urls.end();ui++) - printf(" - %s\n",ui->c_str()); - - return 0; -} diff --git a/examples/referenceinfo.cpp b/examples/referenceinfo.cpp new file mode 100644 index 0000000..b980378 --- /dev/null +++ b/examples/referenceinfo.cpp @@ -0,0 +1,57 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "common.h" +#include + +using namespace Arts; + +int main(int argc, char **argv) +{ + Dispatcher dispatcher; + ObjectReference r; + + if(argc != 2) + { + fprintf(stderr,"usage: %s \n",argv[0]); + exit(1); + } + + if(!dispatcher.stringToObjectReference(r,argv[1])) + { + fprintf(stderr, + "Can't read this object reference (invalid?)\n"); + exit(1); + } + printf("serverID: %s\n",r.serverID.c_str()); + printf("objectID: %ld\n\n",r.objectID); + + printf("URLs:\n"); + std::vector::iterator ui; + for(ui = r.urls.begin(); ui != r.urls.end();ui++) + printf(" - %s\n",ui->c_str()); + + return 0; +} diff --git a/examples/streamsound.cc b/examples/streamsound.cc deleted file mode 100644 index 170d6de..0000000 --- a/examples/streamsound.cc +++ /dev/null @@ -1,106 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "soundserver.h" -#include "stdsynthmodule.h" - -#include -#include -#include -#include -#include - -using namespace std; -using namespace Arts; - -class Sender : public ByteSoundProducer_skel, - public StdSynthModule -{ - bool _finished; - int pos; -public: - Sender() : _finished(false), pos(0) - { - } - long samplingRate() { return 44100; } - long channels() { return 2; } - long bits() { return 16; } - bool finished() { return _finished; } - - static const int packetCount = 10, packetCapacity = 1024; - void streamStart() - { - /* - * start streaming - */ - outdata.setPull(packetCount, packetCapacity); - } - - void request_outdata(DataPacket *packet) - { - /* - * fill the packet with new data - */ - // ----------------- audio fill up start ----------------- - - int j; - mcopbyte *to = &packet->contents[0]; - for(j=0;j> 8) & 0xff; - *to++ = right & 0xff; - *to++ = (right >> 8) & 0xff; - } - - // ------------------ audio fill up end ------------------ - packet->send(); - } -}; - -int main(int argc, char **argv) -{ - Dispatcher dispatcher; - SimpleSoundServer server = Reference("global:Arts_SimpleSoundServer"); - - if(server.isNull()) - { - cerr << "Can't connect to sound server" << endl; - return 1; - } - - ByteSoundProducer sender = ByteSoundProducer::_from_base(new Sender()); - server.attach(sender); - sender.start(); - dispatcher.run(); - server.detach(sender); // in this example: not reached -} diff --git a/examples/streamsound.cpp b/examples/streamsound.cpp new file mode 100644 index 0000000..170d6de --- /dev/null +++ b/examples/streamsound.cpp @@ -0,0 +1,106 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "soundserver.h" +#include "stdsynthmodule.h" + +#include +#include +#include +#include +#include + +using namespace std; +using namespace Arts; + +class Sender : public ByteSoundProducer_skel, + public StdSynthModule +{ + bool _finished; + int pos; +public: + Sender() : _finished(false), pos(0) + { + } + long samplingRate() { return 44100; } + long channels() { return 2; } + long bits() { return 16; } + bool finished() { return _finished; } + + static const int packetCount = 10, packetCapacity = 1024; + void streamStart() + { + /* + * start streaming + */ + outdata.setPull(packetCount, packetCapacity); + } + + void request_outdata(DataPacket *packet) + { + /* + * fill the packet with new data + */ + // ----------------- audio fill up start ----------------- + + int j; + mcopbyte *to = &packet->contents[0]; + for(j=0;j> 8) & 0xff; + *to++ = right & 0xff; + *to++ = (right >> 8) & 0xff; + } + + // ------------------ audio fill up end ------------------ + packet->send(); + } +}; + +int main(int argc, char **argv) +{ + Dispatcher dispatcher; + SimpleSoundServer server = Reference("global:Arts_SimpleSoundServer"); + + if(server.isNull()) + { + cerr << "Can't connect to sound server" << endl; + return 1; + } + + ByteSoundProducer sender = ByteSoundProducer::_from_base(new Sender()); + server.attach(sender); + sender.start(); + dispatcher.run(); + server.detach(sender); // in this example: not reached +} diff --git a/examples/testaggregation.cc b/examples/testaggregation.cc deleted file mode 100644 index c1a73bf..0000000 --- a/examples/testaggregation.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "aggregation.h" -#include - -using namespace std; -using namespace Arts; - -class String_impl : virtual public String_skel { - string _value; -public: - void constructor(const std::string& value) { _value = value; } - string value() { return _value; } - void value(const std::string& newValue) { _value = newValue; } -}; - -REGISTER_IMPLEMENTATION(String_impl); - -void printall(Arts::Object o, std::string pre = "") -{ - String s; - s = DynamicCast(o); - if(!s.isNull()) - cout << pre << " - " << s.value() << endl; - - vector *children = s._queryChildren(); - vector::iterator i; - for(i = children->begin(); i != children->end(); i++) - printall(s._getChild(*i), pre+" "); -} - -/* - * Small test case for aggregation - * - * The idea behind all this is that you can add children to objects, building - * a tree (or if you like graph) of objects without the objects knowing anything - * about this. Aggregation has strong references, that means, the objects you - * add together in a tree will stay this way, as long as you keep a reference - * to the root. - */ -int main() -{ - Dispatcher d; - - String s("spreadsheet"); - s._addChild(String("chart"),"child1"); - s._addChild(String("image"),"child2"); - printall(s); - - cout << "deleting \"child1\"" << endl; - if(!s._removeChild("child1")) cout << "FAIL" << endl; - printall(s); -} diff --git a/examples/testaggregation.cpp b/examples/testaggregation.cpp new file mode 100644 index 0000000..c1a73bf --- /dev/null +++ b/examples/testaggregation.cpp @@ -0,0 +1,73 @@ +/* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ + +#include "aggregation.h" +#include + +using namespace std; +using namespace Arts; + +class String_impl : virtual public String_skel { + string _value; +public: + void constructor(const std::string& value) { _value = value; } + string value() { return _value; } + void value(const std::string& newValue) { _value = newValue; } +}; + +REGISTER_IMPLEMENTATION(String_impl); + +void printall(Arts::Object o, std::string pre = "") +{ + String s; + s = DynamicCast(o); + if(!s.isNull()) + cout << pre << " - " << s.value() << endl; + + vector *children = s._queryChildren(); + vector::iterator i; + for(i = children->begin(); i != children->end(); i++) + printall(s._getChild(*i), pre+" "); +} + +/* + * Small test case for aggregation + * + * The idea behind all this is that you can add children to objects, building + * a tree (or if you like graph) of objects without the objects knowing anything + * about this. Aggregation has strong references, that means, the objects you + * add together in a tree will stay this way, as long as you keep a reference + * to the root. + */ +int main() +{ + Dispatcher d; + + String s("spreadsheet"); + s._addChild(String("chart"),"child1"); + s._addChild(String("image"),"child2"); + printall(s); + + cout << "deleting \"child1\"" << endl; + if(!s._removeChild("child1")) cout << "FAIL" << endl; + printall(s); +} diff --git a/examples/testasubsys.cc b/examples/testasubsys.cc deleted file mode 100644 index b70bf9d..0000000 --- a/examples/testasubsys.cc +++ /dev/null @@ -1,142 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include -#include -#include "audiosubsys.h" -#include "convert.h" -#include "dispatcher.h" - -using namespace std; -using namespace Arts; - -class SinTest : public ASProducer { -protected: - int audiofd; - int done; - AudioSubSystem *as; - bool attached; - -public: - SinTest(); - virtual ~SinTest(); - void needMore(); - void run(long samples); -}; - -SinTest::SinTest() : done(0), as(AudioSubSystem::the()) -{ - // initialize and open audio subsystem (defaults to 44kHz, 16bit, stereo) - attached = as->attachProducer(this); - if(!attached) - { - cout << "audio subsystem is already used?" << endl; - } - else - { - if(as->open() == false) - { - cout << "audio subsystem init failed (" - << as->error() << ")" << endl; - audiofd = -1; - } - else - audiofd = as->selectWriteFD(); - } -} - -SinTest::~SinTest() -{ - // deinitialize the audio subsystem - if(attached) - as->detachProducer(); -} - -void SinTest::run(long samples) -{ - // run this loop until enough samples are produced - while(attached && audiofd >= 0 && (done < samples)) - { - fd_set wfds, efds; - FD_ZERO(&wfds); - FD_ZERO(&efds); - FD_SET(audiofd, &wfds); - FD_SET(audiofd, &efds); - - // look if the audio filedescriptor becomes writeable - int result = select(audiofd+1,0,&wfds,&efds,0); - if(result > 0) - { - // if yes, tell the audio subsystem to do something about it - if(FD_ISSET(audiofd, &wfds)) - as->handleIO(AudioSubSystem::ioWrite); - if(FD_ISSET(audiofd, &efds)) - as->handleIO(AudioSubSystem::ioExcept); - } - else - { - cout << "select returned " << result << endl; - } - } -} - -/* - * needMore is a callback by the audio subsystem, which is made as soon as - * the internal buffers need a refill - */ -void SinTest::needMore() -{ - float left[100], right[100]; - unsigned char out[400]; - - // generate two waves, one 440 Hz (left), one 880Hz (right) - for(int i=0;i<100;i++) - { - left[i] = sin((float)i*6.28/100.0); - right[i] = sin((float)i*6.28/50.0); - } - convert_stereo_2float_i16le(100, left, right, out); - - // write them to the audio subsystem - as->write(out,400); - done += 100; -} - -/* - * This is intended to help testing the audio subsystem with different - * hardware without needing to use the whole server. - * - * Warning: this is *not* an example how to use aRts (there are others), - * but a simple test program for debugging purposes. - */ -int main() -{ - Dispatcher d; // to get startup classes executed - - // the test, generate 88100 samples (2 seconds) of pure sine wave test data - SinTest s; - s.run(88100); - return 0; -} diff --git a/examples/testasubsys.cpp b/examples/testasubsys.cpp new file mode 100644 index 0000000..b70bf9d --- /dev/null +++ b/examples/testasubsys.cpp @@ -0,0 +1,142 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include +#include +#include "audiosubsys.h" +#include "convert.h" +#include "dispatcher.h" + +using namespace std; +using namespace Arts; + +class SinTest : public ASProducer { +protected: + int audiofd; + int done; + AudioSubSystem *as; + bool attached; + +public: + SinTest(); + virtual ~SinTest(); + void needMore(); + void run(long samples); +}; + +SinTest::SinTest() : done(0), as(AudioSubSystem::the()) +{ + // initialize and open audio subsystem (defaults to 44kHz, 16bit, stereo) + attached = as->attachProducer(this); + if(!attached) + { + cout << "audio subsystem is already used?" << endl; + } + else + { + if(as->open() == false) + { + cout << "audio subsystem init failed (" + << as->error() << ")" << endl; + audiofd = -1; + } + else + audiofd = as->selectWriteFD(); + } +} + +SinTest::~SinTest() +{ + // deinitialize the audio subsystem + if(attached) + as->detachProducer(); +} + +void SinTest::run(long samples) +{ + // run this loop until enough samples are produced + while(attached && audiofd >= 0 && (done < samples)) + { + fd_set wfds, efds; + FD_ZERO(&wfds); + FD_ZERO(&efds); + FD_SET(audiofd, &wfds); + FD_SET(audiofd, &efds); + + // look if the audio filedescriptor becomes writeable + int result = select(audiofd+1,0,&wfds,&efds,0); + if(result > 0) + { + // if yes, tell the audio subsystem to do something about it + if(FD_ISSET(audiofd, &wfds)) + as->handleIO(AudioSubSystem::ioWrite); + if(FD_ISSET(audiofd, &efds)) + as->handleIO(AudioSubSystem::ioExcept); + } + else + { + cout << "select returned " << result << endl; + } + } +} + +/* + * needMore is a callback by the audio subsystem, which is made as soon as + * the internal buffers need a refill + */ +void SinTest::needMore() +{ + float left[100], right[100]; + unsigned char out[400]; + + // generate two waves, one 440 Hz (left), one 880Hz (right) + for(int i=0;i<100;i++) + { + left[i] = sin((float)i*6.28/100.0); + right[i] = sin((float)i*6.28/50.0); + } + convert_stereo_2float_i16le(100, left, right, out); + + // write them to the audio subsystem + as->write(out,400); + done += 100; +} + +/* + * This is intended to help testing the audio subsystem with different + * hardware without needing to use the whole server. + * + * Warning: this is *not* an example how to use aRts (there are others), + * but a simple test program for debugging purposes. + */ +int main() +{ + Dispatcher d; // to get startup classes executed + + // the test, generate 88100 samples (2 seconds) of pure sine wave test data + SinTest s; + s.run(88100); + return 0; +} diff --git a/examples/testdhandle.cc b/examples/testdhandle.cc deleted file mode 100644 index 564687d..0000000 --- a/examples/testdhandle.cc +++ /dev/null @@ -1,115 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "gslpp/datahandle.h" -#include "soundserver.h" -#include "stdsynthmodule.h" -#include "artsflow.h" -#include "connect.h" - -#include -#include -#include -#include -#include - -using namespace std; -using namespace Arts; - -int main(int argc, char **argv) -{ - if(argc<2) - { - cerr << "USAGE: " << argv[0] << " [filename]\n"; - exit(1); - } - - Dispatcher dispatcher; - SoundServer server = Reference("global:Arts_SoundServer"); - - cout << "opening '" << argv[1] << "' locally...\n"; - - GSL::WaveFileInfo info(argv[1]); - if(info.error()) - { - cerr << "GSL error " << info.error() << - " (" << gsl_strerror(info.error()) << ") while loading info.\n"; - exit(1); - } - cout << "file contains " << info.waveCount() << " waves:\n"; - for(int i=0; i +#include +#include +#include +#include + +using namespace std; +using namespace Arts; + +int main(int argc, char **argv) +{ + if(argc<2) + { + cerr << "USAGE: " << argv[0] << " [filename]\n"; + exit(1); + } + + Dispatcher dispatcher; + SoundServer server = Reference("global:Arts_SoundServer"); + + cout << "opening '" << argv[1] << "' locally...\n"; + + GSL::WaveFileInfo info(argv[1]); + if(info.error()) + { + cerr << "GSL error " << info.error() << + " (" << gsl_strerror(info.error()) << ") while loading info.\n"; + exit(1); + } + cout << "file contains " << info.waveCount() << " waves:\n"; + for(int i=0; i -#include -#include -#include "dispatcher.h" -#include "thread.h" - -using namespace Arts; -using namespace std; - -class Counter : public Arts::Thread -{ - string name; -public: - Counter(const string& name) :name(name) {} - - void run() { - for(int i = 0;i < 10;i++) - { - printf("[%s] %d\n",name.c_str(),i+1); - sleep(1); - } - printf("[%s] terminating.\n", static_cast - (SystemThreads::the()->getCurrentThread())->name.c_str()); - } -}; - -int main() -{ - Dispatcher dispatcher; - Counter c1("counter1"), c2("counter2"); - - if(SystemThreads::supported()) - printf("We have a system threads (counters should count parallel).\n"); - else - printf("No system threads (counters will not count parallel).\n"); - - c1.start(); - c2.start(); - c1.waitDone(); - c2.waitDone(); - return 0; -} diff --git a/examples/testthreads.cpp b/examples/testthreads.cpp new file mode 100644 index 0000000..ad2e428 --- /dev/null +++ b/examples/testthreads.cpp @@ -0,0 +1,64 @@ +/* + + Copyright (C) 2001-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ + +#include +#include +#include +#include "dispatcher.h" +#include "thread.h" + +using namespace Arts; +using namespace std; + +class Counter : public Arts::Thread +{ + string name; +public: + Counter(const string& name) :name(name) {} + + void run() { + for(int i = 0;i < 10;i++) + { + printf("[%s] %d\n",name.c_str(),i+1); + sleep(1); + } + printf("[%s] terminating.\n", static_cast + (SystemThreads::the()->getCurrentThread())->name.c_str()); + } +}; + +int main() +{ + Dispatcher dispatcher; + Counter c1("counter1"), c2("counter2"); + + if(SystemThreads::supported()) + printf("We have a system threads (counters should count parallel).\n"); + else + printf("No system threads (counters will not count parallel).\n"); + + c1.start(); + c2.start(); + c1.waitDone(); + c2.waitDone(); + return 0; +} diff --git a/examples/x11commtest.cc b/examples/x11commtest.cc deleted file mode 100644 index c1b27dd..0000000 --- a/examples/x11commtest.cc +++ /dev/null @@ -1,76 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - Modified by Nicolas Brodu, brodu@kde.org - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include -#include "common.h" - -using namespace std; -using namespace Arts; - -/* - * Test program for X11GlobalComm (communication over X11 root window - * properties), and since X11GlobalComm is an dynamically extension, - * extension loading is tested as well. - */ -int main(int argc, char **argv) -{ - Dispatcher dispatcher; - GlobalComm gcomm( SubClass("Arts::X11GlobalComm") ); - - if (gcomm.isNull()) { - cerr << "Cannot create a X11GlobalComm object" << endl; - return 2; - } - - if(argc == 4) - { - if(string(argv[1]) == "put") - { - gcomm.put(argv[2],argv[3]); - return 0; - } - } - if(argc == 3) - { - if(string(argv[1]) == "get") - { - cout << gcomm.get(argv[2]) << endl; - return 0; - } - if(string(argv[1]) == "erase") - { - gcomm.erase(argv[2]); - return 0; - } - } - - cerr << "This is a test for the X11GlobalComm class. Use" << endl << endl - << " " << argv[0] << " put " << endl - << " " << argv[0] << " get " << endl - << " " << argv[0] << " erase " << endl << endl - << "to test the communication via X11 RootWindow properties." << endl; - return 1; -} diff --git a/examples/x11commtest.cpp b/examples/x11commtest.cpp new file mode 100644 index 0000000..c1b27dd --- /dev/null +++ b/examples/x11commtest.cpp @@ -0,0 +1,76 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + Modified by Nicolas Brodu, brodu@kde.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include +#include "common.h" + +using namespace std; +using namespace Arts; + +/* + * Test program for X11GlobalComm (communication over X11 root window + * properties), and since X11GlobalComm is an dynamically extension, + * extension loading is tested as well. + */ +int main(int argc, char **argv) +{ + Dispatcher dispatcher; + GlobalComm gcomm( SubClass("Arts::X11GlobalComm") ); + + if (gcomm.isNull()) { + cerr << "Cannot create a X11GlobalComm object" << endl; + return 2; + } + + if(argc == 4) + { + if(string(argv[1]) == "put") + { + gcomm.put(argv[2],argv[3]); + return 0; + } + } + if(argc == 3) + { + if(string(argv[1]) == "get") + { + cout << gcomm.get(argv[2]) << endl; + return 0; + } + if(string(argv[1]) == "erase") + { + gcomm.erase(argv[2]); + return 0; + } + } + + cerr << "This is a test for the X11GlobalComm class. Use" << endl << endl + << " " << argv[0] << " put " << endl + << " " << argv[0] << " get " << endl + << " " << argv[0] << " erase " << endl << endl + << "to test the communication via X11 RootWindow properties." << endl; + return 1; +} -- cgit v1.2.3