diff options
author | geronimo <geronimo013@gmx.de> | 2012-07-30 09:12:30 +0200 |
---|---|---|
committer | geronimo <geronimo013@gmx.de> | 2012-07-30 09:12:30 +0200 |
commit | 2331befb330683d0e5459f9ca2d522f2f06c3d7e (patch) | |
tree | e95c3c4e40d57cbcf6af16d2736f34dce0279c4b /cmps | |
parent | 570a18b0d0a9a00b240504ac949214d6cc96949b (diff) | |
download | cmp-2331befb330683d0e5459f9ca2d522f2f06c3d7e.tar.gz cmp-2331befb330683d0e5459f9ca2d522f2f06c3d7e.tar.bz2 |
worked out commandreader
Diffstat (limited to 'cmps')
-rw-r--r-- | cmps/main.cc | 12 | ||||
-rw-r--r-- | cmps/nbproject/Makefile-Debug.mk | 14 | ||||
-rw-r--r-- | cmps/nbproject/Makefile-Release.mk | 12 | ||||
-rw-r--r-- | cmps/nbproject/configurations.xml | 21 | ||||
-rw-r--r-- | cmps/serverlib/serverlib.layout | 10 | ||||
-rw-r--r-- | cmps/tests/MetaScanTest.cc | 177 |
6 files changed, 234 insertions, 12 deletions
diff --git a/cmps/main.cc b/cmps/main.cc index da5b260..a5d2b04 100644 --- a/cmps/main.cc +++ b/cmps/main.cc @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: main.cc * Created: 2. Juli 2012, 16 * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> * Project: cmps - the backend (server) part of compound media player - * + * * CMP - compound media player - * + * * is a client/server mediaplayer intended to play any media from any workstation * without the need to export or mount shares. cmps is an easy to use backend * with a (ready to use) HTML-interface. Additionally the backend supports * authentication via HTTP-digest authorization. * cmpc is a client with vdr-like osd-menues. - * + * * Copyright (c) 2012 Reinhard Mantey, some rights reserved! * published under Creative Commons by-sa * For details see http://creativecommons.org/licenses/by-sa/3.0/ - * + * * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp - * + * * -------------------------------------------------------------- */ #include <HTTPServer.h> diff --git a/cmps/nbproject/Makefile-Debug.mk b/cmps/nbproject/Makefile-Debug.mk index b3558ee..fc3eebf 100644 --- a/cmps/nbproject/Makefile-Debug.mk +++ b/cmps/nbproject/Makefile-Debug.mk @@ -46,7 +46,8 @@ TESTFILES= \ ${TESTDIR}/TestFiles/f3 \ ${TESTDIR}/TestFiles/f5 \ ${TESTDIR}/TestFiles/f2 \ - ${TESTDIR}/TestFiles/f4 + ${TESTDIR}/TestFiles/f4 \ + ${TESTDIR}/TestFiles/f6 # C Compiler Flags CFLAGS= @@ -126,6 +127,10 @@ ${TESTDIR}/TestFiles/f4: ${TESTDIR}/tests/JSonTest.o ${OBJECTFILES:%.o=%_nomain. ${MKDIR} -p ${TESTDIR}/TestFiles ${LINK.cc} -o ${TESTDIR}/TestFiles/f4 $^ ${LDLIBSOPTIONS} +${TESTDIR}/TestFiles/f6: ${TESTDIR}/tests/MetaScanTest.o ${OBJECTFILES:%.o=%_nomain.o} + ${MKDIR} -p ${TESTDIR}/TestFiles + ${LINK.cc} -o ${TESTDIR}/TestFiles/f6 $^ ${LDLIBSOPTIONS} + ${TESTDIR}/tests/CodecTest.o: tests/CodecTest.cc ${MKDIR} -p ${TESTDIR}/tests @@ -157,6 +162,12 @@ ${TESTDIR}/tests/JSonTest.o: tests/JSonTest.cc $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/fsScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/JSonTest.o tests/JSonTest.cc +${TESTDIR}/tests/MetaScanTest.o: tests/MetaScanTest.cc + ${MKDIR} -p ${TESTDIR}/tests + ${RM} $@.d + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/fsScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/MetaScanTest.o tests/MetaScanTest.cc + + ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc ${MKDIR} -p ${OBJECTDIR} @NMOUTPUT=`${NM} ${OBJECTDIR}/main.o`; \ @@ -179,6 +190,7 @@ ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc ${TESTDIR}/TestFiles/f5 || true; \ ${TESTDIR}/TestFiles/f2 || true; \ ${TESTDIR}/TestFiles/f4 || true; \ + ${TESTDIR}/TestFiles/f6 || true; \ else \ ./${TEST} || true; \ fi diff --git a/cmps/nbproject/Makefile-Release.mk b/cmps/nbproject/Makefile-Release.mk index 29abff0..c4c3c75 100644 --- a/cmps/nbproject/Makefile-Release.mk +++ b/cmps/nbproject/Makefile-Release.mk @@ -46,6 +46,7 @@ TESTFILES= \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps # C Compiler Flags @@ -102,6 +103,10 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps: ${TESTDIR}/tests/JSonTest.o ${O ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps $^ ${LDLIBSOPTIONS} +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps: ${TESTDIR}/tests/MetaScanTest.o ${OBJECTFILES:%.o=%_nomain.o} + ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} + ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps $^ ${LDLIBSOPTIONS} + ${TESTDIR}/tests/CodecTest.o: tests/CodecTest.cc ${MKDIR} -p ${TESTDIR}/tests @@ -133,6 +138,12 @@ ${TESTDIR}/tests/JSonTest.o: tests/JSonTest.cc $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${TESTDIR}/tests/JSonTest.o tests/JSonTest.cc +${TESTDIR}/tests/MetaScanTest.o: tests/MetaScanTest.cc + ${MKDIR} -p ${TESTDIR}/tests + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${TESTDIR}/tests/MetaScanTest.o tests/MetaScanTest.cc + + ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc ${MKDIR} -p ${OBJECTDIR} @NMOUTPUT=`${NM} ${OBJECTDIR}/main.o`; \ @@ -155,6 +166,7 @@ ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ else \ ./${TEST} || true; \ fi diff --git a/cmps/nbproject/configurations.xml b/cmps/nbproject/configurations.xml index 7793b21..e9180ff 100644 --- a/cmps/nbproject/configurations.xml +++ b/cmps/nbproject/configurations.xml @@ -45,6 +45,12 @@ <logicalFolder name="f4" displayName="JSonTest" projectFiles="true" kind="TEST"> <itemPath>tests/JSonTest.cc</itemPath> </logicalFolder> + <logicalFolder name="f6" + displayName="MetaScanTest" + projectFiles="true" + kind="TEST"> + <itemPath>tests/MetaScanTest.cc</itemPath> + </logicalFolder> </logicalFolder> <logicalFolder name="ExternalFiles" displayName="Important Files" @@ -298,6 +304,21 @@ <output>${TESTDIR}/TestFiles/f5</output> </linkerTool> </folder> + <folder path="TestFiles/f6"> + <cTool> + <incDir> + <pElem>.</pElem> + </incDir> + </cTool> + <ccTool> + <incDir> + <pElem>.</pElem> + </incDir> + </ccTool> + <linkerTool> + <output>${TESTDIR}/TestFiles/f6</output> + </linkerTool> + </folder> </conf> <conf name="Release" type="1"> <toolsSet> diff --git a/cmps/serverlib/serverlib.layout b/cmps/serverlib/serverlib.layout index 4ad7fb3..43baef8 100644 --- a/cmps/serverlib/serverlib.layout +++ b/cmps/serverlib/serverlib.layout @@ -1,6 +1,11 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> + <File name="src/AbstractMediaRequestHandler.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> <File name="src/JSonListAssembler.cc" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <Cursor> <Cursor1 position="1183" topLine="0" /> @@ -16,9 +21,4 @@ <Cursor1 position="0" topLine="0" /> </Cursor> </File> - <File name="src/AbstractMediaRequestHandler.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> </CodeBlocks_layout_file> diff --git a/cmps/tests/MetaScanTest.cc b/cmps/tests/MetaScanTest.cc new file mode 100644 index 0000000..bdd51ae --- /dev/null +++ b/cmps/tests/MetaScanTest.cc @@ -0,0 +1,177 @@ +/** + * ======================== legal notice ====================== + * + * File: MetaScanTest.cc + * Created: 27.07.2012, 10:03 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: cmps - the backend (server) part of compound media player + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <File.h> +#include <FileReader.h> +#include <LineReader.h> +#include <ConfigReader.h> +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <wait.h> +#include <tr1/tuple> +#include <util.h> + +static void testPipe(const char *chk = NULL); + +static void parseConfig(const char *FileName) +{ + cConfigReader *cr = new cConfigReader(new cLineReader(new cFileReader(new cFile(FileName)))); + cConfigReader::ConfigEntry *ce; + + while ((ce = cr->ReadValue())) { + std::cout << "config entry [" << std::get<0>(*ce) << "] => " << std::get<1>(*ce) << std::endl; + delete ce; + } + cr->Close(); + delete cr; +} + +static void testMediaFiles(const char *FileName) +{ + cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName))); + const char *line; + + while ((line = lr->ReadLine())) { + std::cout << "media-test-file: " << line << std::endl; + testPipe(line); + } + lr->Close(); + delete lr; +} + +static const short BufferSize = 100; +enum PipeFileDescriptors { + READ_FD = 0, + WRITE_FD = 1 +}; + +static void testCommandReader() +{ + cCommandReader *cr = new cCommandReader("/bin/ls"); + cLineReader *lr = new cLineReader(cr); + char *line; + + cr.AddCommandParameter("-al"); + cr.AddCommandParameter("--color"); + + while ((line = lr->ReadLine())) { + std::cout << "from command: " << line << std::endl; + } +}; + +static void testPipe(const char *chk) +{ + int parent2Child[2]; + int child2Parent[2]; + pid_t pid; + std::string dataReadFromChild; + char buffer[BufferSize + 1]; + ssize_t readResult; + bool run = true; + int status; + + ASSERT_IS(0, pipe(parent2Child)); + ASSERT_IS(0, pipe(child2Parent)); + + switch (pid = fork()) { + case -1: + FAIL("fork failed"); + exit(-1); + + case 0: /* child */ + ASSERT_NOT(-1, dup2(parent2Child[READ_FD], STDIN_FILENO)); + ASSERT_NOT(-1, dup2(child2Parent[WRITE_FD], STDOUT_FILENO)); + ASSERT_NOT(-1, dup2(child2Parent[WRITE_FD], STDERR_FILENO)); + ASSERT_IS(0, close(parent2Child[WRITE_FD])); + ASSERT_IS(0, close(child2Parent[READ_FD])); + + if (chk) { + execlp("mediainfo", "mediainfo", chk, NULL); + } + else execlp("ls", "ls", "-al", "--color", NULL); + FAIL("this line should never be reached!"); + exit(-1); + + default: /* parent */ + std::cout << "child " << pid << " process running ..." << std::endl; + + ASSERT_IS(0, close(parent2Child[READ_FD])); + ASSERT_IS(0, close(child2Parent[WRITE_FD])); + + while (run) { + switch (readResult = read(child2Parent[READ_FD], buffer, BufferSize)) { + case 0: /* end of file, or non-blocking read. */ + std::cout << "End of File reached ..." << std::endl + << "Data received was (" + << dataReadFromChild.size() << "):" << std::endl + << dataReadFromChild << std::endl; + ASSERT_IS(pid, waitpid(pid, &status, 0)); + + std::cout << std::endl + << "child exit status is: " << WEXITSTATUS(status) << std::endl << std::endl; +// exit(0); + run = false; + break; + + case -1: + if ((errno == EINTR) || (errno == EAGAIN)) { + errno = 0; + } + else { + FAIL("read() failed"); + run = false; + } break; + + default: + dataReadFromChild.append(buffer, readResult); + break; + } + } + } +} + + +// mediainfo ${media} | grep "Scan type" +// ffmpeg -i ${media} +int main() +{ + parseConfig("srclient.conf"); + + std::cout << std::endl << "===========================================" << std::endl << std::endl; + parseConfig("srserver.conf"); + + std::cout << std::endl << "===========================================" << std::endl << std::endl; + testCommandReader(); + +// std::cout << std::endl << "===========================================" << std::endl << std::endl; +// testMediaFiles("testMedia.files"); + + cFile::Cleanup(); + return 0; +} |