From 7e1d63dd9fd149e4934bf77095c8610fac786b04 Mon Sep 17 00:00:00 2001 From: Henri Herscher Date: Thu, 20 Oct 2005 13:40:58 +0000 Subject: First checkin git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@2 09dcff7a-b715-0410-9601-b79a96267cd0 --- BUILD_C++.txt | 58 + BUILD_JAVA.txt | 59 + LICENSE.txt | 341 ++ README.txt | 29 + VERSION.txt | 1 + oreka.userlibraries | 72 + orkaudio/App.h | 14 + orkaudio/AudioCapturePlugin.h | 47 + orkaudio/AudioTape.cpp | 385 ++ orkaudio/AudioTape.h | 122 + orkaudio/BUILD.txt | 2 + orkaudio/BatchProcessing.cpp | 107 + orkaudio/BatchProcessing.h | 39 + orkaudio/CapturePluginProxy.cpp | 197 + orkaudio/CapturePluginProxy.h | 49 + orkaudio/CapturePort.cpp | 248 ++ orkaudio/CapturePort.h | 66 + orkaudio/Config.cpp | 112 + orkaudio/Config.h | 98 + orkaudio/ConfigManager.cpp | 98 + orkaudio/ConfigManager.h | 38 + orkaudio/Daemon.cpp | 194 + orkaudio/Daemon.h | 47 + orkaudio/ImmediateProcessing.cpp | 61 + orkaudio/ImmediateProcessing.h | 34 + orkaudio/LogManager.cpp | 37 + orkaudio/LogManager.h | 44 + orkaudio/Makefile.am | 18 + orkaudio/Makefile.cvs | 8 + orkaudio/MultiThreadedServer.cpp | 223 ++ orkaudio/MultiThreadedServer.h | 53 + orkaudio/OrkAudio.cpp | 151 + orkaudio/OrkAudio.dsp | 278 ++ orkaudio/OrkAudio.dsw | 89 + orkaudio/OrkAudio.h | 13 + orkaudio/Reporting.cpp | 65 + orkaudio/Reporting.h | 33 + orkaudio/ThreadSafeQueue.h | 76 + orkaudio/audiocaptureplugins/Makefile.am | 2 + .../common/AudioCapturePluginCommon.cpp | 29 + .../common/AudioCapturePluginCommon.h | 36 + .../audiocaptureplugins/generator/Generator.cpp | 147 + .../audiocaptureplugins/generator/Generator.dsp | 126 + .../generator/GeneratorConfig.cpp | 70 + .../generator/GeneratorConfig.h | 66 + orkaudio/audiocaptureplugins/generator/Makefile.am | 10 + .../sounddevice/SoundDevice.cpp | 252 ++ .../sounddevice/SoundDevice.dsp | 130 + .../sounddevice/SoundDeviceConfig.cpp | 70 + .../sounddevice/SoundDeviceConfig.h | 60 + orkaudio/audiocaptureplugins/voip/Makefile.am | 10 + .../audiocaptureplugins/voip/PacketHeaderDefs.h | 71 + orkaudio/audiocaptureplugins/voip/Rtp.cpp | 257 ++ orkaudio/audiocaptureplugins/voip/Rtp.h | 77 + orkaudio/audiocaptureplugins/voip/SipSession.cpp | 282 ++ orkaudio/audiocaptureplugins/voip/SipSession.h | 87 + orkaudio/audiocaptureplugins/voip/VoIp.cpp | 465 +++ orkaudio/audiocaptureplugins/voip/VoIp.dsp | 158 + orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp | 127 + orkaudio/audiocaptureplugins/voip/VoIpConfig.h | 68 + orkaudio/audiocaptureplugins/voip/g711.c | 285 ++ orkaudio/audiocaptureplugins/voip/g711.h | 21 + orkaudio/audiofile/AudioFile.cpp | 58 + orkaudio/audiofile/AudioFile.h | 69 + orkaudio/audiofile/LibSndFileFile.cpp | 123 + orkaudio/audiofile/LibSndFileFile.h | 46 + orkaudio/audiofile/Makefile.am | 6 + orkaudio/audiofile/PcmFile.cpp | 100 + orkaudio/audiofile/PcmFile.h | 41 + orkaudio/config-template.xml | 24 + orkaudio/config.guess | 1 + orkaudio/config.sub | 1 + orkaudio/configure.in | 10 + orkaudio/install-sh | 276 ++ orkaudio/logging-template.properties | 43 + orkaudio/ltmain.sh | 1 + orkaudio/messages/CaptureMsg.cpp | 84 + orkaudio/messages/CaptureMsg.h | 51 + orkaudio/messages/DeleteTapeMsg.cpp | 60 + orkaudio/messages/DeleteTapeMsg.h | 33 + orkaudio/messages/Makefile.am | 7 + orkaudio/messages/PingMsg.cpp | 60 + orkaudio/messages/PingMsg.h | 46 + orkaudio/messages/TapeMsg.cpp | 56 + orkaudio/messages/TapeMsg.h | 58 + orkaudio/messages/TestMsg.cpp | 53 + orkaudio/messages/TestMsg.h | 55 + orkaudio/missing | 336 ++ orkaudio/mkinstalldirs | 111 + orkbasecxx/AudioCapture.cpp | 201 ++ orkbasecxx/AudioCapture.h | 109 + orkbasecxx/BUILD.txt | 2 + orkbasecxx/Makefile.am | 14 + orkbasecxx/Makefile.cvs | 8 + orkbasecxx/Object.cpp | 54 + orkbasecxx/Object.h | 56 + orkbasecxx/ObjectFactory.cpp | 44 + orkbasecxx/ObjectFactory.h | 39 + orkbasecxx/OrkBase.cpp | 27 + orkbasecxx/OrkBase.dsp | 330 ++ orkbasecxx/OrkBase.dsw | 29 + orkbasecxx/OrkBase.h | 26 + orkbasecxx/OrkClient.cpp | 132 + orkbasecxx/OrkClient.h | 43 + orkbasecxx/StdString.h | 3747 ++++++++++++++++++++ orkbasecxx/Utils.h | 93 + orkbasecxx/config.guess | 1 + orkbasecxx/config.sub | 1 + orkbasecxx/configure.in | 10 + orkbasecxx/install-sh | 276 ++ orkbasecxx/ltmain.sh | 1 + orkbasecxx/messages/AsyncMessage.cpp | 46 + orkbasecxx/messages/AsyncMessage.h | 48 + orkbasecxx/messages/Makefile.am | 8 + orkbasecxx/messages/Message.cpp | 41 + orkbasecxx/messages/Message.h | 55 + orkbasecxx/messages/SyncMessage.cpp | 14 + orkbasecxx/messages/SyncMessage.h | 31 + orkbasecxx/missing | 336 ++ orkbasecxx/mkinstalldirs | 111 + orkbasecxx/serializers/DomSerializer.cpp | 157 + orkbasecxx/serializers/DomSerializer.h | 81 + orkbasecxx/serializers/Makefile.am | 10 + orkbasecxx/serializers/Serializer.cpp | 312 ++ orkbasecxx/serializers/Serializer.h | 86 + orkbasecxx/serializers/SingleLineSerializer.cpp | 203 ++ orkbasecxx/serializers/SingleLineSerializer.h | 44 + orkbasecxx/serializers/UrlSerializer.cpp | 161 + orkbasecxx/serializers/UrlSerializer.h | 44 + orkbasecxx/serializers/XmlRpcSerializer.cpp | 47 + orkbasecxx/serializers/XmlRpcSerializer.h | 45 + orkbasej/.classpath | 11 + orkbasej/.project | 17 + orkbasej/build.xml | 58 + orkbasej/java/hsqldb.hbm.template.xml | 17 + orkbasej/java/log4j.template.properties | 40 + orkbasej/java/mysql.hbm.template.xml | 35 + orkbasej/java/net/sf/oreka/Cycle.java | 16 + orkbasej/java/net/sf/oreka/Direction.java | 16 + orkbasej/java/net/sf/oreka/HibernateManager.java | 67 + orkbasej/java/net/sf/oreka/OrkException.java | 22 + orkbasej/java/net/sf/oreka/OrkObject.java | 23 + orkbasej/java/net/sf/oreka/OrkObjectFactory.java | 66 + orkbasej/java/net/sf/oreka/OrkTest.java | 123 + orkbasej/java/net/sf/oreka/ServiceClass.java | 16 + .../java/net/sf/oreka/messages/AsyncMessage.java | 18 + orkbasej/java/net/sf/oreka/messages/Message.java | 19 + .../sf/oreka/messages/SimpleResponseMessage.java | 56 + .../java/net/sf/oreka/messages/SyncMessage.java | 19 + .../net/sf/oreka/messages/test/TestMessage.java | 97 + .../sf/oreka/messages/test/TestNestedMessage.java | 108 + .../net/sf/oreka/messages/test/TestSubMessage.java | 57 + .../sf/oreka/persistent/AnnotatedTestClass.java | 59 + .../net/sf/oreka/persistent/AnnotationsTest.java | 316 ++ orkbasej/java/net/sf/oreka/persistent/Domain.java | 91 + .../java/net/sf/oreka/persistent/HbnXmlTest.java | 195 + .../net/sf/oreka/persistent/HbnXmlTestClass.java | 62 + .../java/net/sf/oreka/persistent/LoginString.java | 114 + orkbasej/java/net/sf/oreka/persistent/RecPort.java | 33 + .../java/net/sf/oreka/persistent/RecPortFace.java | 49 + .../java/net/sf/oreka/persistent/RecProgram.java | 516 +++ .../java/net/sf/oreka/persistent/RecSegment.java | 321 ++ .../java/net/sf/oreka/persistent/RecSession.java | 79 + orkbasej/java/net/sf/oreka/persistent/RecTape.java | 249 ++ orkbasej/java/net/sf/oreka/persistent/Service.java | 172 + orkbasej/java/net/sf/oreka/persistent/User.java | 133 + .../net/sf/oreka/serializers/DomSerializer.java | 186 + .../sf/oreka/serializers/KeyValueSerializer.java | 47 + .../net/sf/oreka/serializers/OrkSerializer.java | 239 ++ .../serializers/ServletRequestSerializer.java | 79 + .../sf/oreka/serializers/SingleLineSerializer.java | 231 ++ .../oreka/serializers/test/DomSerializerTest.java | 82 + .../serializers/test/NullHttpServletRequest.java | 163 + .../test/ServletRequestSerializerTest.java | 45 + .../serializers/test/SingleLineSerializerTest.java | 172 + .../oreka/serializers/test/TestMessageSimple.xml | 5 + .../oreka/serializers/test/TestNestedMessage.xml | 6 + orkbasej/java/net/sf/oreka/test/FillDatabase.java | 118 + orktrack/.classpath | 10 + orktrack/.project | 18 + orktrack/context/WEB-INF/web.xml | 39 + orktrack/deploy-template.xml | 118 + orktrack/orktrack.config.xml | 3 + .../src/net/sf/oreka/orktrack/CommandServlet.java | 115 + .../src/net/sf/oreka/orktrack/ConfigManager.java | 86 + .../src/net/sf/oreka/orktrack/ContextListener.java | 90 + orktrack/src/net/sf/oreka/orktrack/LogManager.java | 126 + orktrack/src/net/sf/oreka/orktrack/OrkTest.java | 24 + orktrack/src/net/sf/oreka/orktrack/OrkTrack.java | 74 + .../src/net/sf/oreka/orktrack/OrkTrackConfig.java | 46 + orktrack/src/net/sf/oreka/orktrack/Port.java | 274 ++ .../src/net/sf/oreka/orktrack/PortManager.java | 166 + .../src/net/sf/oreka/orktrack/ProgramManager.java | 158 + .../src/net/sf/oreka/orktrack/ServiceManager.java | 54 + .../src/net/sf/oreka/orktrack/UserManager.java | 66 + .../oreka/orktrack/messages/MetadataMessage.java | 207 ++ .../sf/oreka/orktrack/messages/TapeMessage.java | 202 ++ .../oreka/orktrack/messages/UserStateMessage.java | 119 + .../src/net/sf/oreka/orktrack/test/PortTest.java | 307 ++ .../net/sf/oreka/orktrack/test/ProgramTest.java | 128 + orkweb/.classpath | 11 + orkweb/.project | 17 + orkweb/context/WEB-INF/Home.html | 43 + orkweb/context/WEB-INF/Home.page | 11 + orkweb/context/WEB-INF/RecSegments.html | 154 + orkweb/context/WEB-INF/RecSegments.page | 44 + orkweb/context/WEB-INF/RecSegments.properties | 18 + orkweb/context/WEB-INF/TestComponent.html | 10 + orkweb/context/WEB-INF/orkweb.application | 19 + orkweb/context/WEB-INF/web.xml | 42 + orkweb/context/css/base.css | 394 ++ orkweb/context/css/orekastyle.css | 115 + orkweb/context/images/bg_container.gif | Bin 0 -> 181 bytes orkweb/context/images/bg_container.jpg | Bin 0 -> 361 bytes orkweb/context/images/icon_calendar.gif | Bin 0 -> 692 bytes orkweb/context/images/icon_in.gif | Bin 0 -> 302 bytes orkweb/context/images/icon_out.gif | Bin 0 -> 303 bytes orkweb/context/images/icon_pagefirst.gif | Bin 0 -> 686 bytes orkweb/context/images/icon_pagelast.gif | Bin 0 -> 692 bytes orkweb/context/images/icon_pagenext.gif | Bin 0 -> 587 bytes orkweb/context/images/icon_pageprev.gif | Bin 0 -> 375 bytes orkweb/context/images/icon_play.gif | Bin 0 -> 763 bytes orkweb/context/images/logofpo.gif | Bin 0 -> 1515 bytes orkweb/context/images/menuback1.gif | Bin 0 -> 1341 bytes orkweb/deploy-template.xml | 118 + 225 files changed, 23533 insertions(+) create mode 100644 BUILD_C++.txt create mode 100644 BUILD_JAVA.txt create mode 100644 LICENSE.txt create mode 100644 README.txt create mode 100644 VERSION.txt create mode 100644 oreka.userlibraries create mode 100644 orkaudio/App.h create mode 100644 orkaudio/AudioCapturePlugin.h create mode 100644 orkaudio/AudioTape.cpp create mode 100644 orkaudio/AudioTape.h create mode 100644 orkaudio/BUILD.txt create mode 100644 orkaudio/BatchProcessing.cpp create mode 100644 orkaudio/BatchProcessing.h create mode 100644 orkaudio/CapturePluginProxy.cpp create mode 100644 orkaudio/CapturePluginProxy.h create mode 100644 orkaudio/CapturePort.cpp create mode 100644 orkaudio/CapturePort.h create mode 100644 orkaudio/Config.cpp create mode 100644 orkaudio/Config.h create mode 100644 orkaudio/ConfigManager.cpp create mode 100644 orkaudio/ConfigManager.h create mode 100644 orkaudio/Daemon.cpp create mode 100644 orkaudio/Daemon.h create mode 100644 orkaudio/ImmediateProcessing.cpp create mode 100644 orkaudio/ImmediateProcessing.h create mode 100644 orkaudio/LogManager.cpp create mode 100644 orkaudio/LogManager.h create mode 100644 orkaudio/Makefile.am create mode 100644 orkaudio/Makefile.cvs create mode 100644 orkaudio/MultiThreadedServer.cpp create mode 100644 orkaudio/MultiThreadedServer.h create mode 100644 orkaudio/OrkAudio.cpp create mode 100644 orkaudio/OrkAudio.dsp create mode 100644 orkaudio/OrkAudio.dsw create mode 100644 orkaudio/OrkAudio.h create mode 100644 orkaudio/Reporting.cpp create mode 100644 orkaudio/Reporting.h create mode 100644 orkaudio/ThreadSafeQueue.h create mode 100644 orkaudio/audiocaptureplugins/Makefile.am create mode 100644 orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.cpp create mode 100644 orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.h create mode 100644 orkaudio/audiocaptureplugins/generator/Generator.cpp create mode 100644 orkaudio/audiocaptureplugins/generator/Generator.dsp create mode 100644 orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp create mode 100644 orkaudio/audiocaptureplugins/generator/GeneratorConfig.h create mode 100644 orkaudio/audiocaptureplugins/generator/Makefile.am create mode 100644 orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp create mode 100644 orkaudio/audiocaptureplugins/sounddevice/SoundDevice.dsp create mode 100644 orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp create mode 100644 orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h create mode 100644 orkaudio/audiocaptureplugins/voip/Makefile.am create mode 100644 orkaudio/audiocaptureplugins/voip/PacketHeaderDefs.h create mode 100644 orkaudio/audiocaptureplugins/voip/Rtp.cpp create mode 100644 orkaudio/audiocaptureplugins/voip/Rtp.h create mode 100644 orkaudio/audiocaptureplugins/voip/SipSession.cpp create mode 100644 orkaudio/audiocaptureplugins/voip/SipSession.h create mode 100644 orkaudio/audiocaptureplugins/voip/VoIp.cpp create mode 100644 orkaudio/audiocaptureplugins/voip/VoIp.dsp create mode 100644 orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp create mode 100644 orkaudio/audiocaptureplugins/voip/VoIpConfig.h create mode 100644 orkaudio/audiocaptureplugins/voip/g711.c create mode 100644 orkaudio/audiocaptureplugins/voip/g711.h create mode 100644 orkaudio/audiofile/AudioFile.cpp create mode 100644 orkaudio/audiofile/AudioFile.h create mode 100644 orkaudio/audiofile/LibSndFileFile.cpp create mode 100644 orkaudio/audiofile/LibSndFileFile.h create mode 100644 orkaudio/audiofile/Makefile.am create mode 100644 orkaudio/audiofile/PcmFile.cpp create mode 100644 orkaudio/audiofile/PcmFile.h create mode 100644 orkaudio/config-template.xml create mode 100644 orkaudio/config.guess create mode 100644 orkaudio/config.sub create mode 100644 orkaudio/configure.in create mode 100644 orkaudio/install-sh create mode 100644 orkaudio/logging-template.properties create mode 100644 orkaudio/ltmain.sh create mode 100644 orkaudio/messages/CaptureMsg.cpp create mode 100644 orkaudio/messages/CaptureMsg.h create mode 100644 orkaudio/messages/DeleteTapeMsg.cpp create mode 100644 orkaudio/messages/DeleteTapeMsg.h create mode 100644 orkaudio/messages/Makefile.am create mode 100644 orkaudio/messages/PingMsg.cpp create mode 100644 orkaudio/messages/PingMsg.h create mode 100644 orkaudio/messages/TapeMsg.cpp create mode 100644 orkaudio/messages/TapeMsg.h create mode 100644 orkaudio/messages/TestMsg.cpp create mode 100644 orkaudio/messages/TestMsg.h create mode 100644 orkaudio/missing create mode 100644 orkaudio/mkinstalldirs create mode 100644 orkbasecxx/AudioCapture.cpp create mode 100644 orkbasecxx/AudioCapture.h create mode 100644 orkbasecxx/BUILD.txt create mode 100644 orkbasecxx/Makefile.am create mode 100644 orkbasecxx/Makefile.cvs create mode 100644 orkbasecxx/Object.cpp create mode 100644 orkbasecxx/Object.h create mode 100644 orkbasecxx/ObjectFactory.cpp create mode 100644 orkbasecxx/ObjectFactory.h create mode 100644 orkbasecxx/OrkBase.cpp create mode 100644 orkbasecxx/OrkBase.dsp create mode 100644 orkbasecxx/OrkBase.dsw create mode 100644 orkbasecxx/OrkBase.h create mode 100644 orkbasecxx/OrkClient.cpp create mode 100644 orkbasecxx/OrkClient.h create mode 100644 orkbasecxx/StdString.h create mode 100644 orkbasecxx/Utils.h create mode 100644 orkbasecxx/config.guess create mode 100644 orkbasecxx/config.sub create mode 100644 orkbasecxx/configure.in create mode 100644 orkbasecxx/install-sh create mode 100644 orkbasecxx/ltmain.sh create mode 100644 orkbasecxx/messages/AsyncMessage.cpp create mode 100644 orkbasecxx/messages/AsyncMessage.h create mode 100644 orkbasecxx/messages/Makefile.am create mode 100644 orkbasecxx/messages/Message.cpp create mode 100644 orkbasecxx/messages/Message.h create mode 100644 orkbasecxx/messages/SyncMessage.cpp create mode 100644 orkbasecxx/messages/SyncMessage.h create mode 100644 orkbasecxx/missing create mode 100644 orkbasecxx/mkinstalldirs create mode 100644 orkbasecxx/serializers/DomSerializer.cpp create mode 100644 orkbasecxx/serializers/DomSerializer.h create mode 100644 orkbasecxx/serializers/Makefile.am create mode 100644 orkbasecxx/serializers/Serializer.cpp create mode 100644 orkbasecxx/serializers/Serializer.h create mode 100644 orkbasecxx/serializers/SingleLineSerializer.cpp create mode 100644 orkbasecxx/serializers/SingleLineSerializer.h create mode 100644 orkbasecxx/serializers/UrlSerializer.cpp create mode 100644 orkbasecxx/serializers/UrlSerializer.h create mode 100644 orkbasecxx/serializers/XmlRpcSerializer.cpp create mode 100644 orkbasecxx/serializers/XmlRpcSerializer.h create mode 100644 orkbasej/.classpath create mode 100644 orkbasej/.project create mode 100644 orkbasej/build.xml create mode 100644 orkbasej/java/hsqldb.hbm.template.xml create mode 100644 orkbasej/java/log4j.template.properties create mode 100644 orkbasej/java/mysql.hbm.template.xml create mode 100644 orkbasej/java/net/sf/oreka/Cycle.java create mode 100644 orkbasej/java/net/sf/oreka/Direction.java create mode 100644 orkbasej/java/net/sf/oreka/HibernateManager.java create mode 100644 orkbasej/java/net/sf/oreka/OrkException.java create mode 100644 orkbasej/java/net/sf/oreka/OrkObject.java create mode 100644 orkbasej/java/net/sf/oreka/OrkObjectFactory.java create mode 100644 orkbasej/java/net/sf/oreka/OrkTest.java create mode 100644 orkbasej/java/net/sf/oreka/ServiceClass.java create mode 100644 orkbasej/java/net/sf/oreka/messages/AsyncMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/Message.java create mode 100644 orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/SyncMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/test/TestMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/Domain.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/LoginString.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecPort.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecPortFace.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecProgram.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecSegment.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecSession.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecTape.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/Service.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/User.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/DomSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/DomSerializerTest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/NullHttpServletRequest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml create mode 100644 orkbasej/java/net/sf/oreka/test/FillDatabase.java create mode 100644 orktrack/.classpath create mode 100644 orktrack/.project create mode 100644 orktrack/context/WEB-INF/web.xml create mode 100644 orktrack/deploy-template.xml create mode 100644 orktrack/orktrack.config.xml create mode 100644 orktrack/src/net/sf/oreka/orktrack/CommandServlet.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/ConfigManager.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/ContextListener.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/LogManager.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/OrkTest.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/OrkTrack.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/OrkTrackConfig.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/Port.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/PortManager.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/ProgramManager.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/ServiceManager.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/UserManager.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/messages/MetadataMessage.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/messages/TapeMessage.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/messages/UserStateMessage.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/test/PortTest.java create mode 100644 orktrack/src/net/sf/oreka/orktrack/test/ProgramTest.java create mode 100644 orkweb/.classpath create mode 100644 orkweb/.project create mode 100644 orkweb/context/WEB-INF/Home.html create mode 100644 orkweb/context/WEB-INF/Home.page create mode 100644 orkweb/context/WEB-INF/RecSegments.html create mode 100644 orkweb/context/WEB-INF/RecSegments.page create mode 100644 orkweb/context/WEB-INF/RecSegments.properties create mode 100644 orkweb/context/WEB-INF/TestComponent.html create mode 100644 orkweb/context/WEB-INF/orkweb.application create mode 100644 orkweb/context/WEB-INF/web.xml create mode 100644 orkweb/context/css/base.css create mode 100644 orkweb/context/css/orekastyle.css create mode 100644 orkweb/context/images/bg_container.gif create mode 100644 orkweb/context/images/bg_container.jpg create mode 100644 orkweb/context/images/icon_calendar.gif create mode 100644 orkweb/context/images/icon_in.gif create mode 100644 orkweb/context/images/icon_out.gif create mode 100644 orkweb/context/images/icon_pagefirst.gif create mode 100644 orkweb/context/images/icon_pagelast.gif create mode 100644 orkweb/context/images/icon_pagenext.gif create mode 100644 orkweb/context/images/icon_pageprev.gif create mode 100644 orkweb/context/images/icon_play.gif create mode 100644 orkweb/context/images/logofpo.gif create mode 100644 orkweb/context/images/menuback1.gif create mode 100644 orkweb/deploy-template.xml diff --git a/BUILD_C++.txt b/BUILD_C++.txt new file mode 100644 index 0000000..f3615f4 --- /dev/null +++ b/BUILD_C++.txt @@ -0,0 +1,58 @@ + +This file describes how to build the C++ part of the oreka capture system + +===================================== +Build on Linux + +Prerequisites: + +install these packages first using your linux distribution packaging system +or download sources tarballs from the listed websites. + +* log4cxx 0.9.7 - It is important to use this precise version for now + http://logging.apache.org/log4cxx/ +* ACE 5.4.2 + http://www.cs.wustl.edu/~schmidt/ACE.html +* libpcap 0.7.2 + http://www.tcpdump.org/ +* boost 1.31.0 + http://www.boost.org +* xerces-c 2.6 + http://xml.apache.org/xerces-c/ +* libsndfile 1.0.10 + http://www.mega-nerd.com/libsndfile/ + +Build orkbasecxx on the command line: + +* Go to the root directory of the orkbasecxx +* libtoolize --force +* make -f Makefile.cvs +* ./configure +* make +* make install + +Build orkaudio on the command line: + +* Go to the root directory of the orkaudio +* libtoolize --force +* make -f Makefile.cvs +* ./configure +* make + +For debug binary: modify above as follows +* ./configure --enable-debug=full +* CXXFLAGS="-O0 -g3" +* make -e + +Build using Kdevelop + +* Project/import existing project (libtool based c++ project) + +===================================== +Build on Windows/MSVC6 (SP6) + +* Download the c++ win32 external library pack and unpack into c:\devExt + (if you change this location, you need to change all references in the dsp files) +* Load orkaudio\OrkAudio.dsw into MSVC +* Select orkbase as active project, build +* Select orkaudio as active project, build \ No newline at end of file diff --git a/BUILD_JAVA.txt b/BUILD_JAVA.txt new file mode 100644 index 0000000..97cf389 --- /dev/null +++ b/BUILD_JAVA.txt @@ -0,0 +1,59 @@ + +Building: + +* Install Eclipse 3.1 or later +* Run Eclipse +* /File/Switch workspace/ -> select folder containing this file +* /File/import existing project into workspace/ -> select 1. orkbasej, 2. orktrack 3. orkweb +* /Window/open perspective/java +* Set the compiler compliance for the worskspace to Java 5 (Java 1.5) /Window/preferences/ -> /java/compiler/ +* Import user libraries: + - Get the external java libraries pack from oreka.sourceforge.net and unzip it into {WORKSPACE}/lib + - Edit oreka.userlibraries, search and replace the absolute path to jar files with your own. + - /Window/preferences/ -> /java/buidpath/user libraries/ -> import -> select your modified oreka.userlibraries file +* At this point, all three projects should compile automatically without an error + +Install required infrastructure software: + +* Install Java 5 JDK +* Install Tomcat 5.5 or later, point it the the Java 5 JDK +* Copy all jar files from the external java libraries pack to {TOMCAT_HOME}/shared/lib +* Make note of the admin password +* Install MySQL or any database compatible with hibernate +* Create a database for storing oreka data +* Create a user/password for reading/writing the newly created database + +Install orktrack: + +* Create a folder for configuration and logging such as c:\oreka\orktrack +* Copy orkbasej/java/log4j.template.properties to this folder and change according to needs +* Copy orkbasej/java/mysql.hbm.template.xml to this folder and change according to needs +* Copy orktrack/orktrack.config.xml to this folder and change according to needs +* Modify orktrack/WEB-INF/web.xml and make it point to those newly created config files +* Copy orktrack/deploy-template.xml to orktrack/deploy.xml and change deploy.xml according to your setup. +* Run deploy.xml as ant script (Right click/Run as). This should result in the following message: + "[echo] OK - Deployed application at context path /orktrack" +* Point your browser to your Tomcat manager (e.g. http://localhost:8080/manager/html) + and check that orktrack has started, otherwise, check Tomcat logs + + +Install orkweb: + +* Create a folder for configuration and logging such as c:\oreka\orkweb +* Copy orkbasej/java/log4j.template.properties to this folder and change according to needs +* Copy orkbasej/java/mysql.hbm.template.xml to this folder and change according to needs +* Modify orkweb/WEB-INF/web.xml and make it point to those newly created config files +* Copy orktrack/deploy-template.xml to orktrack/deploy.xml and change deploy.xml according to your setup. +* Run deploy.xml as ant script (Right click/Run as). This should result in the following message: + "[echo] OK - Deployed application at context path /orktrack" +* Point your browser to your Tomcat manager (e.g. http://localhost:8080/manager/html) + and check that orkweb has started, otherwise, check Tomcat logs +* Point your browser to the newly deployed application (e.g. http://localhost:8080/orkweb/app) + + +Test orkweb: + +* Edit orkbasej/java/net/sf/oreka/test/FillDatabase.java and point it to your own hibernate config file created earlier +* Run FillDatabase.java as a Java application. This will fill your oreka database with test data +* Point your browser to orkweb as described above +* Browse the test data \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..a52b16e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,341 @@ + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..0559bae --- /dev/null +++ b/README.txt @@ -0,0 +1,29 @@ + +Welcome to Oreka, an open media capture and retrieval platform + +Copyright (C) 2005, orecx LLC http://www.orecx.com + +This program is free software, distributed under the terms of +the GNU General Public License. + +The platform currently comprises three services: + +* orkaudio: the audio capture and storage daemon with pluggable capture modules + currently comes with modules for VoIP and sound device recording. + +* orktrack: logs all activity from one or more orkaudio services to any mainstream database. + +* orkweb: Web based user interface for retrieval. + +To get started: + +* This is the source distribution package. I you want to get going fast, get binary packages from the project webpage. +* Refer to BUILD_C++.txt for building orkaudio and associated capture modules +* Refer to BUILD_JAVA.txt for building orktrack and orkweb + +This package is organized as follows: + +* orkbasecxx is the base C++ library +* orkaudio is the audio capture and storage service with pluggable modules +* orkbasej is the base java library +* orkweb is a j2ee tapestry based front-end for media retrieval \ No newline at end of file diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..9346573 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +Oreka system version 0.1 \ No newline at end of file diff --git a/oreka.userlibraries b/oreka.userlibraries new file mode 100644 index 0000000..d2d0d63 --- /dev/null +++ b/oreka.userlibraries @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/orkaudio/App.h b/orkaudio/App.h new file mode 100644 index 0000000..19b5b95 --- /dev/null +++ b/orkaudio/App.h @@ -0,0 +1,14 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + + diff --git a/orkaudio/AudioCapturePlugin.h b/orkaudio/AudioCapturePlugin.h new file mode 100644 index 0000000..b3469ec --- /dev/null +++ b/orkaudio/AudioCapturePlugin.h @@ -0,0 +1,47 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __AUDIOCAPTUREPLUGIN_H__ +#define __AUDIOCAPTUREPLUGIN_H__ + +#include "AudioCapture.h" +#include "LogManager.h" +#include "xercesc/dom/DOMNode.hpp" + +using namespace XERCES_CPP_NAMESPACE; + +#ifdef WIN32 +#define __CDECL__ __cdecl +#else +#define __CDECL__ +#endif + +#define AUDIO_CAPTURE_PLUGIN_INTERFACE_VERSION 1 + +// Callback definitions +typedef void (__CDECL__*AudioChunkCallBackFunction)(AudioChunkRef, CStdString& capturePort, bool remote = false); +typedef void (__CDECL__*CaptureEventCallBackFunction)(CaptureEventRef, CStdString& capturePort); + + +// Exported functions definitions +typedef void (__CDECL__* RegisterCallBacksFunction)(AudioChunkCallBackFunction, CaptureEventCallBackFunction, LogManager*); +typedef void (__CDECL__* InitializeFunction)(); +typedef void (__CDECL__* RunFunction)(); +typedef void (__CDECL__* ConfigureFunction)(DOMNode*); +typedef void (__CDECL__* StartCaptureFunction)(CStdString& port); +typedef void (__CDECL__* StopCaptureFunction)(CStdString& port); + + + +#endif + diff --git a/orkaudio/AudioTape.cpp b/orkaudio/AudioTape.cpp new file mode 100644 index 0000000..312524a --- /dev/null +++ b/orkaudio/AudioTape.cpp @@ -0,0 +1,385 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "ConfigManager.h" +#include "AudioTape.h" +#include "ace/OS_NS_time.h" +#include "Utils.h" +#include "ThreadSafeQueue.h" +#include "audiofile/PcmFile.h" +#include "LogManager.h" +#include "audiofile/LibSndFileFile.h" +#include "messages/TapeMsg.h" + +AudioTapeDescription::AudioTapeDescription() +{ + m_direction = CaptureEvent::DirUnkn; + m_duration = 0; + m_beginDate = 0; +} + +void AudioTapeDescription::Define(Serializer* s) +{ + s->DateValue("date", m_beginDate); + s->IntValue("duration", m_duration); + s->EnumValue("direction", (int&)m_direction, CaptureEvent::DirectionToEnum, CaptureEvent::DirectionToString); + s->StringValue("capturePort", m_capturePort); + s->StringValue("localParty", m_localParty); + s->StringValue("remoteParty", m_remoteParty); + s->StringValue("localEntryPoint", m_localEntryPoint); +} + +void AudioTapeDescription::Validate(){} + +CStdString AudioTapeDescription::GetClassName() +{ + return "tapedescription"; +} + +ObjectRef AudioTapeDescription::NewInstance() +{ + ObjectRef ref(new AudioTapeDescription()); + return ref; +} + +ObjectRef AudioTapeDescription::Process() +{ + ObjectRef ref; + return ref; +} + + +//=================================================== +AudioTape::AudioTape(CStdString &portId) +{ + m_portId = portId; + m_state = StateCreated; + m_beginDate = ACE_OS::time(NULL); + m_endDate = 0; + m_duration = 0; + m_direction = CaptureEvent::DirUnkn; + m_shouldStop = false; + + GenerateFilePathAndIdentifier(); +} + + +void AudioTape::AddAudioChunk(AudioChunkRef chunkRef, bool remote) +{ + // Add the chunk to the local queue + { + MutexSentinel sentinel(m_mutex); + if(remote) + { + m_remoteChunkQueue.push(chunkRef); + } + else + { + m_chunkQueue.push(chunkRef); + } + } +} + +void AudioTape::Write() +{ + // Get the latest audio chunks and write them to disk + bool done = false; + while(!done && m_state != StateStopped && m_state != StateError) + { + // Get the oldest audio chunk + AudioChunkRef chunkRef; + { + MutexSentinel sentinel(m_mutex); + if (m_chunkQueue.size() > 0) + { + chunkRef = m_chunkQueue.front(); + m_chunkQueue.pop(); + } + else + { + done = true; + } + } + if(!done) + { + try + { + // Need to create file appender when receiving first audio chunk + if (m_state == StateCreated) + { + m_state = StateActive; + + switch(chunkRef->m_encoding) + { + case AudioChunk::PcmAudio: + m_audioFileRef.reset(new PcmFile); + break; + case AudioChunk::UlawAudio: + m_audioFileRef.reset(new LibSndFileFile(SF_FORMAT_ULAW | SF_FORMAT_WAV)); + break; + case AudioChunk::AlawAudio: + m_audioFileRef.reset(new LibSndFileFile(SF_FORMAT_ALAW | SF_FORMAT_WAV)); + break; + default: + LOG4CXX_ERROR(LOG.portLog, "#" + m_portId + ": received unsupported audio encoding from capture plugin:" + FileFormatToString(chunkRef->m_encoding)); + m_state = StateError; + } + if (m_state == StateActive) + { + // A file format was successfully added to the tape, open it + CStdString file = m_filePath + m_fileIdentifier; + m_audioFileRef->Open(file, AudioFile::WRITE); + + // determine what final extension the file will have after optional compression + if(CONFIG.m_storageAudioFormat == FfNative) + { + m_fileExtension = m_audioFileRef->GetExtension(); + } + else + { + m_fileExtension = GetFileFormatExtension(CONFIG.m_storageAudioFormat); + } + } + } + if (m_state == StateActive) + { + m_audioFileRef->WriteChunk(chunkRef); + + if (CONFIG.m_logRms) + { + // Compute RMS, RMS dB and log + CStdString rmsString; + rmsString.Format("%.1f dB:%.1f", chunkRef.get()->ComputeRms(), chunkRef.get()->ComputeRmsDb()); + LOG4CXX_INFO(LOG.portLog, m_portId + " RMS: " + rmsString); + } + } + } + catch (CStdString& e) + { + LOG4CXX_INFO(LOG.portLog, "#" + m_portId + ": " + e); + m_state = StateError; + } + } + } + + if (m_shouldStop) + { + m_state = StateStopped; + } + + if (m_state == StateStopped || m_state == StateError) + { + if(m_audioFileRef.get()) + { + m_audioFileRef->Close(); + } + } +} + +void AudioTape::SetShouldStop() +{ + m_shouldStop = true; +} + +void AudioTape::AddCaptureEvent(CaptureEventRef eventRef, bool send) +{ + // Extract useful info from well known events + switch(eventRef->m_type) + { + case CaptureEvent::EtStop: + m_shouldStop = true; + + m_duration = time(NULL) - m_beginDate; + + { + // Log the call details + AudioTapeDescription atd; + atd.m_beginDate = m_beginDate; + atd.m_capturePort = m_portId; + atd.m_direction = m_direction; + atd.m_duration = m_duration; + atd.m_localEntryPoint = m_localEntryPoint; + atd.m_localParty = m_localParty; + atd.m_remoteParty = m_remoteParty; + CStdString description = atd.SerializeSingleLine(); + LOG4CXX_INFO(LOG.tapelistLog, description); + } + break; + case CaptureEvent::EtDirection: + m_direction = (CaptureEvent::DirectionEnum)CaptureEvent::DirectionToEnum(eventRef->m_value); + break; + case CaptureEvent::EtRemoteParty: + m_remoteParty = eventRef->m_value; + break; + case CaptureEvent::EtLocalParty: + m_localParty = eventRef->m_value; + break; + case CaptureEvent::EtLocalEntryPoint: + m_localEntryPoint = eventRef->m_value; + break; + } + + // Store the capture event locally + { + MutexSentinel sentinel(m_mutex); + m_eventQueue.push(eventRef); + if (send) + { + m_toSendEventQueue.push(eventRef); + } + } +} + +void AudioTape::GetMessage(MessageRef& msgRef) +{ + CaptureEventRef captureEventRef; + { + MutexSentinel sentinel(m_mutex); + captureEventRef = m_toSendEventQueue.front(); + m_toSendEventQueue.pop(); + } + + msgRef.reset(new TapeMsg); + TapeMsg* pTapeMsg = (TapeMsg*)msgRef.get(); + if(captureEventRef->m_type == CaptureEvent::EtStart || captureEventRef->m_type == CaptureEvent::EtStop) + { + if (captureEventRef->m_type == CaptureEvent::EtStart) + { + pTapeMsg->m_timestamp = m_beginDate; + } + else + { + pTapeMsg->m_timestamp = m_endDate; + } + + pTapeMsg->m_fileName = m_filePath + m_fileIdentifier + m_fileExtension; + pTapeMsg-> m_stage = CaptureEvent::EventTypeToString(captureEventRef->m_type); + pTapeMsg->m_capturePort = m_portId; + pTapeMsg->m_localParty = m_localParty; + pTapeMsg->m_localEntryPoint = m_localEntryPoint; + pTapeMsg->m_remoteParty = m_remoteParty; + pTapeMsg->m_direction = CaptureEvent::DirectionToString(m_direction); + pTapeMsg->m_duration = m_duration; + pTapeMsg->m_timestamp = m_beginDate; + } + else + { + // This should be a key-value pair message + } +} + +void AudioTape::GenerateFilePathAndIdentifier() +{ + struct tm date = {0}; + ACE_OS::localtime_r(&m_beginDate, &date); + int month = date.tm_mon + 1; // january=0, decembre=11 + int year = date.tm_year + 1900; + m_filePath.Format("%.4d/%.2d/%.2d/%.2d/", year, month, date.tm_mday, date.tm_hour); + m_fileIdentifier.Format("%.4d%.2d%.2d_%.2d%.2d%.2d_%s", year, month, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec, m_portId); +} + + +CStdString AudioTape::GetIdentifier() +{ + return m_fileIdentifier; +} + +CStdString AudioTape::GetPath() +{ + return m_filePath; +} + +bool AudioTape::IsStoppedAndValid() +{ + if (m_state == StateStopped) + { + return true; + } + else + { + return false; + } +} + +AudioFileRef AudioTape::GetAudioFileRef() +{ + return m_audioFileRef; +} + +//======================================== +// File format related methods + +int AudioTape::FileFormatToEnum(CStdString& format) +{ + int formatEnum = FfUnknown; + if(format.CompareNoCase(FF_NATIVE) == 0) + { + formatEnum = FfNative; + } + else if (format.CompareNoCase(FF_GSM) == 0) + { + formatEnum = FfGsm; + } + else if (format.CompareNoCase(FF_ULAW) == 0) + { + formatEnum = FfUlaw; + } + else if (format.CompareNoCase(FF_ALAW) == 0) + { + formatEnum = FfAlaw; + } + return formatEnum; +} + +CStdString AudioTape::FileFormatToString(int formatEnum) +{ + CStdString formatString; + switch (formatEnum) + { + case FfNative: + formatString = FF_NATIVE; + break; + case FfGsm: + formatString = FF_GSM; + break; + case FfUlaw: + formatString = FF_ULAW; + break; + case FfAlaw: + formatString = FF_ALAW; + break; + default: + formatString = FF_UNKNOWN; + } + return formatString; +} + +CStdString AudioTape::GetFileFormatExtension(FileFormatEnum formatEnum) +{ + CStdString extension; + switch (formatEnum) + { + case FfGsm: + case FfUlaw: + case FfAlaw: + extension = ".wav"; + break; + default: + CStdString formatEnumString = IntToString(formatEnum); + throw (CStdString("AudioTape::GetFileFormatExtension: unknown file format:") + formatEnumString); + } + return extension; +} + + + diff --git a/orkaudio/AudioTape.h b/orkaudio/AudioTape.h new file mode 100644 index 0000000..113ff23 --- /dev/null +++ b/orkaudio/AudioTape.h @@ -0,0 +1,122 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __AUDIOTAPE_H__ +#define __AUDIOTAPE_H__ + +#include "ace/Thread_Mutex.h" +#include "time.h" +#include "StdString.h" +#include "boost/shared_ptr.hpp" +#include +#include "AudioCapture.h" +#include "audiofile/AudioFile.h" +#include "messages/Message.h" + +class AudioTapeDescription : public Object +{ +public: + AudioTapeDescription(); + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + + ObjectRef Process(); + + CStdString m_capturePort; + CStdString m_localParty; + CStdString m_localEntryPoint; + CStdString m_remoteParty; + CaptureEvent::DirectionEnum m_direction; + time_t m_beginDate; + int m_duration; +}; + +class AudioTape +{ +public: + typedef enum + { + StateUnknown = 0, + StateCreated = 1, + StateActive = 2, + StateStopped = 3, + StateError = 4, + StateInvalid = 5 + } StateEnum; + +#define FF_NATIVE "native" +#define FF_GSM "GSM" +#define FF_ULAW "ulaw" +#define FF_ALAW "alaw" +#define FF_UNKNOWN "unknown" + typedef enum + { + FfUnknown = 0, + FfNative = 1, + FfGsm = 2, + FfUlaw = 3, + FfAlaw = 4, + FfInvalid = 5 + } FileFormatEnum; + static int FileFormatToEnum(CStdString& format); + static CStdString FileFormatToString(int formatEnum); + static CStdString GetFileFormatExtension(FileFormatEnum); + + + AudioTape(CStdString &portId); + + void AddAudioChunk(AudioChunkRef chunkRef, bool remote = false); + void Write(); + void SetShouldStop(); + bool IsStoppedAndValid(); + void AddCaptureEvent(CaptureEventRef eventRef, bool send = true); + void GetMessage(MessageRef& msg); + /** Returns an identifier for the tape which corresponds to the filename without extension */ + CStdString GetIdentifier(); + CStdString GetPath(); + AudioFileRef GetAudioFileRef(); + + CStdString m_portId; + CStdString m_localParty; + CStdString m_localEntryPoint; + CStdString m_remoteParty; + CaptureEvent::DirectionEnum m_direction; + time_t m_beginDate; + time_t m_endDate; + time_t m_duration; +private: + void GenerateFilePathAndIdentifier(); + + CStdString m_filePath; + CStdString m_fileIdentifier; + CStdString m_fileExtension; //Corresponds to the extension the tape will have after compression + + std::queue m_chunkQueue; + std::queue m_remoteChunkQueue; // used if stereo capture + + std::queue m_eventQueue; + std::queue m_toSendEventQueue; + + AudioFileRef m_audioFileRef; + ACE_Thread_Mutex m_mutex; + StateEnum m_state; + bool m_shouldStop; +}; + +typedef boost::shared_ptr AudioTapeRef; + +#endif + diff --git a/orkaudio/BUILD.txt b/orkaudio/BUILD.txt new file mode 100644 index 0000000..70f9ba3 --- /dev/null +++ b/orkaudio/BUILD.txt @@ -0,0 +1,2 @@ + +To build this, please see ../BUILD_C++.txt \ No newline at end of file diff --git a/orkaudio/BatchProcessing.cpp b/orkaudio/BatchProcessing.cpp new file mode 100644 index 0000000..6aa1600 --- /dev/null +++ b/orkaudio/BatchProcessing.cpp @@ -0,0 +1,107 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "ConfigManager.h" +#include "BatchProcessing.h" +#include "LogManager.h" +#include "ace/OS_NS_unistd.h" +#include "audiofile/LibSndFileFile.h" + +BatchProcessing BatchProcessing::m_batchProcessingSingleton; + +BatchProcessing::BatchProcessing() +{ + m_threadCount = 0; +} + + +BatchProcessing* BatchProcessing::GetInstance() +{ + return &m_batchProcessingSingleton; +} + +void BatchProcessing::AddAudioTape(AudioTapeRef audioTapeRef) +{ + if (!m_audioTapeQueue.push(audioTapeRef)) + { + // Log error + LOG4CXX_ERROR(LOG.batchProcessingLog, CStdString("BatchProcessing: queue full")); + } +} + +void BatchProcessing::ThreadHandler(void *args) +{ + BatchProcessing* pBatchProcessing = BatchProcessing::GetInstance(); + int threadId = 0; + { + MutexSentinel sentinel(pBatchProcessing->m_mutex); + threadId = pBatchProcessing->m_threadCount++; + } + CStdString threadIdString = IntToString(threadId); + LOG4CXX_DEBUG(LOG.batchProcessingLog, CStdString("Created thread #") + threadIdString); + + for(;;) + { + try + { + AudioTapeRef audioTapeRef = pBatchProcessing->m_audioTapeQueue.pop(); + CStdString threadIdString = IntToString(threadId); + LOG4CXX_INFO(LOG.batchProcessingLog, CStdString("Th") + threadIdString + " processing: " + audioTapeRef->GetIdentifier()); + + AudioFileRef fileRef = audioTapeRef->GetAudioFileRef(); + fileRef->MoveOrig(); + fileRef->Open(AudioFile::READ); + + AudioChunkRef chunkRef; + AudioFileRef outFileRef; + + switch(CONFIG.m_storageAudioFormat) + { + case AudioTape::FfUlaw: + outFileRef.reset(new LibSndFileFile(SF_FORMAT_ULAW | SF_FORMAT_WAV)); + break; + case AudioTape::FfAlaw: + outFileRef.reset(new LibSndFileFile(SF_FORMAT_ALAW | SF_FORMAT_WAV)); + break; + case AudioTape::FfGsm: + default: + outFileRef.reset(new LibSndFileFile(SF_FORMAT_GSM610 | SF_FORMAT_WAV)); + } + CStdString file = audioTapeRef->GetPath() + audioTapeRef->GetIdentifier(); + outFileRef->Open(file, AudioFile::WRITE); + + while(fileRef->ReadChunkMono(chunkRef)) + { + outFileRef->WriteChunk(chunkRef); + } + + if(CONFIG.m_deleteNativeFile) + { + fileRef->Close(); + fileRef->Delete(); + CStdString threadIdString = IntToString(threadId); + LOG4CXX_INFO(LOG.batchProcessingLog, CStdString("Th") + threadIdString + " deleting native: " + audioTapeRef->GetIdentifier()); + } + } + catch (CStdString& e) + { + LOG4CXX_ERROR(LOG.batchProcessingLog, CStdString("BatchProcessing: ") + e); + } + catch(...) + { + } + + } +} + + diff --git a/orkaudio/BatchProcessing.h b/orkaudio/BatchProcessing.h new file mode 100644 index 0000000..73a62f0 --- /dev/null +++ b/orkaudio/BatchProcessing.h @@ -0,0 +1,39 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __BATCHPROCESSING_H__ +#define __BATCHPROCESSING_H__ + +#include "ThreadSafeQueue.h" +#include "AudioTape.h" +#include "ace/Thread_Mutex.h" + +class BatchProcessing +{ +public: + static BatchProcessing* GetInstance(); + static void ThreadHandler(void *args); + + void AddAudioTape(AudioTapeRef audioTapeRef); +private: + BatchProcessing(); + + static BatchProcessing m_batchProcessingSingleton; + ThreadSafeQueue m_audioTapeQueue; + + size_t m_threadCount; + ACE_Thread_Mutex m_mutex; +}; + +#endif + diff --git a/orkaudio/CapturePluginProxy.cpp b/orkaudio/CapturePluginProxy.cpp new file mode 100644 index 0000000..7c4acbc --- /dev/null +++ b/orkaudio/CapturePluginProxy.cpp @@ -0,0 +1,197 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "CapturePluginProxy.h" +#include "ace/OS_NS_dirent.h" +#include "ace/OS_NS_string.h" +#include "ConfigManager.h" +#include "CapturePort.h" + +CapturePluginProxy::CapturePluginProxy() +{ + m_configureFunction = NULL; + m_registerCallBacksFunction = NULL; + m_initializeFunction = NULL; + m_runFunction = NULL; + m_startCaptureFunction = NULL; + m_stopCaptureFunction = NULL; + + m_loaded = false; +} + +bool CapturePluginProxy::Initialize() +{ + // Get the desired capture plugin from the config file, or else, use the first dll encountered. + CStdString pluginDirectory = CONFIG.m_capturePluginPath + "/"; + CStdString pluginPath; + if (!CONFIG.m_capturePlugin.IsEmpty()) + { + // A specific plugin was specified in the config file + pluginPath = pluginDirectory + CONFIG.m_capturePlugin; + } + else + { + // No plugin specified, find the first one in the plugin directory + ACE_DIR* dir = ACE_OS::opendir((PCSTR)pluginDirectory); + if (!dir) + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Capture plugin directory could not be found:" + pluginDirectory)); + } + else + { + dirent* dirEntry = NULL; + bool found = false; + bool done = false; + while(!found && !done) + { + dirEntry = ACE_OS::readdir(dir); + if(dirEntry) + { + if (ACE_OS::strstr(dirEntry->d_name, ".dll")) + { + found = true; + done = true; + pluginPath = pluginDirectory + dirEntry->d_name; + } + } + else + { + done = true; + } + } + ACE_OS::closedir(dir); + } + } + if (!pluginPath.IsEmpty()) + { + m_dll.open((PCSTR)pluginPath); + ACE_TCHAR* error = m_dll.error(); + if(error) + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to load the following plugin: ") + pluginPath); + } + else + { + // Ok, the dll has been successfully loaded + RegisterCallBacksFunction registerCallBacks; + registerCallBacks = (RegisterCallBacksFunction)m_dll.symbol("RegisterCallBacks"); + registerCallBacks(AudioChunkCallBack, CaptureEventCallBack, LogManagerSingleton::instance()); + + m_configureFunction = (ConfigureFunction)m_dll.symbol("Configure"); + if (m_configureFunction) + { + ConfigManagerSingleton::instance()->AddConfigureFunction(m_configureFunction); + + m_initializeFunction = (InitializeFunction)m_dll.symbol("Initialize"); + if (m_initializeFunction) + { + m_initializeFunction(); + + m_runFunction = (RunFunction)m_dll.symbol("Run"); + if (m_runFunction) + { + m_startCaptureFunction = (StartCaptureFunction)m_dll.symbol("StartCapture"); + if (m_startCaptureFunction) + { + m_stopCaptureFunction = (StopCaptureFunction)m_dll.symbol("StopCapture"); + if (m_stopCaptureFunction) + { + m_loaded = true; + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find StopCapture function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find StartCapture function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find Run function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find Initialize function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find Configure function in ") + pluginPath); + } + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to find any capture plugin in: ") + pluginDirectory); + } + + return m_loaded; +} + +void CapturePluginProxy::Run() +{ + m_runFunction(); +} + +void CapturePluginProxy::StartCapture(CStdString& capturePort) +{ + if(m_loaded) + { + m_startCaptureFunction(capturePort); + } + else + { + throw(CStdString("StartCapture: Capture plugin not yet loaded")); + } +} + +void CapturePluginProxy::StopCapture(CStdString& capturePort) +{ + if(m_loaded) + { + m_stopCaptureFunction(capturePort); + } + else + { + throw(CStdString("StopCapture: Capture plugin not yet loaded")); + } +} + +void __CDECL__ CapturePluginProxy::AudioChunkCallBack(AudioChunkRef chunkRef, CStdString& capturePort, bool remote) +{ + // find the right port and give it the audio chunk + CapturePortRef portRef = CapturePortsSingleton::instance()->AddAndReturnPort(capturePort); + portRef->AddAudioChunk(chunkRef, remote); +} + +void __CDECL__ CapturePluginProxy::CaptureEventCallBack(CaptureEventRef eventRef, CStdString& capturePort) +{ + if(CONFIG.m_vad || CONFIG.m_audioSegmentation) + { + if (eventRef->m_type == CaptureEvent::EtStart || eventRef->m_type == CaptureEvent::EtStop) + { + LOG4CXX_ERROR(LOG.portLog, "#" + capturePort + ": received start or stop while in VAD or audio segmentation mode"); + } + } + else + { + // find the right port and give it the event + CapturePortRef portRef = CapturePortsSingleton::instance()->AddAndReturnPort(capturePort); + portRef->AddCaptureEvent(eventRef); + } +} + diff --git a/orkaudio/CapturePluginProxy.h b/orkaudio/CapturePluginProxy.h new file mode 100644 index 0000000..1efc520 --- /dev/null +++ b/orkaudio/CapturePluginProxy.h @@ -0,0 +1,49 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __CAPTUREPLUGINPROXY_H__ +#define __CAPTUREPLUGINPROXY_H__ + +#include "ace/Singleton.h" +#include "ace/Thread_Mutex.h" +#include "ace/DLL.h" +#include "AudioCapture.h" +#include "AudioCapturePlugin.h" + +class CapturePluginProxy +{ +public: + CapturePluginProxy(); + bool Initialize(); + void Run(); + void StartCapture(CStdString& capturePort); + void StopCapture(CStdString& capturePort); + + static void __CDECL__ AudioChunkCallBack(AudioChunkRef chunkRef, CStdString& capturePort, bool remote = false); + static void __CDECL__ CaptureEventCallBack(CaptureEventRef eventRef, CStdString& capturePort); +private: + ConfigureFunction m_configureFunction; + RegisterCallBacksFunction m_registerCallBacksFunction; + InitializeFunction m_initializeFunction; + RunFunction m_runFunction; + StartCaptureFunction m_startCaptureFunction; + StopCaptureFunction m_stopCaptureFunction; + + ACE_DLL m_dll; + bool m_loaded; +}; + +typedef ACE_Singleton CapturePluginProxySingleton; + +#endif + diff --git a/orkaudio/CapturePort.cpp b/orkaudio/CapturePort.cpp new file mode 100644 index 0000000..52ca35c --- /dev/null +++ b/orkaudio/CapturePort.cpp @@ -0,0 +1,248 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "CapturePort.h" +#include "Utils.h" +#include "ImmediateProcessing.h" +#include "LogManager.h" +#include "Reporting.h" +#include "ConfigManager.h" + +CapturePort::CapturePort(CStdString& Id) +{ + m_Id = Id; + m_vadBelowThresholdSec = 0.0; + m_vadUp = false; + m_capturing = false; +} + +CStdString CapturePort::ToString() +{ + CStdString ret; + return ret; +} + +void CapturePort::AddAudioChunk(AudioChunkRef chunkRef, bool remote) +{ + time_t now = time(NULL); + + if(CONFIG.m_audioSegmentation) + { + if (m_audioTapeRef.get()) + { + if ((now - m_audioTapeRef->m_beginDate) >= CONFIG.m_audioSegmentDuration) + { + // signal current tape stop event + CaptureEventRef eventRef(new CaptureEvent); + eventRef->m_type = CaptureEvent::EtStop; + eventRef->m_timestamp = now; + AddCaptureEvent(eventRef); + + // create new tape + m_audioTapeRef.reset(new AudioTape(m_Id)); + + // signal new tape start event + eventRef.reset(new CaptureEvent); + eventRef->m_type = CaptureEvent::EtStart; + eventRef->m_timestamp = now; + AddCaptureEvent(eventRef); + } + } + else + { + // create new tape + m_audioTapeRef.reset(new AudioTape(m_Id)); + + // signal new tape start event + CaptureEventRef eventRef(new CaptureEvent); + eventRef->m_type = CaptureEvent::EtStart; + eventRef->m_timestamp = now; + AddCaptureEvent(eventRef); + } + } + else if (CONFIG.m_vad) + { + if(chunkRef->m_encoding == AudioChunk::PcmAudio) + { + if(m_vadUp) + { + // There is an ongoing capture + if (chunkRef->ComputeRmsDb() < CONFIG.m_vadLowThresholdDb) + { + // Level has gone below low threshold, increase holdon counter + m_vadBelowThresholdSec += chunkRef->GetDurationSec(); + } + else + { + // Level has gone above low threshold, reset holdon counter + m_vadBelowThresholdSec = 0.0; + } + + if (m_vadBelowThresholdSec > CONFIG.m_vadHoldOnSec) + { + // no activity detected for more than hold on time + m_vadUp = false; + + // signal current tape stop event + CaptureEventRef eventRef(new CaptureEvent); + eventRef->m_type = CaptureEvent::EtStop; + eventRef->m_timestamp = now; + AddCaptureEvent(eventRef); + } + } + else + { + // No capture is taking place yet + if (chunkRef->ComputeRmsDb() > CONFIG.m_vadHighThresholdDb) + { + // Voice detected, start a new capture + m_vadBelowThresholdSec = 0.0; + m_vadUp = true; + + // create new tape + m_audioTapeRef.reset(new AudioTape(m_Id)); + + // signal new tape start event + CaptureEventRef eventRef(new CaptureEvent); + eventRef->m_type = CaptureEvent::EtStart; + eventRef->m_timestamp = now; + AddCaptureEvent(eventRef); + } + } + } + else + { + LOG4CXX_ERROR(LOG.portLog, CStdString("Voice activity detection cannot be used on non PCM audio")); + } + } + + // ############ + //if (!m_audioTapeRef.get()) + //{ + // m_audioTapeRef.reset(new AudioTape(m_Id)); + // LOG4CXX_WARN(LOG.portLog, CStdString("Got impromptu audio")); + //} + + if (m_audioTapeRef.get() && m_capturing) + { + m_audioTapeRef->AddAudioChunk(chunkRef, remote); + + // Signal to immediate processing thread that tape has new stuff + ImmediateProcessing::GetInstance()->AddAudioTape(m_audioTapeRef); + } +} + +void CapturePort::AddCaptureEvent(CaptureEventRef eventRef) +{ + AudioTapeRef audioTapeRef = m_audioTapeRef; + + // First of all, handle tape start + if (eventRef->m_type == CaptureEvent::EtStart) + { + m_capturing = true; + if (audioTapeRef.get()) + { + audioTapeRef->SetShouldStop(); // force stop of previous tape + } + audioTapeRef.reset(new AudioTape(m_Id)); // Create a new tape + audioTapeRef->AddCaptureEvent(eventRef, true); + Reporting::GetInstance()->AddAudioTape(audioTapeRef); + m_audioTapeRef = audioTapeRef; + LOG4CXX_INFO(LOG.portLog, "#" + m_Id + ": start"); + } + + if (!audioTapeRef.get()) + { + LOG4CXX_WARN(LOG.portLog, "#" + m_Id + ": received unexpected capture event:" + + CaptureEvent::EventTypeToString(eventRef->m_type)); + } + else + { + // Ok, at this point, we know we have a valid audio tape + switch(eventRef->m_type) + { + case CaptureEvent::EtStop: + + m_capturing = false; + LOG4CXX_INFO(LOG.portLog, "#" + m_Id + ": stop"); + audioTapeRef->AddCaptureEvent(eventRef, true); + + if (m_audioTapeRef->GetAudioFileRef().get()) + { + // Notify immediate processing that tape has stopped + ImmediateProcessing::GetInstance()->AddAudioTape(m_audioTapeRef); + // Reporting needs to send a stop message + Reporting::GetInstance()->AddAudioTape(audioTapeRef); + } + else + { + // Received a stop but there is no valid audio file associated with the tape + LOG4CXX_WARN(LOG.portLog, "#" + m_Id + ": no audio reported between last start and stop"); + } + break; + case CaptureEvent::EtDirection: + case CaptureEvent::EtRemoteParty: + case CaptureEvent::EtLocalParty: + case CaptureEvent::EtLocalEntryPoint: + default: + audioTapeRef->AddCaptureEvent(eventRef, false); + } + } +} + + +//======================================= + +void CapturePorts::Initialize() +{ + m_ports.clear(); +} + +CapturePortRef CapturePorts::GetPort(CStdString & portId) +{ + std::map::iterator pair; + + pair = m_ports.find(portId); + + if (pair == m_ports.end()) + { + CapturePortRef nullPortRef; + return nullPortRef; + } + else + { + return pair->second; + } +} + +CapturePortRef CapturePorts::AddAndReturnPort(CStdString & portId) +{ + //MutexGuard mutexGuard(m_mutex); // To make sure a channel cannot be created twice + + CapturePortRef portRef = GetPort(portId); + if (portRef.get() == NULL) + { + // The port does not already exist, create it. + CapturePortRef newPortRef(new CapturePort(portId)); + m_ports.insert(std::make_pair(portId, newPortRef)); + return newPortRef; + } + else + { + return portRef; + } +} + + diff --git a/orkaudio/CapturePort.h b/orkaudio/CapturePort.h new file mode 100644 index 0000000..6d665b1 --- /dev/null +++ b/orkaudio/CapturePort.h @@ -0,0 +1,66 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#pragma warning( disable: 4786 ) + +#ifndef __PORT_H__ +#define __PORT_H__ + +#include +#include "boost/shared_ptr.hpp" +#include "ace/Thread_Mutex.h" +#include "ace/Singleton.h" + +#include "StdString.h" + +#include "AudioCapture.h" +#include "AudioTape.h" + + +/** Base class for all types of capture ports. */ +class CapturePort +{ +public: + CapturePort(CStdString& Id); + CStdString ToString(); + + void AddAudioChunk(AudioChunkRef chunkRef, bool remote = false); + void AddCaptureEvent(CaptureEventRef eventRef); +private: + CStdString m_Id; + AudioTapeRef m_audioTapeRef; + ACE_Thread_Mutex m_mutex; + bool m_capturing; + double m_vadBelowThresholdSec; + bool m_vadUp; +}; + +typedef boost::shared_ptr CapturePortRef; + +/** This singleton holds all dynamically created capture ports and allows convenient access. */ +class CapturePorts +{ +public: + void Initialize(); + CapturePortRef GetPort(CStdString & portId); + /** Tries to find a capture port from its ID. If unsuccessful, creates a new one and returns it */ + CapturePortRef AddAndReturnPort(CStdString & portId); +private: + std::map m_ports; + ACE_Thread_Mutex m_mutex; +}; + +typedef ACE_Singleton CapturePortsSingleton; + +#endif + diff --git a/orkaudio/Config.cpp b/orkaudio/Config.cpp new file mode 100644 index 0000000..0f6d0cc --- /dev/null +++ b/orkaudio/Config.cpp @@ -0,0 +1,112 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "serializers/Serializer.h" +#include "Config.h" +#include "LogManager.h" + +Config::Config() +{ + m_logMessages = LOG_MESSAGES_DEFAULT; + m_logRms = LOG_RMS_DEFAULT; + m_enableReporting = ENABLE_REPORTING_DEFAULT; + m_capturePluginPath = CAPTURE_PLUGIN_PATH_DEFAULT; + m_storageAudioFormat = STORAGE_AUDIO_FORMAT_DEFAULT; + m_numBatchThreads = NUM_BATCH_THREADS_DEFAULT; + m_deleteNativeFile = DELETE_NATIVE_FILE_DEFAULT; + m_audioChunkDefaultSize = AUDIO_CHUNK_DEFAULT_SIZE_DEFAULT; + m_audioSegmentation = AUDIO_SEGMENTATION_DEFAULT; + m_audioSegmentDuration = AUDIO_SEGMENT_DURATION_DEFAULT; + m_vad = VAD_DEFAULT; + m_vadHighThresholdDb = VAD_HIGH_THRESHOLD_DB_DEFAULT; + m_vadLowThresholdDb = VAD_LOW_THRESHOLD_DB_DEFAULT; + m_vadHoldOnSec = VAD_HOLD_ON_SEC_DEFAULT; + m_trackerHostname = TRACKER_HOSTNAME_DEFAULT; + m_trackerTcpPort = TRACKER_TCP_PORT_DEFAULT; + m_trackerServicename = TRACKER_SERVICENAME_DEFAULT; + + char hostname[40]; + ACE_OS::hostname(hostname, 40); + ACE_OS::hostname(hostname, HOSTNAME_BUF_LEN); + m_serviceName = CStdString("orkaudio-") + hostname; + + m_reportingRetryDelay = 5; + m_clientTimeout = 5; +} + +void Config::Define(Serializer* s) +{ + s->BoolValue(LOG_MESSAGES_PARAM, m_logMessages); + s->BoolValue(LOG_RMS_PARAM, m_logRms); + s->BoolValue(ENABLE_REPORTING_PARAM, m_enableReporting); + s->StringValue(CAPTURE_PLUGIN_PARAM, m_capturePlugin); + s->StringValue(CAPTURE_PLUGIN_PATH_PARAM, m_capturePluginPath); + s->EnumValue(STORAGE_AUDIO_FORMAT_PARAM, (int&)m_storageAudioFormat, AudioTape::FileFormatToEnum, AudioTape::FileFormatToString); + s->IntValue(NUM_BATCH_THREADS_PARAM, m_numBatchThreads); + s->BoolValue(DELETE_NATIVE_FILE_PARAM, m_deleteNativeFile); + s->IntValue(AUDIO_CHUNK_DEFAULT_SIZE_PARAM, m_audioChunkDefaultSize); + s->BoolValue(AUDIO_SEGMENTATION_PARAM, m_audioSegmentation); + s->IntValue(AUDIO_SEGMENT_DURATION_PARAM, m_audioSegmentDuration); + s->BoolValue(VAD_PARAM, m_vad); + s->DoubleValue(VAD_HIGH_THRESHOLD_DB_PARAM, m_vadHighThresholdDb); + s->DoubleValue(VAD_LOW_THRESHOLD_DB_PARAM, m_vadLowThresholdDb); + s->DoubleValue(VAD_HOLD_ON_SEC_PARAM, m_vadHoldOnSec); + s->StringValue(TRACKER_HOSTNAME_PARAM, m_trackerHostname); + s->IntValue(TRACKER_TCP_PORT_PARAM, m_trackerTcpPort); + s->StringValue(TRACKER_SERVICENAME_PARAM, m_trackerServicename); + s->StringValue(SERVICE_NAME_PARAM, m_serviceName); + s->IntValue(REPORTING_RETRY_DELAY_PARAM, m_reportingRetryDelay); + s->IntValue(CLIENT_TIMEOUT_PARAM, m_clientTimeout); +} + +void Config::Validate() +{ + if (m_storageAudioFormat <= AudioTape::FfUnknown || m_storageAudioFormat >= AudioTape::FfInvalid) + { + throw CStdString(CStdString("Config::Validate: value out of range:") + STORAGE_AUDIO_FORMAT_PARAM); + } + if (m_numBatchThreads > 2) + { + LOG4CXX_WARN(LOG.configLog, "It is not recommended to have more batch threads than CPUs"); + } + if (m_vadHighThresholdDb < -45.0 || m_vadHighThresholdDb>0.0) + { + throw CStdString(CStdString("Config::Validate: value out of range:") + VAD_HIGH_THRESHOLD_DB_PARAM); + } + if (m_vadLowThresholdDb < -45.0 || m_vadLowThresholdDb>0.0) + { + throw CStdString(CStdString("Config::Validate: value out of range:") + VAD_LOW_THRESHOLD_DB_PARAM); + } + if (m_vadHighThresholdDb < m_vadLowThresholdDb) + { + throw CStdString(CStdString("Config::Validate: ") + VAD_LOW_THRESHOLD_DB_PARAM + " should be lower than " + VAD_HIGH_THRESHOLD_DB_PARAM); + } + if (m_vad && m_audioSegmentation) + { + throw CStdString(CStdString("Config::Validate: please choose between audio segmentation and VAD ! Both cannot be true at the same time")); + } +} + +CStdString Config::GetClassName() +{ + return CStdString("Config"); +} + +ObjectRef Config::NewInstance() +{ + return ObjectRef(new Config); +} + diff --git a/orkaudio/Config.h b/orkaudio/Config.h new file mode 100644 index 0000000..6b0567a --- /dev/null +++ b/orkaudio/Config.h @@ -0,0 +1,98 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#include "StdString.h" +#include "Object.h" +#include "AudioTape.h" + +#define LOG_MESSAGES_PARAM "LogMessages" +#define LOG_MESSAGES_DEFAULT false +#define CAPTURE_PLUGIN_PARAM "CapturePlugin" +#define CAPTURE_PLUGIN_DEFAULT "" +#define CAPTURE_PLUGIN_PATH_PARAM "CapturePluginPath" +#define CAPTURE_PLUGIN_PATH_DEFAULT "AudioCapturePlugins" +#define STORAGE_AUDIO_FORMAT_PARAM "StorageAudioFormat" +#define STORAGE_AUDIO_FORMAT_DEFAULT (AudioTape::FfGsm) +#define NUM_BATCH_THREADS_PARAM "NumBatchThreads" +#define NUM_BATCH_THREADS_DEFAULT 1 +#define DELETE_NATIVE_FILE_PARAM "DeleteNativeFile" +#define DELETE_NATIVE_FILE_DEFAULT true +#define ENABLE_REPORTING_PARAM "EnableReporting" +#define ENABLE_REPORTING_DEFAULT true +#define AUDIO_CHUNK_DEFAULT_SIZE_PARAM "AudioChunkDefaultSize" +#define AUDIO_CHUNK_DEFAULT_SIZE_DEFAULT 8000 +#define AUDIO_SEGMENTATION_PARAM "AudioSegmentation" +#define AUDIO_SEGMENTATION_DEFAULT false +#define AUDIO_SEGMENT_DURATION_PARAM "AudioSegmentDuration" +#define AUDIO_SEGMENT_DURATION_DEFAULT 60 +#define LOG_RMS_PARAM "LogRms" +#define LOG_RMS_DEFAULT false +#define VAD_PARAM "VAD" +#define VAD_DEFAULT false +#define VAD_HIGH_THRESHOLD_DB_PARAM "VadHighThresholdDb" +#define VAD_HIGH_THRESHOLD_DB_DEFAULT -12.2 +#define VAD_LOW_THRESHOLD_DB_PARAM "VadLowThresholdDb" +#define VAD_LOW_THRESHOLD_DB_DEFAULT -12.5 +#define VAD_HOLD_ON_SEC_PARAM "VadHoldOnSec" +#define VAD_HOLD_ON_SEC_DEFAULT 4 +#define TRACKER_HOSTNAME_PARAM "TrackerHostname" +#define TRACKER_HOSTNAME_DEFAULT "localhost" +#define TRACKER_TCP_PORT_PARAM "TrackerTcpPort" +#define TRACKER_TCP_PORT_DEFAULT 8080 +#define TRACKER_SERVICENAME_PARAM "TrackerServicename" +#define TRACKER_SERVICENAME_DEFAULT "orktrack" +#define SERVICE_NAME_PARAM "ServiceName" +#define REPORTING_RETRY_DELAY_PARAM "ReportingRetryDelay" +#define CLIENT_TIMEOUT_PARAM "ClientTimeout" + + +class Config : public Object +{ +public: + Config(); + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + bool m_logMessages; + bool m_logRms; + bool m_enableReporting; + CStdString m_capturePlugin; + CStdString m_capturePluginPath; + int m_numBatchThreads; + bool m_deleteNativeFile; + int m_audioChunkDefaultSize; + bool m_audioSegmentation; + int m_audioSegmentDuration; + AudioTape::FileFormatEnum m_storageAudioFormat; + bool m_vad; + double m_vadHighThresholdDb; + double m_vadLowThresholdDb; + double m_vadHoldOnSec; + CStdString m_trackerHostname; + CStdString m_trackerServicename; + int m_trackerTcpPort; + CStdString m_serviceName; + int m_reportingRetryDelay; + int m_clientTimeout; +}; + + +#endif + diff --git a/orkaudio/ConfigManager.cpp b/orkaudio/ConfigManager.cpp new file mode 100644 index 0000000..df38818 --- /dev/null +++ b/orkaudio/ConfigManager.cpp @@ -0,0 +1,98 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include +#include +#include +#include +#include "serializers/DomSerializer.h" +#include "ConfigManager.h" +#include "LogManager.h" + +#define CONFIG_FILE_NAME "config.xml" + + +void ConfigManager::Initialize() +{ + bool failed = false; + m_configTopNode = NULL; + + try + { + XMLPlatformUtils::Initialize(); + XercesDOMParser *parser = new XercesDOMParser; + parser->parse(CONFIG_FILE_NAME); + DOMNode *doc = NULL; + doc = parser->getDocument(); + + if (doc) + { + DOMNode *firstChild = doc->getFirstChild(); + if (firstChild) + { + m_configTopNode = firstChild; + m_config.DeSerializeDom(firstChild); + + /* + // Write out config to a file + DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm()); + XERCES_CPP_NAMESPACE::DOMDocument* myDoc; + myDoc = impl->createDocument( + 0, // root element namespace URI. + XStr("root").unicodeForm(), // root element name + 0); // document type object (DTD). + m_config.SerializeDom(myDoc); + CStdString toto = DomSerializer::DomNodeToString(myDoc); + FILE* file = fopen("zzz.xml", "w"); + fwrite((PCSTR)toto,1,toto.GetLength(),file); + fclose(file); + */ + } + else + { + LOG4CXX_ERROR(LOG.configLog, CStdString("Could not parse config file:") + CONFIG_FILE_NAME); + failed = true; + } + } + else + { + LOG4CXX_WARN(LOG.configLog, CStdString("Could not find config file:") + CONFIG_FILE_NAME); + } + } + catch (const CStdString& e) + { + LOG4CXX_ERROR(LOG.configLog, e); + failed = true; + } + catch(const XMLException& e) + { + LOG4CXX_ERROR(LOG.configLog, e.getMessage()); + failed = true; + } + if (failed) + { + exit(0); + } +} + + +void ConfigManager::AddConfigureFunction(ConfigureFunction configureFunction) +{ + m_configureFunction = configureFunction; + // Cal the external configure callback straight away + m_configureFunction(m_configTopNode); +} + diff --git a/orkaudio/ConfigManager.h b/orkaudio/ConfigManager.h new file mode 100644 index 0000000..a3eb42b --- /dev/null +++ b/orkaudio/ConfigManager.h @@ -0,0 +1,38 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __CONFIGMANAGER_H__ +#define __CONFIGMANAGER_H__ + +#include "ace/Singleton.h" +#include "Config.h" +#include "AudioCapturePlugin.h" + +class ConfigManager +{ +public: + void Initialize(); + void AddConfigureFunction(ConfigureFunction); + + Config m_config; +private: + ConfigureFunction m_configureFunction; + DOMNode* m_configTopNode; +}; + +typedef ACE_Singleton ConfigManagerSingleton; + +#define CONFIG ConfigManagerSingleton::instance()->m_config + +#endif + diff --git a/orkaudio/Daemon.cpp b/orkaudio/Daemon.cpp new file mode 100644 index 0000000..f834a7a --- /dev/null +++ b/orkaudio/Daemon.cpp @@ -0,0 +1,194 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#ifdef WIN32 +#include +#include +SERVICE_STATUS serviceStatus; +SERVICE_STATUS_HANDLE serviceStatusHandle = 0; +HANDLE stopServiceEvent = 0; +#endif +#include "Daemon.h" + +#ifdef WIN32 +void WINAPI ServiceControlHandler( DWORD controlCode ) +{ + switch ( controlCode ) + { + case SERVICE_CONTROL_INTERROGATE: + break; + + case SERVICE_CONTROL_SHUTDOWN: + case SERVICE_CONTROL_STOP: + serviceStatus.dwCurrentState = SERVICE_STOP_PENDING; + SetServiceStatus( serviceStatusHandle, &serviceStatus ); + DaemonSingleton::instance()->Stop(); + return; + + case SERVICE_CONTROL_PAUSE: + break; + + case SERVICE_CONTROL_CONTINUE: + break; + + default: + ; + } + + SetServiceStatus( serviceStatusHandle, &serviceStatus ); +} +#endif + +void Daemon::Initialize(CStdString serviceName, DaemonHandler runHandler, DaemonHandler stopHandler) +{ + m_runHandler = runHandler; + m_stopHandler = stopHandler; + m_serviceName = serviceName; +} + +void Daemon::Start() +{ +#ifdef WIN32 + // change current directory to service location (default for NT services is system32) + CStdString workingDirectory; + + TCHAR path[ _MAX_PATH + 1 ]; + if ( GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0 ) + { + CStdString pathString = path; + int lastBackSlashPosition = pathString.ReverseFind("\\"); + if (lastBackSlashPosition != -1) + { + workingDirectory = pathString.Left(lastBackSlashPosition); + chdir((PCSTR)workingDirectory); + } + } + + SERVICE_TABLE_ENTRY serviceTable[] = + { + { (char *)(PCSTR)m_serviceName, Daemon::Run }, + { 0, 0 } + }; + + StartServiceCtrlDispatcher( serviceTable ); +#else + Daemon::Run(); +#endif +} + +#ifdef WIN32 +void WINAPI Daemon::Run( DWORD /*argc*/, TCHAR* /*argv*/[] ) +#else +void Daemon::Run() +#endif +{ +#ifdef WIN32 + // initialise service status + serviceStatus.dwServiceType = SERVICE_WIN32; + serviceStatus.dwCurrentState = SERVICE_START_PENDING; + serviceStatus.dwControlsAccepted = 0; + serviceStatus.dwWin32ExitCode = NO_ERROR; + serviceStatus.dwServiceSpecificExitCode = NO_ERROR; + serviceStatus.dwCheckPoint = 0; + serviceStatus.dwWaitHint = 0; + + serviceStatusHandle = RegisterServiceCtrlHandler( (PCSTR)DaemonSingleton::instance()->m_serviceName, ServiceControlHandler ); + if ( serviceStatusHandle ) + { + // service is starting + serviceStatus.dwCurrentState = SERVICE_START_PENDING; + SetServiceStatus( serviceStatusHandle, &serviceStatus ); + + // running + serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); + serviceStatus.dwCurrentState = SERVICE_RUNNING; + SetServiceStatus( serviceStatusHandle, &serviceStatus ); + } +#endif + + DaemonSingleton::instance()->m_runHandler(); + +#ifdef WIN32 + // service was stopped + serviceStatus.dwCurrentState = SERVICE_STOP_PENDING; + SetServiceStatus( serviceStatusHandle, &serviceStatus ); + + // do cleanup here + CloseHandle( stopServiceEvent ); + stopServiceEvent = 0; + + // service is now stopped + serviceStatus.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); + serviceStatus.dwCurrentState = SERVICE_STOPPED; + SetServiceStatus( serviceStatusHandle, &serviceStatus ); +#endif +} + +void Daemon::Stop() +{ + m_stopHandler(); +} + +void Daemon::Install() +{ +#ifdef WIN32 + SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CREATE_SERVICE ); + + if ( serviceControlManager ) + { + TCHAR path[ _MAX_PATH + 1 ]; + if ( GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0 ) + { + SC_HANDLE service = CreateService( serviceControlManager, + (PCSTR)m_serviceName, (PCSTR)m_serviceName, + SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, + SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, path, + 0, 0, 0, 0, 0 ); + if ( service ) + CloseServiceHandle( service ); + } + + CloseServiceHandle( serviceControlManager ); + } +#endif +} + +void Daemon::Uninstall() +{ +#ifdef WIN32 + SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CONNECT ); + + if ( serviceControlManager ) + { + SC_HANDLE service = OpenService( serviceControlManager, + (PCSTR)m_serviceName, SERVICE_QUERY_STATUS | DELETE ); + if ( service ) + { + SERVICE_STATUS serviceStatus; + if ( QueryServiceStatus( service, &serviceStatus ) ) + { + if ( serviceStatus.dwCurrentState == SERVICE_STOPPED ) + DeleteService( service ); + } + + CloseServiceHandle( service ); + } + + CloseServiceHandle( serviceControlManager ); + } +#endif +} + diff --git a/orkaudio/Daemon.h b/orkaudio/Daemon.h new file mode 100644 index 0000000..e19fff7 --- /dev/null +++ b/orkaudio/Daemon.h @@ -0,0 +1,47 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __DAEMON_H__ +#define __DAEMON_H__ + +#include "StdString.h" +#include "ace/Singleton.h" +#include "ace/Thread_Mutex.h" + +typedef void (*DaemonHandler)(void); + +class Daemon +{ +public: + //void Initialize(CStdString serviceName, void (*RunHandler)(void), void(*StopHandler)(void)); + void Initialize(CStdString serviceName, DaemonHandler runHandler, DaemonHandler stopHandler); + void Start(); + void Stop(); + void Install(); + void Uninstall(); +private: +#ifdef WIN32 + static void WINAPI Run( DWORD /*argc*/, TCHAR* /*argv*/[] ); +#else + static void Run(); +#endif + + DaemonHandler m_runHandler; + DaemonHandler m_stopHandler; + CStdString m_serviceName; +}; + +typedef ACE_Singleton DaemonSingleton; + +#endif + diff --git a/orkaudio/ImmediateProcessing.cpp b/orkaudio/ImmediateProcessing.cpp new file mode 100644 index 0000000..197f505 --- /dev/null +++ b/orkaudio/ImmediateProcessing.cpp @@ -0,0 +1,61 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "ImmediateProcessing.h" +#include "LogManager.h" +#include "ace/OS_NS_unistd.h" +#include "BatchProcessing.h" + +ImmediateProcessing ImmediateProcessing::m_immediateProcessingSingleton; + +ImmediateProcessing* ImmediateProcessing::GetInstance() +{ + return &m_immediateProcessingSingleton; +} + +void ImmediateProcessing::AddAudioTape(AudioTapeRef audioTapeRef) +{ + if (!m_audioTapeQueue.push(audioTapeRef)) + { + // Log error + LOG4CXX_ERROR(LOG.immediateProcessingLog, CStdString("ImmediateProcessing: queue full")); + } +} + +void ImmediateProcessing::ThreadHandler(void *args) +{ + ImmediateProcessing* pImmediateProcessing = ImmediateProcessing::GetInstance(); + + for(;;) + { + try + { + AudioTapeRef audioTapeRef = pImmediateProcessing->m_audioTapeQueue.pop(); + //LOG4CXX_DEBUG(LOG.immediateProcessingLog, CStdString("Got chunk")); + + audioTapeRef->Write(); + + if (audioTapeRef->IsStoppedAndValid()) + { + // Forward to batch processing thread + BatchProcessing::GetInstance()->AddAudioTape(audioTapeRef); + } + } + catch (CStdString& e) + { + LOG4CXX_ERROR(LOG.immediateProcessingLog, CStdString("ImmediateProcessing: ") + e); + } + } +} + + diff --git a/orkaudio/ImmediateProcessing.h b/orkaudio/ImmediateProcessing.h new file mode 100644 index 0000000..617f105 --- /dev/null +++ b/orkaudio/ImmediateProcessing.h @@ -0,0 +1,34 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __IMMEDIATEPROCESSING_H__ +#define __IMMEDIATEPROCESSING_H__ + +#include "ThreadSafeQueue.h" +#include "AudioTape.h" + +class ImmediateProcessing +{ +public: + static ImmediateProcessing* GetInstance(); + static void ThreadHandler(void *args); + + void AddAudioTape(AudioTapeRef audioTapeRef); +private: + static ImmediateProcessing m_immediateProcessingSingleton; + ThreadSafeQueue m_audioTapeQueue; + +}; + +#endif + diff --git a/orkaudio/LogManager.cpp b/orkaudio/LogManager.cpp new file mode 100644 index 0000000..6639c98 --- /dev/null +++ b/orkaudio/LogManager.cpp @@ -0,0 +1,37 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "LogManager.h" +#include +#include + +void LogManager::Initialize() +{ + BasicConfigurator::configure(); + + // If this one fails, the above default configuration stays valid + PropertyConfigurator::configure("logging.properties"); + + rootLog = Logger::getLogger("root"); + topLog = Logger::getLogger("top"); + immediateProcessingLog = Logger::getLogger("immediateProcessing"); + batchProcessingLog = Logger::getLogger("batchProcessing"); + portLog = Logger::getLogger("port"); + fileLog = Logger::getLogger("file"); + reportingLog = Logger::getLogger("reporting"); + configLog = Logger::getLogger("config"); + tapelistLog = Logger::getLogger("tapelist"); +} + diff --git a/orkaudio/LogManager.h b/orkaudio/LogManager.h new file mode 100644 index 0000000..e605aa5 --- /dev/null +++ b/orkaudio/LogManager.h @@ -0,0 +1,44 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __LOGMANAGER_H__ +#define __LOGMANAGER_H__ + +#include +#include "ace/Singleton.h" + +using namespace log4cxx; + + +class LogManager +{ +public: + void Initialize(); + + LoggerPtr rootLog; + LoggerPtr topLog; + LoggerPtr immediateProcessingLog; + LoggerPtr batchProcessingLog; + LoggerPtr portLog; + LoggerPtr fileLog; + LoggerPtr reportingLog; + LoggerPtr configLog; + LoggerPtr tapelistLog; +}; + +typedef ACE_Singleton LogManagerSingleton; + +#define LOG (*LogManagerSingleton::instance()) + +#endif + diff --git a/orkaudio/Makefile.am b/orkaudio/Makefile.am new file mode 100644 index 0000000..659c8d1 --- /dev/null +++ b/orkaudio/Makefile.am @@ -0,0 +1,18 @@ +# not a GNU package. You can remove this line, if +# have all needed files, that a GNU package needs +AUTOMAKE_OPTIONS = foreign 1.4 + + +bin_PROGRAMS = orkaudio +orkaudio_LDADD = +orkaudio_LDFLAGS = -lsndfile -lACE -lxerces-c -llog4cxx -lorkbase +orkaudio_SOURCES = OrkAudio.cpp AudioTape.cpp \ + BatchProcessing.cpp CapturePluginProxy.cpp \ + CapturePort.cpp Config.cpp ConfigManager.cpp \ + Daemon.cpp ImmediateProcessing.cpp LogManager.cpp \ + MultiThreadedServer.cpp Reporting.cpp +AM_CPPFLAGS = -D_REENTRANT +INCLUDES = -I@top_srcdir@ -I../orkbasecxx +SUBDIRS = audiocaptureplugins messages audiofile +orkaudio_LDADD = $(top_builddir)/messages/libmessages.la \ + $(top_builddir)/audiofile/libaudiofile.la diff --git a/orkaudio/Makefile.cvs b/orkaudio/Makefile.cvs new file mode 100644 index 0000000..d160702 --- /dev/null +++ b/orkaudio/Makefile.cvs @@ -0,0 +1,8 @@ +default: all + +all: + aclocal + autoheader + automake + autoconf + diff --git a/orkaudio/MultiThreadedServer.cpp b/orkaudio/MultiThreadedServer.cpp new file mode 100644 index 0000000..458f781 --- /dev/null +++ b/orkaudio/MultiThreadedServer.cpp @@ -0,0 +1,223 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "MultiThreadedServer.h" + +#include "ace/INET_Addr.h" +#include "ace/OS_NS_string.h" +#include "ObjectFactory.h" +#include "serializers/SingleLineSerializer.h" +#include "serializers/DomSerializer.h" +#include "serializers/UrlSerializer.h" +#include "LogManager.h" +#include "Utils.h" +#include +#include +#include +#include + + +int CommandLineServer::open (void *void_acceptor) +{ + return this->activate (THR_DETACHED); +} + + +void CommandLineServer::run(void* args) +{ + unsigned short tcpPort = (unsigned short)args; + CommandLineAcceptor peer_acceptor; + ACE_INET_Addr addr (tcpPort); + ACE_Reactor reactor; + + if (peer_acceptor.open (addr, &reactor) == -1) + { + CStdString tcpPortString = IntToString(tcpPort); + LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to start command line server on port:") + tcpPortString); + } + else + { + for(;;) + { + reactor.handle_events(); + } + } +} + +int CommandLineServer::svc(void) +{ + for (bool active = true;active == true;) + { + char buf[2048]; + ACE_Time_Value timeout; + timeout.sec(3600); + int i = 0; + + // Display prompt + char prompt[] = "\r\n>"; + peer().send(prompt, 3); + + // Get one command line + bool foundCRLF = false; + while(active && !foundCRLF && i<2040) + { + ssize_t size = peer().recv(buf+i, 2040-i, &timeout); + + if (size == 0 || size == -1) + { + active = false; + } + else + { + for(int j=0; jNewInstance(className); + if (objRef.get()) + { + objRef->DeSerializeSingleLine(command); + ObjectRef response = objRef->Process(); + CStdString responseString = response->SerializeSingleLine(); + peer().send((PCSTR)responseString, responseString.GetLength()); + } + else + { + CStdString error = "Unrecognized command"; + peer().send(error, error.GetLength()); ; + } + } + catch (CStdString& e) + { + peer().send(e, e.GetLength()); ; + } + } + } + i += size; + } + } + } + return 0; +} + + +//============================================================== + +int HttpServer::open (void *void_acceptor) +{ + return this->activate (THR_DETACHED); +} + + +void HttpServer::run(void* args) +{ + unsigned short tcpPort = (unsigned short)args; + HttpAcceptor peer_acceptor; + ACE_INET_Addr addr (tcpPort); + ACE_Reactor reactor; + + if (peer_acceptor.open (addr, &reactor) == -1) + { + CStdString tcpPortString = IntToString(tcpPort); + LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to start http server on port:") + tcpPortString); + } + else + { + for(;;) + { + reactor.handle_events(); + } + } +} + +int HttpServer::svc(void) +{ + char buf[2048]; + buf[2047] = '\0'; // security + ACE_Time_Value timeout; + + ssize_t size = peer().recv(buf, 2040); + + if (size > 5) + { + try + { + int startUrlOffset = 5; // get rid of "GET /" from Http request, so skip 5 chars + char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP"); // detect location of post-URL trailing stuff + if(!stopUrl) + { + throw (CStdString("Malformed http request")); ; + } + *stopUrl = '\0'; // Remove post-URL trailing stuff + CStdString url(buf+startUrlOffset); + int queryOffset = url.Find("?"); + if (queryOffset > 0) + { + // Strip beginning of URL in case the command is received as an URL "query" of the form: + // http://hostname/service/command?type=ping + url = url.Right(url.size() - queryOffset - 1); + } + + + CStdString className = UrlSerializer::FindClass(url); + ObjectRef objRef = ObjectFactorySingleton::instance()->NewInstance(className); + if (objRef.get()) + { + objRef->DeSerializeUrl(url); + ObjectRef response = objRef->Process(); + + DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm()); + XERCES_CPP_NAMESPACE::DOMDocument* myDoc; + myDoc = impl->createDocument( + 0, // root element namespace URI. + XStr("response").unicodeForm(), // root element name + 0); // document type object (DTD). + response->SerializeDom(myDoc); + CStdString pingResponse = DomSerializer::DomNodeToString(myDoc); + + CStdString httpOk("HTTP/1.0 200 OK\r\nContent-type: text/xml\r\n\r\n"); + peer().send(httpOk, httpOk.GetLength()); + peer().send(pingResponse, pingResponse.GetLength()); + } + else + { + throw (CStdString("Command not found:") + className); ; + } + + } + catch (CStdString &e) + { + CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n"); + error = error + e + "\r\n"; + peer().send(error, error.GetLength()); + } + catch(const XMLException& e) + { + CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nXML Error\r\n"); + peer().send(error, error.GetLength()); + } + } + else + { + CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n"); + peer().send(notFound, notFound.GetLength()); + } + return 0; +} + diff --git a/orkaudio/MultiThreadedServer.h b/orkaudio/MultiThreadedServer.h new file mode 100644 index 0000000..19c58bc --- /dev/null +++ b/orkaudio/MultiThreadedServer.h @@ -0,0 +1,53 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __MULTITHREADEDSERVER_H__ +#define __MULTITHREADEDSERVER_H__ + +#include "ace/Acceptor.h" +#include "ace/SOCK_Acceptor.h" + +/** This server accepts permanent telnet like connections. + commands are accepted in "single line" format. + one thread per connection +*/ +class CommandLineServer : public ACE_Svc_Handler +{ +public: + virtual int open (void *); + /** daemon thread */ + static void run(void *args); + /** service routine */ + virtual int svc (void); +}; +typedef ACE_Acceptor CommandLineAcceptor; + + +/** This server is a lightweight http server that extracts commands from URLs and outputs results in xml format + one thread per connection + Example url: + http://localhost:23000/message=print&text=hello +*/ +class HttpServer : public ACE_Svc_Handler +{ +public: + virtual int open (void *); + /** daemon thread */ + static void run(void *args); + /** service routine */ + virtual int svc (void); +}; +typedef ACE_Acceptor HttpAcceptor; + +#endif + diff --git a/orkaudio/OrkAudio.cpp b/orkaudio/OrkAudio.cpp new file mode 100644 index 0000000..45a1434 --- /dev/null +++ b/orkaudio/OrkAudio.cpp @@ -0,0 +1,151 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + + +#include "stdio.h" + +#include "MultiThreadedServer.h" +#include "ace/Thread_Manager.h" +#include "OrkAudio.h" +#include "Utils.h" +#include "messages/TapeMsg.h" +#include "messages/PingMsg.h" +#include "messages/DeleteTapeMsg.h" +#include "messages/CaptureMsg.h" +#include "messages/TestMsg.h" +#include "Config.h" +#include "LogManager.h" +#include "ImmediateProcessing.h" +#include "BatchProcessing.h" +#include "Reporting.h" +#include "ConfigManager.h" +#include "Daemon.h" +#include "ObjectFactory.h" +#include "CapturePluginProxy.h" +#include "ace/OS_NS_arpa_inet.h" + + +static volatile bool serviceStop = false; + +void StopHandler() +{ + serviceStop = true; +} + +void MainThread() +{ + LogManagerSingleton::instance()->Initialize(); + LOG4CXX_INFO(LOG.rootLog, CStdString("\n\nOrkAudio service starting\n")); + + // Initialize object factory and register existing objects + ObjectFactorySingleton::instance()->Initialize(); + + ObjectRef objRef; + objRef.reset(new PingMsg); + ObjectFactorySingleton::instance()->RegisterObject(objRef); + objRef.reset(new TapeMsg); + ObjectFactorySingleton::instance()->RegisterObject(objRef); + objRef.reset(new SimpleResponseMsg); + ObjectFactorySingleton::instance()->RegisterObject(objRef); + objRef.reset(new DeleteTapeMsg); + ObjectFactorySingleton::instance()->RegisterObject(objRef); + objRef.reset(new CaptureMsg); + ObjectFactorySingleton::instance()->RegisterObject(objRef); + objRef.reset(new TestMsg); + ObjectFactorySingleton::instance()->RegisterObject(objRef); + + ConfigManagerSingleton::instance()->Initialize(); + + if (!ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(ImmediateProcessing::ThreadHandler))) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create immediate processing thread")); + } + if(CONFIG.m_storageAudioFormat != AudioTape::FfNative) + { + // storage format is not native, which means we need batch workers to compress to wanted format + if (!ACE_Thread_Manager::instance()->spawn_n(CONFIG.m_numBatchThreads, ACE_THR_FUNC(BatchProcessing::ThreadHandler))) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create batch processing thread")); + } + } + if (!ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(Reporting::ThreadHandler))) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create reporting thread")); + } + // Create command line server on port 10000 + if (!ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(CommandLineServer::run), (void *)10000)) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create command line server")); + } + + // Create Http server on port 20000 + if (!ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(HttpServer::run), (void *)20000)) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create Http server")); + } + + if(CapturePluginProxySingleton::instance()->Initialize()) + { + CapturePluginProxySingleton::instance()->Run(); + } + + //ACE_Thread_Manager::instance ()->wait (); + while(serviceStop == false) + { + ACE_OS::sleep(1); + } + LOG4CXX_INFO(LOG.rootLog, CStdString("Stopping service")); +} + + +int main(int argc, char* argv[]) +{ + // figure out service name + CStdString program(argv[0]); + CStdString serviceNameWithExtension = BaseName(program); + CStdString serviceName = StripFileExtension(serviceNameWithExtension); + if (serviceName.IsEmpty()) + { + return -1; + } + + DaemonSingleton::instance()->Initialize(serviceName, MainThread, StopHandler); + CStdString argument = argv[1]; + + if (argc>1) + { + if (argument.CompareNoCase("debug") == 0) + { + MainThread(); + } + else if (argument.CompareNoCase("install") == 0) + { + DaemonSingleton::instance()->Install(); + } + else if (argument.CompareNoCase("uninstall") == 0) + { + DaemonSingleton::instance()->Uninstall(); + } + else + { + printf("Argument incorrect. Possibilies are:\n\tdebug\n\tinstall\n\tuninstall\n"); + } + } + else + { + // No arguments, launch the daemon + DaemonSingleton::instance()->Start(); + } + return 0; +} + diff --git a/orkaudio/OrkAudio.dsp b/orkaudio/OrkAudio.dsp new file mode 100644 index 0000000..d32442d --- /dev/null +++ b/orkaudio/OrkAudio.dsp @@ -0,0 +1,278 @@ +# Microsoft Developer Studio Project File - Name="OrkAudio" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=OrkAudio - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "OrkAudio.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "OrkAudio.mak" CFG="OrkAudio - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "OrkAudio - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "OrkAudio - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "OrkAudio - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /Op /Ob0 /I "." /I "..\OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0\\" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "C:\devExt\libsndfile\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 OrkBase.lib LIBSNDFILE.lib xerces-c_2.lib log4cxx.lib ace.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /libpath:"..\OrkbaseCxx\Release" /libpath:"C:\devExt\ACE_wrappers\lib" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\lib" /libpath:"C:\devExt\libsndfile\Release" + +!ELSEIF "$(CFG)" == "OrkAudio - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "..\OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0\\" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "C:\devExt\libsndfile\src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 OrkBaseD.lib LIBSNDFILE.lib xerces-c_2D.lib log4cxx.lib aced.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\OrkbaseCxx\Debug" /libpath:"C:\devExt\ACE_wrappers\lib" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\lib" /libpath:"C:\devExt\libsndfile\Debug" + +!ENDIF + +# Begin Target + +# Name "OrkAudio - Win32 Release" +# Name "OrkAudio - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Group "Messages" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Messages\CaptureMsg.cpp +# End Source File +# Begin Source File + +SOURCE=.\Messages\CaptureMsg.h +# End Source File +# Begin Source File + +SOURCE=.\Messages\DeleteTapeMsg.cpp +# End Source File +# Begin Source File + +SOURCE=.\Messages\DeleteTapeMsg.h +# End Source File +# Begin Source File + +SOURCE=.\Messages\PingMsg.cpp +# End Source File +# Begin Source File + +SOURCE=.\Messages\PingMsg.h +# End Source File +# Begin Source File + +SOURCE=.\Messages\TapeMsg.cpp +# End Source File +# Begin Source File + +SOURCE=.\Messages\TapeMsg.h +# End Source File +# Begin Source File + +SOURCE=.\messages\TestMsg.cpp +# End Source File +# Begin Source File + +SOURCE=.\messages\TestMsg.h +# End Source File +# End Group +# Begin Group "AudioFile" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\AudioFile\AudioFile.cpp +# End Source File +# Begin Source File + +SOURCE=.\AudioFile\AudioFile.h +# End Source File +# Begin Source File + +SOURCE=.\AudioFile\LibSndFileFile.cpp +# End Source File +# Begin Source File + +SOURCE=.\AudioFile\LibSndFileFile.h +# End Source File +# Begin Source File + +SOURCE=.\AudioFile\PcmFile.cpp +# End Source File +# Begin Source File + +SOURCE=.\AudioFile\PcmFile.h +# End Source File +# End Group +# Begin Source File + +SOURCE=.\App.h +# End Source File +# Begin Source File + +SOURCE=.\AudioCapturePlugin.h +# End Source File +# Begin Source File + +SOURCE=.\AudioTape.cpp +# End Source File +# Begin Source File + +SOURCE=.\AudioTape.h +# End Source File +# Begin Source File + +SOURCE=.\BatchProcessing.cpp +# End Source File +# Begin Source File + +SOURCE=.\BatchProcessing.h +# End Source File +# Begin Source File + +SOURCE=.\CapturePluginProxy.cpp +# End Source File +# Begin Source File + +SOURCE=.\CapturePluginProxy.h +# End Source File +# Begin Source File + +SOURCE=.\CapturePort.cpp +# End Source File +# Begin Source File + +SOURCE=.\CapturePort.h +# End Source File +# Begin Source File + +SOURCE=.\Config.cpp +# End Source File +# Begin Source File + +SOURCE=.\Config.h +# End Source File +# Begin Source File + +SOURCE=.\ConfigManager.cpp +# End Source File +# Begin Source File + +SOURCE=.\ConfigManager.h +# End Source File +# Begin Source File + +SOURCE=.\Daemon.cpp +# End Source File +# Begin Source File + +SOURCE=.\Daemon.h +# End Source File +# Begin Source File + +SOURCE=.\ImmediateProcessing.cpp +# End Source File +# Begin Source File + +SOURCE=.\ImmediateProcessing.h +# End Source File +# Begin Source File + +SOURCE=.\LogManager.cpp +# End Source File +# Begin Source File + +SOURCE=.\LogManager.h +# End Source File +# Begin Source File + +SOURCE=.\MultiThreadedServer.cpp +# End Source File +# Begin Source File + +SOURCE=.\MultiThreadedServer.h +# End Source File +# Begin Source File + +SOURCE=.\OrkAudio.cpp +# End Source File +# Begin Source File + +SOURCE=.\OrkAudio.h +# End Source File +# Begin Source File + +SOURCE=.\Reporting.cpp +# End Source File +# Begin Source File + +SOURCE=.\Reporting.h +# End Source File +# Begin Source File + +SOURCE=.\ThreadSafeQueue.h +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/orkaudio/OrkAudio.dsw b/orkaudio/OrkAudio.dsw new file mode 100644 index 0000000..5c6f152 --- /dev/null +++ b/orkaudio/OrkAudio.dsw @@ -0,0 +1,89 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "ACE"=..\..\devExt\ACE_wrappers\ace\ACE.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "Generator"=.\AUDIOCAPTUREPLUGINS\Generator\Generator.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "OrkAudio"=.\OrkAudio.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "OrkBase"=..\OrkBaseCxx\OrkBase.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "SoundDevice"=.\AudioCapturePlugins\SoundDevice\SoundDevice.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "VoIp"=.\audiocaptureplugins\voip\VoIp.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/orkaudio/OrkAudio.h b/orkaudio/OrkAudio.h new file mode 100644 index 0000000..f9a8c47 --- /dev/null +++ b/orkaudio/OrkAudio.h @@ -0,0 +1,13 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + diff --git a/orkaudio/Reporting.cpp b/orkaudio/Reporting.cpp new file mode 100644 index 0000000..1360dfe --- /dev/null +++ b/orkaudio/Reporting.cpp @@ -0,0 +1,65 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "ConfigManager.h" +#include "Reporting.h" +#include "LogManager.h" +#include "messages/Message.h" +#include "OrkClient.h" + +Reporting Reporting::m_reportingSingleton; + +Reporting* Reporting::GetInstance() +{ + return &m_reportingSingleton; +} + +void Reporting::AddAudioTape(AudioTapeRef audioTapeRef) +{ + if (!m_audioTapeQueue.push(audioTapeRef)) + { + LOG4CXX_ERROR(LOG.reportingLog, CStdString("Reporting: queue full")); + } +} + +void Reporting::ThreadHandler(void *args) +{ + Reporting* pReporting = Reporting::GetInstance(); + + for(;;) + { + AudioTapeRef audioTapeRef = pReporting->m_audioTapeQueue.pop(); + + MessageRef msgRef; + audioTapeRef->GetMessage(msgRef); + if(msgRef.get() && CONFIG.m_enableReporting) + { + CStdString msgAsSingleLineString = msgRef->SerializeSingleLine(); + LOG4CXX_INFO(LOG.reportingLog, msgAsSingleLineString); + + OrkHttpSingleLineClient c; + SimpleResponseMsg srm; + while (!c.Execute((SyncMessage&)(*msgRef.get()), srm, CONFIG.m_trackerHostname, CONFIG.m_trackerTcpPort, CONFIG.m_trackerServicename, CONFIG.m_clientTimeout)) + { + ACE_OS::sleep(5); + } + //CStdString host("foo"); + //while (!msgRef->InvokeXmlRpc(host, 10000)) + //{ + // ACE_OS::sleep(5); + //} + } + } +} + + diff --git a/orkaudio/Reporting.h b/orkaudio/Reporting.h new file mode 100644 index 0000000..0d09333 --- /dev/null +++ b/orkaudio/Reporting.h @@ -0,0 +1,33 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __REPORTING_H__ +#define __REPORTING_H__ + +#include "ThreadSafeQueue.h" +#include "AudioTape.h" + +class Reporting +{ +public: + static Reporting* GetInstance(); + static void ThreadHandler(void *args); + + void AddAudioTape(AudioTapeRef audioTapeRef); +private: + static Reporting m_reportingSingleton; + ThreadSafeQueue m_audioTapeQueue; +}; + +#endif + diff --git a/orkaudio/ThreadSafeQueue.h b/orkaudio/ThreadSafeQueue.h new file mode 100644 index 0000000..4fcc330 --- /dev/null +++ b/orkaudio/ThreadSafeQueue.h @@ -0,0 +1,76 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __THREADSAFEQUEUE_H__ +#define __THREADSAFEQUEUE_H__ + +#include +#include "ace/Thread_Mutex.h" +#include "ace/Thread_Semaphore.h" +#include "Utils.h" + +/** Thread safe queue holding objects of arbitrary class. + Enqueuing is never blocking + Dequeuing is blocking when the queue is empty + */ +template class ThreadSafeQueue +{ +public: + ThreadSafeQueue(int size = 1000) + { + m_size = size; + m_semaphore.acquire(); // reset count to zero + }; + + bool push(T &); + T pop(); +private: + int m_size; + ACE_Thread_Mutex m_mutex; + ACE_Thread_Semaphore m_semaphore; + std::queue m_queue; +}; + + +/** Push an element onto the queue, returns false if queue full (never blocks) */ +template bool ThreadSafeQueue::push(T &element) +{ + bool result = false; + MutexSentinel mutexSentinel(m_mutex); + + if (m_queue.size() < (unsigned int)m_size) + { + m_queue.push(element); + result = true; + } + + m_semaphore.release(); + return result; +} + +/** Pop and element from the queue, or blocks until one available */ +template T ThreadSafeQueue::pop() +{ + m_semaphore.acquire(); + + MutexSentinel mutexSentinel(m_mutex); + + T element = m_queue.front(); + m_queue.pop(); + + return element; +} + + +#endif // __THREADSAFEQUEUE_H__ + diff --git a/orkaudio/audiocaptureplugins/Makefile.am b/orkaudio/audiocaptureplugins/Makefile.am new file mode 100644 index 0000000..bc31197 --- /dev/null +++ b/orkaudio/audiocaptureplugins/Makefile.am @@ -0,0 +1,2 @@ +METASOURCES = AUTO +SUBDIRS = generator voip diff --git a/orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.cpp b/orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.cpp new file mode 100644 index 0000000..31c8503 --- /dev/null +++ b/orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.cpp @@ -0,0 +1,29 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "AudioCapturePluginCommon.h" + + +AudioChunkCallBackFunction g_audioChunkCallBack; +CaptureEventCallBackFunction g_captureEventCallBack; +LogManager* g_logManager; + +void __CDECL__ RegisterCallBacks(AudioChunkCallBackFunction audioCallBack, CaptureEventCallBackFunction captureEventCallBack, LogManager* logManager) +{ + g_audioChunkCallBack = audioCallBack; + g_captureEventCallBack = captureEventCallBack; + g_logManager = logManager; +} diff --git a/orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.h b/orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.h new file mode 100644 index 0000000..b7940ef --- /dev/null +++ b/orkaudio/audiocaptureplugins/common/AudioCapturePluginCommon.h @@ -0,0 +1,36 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __AUDIOCAPTUREPLUGINCOMMON_H__ +#define __AUDIOCAPTUREPLUGINCOMMON_H__ + +#include "AudioCapturePlugin.h" + +#ifdef WIN32 + #define DLL_EXPORT __declspec( dllexport ) +#else + #define DLL_EXPORT +#endif + +// Shared library exports +extern "C" // to avoid function name decoration, makes them easier to lookup +{ +DLL_EXPORT void __CDECL__ RegisterCallBacks(AudioChunkCallBackFunction, CaptureEventCallBackFunction, LogManager*); +DLL_EXPORT void __CDECL__ Run(); +DLL_EXPORT void __CDECL__ Initialize(); +DLL_EXPORT void __CDECL__ Configure(DOMNode*); +DLL_EXPORT void __CDECL__ StartCapture(CStdString& capturePort); +DLL_EXPORT void __CDECL__ StopCapture(CStdString& capturePort); +} + +#endif diff --git a/orkaudio/audiocaptureplugins/generator/Generator.cpp b/orkaudio/audiocaptureplugins/generator/Generator.cpp new file mode 100644 index 0000000..77bfdf9 --- /dev/null +++ b/orkaudio/audiocaptureplugins/generator/Generator.cpp @@ -0,0 +1,147 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "AudioCapturePlugin.h" +#include "AudioCapturePluginCommon.h" +#include "ConfigManager.h" +#include "GeneratorConfig.h" + +extern AudioChunkCallBackFunction g_audioChunkCallBack; +extern CaptureEventCallBackFunction g_captureEventCallBack; +extern LogManager* g_logManager; + +GeneratorConfigTopObjectRef g_generatorConfigTopObjectRef; +#define GCONFIG g_generatorConfigTopObjectRef.get()->m_config + +void Configure(DOMNode* node) +{ + if (node) + { + GeneratorConfigTopObjectRef generatorConfigTopObjectRef(new GeneratorConfigTopObject); + try + { + generatorConfigTopObjectRef.get()->DeSerializeDom(node); + g_generatorConfigTopObjectRef = generatorConfigTopObjectRef; + } + catch (CStdString& e) + { + LOG4CXX_WARN(g_logManager->rootLog, "Generator.dll: " + e + " - using defaults"); + } + } + else + { + LOG4CXX_WARN(g_logManager->rootLog, "Generator.dll: got empty DOM tree"); + } +} + +void Initialize() +{ + // create a default config object in case it was not properly initialized by Configure + if (!g_generatorConfigTopObjectRef.get()) + { + g_generatorConfigTopObjectRef.reset(new GeneratorConfigTopObject); + } +} + +void Run() +{ + +#define NUM_SAMPLES_PER_CHUNK 8000 + + // Load test file data into memory + int fileSize = 0; + int audioBufferSize = 0; + int numChunks; + short* audioBuffer = NULL; + FILE* file = fopen((PCSTR)GCONFIG.m_audioFilename,"rb"); + if (file) + { + fseek (file, 0, SEEK_END); + fileSize = ftell(file); + fseek (file, 0, SEEK_SET); + + // round up file size to the next NUM_SAMPLES_PER_CHUNK multiple + numChunks = (fileSize/NUM_SAMPLES_PER_CHUNK) + 1; + fileSize = numChunks * NUM_SAMPLES_PER_CHUNK; + + audioBuffer = (short *)malloc(sizeof(short)*fileSize); + audioBufferSize = fileSize/sizeof(short); + for(int i=0; irootLog, "Generator.dll: Could not load audio test file:" + GCONFIG.m_audioFilename + " using empty buffer instead"); + + numChunks = 1; + audioBuffer = (short *)malloc(sizeof(short)*NUM_SAMPLES_PER_CHUNK); + audioBufferSize = NUM_SAMPLES_PER_CHUNK; + for(int i=0; im_type = CaptureEvent::EtStop; + stopEvent->m_timestamp = time(NULL); + g_captureEventCallBack(stopEvent, portName); + + CaptureEventRef startEvent(new CaptureEvent); + startEvent->m_type = CaptureEvent::EtStart; + startEvent->m_timestamp = time(NULL); + g_captureEventCallBack(startEvent, portName); + } + // send audio buffer + AudioChunkRef chunkRef(new AudioChunk); + int sampleOffset = (elapsed % numChunks)*NUM_SAMPLES_PER_CHUNK; + chunkRef->SetBuffer(audioBuffer+sampleOffset, sizeof(short)*NUM_SAMPLES_PER_CHUNK, AudioChunk::PcmAudio); + g_audioChunkCallBack(chunkRef, portName); + } + + ACE_OS::sleep(1); + elapsed++; + } +} + + +void __CDECL__ StartCapture(CStdString& capturePort) +{ + ; +} + +void __CDECL__ StopCapture(CStdString& capturePort) +{ + ; +} diff --git a/orkaudio/audiocaptureplugins/generator/Generator.dsp b/orkaudio/audiocaptureplugins/generator/Generator.dsp new file mode 100644 index 0000000..23353c7 --- /dev/null +++ b/orkaudio/audiocaptureplugins/generator/Generator.dsp @@ -0,0 +1,126 @@ +# Microsoft Developer Studio Project File - Name="Generator" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=Generator - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Generator.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Generator.mak" CFG="Generator - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Generator - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "Generator - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Generator - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 OrkBase.lib ace.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"../../../OrkBaseCxx/Release" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\ACE_wrappers\lib" + +!ELSEIF "$(CFG)" == "Generator - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GENERATOR_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 OrkBaseD.lib aced.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"../../../OrkBaseCxx/Debug" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\ACE_wrappers\lib" + +!ENDIF + +# Begin Target + +# Name "Generator - Win32 Release" +# Name "Generator - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\AudioCapturePlugin.h +# End Source File +# Begin Source File + +SOURCE=..\Common\AudioCapturePluginCommon.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\AudioCapturePluginCommon.h +# End Source File +# Begin Source File + +SOURCE=.\Generator.cpp +# End Source File +# Begin Source File + +SOURCE=.\GeneratorConfig.cpp +# End Source File +# Begin Source File + +SOURCE=.\GeneratorConfig.h +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp new file mode 100644 index 0000000..785e33f --- /dev/null +++ b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.cpp @@ -0,0 +1,70 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "serializers/Serializer.h" +#include "GeneratorConfig.h" + +GeneratorConfig::GeneratorConfig() +{ + m_numConcurrentPorts = NUM_CONCURRENT_PORTS_DEFAULT; + m_audioDuration = AUDIO_DURATION_DEFAULT; + m_audioFilename = AUDIO_FILE_NAME_DEFAULT; +} + +void GeneratorConfig::Define(Serializer* s) +{ + s->IntValue(NUM_CONCURRENT_PORTS_PARAM, m_numConcurrentPorts); + s->IntValue(AUDIO_DURATION_PARAM, m_audioDuration); + s->StringValue(AUDIO_FILE_NAME_PARAM, m_audioFilename); +} + +void GeneratorConfig::Validate() +{ + ; +} + +CStdString GeneratorConfig::GetClassName() +{ + return CStdString("GeneratorConfig"); +} + +ObjectRef GeneratorConfig::NewInstance() +{ + return ObjectRef(new GeneratorConfig); +} + +//==================================== + + +void GeneratorConfigTopObject::Define(Serializer* s) +{ + s->ObjectValue(GENERATOR_CONFIG_PARAM, m_config, true); +} + +void GeneratorConfigTopObject::Validate() +{ + ; +} + +CStdString GeneratorConfigTopObject::GetClassName() +{ + return CStdString("GeneratorConfigTopObject"); +} + +ObjectRef GeneratorConfigTopObject::NewInstance() +{ + return ObjectRef(new GeneratorConfigTopObject); +} + diff --git a/orkaudio/audiocaptureplugins/generator/GeneratorConfig.h b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.h new file mode 100644 index 0000000..8e9c6a1 --- /dev/null +++ b/orkaudio/audiocaptureplugins/generator/GeneratorConfig.h @@ -0,0 +1,66 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __GENERATORCONFIG_H__ +#define __GENERATORCONFIG_H__ + +#include "StdString.h" +#include "Object.h" +#include "boost/shared_ptr.hpp" + +#define NUM_CONCURRENT_PORTS_PARAM "NumConcurrentPorts" +#define NUM_CONCURRENT_PORTS_DEFAULT 10 +#define AUDIO_DURATION_PARAM "AudioDuration" +#define AUDIO_DURATION_DEFAULT 10 +#define AUDIO_FILE_NAME_PARAM "AudioFilename" +#define AUDIO_FILE_NAME_DEFAULT "test.wav" + +/** This class defines various configuration parameters for the generator. */ +class GeneratorConfig : public Object +{ +public: + GeneratorConfig(); + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + int m_numConcurrentPorts; + int m_audioDuration; + CStdString m_audioFilename; +}; + +//======================================== + +#define GENERATOR_CONFIG_PARAM "Generator" + +/** This class represents the top of the configuration hierarchy for the generator. */ +class GeneratorConfigTopObject : public Object +{ +public: + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + GeneratorConfig m_config; +}; + +typedef boost::shared_ptr GeneratorConfigTopObjectRef; + + +#endif diff --git a/orkaudio/audiocaptureplugins/generator/Makefile.am b/orkaudio/audiocaptureplugins/generator/Makefile.am new file mode 100644 index 0000000..44624f8 --- /dev/null +++ b/orkaudio/audiocaptureplugins/generator/Makefile.am @@ -0,0 +1,10 @@ +METASOURCES = AUTO +lib_LTLIBRARIES = libgenerator.la +libgenerator_la_SOURCES = GeneratorConfig.cpp Generator.cpp \ + AudioCapturePluginCommon.cpp +libgenerator_la_LDFLAGS = -module +AM_CPPFLAGS = -D_REENTRANT +libgenerator_la_LIBADD = -lACE -lxerces-c -llog4cxx -lorkbase +INCLUDES = -I@top_srcdir@ -I../../../orkbasecxx -I../common +AudioCapturePluginCommon.cpp: + ln -s ../common/AudioCapturePluginCommon.cpp AudioCapturePluginCommon.cpp diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp b/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp new file mode 100644 index 0000000..2a6bef4 --- /dev/null +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.cpp @@ -0,0 +1,252 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "ace/OS_NS_unistd.h" +#include "ace/Singleton.h" +#include "ace/Min_Max.h" +#include "AudioCapturePlugin.h" +#include "AudioCapturePluginCommon.h" +#include "portaudio.h" +#include "Utils.h" +#include "SoundDeviceConfig.h" + +extern AudioChunkCallBackFunction g_audioChunkCallBack; +extern CaptureEventCallBackFunction g_captureEventCallBack; +extern LogManager* g_logManager; + +SoundDeviceConfigTopObjectRef g_soundDeviceConfigTopObjectRef; +#define DLLCONFIG g_soundDeviceConfigTopObjectRef.get()->m_config + + +typedef struct +{ + PaDeviceID deviceID; + int channelCount; + PortAudioStream* stream; +} DeviceUserData; + +int portAudioCallBack(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData) +{ + DeviceUserData *device = (DeviceUserData *)userData; + short * inputSamples = (short *)inputBuffer; + CStdString portName; + + if (device->channelCount == 2) + { + // stereo -> split into two different chunks + short* rightBuffer = new short[DLLCONFIG.m_audioChunkSize]; + short* leftBuffer = new short[DLLCONFIG.m_audioChunkSize]; + + for (int sampleId=0; sampleIdSetBuffer(rightBuffer, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio); + portName.Format("port%d-%d", device->deviceID, 1); + g_audioChunkCallBack(chunkRef, portName); + + chunkRef.reset(new AudioChunk); + chunkRef->SetBuffer(leftBuffer, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio); + portName.Format("port%d-%d", device->deviceID, 2); + g_audioChunkCallBack(chunkRef, portName); + + delete rightBuffer; + delete leftBuffer; + } + else + { + // mono + AudioChunkRef chunkRef(new AudioChunk); + chunkRef->SetBuffer(inputSamples, sizeof(short)*framesPerBuffer, AudioChunk::PcmAudio); + portName.Format("port%d", device->deviceID); + g_audioChunkCallBack(chunkRef, portName); + } + + return 0; +} + + +class SoundDevice +{ +public: + SoundDevice(); + void Initialize(); + void Run(); + void StartCapture(CStdString& port); + void StopCapture(CStdString& port); +private: + DeviceUserData** m_devices; + int m_deviceCount; + PaStream* m_stream; +}; + +typedef ACE_Singleton SoundDeviceSingleton; + +SoundDevice::SoundDevice() +{ + m_deviceCount = 0; + m_devices = NULL; +} + +void Configure(DOMNode* node) +{ + if (node) + { + SoundDeviceConfigTopObjectRef soundDeviceConfigTopObjectRef(new SoundDeviceConfigTopObject); + try + { + soundDeviceConfigTopObjectRef.get()->DeSerializeDom(node); + g_soundDeviceConfigTopObjectRef = soundDeviceConfigTopObjectRef; + } + catch (CStdString& e) + { + LOG4CXX_WARN(g_logManager->rootLog, "SoundDevice.dll: " + e + " - using defaults"); + } + } + else + { + LOG4CXX_WARN(g_logManager->rootLog, "SoundDevice.dll: got empty DOM tree"); + } +} + + +void SoundDevice::Initialize() +{ + LOG4CXX_INFO(g_logManager->rootLog, "Initializing Sound Device plugin"); + + // create a default config object in case it was not properly initialized by Configure + if(!g_soundDeviceConfigTopObjectRef.get()) + { + g_soundDeviceConfigTopObjectRef.reset(new SoundDeviceConfigTopObject); + } + + + PaError result = Pa_Initialize(); + if (result) + { + LOG4CXX_ERROR(g_logManager->rootLog, "Could not initialize Sound Device plugin"); + } + + m_deviceCount = Pa_CountDevices(); + m_devices = new DeviceUserData*[m_deviceCount]; + + for( PaDeviceID deviceID=0; deviceIDdeviceID = deviceID; + m_devices[deviceID]->channelCount = ace_max(deviceInfo->maxInputChannels,2); + m_devices[deviceID]->stream = NULL; + CStdString deviceName(deviceInfo->name); + + if (deviceInfo->maxInputChannels > 0 && deviceName.Find("Primary") == -1) // Primary audio device is a duplicate of one of the devices + { + CStdString capturePorts; + if (deviceInfo->maxInputChannels > 1) + { + capturePorts.Format("port%d-1, port%d-2", deviceID, deviceID); // stereo + } + else + { + capturePorts.Format("port%d-1", deviceID); // mono + } + + CStdString maxInputChannelsString = IntToString(deviceInfo->maxInputChannels); + LOG4CXX_INFO(g_logManager->rootLog, "Ports:" + capturePorts + " Name:" + deviceName + " Channels:" + maxInputChannelsString); + + result = Pa_OpenStream( &m_devices[deviceID]->stream, + deviceID, + m_devices[deviceID]->channelCount, + paInt16, + NULL, + paNoDevice , + 0, + paInt16, + NULL, + 8000.0, + DLLCONFIG.m_audioChunkSize, + 0, + 0, + portAudioCallBack, + (void*)m_devices[deviceID] ); + + if (result) + { + CStdString deviceIdString = IntToString(deviceID); + LOG4CXX_ERROR(g_logManager->rootLog, "Device:" + deviceIdString + CStdString(" Pa_OpenStream error:") + Pa_GetErrorText(result)); + } + } + } +} + +void SoundDevice::Run() +{ + for( PaDeviceID deviceID=0; deviceIDchannelCount > 0 && m_devices[deviceID]->stream) + { + PaError result = Pa_StartStream(m_devices[deviceID]->stream); + if (result) + { + CStdString deviceIdString = IntToString(deviceID); + LOG4CXX_ERROR(g_logManager->rootLog, "Device:" + deviceIdString + CStdString(" Pa_StartStream error:") + Pa_GetErrorText(result)); + } + } + } +} + +void SoundDevice::StartCapture(CStdString& port) +{ + CaptureEventRef startEvent(new CaptureEvent); + startEvent->m_type = CaptureEvent::EtStart; + startEvent->m_timestamp = time(NULL); + g_captureEventCallBack(startEvent, port); +} + +void SoundDevice::StopCapture(CStdString& port) +{ + CaptureEventRef stopEvent(new CaptureEvent); + stopEvent->m_type = CaptureEvent::EtStop; + stopEvent->m_timestamp = time(NULL); + g_captureEventCallBack(stopEvent, port); +} + +void __CDECL__ Initialize() +{ + SoundDeviceSingleton::instance()->Initialize(); +} + +void __CDECL__ Run() +{ + SoundDeviceSingleton::instance()->Run(); + for(;;) + { + // if this idle thread is missing, it will crash winmm + ACE_OS::sleep(5); + } +} + +void __CDECL__ StartCapture(CStdString& capturePort) +{ + SoundDeviceSingleton::instance()->StartCapture(capturePort); +} + +void __CDECL__ StopCapture(CStdString& capturePort) +{ + SoundDeviceSingleton::instance()->StopCapture(capturePort); +} \ No newline at end of file diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.dsp b/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.dsp new file mode 100644 index 0000000..844f5a6 --- /dev/null +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDevice.dsp @@ -0,0 +1,130 @@ +# Microsoft Developer Studio Project File - Name="SoundDevice" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=SoundDevice - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "SoundDevice.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "SoundDevice.mak" CFG="SoundDevice - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "SoundDevice - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "SoundDevice - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "SoundDevice - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SOUNDDEVICE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\portaudio_v18\pa_common" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SOUNDDEVICE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 OrkBase.lib winmm.lib dsound.lib ace.lib PAStaticDS.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"../../../OrkBaseCxx/Release" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\portaudio_v18\winproj\Lib" /libpath:"C:\devExt\ACE_wrappers\lib" + +!ELSEIF "$(CFG)" == "SoundDevice - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SOUNDDEVICE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\portaudio_v18\pa_common" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SOUNDDEVICE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 OrkBaseD.lib winmm.lib dsound.lib aced.lib PAStaticDSD.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"../../../OrkBaseCxx/Debug" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\portaudio_v18\winproj\Lib" /libpath:"C:\devExt\ACE_wrappers\lib" + +!ENDIF + +# Begin Target + +# Name "SoundDevice - Win32 Release" +# Name "SoundDevice - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\AudioCapturePlugin.h +# End Source File +# Begin Source File + +SOURCE=..\Common\AudioCapturePluginCommon.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\AudioCapturePluginCommon.h +# End Source File +# Begin Source File + +SOURCE=..\..\ConfigManager.h +# End Source File +# Begin Source File + +SOURCE=.\SoundDevice.cpp +# End Source File +# Begin Source File + +SOURCE=.\SoundDeviceConfig.cpp +# End Source File +# Begin Source File + +SOURCE=.\SoundDeviceConfig.h +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp new file mode 100644 index 0000000..998eb72 --- /dev/null +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.cpp @@ -0,0 +1,70 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "Serializers/Serializer.h" +#include "SoundDeviceConfig.h" + +SoundDeviceConfig::SoundDeviceConfig() +{ + m_audioChunkSize = AUDIO_CHUNK_SIZE_DEFAULT; +} + +void SoundDeviceConfig::Define(Serializer* s) +{ + s->IntValue(AUDIO_CHUNK_SIZE_PARAM, m_audioChunkSize); +} + +void SoundDeviceConfig::Validate() +{ + if(m_audioChunkSize > 80000 || m_audioChunkSize<100) + { + CStdString audioChunkSizeString = IntToString(m_audioChunkSize); + throw(CStdString("SoundDeviceConfig: ") + AUDIO_CHUNK_SIZE_PARAM + "=" + audioChunkSizeString + " this is out of range"); + } +} + +CStdString SoundDeviceConfig::GetClassName() +{ + return CStdString("SoundDeviceConfig"); +} + +ObjectRef SoundDeviceConfig::NewInstance() +{ + return ObjectRef(new SoundDeviceConfig); +} + +//==================================== + + +void SoundDeviceConfigTopObject::Define(Serializer* s) +{ + s->ObjectValue(SOUND_DEVICE_CONFIG_PARAM, m_config, true); +} + +void SoundDeviceConfigTopObject::Validate() +{ + ; +} + +CStdString SoundDeviceConfigTopObject::GetClassName() +{ + return CStdString("SoundDeviceConfigTopObject"); +} + +ObjectRef SoundDeviceConfigTopObject::NewInstance() +{ + return ObjectRef(new SoundDeviceConfigTopObject); +} \ No newline at end of file diff --git a/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h new file mode 100644 index 0000000..6453523 --- /dev/null +++ b/orkaudio/audiocaptureplugins/sounddevice/SoundDeviceConfig.h @@ -0,0 +1,60 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __SOUNDDEVICECONFIG_H__ +#define __SOUNDDEVICECONFIG_H__ + +#include "StdString.h" +#include "Object.h" +#include "boost/shared_ptr.hpp" + +#define AUDIO_CHUNK_SIZE_PARAM "AudioChunkSize" +#define AUDIO_CHUNK_SIZE_DEFAULT 8000 + +/** This class defines various configuration parameters for the generator. */ +class SoundDeviceConfig : public Object +{ +public: + SoundDeviceConfig(); + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + int m_audioChunkSize; +}; + +//======================================== + +#define SOUND_DEVICE_CONFIG_PARAM "SoundDevicePlugin" + +/** This class represents the top of the configuration hierarchy for the generator. */ +class SoundDeviceConfigTopObject : public Object +{ +public: + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + SoundDeviceConfig m_config; +}; + +typedef boost::shared_ptr SoundDeviceConfigTopObjectRef; + + +#endif \ No newline at end of file diff --git a/orkaudio/audiocaptureplugins/voip/Makefile.am b/orkaudio/audiocaptureplugins/voip/Makefile.am new file mode 100644 index 0000000..a11ff07 --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/Makefile.am @@ -0,0 +1,10 @@ +METASOURCES = AUTO +lib_LTLIBRARIES = libvoip.la +libvoip_la_SOURCES = VoIpConfig.cpp VoIp.cpp g711.c Rtp.cpp SipSession.cpp \ + AudioCapturePluginCommon.cpp +libvoip_la_LDFLAGS = -module +AM_CPPFLAGS = -D_REENTRANT +libvoip_la_LIBADD = -lACE -lxerces-c -llog4cxx -lorkbase -lpcap +INCLUDES = -I@top_srcdir@ -I../../../orkbasecxx -I../common +AudioCapturePluginCommon.cpp: + ln -s ../common/AudioCapturePluginCommon.cpp AudioCapturePluginCommon.cpp diff --git a/orkaudio/audiocaptureplugins/voip/PacketHeaderDefs.h b/orkaudio/audiocaptureplugins/voip/PacketHeaderDefs.h new file mode 100644 index 0000000..1293c5c --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/PacketHeaderDefs.h @@ -0,0 +1,71 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + + +#ifndef __PACKETHEADERDEFS_H__ +#define __PACKETHEADERDEFS_H__ + + +// Structure of Ethernet header +typedef struct +{ + unsigned char sourceMac[6]; + unsigned char destinationMac[6]; + unsigned short length; + +} EthernetHeaderStruct; + +// Structure of an internet header, naked of options, only valid for little endian +typedef struct +{ + unsigned char ip_hl:4; // Header length + unsigned char ip_v:4; // IP protocol version + unsigned char ip_tos; // Type of service + unsigned short ip_len; // Total length + unsigned short ip_id; // Identification + unsigned short ip_off; // Fragment offset field + unsigned char ip_ttl; // Time to live + unsigned char ip_p; // Protocol + unsigned short ip_sum; // Header checksum + struct in_addr ip_src; // Source address + struct in_addr ip_dest; // Destination address +} IpHeaderStruct; + +// Structure of UDP header +typedef struct +{ + unsigned short source; // Source port + unsigned short dest; // Destination port + unsigned short len; // UDP length + unsigned short check; // UDP Checksum +} UdpHeaderStruct; + +#define RTP_PT_PCMU 0 +#define RTP_PT_PCMA 8 + +// Structure of RTP header, only valid for little endian +typedef struct { + unsigned short cc:4; // CSRC count + unsigned short x:1; // header extension flag + unsigned short p:1; // padding flag + unsigned short version:2; // protocol version + unsigned short pt:7; // payload type + unsigned short m:1; // marker bit + unsigned short seq; // sequence number + unsigned int ts; // timestamp + unsigned int ssrc; // synchronization source + //unsigned int csrc[1]; // optional CSRC list +} RtpHeaderStruct; + +#endif + diff --git a/orkaudio/audiocaptureplugins/voip/Rtp.cpp b/orkaudio/audiocaptureplugins/voip/Rtp.cpp new file mode 100644 index 0000000..931aed7 --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/Rtp.cpp @@ -0,0 +1,257 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "Rtp.h" +#include "AudioCapturePlugin.h" +#include "AudioCapturePluginCommon.h" +#include "PacketHeaderDefs.h" +#include "assert.h" + +extern "C" +{ +#include "g711.h" +} +extern AudioChunkCallBackFunction g_audioChunkCallBack; + + +RtpRingBuffer::RtpRingBuffer() +{ + m_writePtr = m_buffer; + m_readPtr = m_buffer; + m_bufferEnd = m_buffer + NUM_SAMPLES_CIRCULAR_BUFFER; + m_writeTimestamp = 0; + m_readTimestamp = 0; + m_log = Logger::getLogger("rtpringbuffer"); + m_shippedSamples = 0; +} + + +void RtpRingBuffer::AddRtpPacket(RtpPacketInfoRef& rtpInfo) +{ + unsigned int rtpEndTimestamp = rtpInfo->m_timestamp + rtpInfo->m_payloadSize; + + if(m_writeTimestamp == 0) + { + // First RTP packet of the session + LOG4CXX_DEBUG(m_log, m_capturePort + " first packet"); + m_writeTimestamp = rtpInfo->m_timestamp; + m_readTimestamp = m_writeTimestamp; + StoreRtpPacket(rtpInfo); + } + else if (rtpInfo->m_timestamp >= m_readTimestamp) // drop packets that are older than last shipment + { + if( (int)(rtpEndTimestamp - m_writeTimestamp) <= (int)FreeSpace()) + { + // RTP packet fits into current buffer + StoreRtpPacket(rtpInfo); + + if(UsedSpace() > NUM_SAMPLES_TRIGGER) + { + // We have enough stuff, make a shipment + CreateShipment(0); + } + } + else + { + // RTP packet does not fit into current buffer + // work out how much silence we need to add to the current buffer when shipping + size_t silenceSize = rtpInfo->m_timestamp - m_writeTimestamp; + CreateShipment(silenceSize); + + // reset buffer + m_writePtr = m_buffer; + m_readPtr = m_buffer; + m_writeTimestamp = rtpInfo->m_timestamp; + m_readTimestamp = m_writeTimestamp; + + // Store new packet + StoreRtpPacket(rtpInfo); + } + } + else + { + LOG4CXX_DEBUG(m_log, m_capturePort + " packet too old, dropped"); + } + CStdString debug; + debug.Format("free:%u used:%u wr:%x rd:%x wrts:%u rdts:%d", FreeSpace(), UsedSpace(), m_writePtr, m_readPtr, m_writeTimestamp, m_readTimestamp); + LOG4CXX_DEBUG(m_log, debug); +} + +// Writes to the internal buffer without any size verification +void RtpRingBuffer::StoreRtpPacket(RtpPacketInfoRef& rtpInfo) +{ + CStdString debug; + + // 1. Silence from write pointer until end of RTP packet + unsigned int endRtpTimestamp = rtpInfo->m_timestamp + rtpInfo->m_payloadSize; + if (endRtpTimestamp > m_writeTimestamp) + { + for(int i=0; i<(endRtpTimestamp - m_writeTimestamp); i++) + { + *m_writePtr = 0; + m_writePtr++; + if(m_writePtr >= m_bufferEnd) + { + m_writePtr = m_buffer; + } + } + int silenceSize = endRtpTimestamp - m_writeTimestamp; + m_writeTimestamp = endRtpTimestamp; + debug.Format("Zeroed %d samples, wr:%x wrts:%u", silenceSize, m_writePtr, m_writeTimestamp); + LOG4CXX_DEBUG(m_log, debug); + } + + // 2. Mix in the latest samples from this RTP packet + unsigned int timestampDelta = m_writeTimestamp - rtpInfo->m_timestamp; + ASSERT(timestampDelta>=0); + short* tempWritePtr = CicularPointerSubtractOffset(m_writePtr, timestampDelta); + unsigned char* payload = rtpInfo->m_payload; + + for(int i=0; im_payloadSize ; i++) + { + if(rtpInfo->m_payloadType == RTP_PT_PCMA) + { + *tempWritePtr += (short)alaw2linear(payload[i]); + } + else if(rtpInfo->m_payloadType == RTP_PT_PCMU) + { + *tempWritePtr += (short)ulaw2linear(payload[i]); + } + tempWritePtr++; + if(tempWritePtr >= m_bufferEnd) + { + tempWritePtr = m_buffer; + } + } + debug.Format("Copied %d samples, tmpwr:%x", rtpInfo->m_payloadSize, tempWritePtr); + LOG4CXX_DEBUG(m_log, debug); +} + +short* RtpRingBuffer::CircularPointerAddOffset(short *ptr, size_t offset) +{ + if((ptr + offset) >= m_bufferEnd) + { + return m_buffer + offset - (m_bufferEnd-ptr); + } + else + { + return ptr + offset; + } +} + +short* RtpRingBuffer::CicularPointerSubtractOffset(short *ptr, size_t offset) +{ + if((ptr-offset) < m_buffer) + { + return m_bufferEnd - offset + (ptr-m_buffer); + } + else + { + return ptr - offset; + } +} + +void RtpRingBuffer::CreateShipment(size_t silenceSize) +{ + // 1. ship from readPtr until stop pointer or until end of buffer if wrapped + bool bufferWrapped = false; + short* stopPtr = NULL; + short* wrappedStopPtr = NULL; + if (silenceSize) + { + // There is additional silence to ship, do not take holdoff into account + stopPtr = m_writePtr; + } + else + { + stopPtr = CicularPointerSubtractOffset(m_writePtr, NUM_SAMPLES_SHIPMENT_HOLDOFF); + } + + if (stopPtr < m_readPtr) + { + wrappedStopPtr = stopPtr; + stopPtr = m_bufferEnd; + bufferWrapped = true; + } + size_t shortSize = stopPtr-m_readPtr; + size_t byteSize = shortSize*2; + AudioChunkRef chunk(new AudioChunk()); + chunk->SetBuffer((void*)m_readPtr, byteSize, AudioChunk::PcmAudio); + g_audioChunkCallBack(chunk, m_capturePort); + m_shippedSamples += shortSize; + m_readPtr = CircularPointerAddOffset(m_readPtr ,shortSize); + m_readTimestamp += shortSize; + + CStdString debug; + debug.Format("Ship %d samples, rd:%x rdts:%u", shortSize, m_readPtr, m_readTimestamp); + LOG4CXX_DEBUG(m_log, debug); + + + // 2. ship from beginning of buffer until stop ptr + if(bufferWrapped) + { + shortSize = wrappedStopPtr - m_buffer; + byteSize = shortSize*2; + chunk.reset(new AudioChunk()); + chunk->SetBuffer((void*)m_buffer, byteSize, AudioChunk::PcmAudio); + g_audioChunkCallBack(chunk, m_capturePort); + m_shippedSamples += shortSize; + m_readPtr = CircularPointerAddOffset(m_readPtr ,shortSize); + m_readTimestamp += shortSize; + debug.Format("Ship wrapped %d samples, rd:%x rdts:%u", shortSize, m_readPtr, m_readTimestamp); + LOG4CXX_DEBUG(m_log, debug); + } + + // 3. ship silence + if (silenceSize) + { + byteSize = silenceSize*2; + char* silenceBuffer = (char*)calloc(byteSize, 1); + if (silenceBuffer) + { + AudioChunkRef chunk(new AudioChunk()); + chunk->SetBuffer((void*)silenceBuffer, byteSize, AudioChunk::PcmAudio); + g_audioChunkCallBack(chunk, m_capturePort); + m_shippedSamples += silenceSize; + m_readPtr = CircularPointerAddOffset(m_readPtr ,silenceSize); + m_readTimestamp += silenceSize; + } + debug.Format("Ship %d silence samples, rd:%x rdts:%u", silenceSize, m_readPtr, m_readTimestamp); + LOG4CXX_DEBUG(m_log, debug); + } +} + + +unsigned int RtpRingBuffer::UsedSpace() +{ + if(m_writePtr >= m_readPtr) + { + return m_writePtr - m_readPtr; + } + return NUM_SAMPLES_CIRCULAR_BUFFER + m_writePtr - m_readPtr; +} + + +unsigned int RtpRingBuffer::FreeSpace() +{ + return NUM_SAMPLES_CIRCULAR_BUFFER - UsedSpace(); +} + +void RtpRingBuffer::SetCapturePort(CStdString& port) +{ + m_capturePort = port; +} + diff --git a/orkaudio/audiocaptureplugins/voip/Rtp.h b/orkaudio/audiocaptureplugins/voip/Rtp.h new file mode 100644 index 0000000..0366ef4 --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/Rtp.h @@ -0,0 +1,77 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __RTP_H__ +#define __RTP_H__ + +#include "AudioCapture.h" +#include "boost/shared_ptr.hpp" +#include "StdString.h" +#include "LogManager.h" + +#define NUM_SAMPLES_CIRCULAR_BUFFER 8000 +#define NUM_SAMPLES_TRIGGER 4000 // when we have this number of available samples make a shipment +#define NUM_SAMPLES_SHIPMENT_HOLDOFF 2000 // when shipping, ship everything but this number of samples + + +// useful info we extract from an RTP packet +class RtpPacketInfo +{ +public: + //CStdString m_sourceMac; + //CStdString m_destMac; + struct in_addr m_sourceIp; + struct in_addr m_destIp; + unsigned short m_sourcePort; + unsigned short m_destPort; + unsigned int m_payloadSize; + unsigned short m_payloadType; + unsigned char* m_payload; + unsigned short m_seqNum; + unsigned int m_timestamp; +}; +typedef boost::shared_ptr RtpPacketInfoRef; + + +// Ring buffer based on RTP timestamps +// Gathers both sides of the conversation and mixes them into single channel +// Robust to silence suppression +// Supports RTP buffers of arbitrary sizes in both directions. +class RtpRingBuffer +{ +public: + RtpRingBuffer(); + void AddRtpPacket(RtpPacketInfoRef&); + void SetCapturePort(CStdString& port); +private: + void StoreRtpPacket(RtpPacketInfoRef&); + void CreateShipment(size_t silenceSize); + unsigned int FreeSpace(); + unsigned int UsedSpace(); + short* GetHoldOffPtr(); + short* CircularPointerAddOffset(short *ptr, size_t offset); + short* CicularPointerSubtractOffset(short *ptr, size_t offset); + + short* m_writePtr; // pointer after newest RTP data we've received + short* m_readPtr; // where to read from next + unsigned int m_readTimestamp; // timestamp that the next shipment will have + unsigned int m_writeTimestamp; // timestamp that the next RTP buffer should have + short* m_bufferEnd; + short m_buffer[NUM_SAMPLES_CIRCULAR_BUFFER]; + CStdString m_capturePort; + LoggerPtr m_log; + unsigned int m_shippedSamples; +}; + +#endif + diff --git a/orkaudio/audiocaptureplugins/voip/SipSession.cpp b/orkaudio/audiocaptureplugins/voip/SipSession.cpp new file mode 100644 index 0000000..e62a612 --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/SipSession.cpp @@ -0,0 +1,282 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "SipSession.h" +#include "AudioCapturePlugin.h" +#include "AudioCapturePluginCommon.h" +#include +#include "VoIpConfig.h" +#include "ace/OS_NS_arpa_inet.h" + +extern AudioChunkCallBackFunction g_audioChunkCallBack; +extern CaptureEventCallBackFunction g_captureEventCallBack; + +extern VoIpConfigTopObjectRef g_VoIpConfigTopObjectRef; +#define DLLCONFIG g_VoIpConfigTopObjectRef.get()->m_config + + +SipSession::SipSession() +{ + m_lastUpdated = time(NULL); + m_log = Logger::getLogger("sipsession"); + m_invitorIp.s_addr = 0; + m_inviteeIp.s_addr = 0; + m_direction = CaptureEvent::DirUnkn; +} + +void SipSession::Stop() +{ + LOG4CXX_DEBUG(m_log, m_ipAndPort + " SIP Session stop"); + CaptureEventRef stopEvent(new CaptureEvent); + stopEvent->m_type = CaptureEvent::EtStop; + stopEvent->m_timestamp = time(NULL); + g_captureEventCallBack(stopEvent, m_ipAndPort); +} + +void SipSession::Start() +{ + LOG4CXX_DEBUG(m_log, m_ipAndPort + " SIP Session start"); + m_rtpRingBuffer.SetCapturePort(m_ipAndPort); + CaptureEventRef startEvent(new CaptureEvent); + startEvent->m_type = CaptureEvent::EtStart; + startEvent->m_timestamp = time(NULL); + g_captureEventCallBack(startEvent, m_ipAndPort); +} + +void SipSession::ProcessMetadataIncoming() +{ + m_remoteParty = m_invite->m_from; + m_localParty = m_invite->m_to; + m_direction = CaptureEvent::DirIn; +} + +void SipSession::ProcessMetadataOutgoing() +{ + m_remoteParty = m_invite->m_to; + m_localParty = m_invite->m_from; + m_direction = CaptureEvent::DirOut; +} + +void SipSession::ProcessMetadata(RtpPacketInfoRef& rtpPacket) +{ + bool done = false; + + // work out invitee IP address + if(rtpPacket->m_sourceIp.s_addr == m_invitorIp.s_addr) + { + m_inviteeIp = rtpPacket->m_destIp; + } + else if(rtpPacket->m_destIp.s_addr == m_invitorIp.s_addr) + { + m_inviteeIp = rtpPacket->m_sourceIp; + } + else + { + LOG4CXX_DEBUG(m_log, m_ipAndPort + " alien RTP packet"); + } + + // work out capture port and direction + if(DLLCONFIG.IsMediaGateway(m_invitorIp)) + { + if(DLLCONFIG.IsMediaGateway(m_inviteeIp)) + { + // dismiss + } + if(DLLCONFIG.IsPartOfLan(m_inviteeIp)) + { + ProcessMetadataIncoming(); + } + } + else if (DLLCONFIG.IsPartOfLan(m_invitorIp)) + { + ProcessMetadataOutgoing(); + } + else + { + // SIP invitor IP address is an outside IP address + if(DLLCONFIG.IsMediaGateway(m_inviteeIp)) + { + // dismiss + } + else if(DLLCONFIG.IsPartOfLan(m_inviteeIp)) + { + ProcessMetadataIncoming(); + } + else + { + // SIP invitee IP address is an outside IP address + ProcessMetadataOutgoing(); + } + } + ReportMetadata(); +} + +void SipSession::ReportMetadata() +{ + // report Local party + CaptureEventRef event(new CaptureEvent()); + event->m_type = CaptureEvent::EtLocalParty; + event->m_value = m_localParty; + g_captureEventCallBack(event, m_ipAndPort); + + // Report remote party + event.reset(new CaptureEvent()); + event->m_type = CaptureEvent::EtRemoteParty; + event->m_value = m_remoteParty; + g_captureEventCallBack(event, m_ipAndPort); + + // report direction + event.reset(new CaptureEvent()); + event->m_type = CaptureEvent::EtDirection; + event->m_value = CaptureEvent::DirectionToString(m_direction); + g_captureEventCallBack(event, m_ipAndPort); +} + + +void SipSession::AddRtpPacket(RtpPacketInfoRef& rtpPacket) +{ + // if first RTP packet, start session + if(m_lastRtpPacket.get() == NULL) + { + Start(); + ProcessMetadata(rtpPacket); + } + m_lastRtpPacket = rtpPacket; + + // send audio buffer + //AudioChunkRef chunkRef(new AudioChunk); + //chunkRef->SetBuffer(rtpPacket->m_payload, rtpPacket->m_payloadSize, AudioChunk::AlawAudio); + //g_audioChunkCallBack(chunkRef, m_ipAndPort); + + m_rtpRingBuffer.AddRtpPacket(rtpPacket); + + m_lastUpdated = time(NULL); +} + + +void SipSession::ReportSipInvite(SipInviteInfoRef& invite) +{ + m_invite = invite; + m_invitorIp = invite->m_fromIp; +} + +//===================================================================== +SipSessions::SipSessions() +{ + m_log = Logger::getLogger("sipsessions"); +} + + +void SipSessions::ReportSipInvite(SipInviteInfoRef& invite) +{ + CStdString key = CStdString(ACE_OS::inet_ntoa(invite->m_fromIp)) + "," + invite->m_fromRtpPort; + std::map::iterator pair; + + pair = m_byIpAndPort.find(key); + + if (pair != m_byIpAndPort.end()) + { + // A session exists ont the same IP+port, stop old session + SipSessionRef session = pair->second; + Stop(session); + } + // create new session and insert into both maps + SipSessionRef session(new SipSession()); + session->m_ipAndPort = key; + session->ReportSipInvite(invite); + m_byCallId.insert(std::make_pair(invite->m_callId, session)); + m_byIpAndPort.insert(std::make_pair(key, session)); +} + +void SipSessions::ReportSipBye(SipByeInfo bye) +{ + std::map::iterator pair; + pair = m_byCallId.find(bye.m_callId); + + if (pair != m_byCallId.end()) + { + // Session found: stop it + SipSessionRef session = pair->second; + Stop(session); + } +} + +void SipSessions::Stop(SipSessionRef& session) +{ + session->Stop(); + m_byIpAndPort.erase(session->m_ipAndPort); + m_byCallId.erase(session->m_invite->m_callId); +} + + +void SipSessions::ReportRtpPacket(RtpPacketInfoRef& rtpPacket) +{ + // Does a session exist with this source Ip+Port + SipSessionRef session; + CStdString port = IntToString(rtpPacket->m_sourcePort); + CStdString ipAndPort = CStdString(ACE_OS::inet_ntoa(rtpPacket->m_sourceIp)) + "," + port; + std::map::iterator pair; + + pair = m_byIpAndPort.find(ipAndPort); + if (pair != m_byIpAndPort.end()) + { + session = pair->second; + } + else + { + // Does a session exist with this destination Ip+Port + port = IntToString(rtpPacket->m_destPort); + ipAndPort = CStdString(ACE_OS::inet_ntoa(rtpPacket->m_destIp)) + "," + port; + pair = m_byIpAndPort.find(ipAndPort); + if (pair != m_byIpAndPort.end()) + { + session = pair->second; + } + } + if (!session.get() == NULL) + { + // Found a session give it the RTP packet info + session->AddRtpPacket(rtpPacket); + } +} + +void SipSessions::Hoover(time_t now) +{ + CStdString numSessions = IntToString(m_byIpAndPort.size()); + LOG4CXX_DEBUG(m_log, "Hoover - check " + numSessions + " sessions time:" + IntToString(now)); + + // Go round the sessions and find inactive ones + std::map::iterator pair; + std::list toDismiss; + + for(pair = m_byIpAndPort.begin(); pair != m_byIpAndPort.end(); pair++) + { + SipSessionRef session = pair->second; + if((now - session->m_lastUpdated) > 10) + { + toDismiss.push_back(session); + } + } + + // discard inactive sessions + for (std::list::iterator it = toDismiss.begin(); it != toDismiss.end() ; it++) + { + SipSessionRef session = *it; + LOG4CXX_DEBUG(m_log, session->m_ipAndPort + " Expired"); + Stop(session); + } +} + diff --git a/orkaudio/audiocaptureplugins/voip/SipSession.h b/orkaudio/audiocaptureplugins/voip/SipSession.h new file mode 100644 index 0000000..4702bac --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/SipSession.h @@ -0,0 +1,87 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __SIPSESSION_H__ +#define __SIPSESSION_H__ + +#include "SipSession.h" +#include "Rtp.h" +#include +#include "ace/Singleton.h" + +class SipInviteInfo +{ +public: + struct in_addr m_fromIp; + CStdString m_fromRtpPort; + CStdString m_from; + CStdString m_to; + CStdString m_callId; +}; +typedef boost::shared_ptr SipInviteInfoRef; + +class SipByeInfo +{ +public: + CStdString m_callId; +}; + + +class SipSession +{ +public: + SipSession(); + void Stop(); + void Start(); + void AddRtpPacket(RtpPacketInfoRef& rtpPacket); + void ReportSipInvite(SipInviteInfoRef& invite); + + CStdString m_ipAndPort; + SipInviteInfoRef m_invite; + time_t m_lastUpdated; +private: + void ProcessMetadata(RtpPacketInfoRef&); + void ProcessMetadataIncoming(); + void ProcessMetadataOutgoing(); + void ReportMetadata(); + + RtpPacketInfoRef m_lastRtpPacket; + RtpRingBuffer m_rtpRingBuffer; + struct in_addr m_invitorIp; + struct in_addr m_inviteeIp; + LoggerPtr m_log; + CStdString m_capturePort; + CStdString m_localParty; + CStdString m_remoteParty; + CaptureEvent::DirectionEnum m_direction; +}; +typedef boost::shared_ptr SipSessionRef; + +class SipSessions +{ +public: + SipSessions(); + void Stop(SipSessionRef& session); + void ReportSipInvite(SipInviteInfoRef& invite); + void ReportSipBye(SipByeInfo bye); + void ReportRtpPacket(RtpPacketInfoRef& rtpPacket); + void Hoover(time_t now); +private: + std::map m_byIpAndPort; + std::map m_byCallId; + LoggerPtr m_log; +}; +typedef ACE_Singleton SipSessionsSingleton; + +#endif + diff --git a/orkaudio/audiocaptureplugins/voip/VoIp.cpp b/orkaudio/audiocaptureplugins/voip/VoIp.cpp new file mode 100644 index 0000000..e7a3b6d --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/VoIp.cpp @@ -0,0 +1,465 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_string.h" +#include "ace/Singleton.h" +#include "ace/Min_Max.h" +#include "ace/OS_NS_arpa_inet.h" +#include "ace/OS_NS_ctype.h" +#include "AudioCapturePlugin.h" +#include "AudioCapturePluginCommon.h" +#include "Utils.h" +#include "VoIpConfig.h" +#include "pcap.h" +#include "PacketHeaderDefs.h" +#include "Rtp.h" +#include "SipSession.h" + +extern AudioChunkCallBackFunction g_audioChunkCallBack; +extern CaptureEventCallBackFunction g_captureEventCallBack; +extern LogManager* g_logManager; + +#include "LogManager.h" + +static LoggerPtr s_log; +static LoggerPtr s_sipExtractionLog; +time_t lastHooveringTime; + +VoIpConfigTopObjectRef g_VoIpConfigTopObjectRef; +#define DLLCONFIG g_VoIpConfigTopObjectRef.get()->m_config + +// find the address that follows the given search string between start and stop pointers +char* memFindAfter(char* toFind, char* start, char* stop) +{ + for(char * ptr = start; (ptrversion == 2) + { + u_short source = ntohs(udpHeader->source); + u_short dest = ntohs(udpHeader->dest); + if(!(ntohs(udpHeader->source)%2) && !(ntohs(udpHeader->dest)%2)) // udp ports must be even + { + if(rtpHeader->pt == RTP_PT_PCMU || rtpHeader->pt == RTP_PT_PCMA) + { + result = true; + u_char* payload = (u_char *)rtpHeader + sizeof(RtpHeaderStruct); + u_char* packetEnd = (u_char *)ipHeader + ntohs(ipHeader->ip_len); + u_int payloadLength = packetEnd - payload; + + RtpPacketInfoRef rtpInfo(new RtpPacketInfo()); + rtpInfo->m_sourceIp = ipHeader->ip_src; + rtpInfo->m_destIp = ipHeader->ip_dest; + rtpInfo->m_sourcePort = ntohs(udpHeader->source); + rtpInfo->m_destPort = ntohs(udpHeader->dest); + rtpInfo->m_payloadSize = payloadLength; + rtpInfo->m_payloadType = rtpHeader->pt; + rtpInfo->m_seqNum = ntohs(rtpHeader->seq); + rtpInfo->m_timestamp = ntohl(rtpHeader->ts); + rtpInfo->m_payload = payload; + + CStdString debug; + debug.Format("%s,%d seq:%u ts:%u len:%d", ACE_OS::inet_ntoa(rtpInfo->m_sourceIp), rtpInfo->m_sourcePort, ntohs(rtpHeader->seq), ntohl(rtpHeader->ts), payloadLength); + LOG4CXX_DEBUG(s_log, debug); + + SipSessionsSingleton::instance()->ReportRtpPacket(rtpInfo); + } + } + } + return result; +} + + +bool TrySipBye(EthernetHeaderStruct* ethernetHeader, IpHeaderStruct* ipHeader, UdpHeaderStruct* udpHeader, u_char* udpPayload) +{ + bool result = false; + if (memcmp("BYE", (void*)udpPayload, 1) == 0) + { + result = true; + int sipLength = ntohs(udpHeader->len); + char* sipEnd = (char*)udpPayload + sipLength; + SipByeInfo info; + char* callIdField = memFindAfter("Call-ID: ", (char*)udpPayload, sipEnd); + if(callIdField) + { + GrabToken(callIdField, info.m_callId); + SipSessionsSingleton::instance()->ReportSipBye(info); + } + LOG4CXX_DEBUG(s_log, "SIP BYE"); + } + return result; +} + +bool TrySipInvite(EthernetHeaderStruct* ethernetHeader, IpHeaderStruct* ipHeader, UdpHeaderStruct* udpHeader, u_char* udpPayload) +{ + bool result = false; + if (memcmp("INVITE", (void*)udpPayload, 1) == 0) + { + result = true; + + int sipLength = ntohs(udpHeader->len); + char* sipEnd = (char*)udpPayload + sipLength; + + SipInviteInfoRef info(new SipInviteInfo()); + + char* fromField = memFindAfter("From: ", (char*)udpPayload, sipEnd); + char* toField = NULL; + char* callIdField = NULL; + char* audioField = NULL; + + if(fromField) + { + if(s_sipExtractionLog->isDebugEnabled()) + { + CStdString from; + GrabLine(fromField, sipEnd, from); + s_sipExtractionLog->forcedLog(Level::DEBUG, "from: " + from); + } + + char* fromFieldEnd = memFindEOL(fromField, sipEnd); + + char* sipUser = memFindAfter("sip:", fromField, fromFieldEnd); + if(sipUser) + { + GrabAlphaNumToken(sipUser, fromFieldEnd, info->m_from); + } + else + { + GrabAlphaNumToken(fromField, fromFieldEnd, info->m_from); + } + toField = memFindAfter("To: ", fromField, sipEnd); + } + if(toField) + { + char* toFieldEnd = NULL; + if(s_sipExtractionLog->isDebugEnabled()) + { + CStdString to; + toFieldEnd = GrabLine(toField, sipEnd, to); + s_sipExtractionLog->forcedLog(Level::DEBUG, "to: " + to); + } + + char* sipUser = memFindAfter("sip:", toField, toFieldEnd); + if(sipUser) + { + GrabAlphaNumToken(sipUser, toFieldEnd, info->m_to); + } + else + { + GrabAlphaNumToken(toField, toFieldEnd, info->m_to); + } + callIdField = memFindAfter("Call-ID: ", toField, sipEnd); + } + if(callIdField) + { + GrabToken(callIdField, info->m_callId); + audioField = memFindAfter("m=audio ", callIdField, sipEnd); + } + if(audioField) + { + GrabToken(audioField, info->m_fromRtpPort); + info->m_fromIp = ipHeader->ip_src; + SipSessionsSingleton::instance()->ReportSipInvite(info); + } + LOG4CXX_DEBUG(s_log, "SIP INVITE"); + } + return result; +} + +void HandlePacket(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) +{ + EthernetHeaderStruct* ethernetHeader = (EthernetHeaderStruct *)pkt_data; + IpHeaderStruct* ipHeader = (IpHeaderStruct*)((char*)ethernetHeader + sizeof(EthernetHeaderStruct)); + int ipHeaderLength = ipHeader->ip_hl*4; + + //CStdString source = ACE_OS::inet_ntoa(ipHeader->ip_src); + //CStdString dest = ACE_OS::inet_ntoa(ipHeader->ip_dest); + //CStdString debug; + //debug.Format("%x, %x", ethernetHeader, ipHeader); + //LOG4CXX_INFO(s_log, source + "-" + dest); + + //LOG4CXX_DEBUG(s_log, "*"); + + if(ipHeader->ip_p == IPPROTO_UDP) + { + UdpHeaderStruct* udpHeader = (UdpHeaderStruct*)((char *)ipHeader + ipHeaderLength); + + if( ntohs(udpHeader->source) > 5000 && ntohs(udpHeader->dest) > 5000 ) + { + u_char* udpPayload = (u_char *)udpHeader + sizeof(UdpHeaderStruct); + + + bool detectedUsefulPacket = TryRtp(ethernetHeader, ipHeader, udpHeader, udpPayload); + + if(!detectedUsefulPacket) + { + detectedUsefulPacket= TrySipInvite(ethernetHeader, ipHeader, udpHeader, udpPayload); + } + if(!detectedUsefulPacket) + { + detectedUsefulPacket = TrySipBye(ethernetHeader, ipHeader, udpHeader, udpPayload); + } + } + } + + time_t now = time(NULL); + if((now - lastHooveringTime) > 5) + { + lastHooveringTime = now; + SipSessionsSingleton::instance()->Hoover(now); + } +} + + +class VoIp +{ +public: + VoIp(); + void Initialize(); + void Run(); + void StartCapture(CStdString& port); + void StopCapture(CStdString& port); +private: + pcap_t* m_pcapHandle; +}; + +typedef ACE_Singleton VoIpSingleton; + +VoIp::VoIp() +{ + m_pcapHandle = NULL; +} + +void Configure(DOMNode* node) +{ + if (node) + { + VoIpConfigTopObjectRef VoIpConfigTopObjectRef(new VoIpConfigTopObject); + try + { + VoIpConfigTopObjectRef.get()->DeSerializeDom(node); + g_VoIpConfigTopObjectRef = VoIpConfigTopObjectRef; + } + catch (CStdString& e) + { + LOG4CXX_WARN(g_logManager->rootLog, "VoIp.dll: " + e); + } + } + else + { + LOG4CXX_WARN(g_logManager->rootLog, "VoIp.dll: got empty DOM tree"); + } +} + + +void VoIp::Initialize() +{ + s_log = Logger::getLogger("voip"); + s_sipExtractionLog = Logger::getLogger("sipextraction"); + LOG4CXX_INFO(s_log, "Initializing VoIP plugin"); + + // create a default config object in case it was not properly initialized by Configure + if(!g_VoIpConfigTopObjectRef.get()) + { + g_VoIpConfigTopObjectRef.reset(new VoIpConfigTopObject); + } + +/* + char addr1[] = "10.1.2.3"; + char addr2[] = "192.168.5.6"; + char addr3[] = "45.168.5.6"; + struct in_addr addr; + ACE_OS::inet_aton(addr1, &addr); + bool result = DLLCONFIG.IsPartOfLan(addr); + result = DLLCONFIG.IsMediaGateway(addr); + ACE_OS::inet_aton(addr2, &addr); + result = DLLCONFIG.IsPartOfLan(addr); + result = DLLCONFIG.IsMediaGateway(addr); + ACE_OS::inet_aton(addr3, &addr); + result = DLLCONFIG.IsPartOfLan(addr); + result = DLLCONFIG.IsMediaGateway(addr); +*/ + + pcap_if_t* devices = NULL; + pcap_if_t* deviceToSniff = NULL; + lastHooveringTime = time(NULL); + + char * error = NULL; + if (pcap_findalldevs(&devices, error) == -1) + { + LOG4CXX_ERROR(s_log, CStdString("pcap error when discovering devices: ") + error); + } + else + { + if(devices) + { + LOG4CXX_INFO(s_log, CStdString("Available pcap devices:")); + + for (pcap_if_t* device = devices; device != NULL; device = device->next) + { + LOG4CXX_INFO(s_log, CStdString("\t* ") + device->description + " " + device->name ); + if(DLLCONFIG.m_device.Equals(device->name)) + { + deviceToSniff = device; + } + } + if (!deviceToSniff) + { + LOG4CXX_ERROR(s_log, CStdString("pcap could not find wanted device: ") + DLLCONFIG.m_device); + } + else + { + #define PROMISCUOUS 1 + if ((m_pcapHandle = pcap_open_live(deviceToSniff->name, 1500, PROMISCUOUS, + 500, error)) == NULL) + { + LOG4CXX_ERROR(s_log, CStdString("pcap error when opening device: ") + deviceToSniff->name); + } + else + { + LOG4CXX_INFO(s_log, CStdString("successfully opened device: ") + deviceToSniff->name); + + //unsigned int netMask = 0xffffff; + //if(deviceToSniff->addresses != NULL) + //{ + // netMask=((struct sockaddr_in *)(device->addresses->netmask))->sin_addr.s_addr; + //} + + //struct bpf_program program; + //if (pcap_compile(m_pcapHandle, &program, "ip proto icmp", 1, 0xffffffff) < 0) + //{ + // LOG4CXX_ERROR(s_log, CStdString("unable to compile pcap filter")); + //} + } + } + } + else + { + LOG4CXX_ERROR(s_log, CStdString("pcap could not find any device")); + } + } + +} + +void VoIp::Run() +{ + LOG4CXX_INFO(s_log, "Running VoIp.dll"); + pcap_loop(m_pcapHandle, 0, HandlePacket, NULL); +} + +void VoIp::StartCapture(CStdString& port) +{ + ; +} + +void VoIp::StopCapture(CStdString& port) +{ + ; +} + +void __CDECL__ Initialize() +{ + VoIpSingleton::instance()->Initialize(); +} + +void __CDECL__ Run() +{ + VoIpSingleton::instance()->Run(); +} + +void __CDECL__ StartCapture(CStdString& capturePort) +{ + ; +} + +void __CDECL__ StopCapture(CStdString& capturePort) +{ + ; +} + diff --git a/orkaudio/audiocaptureplugins/voip/VoIp.dsp b/orkaudio/audiocaptureplugins/voip/VoIp.dsp new file mode 100644 index 0000000..c58a936 --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/VoIp.dsp @@ -0,0 +1,158 @@ +# Microsoft Developer Studio Project File - Name="VoIp" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=VoIp - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "VoIp.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "VoIp.mak" CFG="VoIp - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "VoIp - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "VoIp - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "VoIp - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "VoIp_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "C:\devExt\winpcap\WpdPack\Include" /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "VoIp_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 packet.lib wpcap.lib wininet.lib OrkBase.lib ace.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"C:\devExt\winpcap\WpdPack\Lib" /libpath:"../../../OrkBaseCxx/Release" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\ACE_wrappers\lib" + +!ELSEIF "$(CFG)" == "VoIp - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "VoIp_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "C:\devExt\winpcap\WpdPack\Include" /I "../.." /I "../../../OrkBaseCxx" /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "../Common" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "VoIp_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 packet.lib wpcap.lib wininet.lib OrkBaseD.lib aced.lib log4cxx.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"C:\devExt\winpcap\WpdPack\Lib" /libpath:"../../../OrkBaseCxx/Debug" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\ACE_wrappers\lib" + +!ENDIF + +# Begin Target + +# Name "VoIp - Win32 Release" +# Name "VoIp - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\AudioCapturePlugin.h +# End Source File +# Begin Source File + +SOURCE=..\Common\AudioCapturePluginCommon.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\AudioCapturePluginCommon.h +# End Source File +# Begin Source File + +SOURCE=..\..\ConfigManager.h +# End Source File +# Begin Source File + +SOURCE=.\g711.c +# End Source File +# Begin Source File + +SOURCE=.\g711.h +# End Source File +# Begin Source File + +SOURCE=.\PacketHeaderDefs.h +# End Source File +# Begin Source File + +SOURCE=.\Rtp.cpp +# End Source File +# Begin Source File + +SOURCE=.\Rtp.h +# End Source File +# Begin Source File + +SOURCE=.\SipSession.cpp +# End Source File +# Begin Source File + +SOURCE=.\SipSession.h +# End Source File +# Begin Source File + +SOURCE=.\VoIp.cpp +# End Source File +# Begin Source File + +SOURCE=.\VoIpConfig.cpp +# End Source File +# Begin Source File + +SOURCE=.\VoIpConfig.h +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp b/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp new file mode 100644 index 0000000..a632bdc --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp @@ -0,0 +1,127 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "serializers/Serializer.h" +#include "VoIpConfig.h" +#include "ace/OS_NS_arpa_inet.h" + +VoIpConfig::VoIpConfig() +{ + // Standard LAN internal IP range masks + m_asciiLanMasks.push_back("192.168.255.255"); + m_asciiLanMasks.push_back("10.255.255.255"); + m_asciiLanMasks.push_back("172.31.255.255"); +} + +void VoIpConfig::Define(Serializer* s) +{ + s->StringValue(DEVICE_PARAM, m_device); + s->CsvValue("LanMasks", m_asciiLanMasks); + s->CsvValue("MediaGateways", m_asciiMediaGateways); +} + +void VoIpConfig::Validate() +{ + // iterate over ascii LAN masks and populate the binary LAN Masks list + m_lanMasks.clear(); + std::list::iterator it; + for(it = m_asciiLanMasks.begin(); it != m_asciiLanMasks.end(); it++) + { + struct in_addr a; + if(ACE_OS::inet_aton((PCSTR)*it, &a)) + { + m_lanMasks.push_back((unsigned int)a.s_addr); + } + else + { + throw (CStdString("VoIpConfig: invalid IP address in LanMasks:" + *it)); + } + } + + // iterate over ascii Media gateway IP addresses and populate the binary Media gateway IP addresses list + m_mediaGateways.clear(); + for(it = m_asciiMediaGateways.begin(); it != m_asciiMediaGateways.end(); it++) + { + struct in_addr a; + if(ACE_OS::inet_aton((PCSTR)*it, &a)) + { + m_mediaGateways.push_back((unsigned int)a.s_addr); + } + else + { + throw (CStdString("VoIpConfig: invalid IP address in MediaGateways:" + *it)); + } + } +} + +bool VoIpConfig::IsPartOfLan(struct in_addr addr) +{ + for(std::list::iterator it = m_lanMasks.begin(); it != m_lanMasks.end(); it++) + { + if(((unsigned int)addr.s_addr & *it) == (unsigned int)addr.s_addr) + { + return true; + } + } + return false; +} + +bool VoIpConfig::IsMediaGateway(struct in_addr addr) +{ + for(std::list::iterator it = m_mediaGateways.begin(); it != m_mediaGateways.end(); it++) + { + if((unsigned int)addr.s_addr == *it) + { + return true; + } + } + return false; +} + + +CStdString VoIpConfig::GetClassName() +{ + return CStdString("VoIpConfig"); +} + +ObjectRef VoIpConfig::NewInstance() +{ + return ObjectRef(new VoIpConfig); +} + +//==================================== + + +void VoIpConfigTopObject::Define(Serializer* s) +{ + s->ObjectValue(SOUND_DEVICE_CONFIG_PARAM, m_config, true); +} + +void VoIpConfigTopObject::Validate() +{ + ; +} + +CStdString VoIpConfigTopObject::GetClassName() +{ + return CStdString("VoIpConfigTopObject"); +} + +ObjectRef VoIpConfigTopObject::NewInstance() +{ + return ObjectRef(new VoIpConfigTopObject); +} + diff --git a/orkaudio/audiocaptureplugins/voip/VoIpConfig.h b/orkaudio/audiocaptureplugins/voip/VoIpConfig.h new file mode 100644 index 0000000..7bea647 --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/VoIpConfig.h @@ -0,0 +1,68 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __VOIPCONFIG_H__ +#define __VOIPCONFIG_H__ + +#include +#include "StdString.h" +#include "Object.h" +#include "boost/shared_ptr.hpp" + +#define DEVICE_PARAM "Device" + +/** This class defines various configuration parameters for the generator. */ +class VoIpConfig : public Object +{ +public: + VoIpConfig(); + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + bool IsPartOfLan(struct in_addr); + bool IsMediaGateway(struct in_addr); + + CStdString m_device; + std::list m_mediaGateways; + std::list m_asciiMediaGateways; + std::list m_lanMasks; + std::list m_asciiLanMasks; +}; + +//======================================== + +#define SOUND_DEVICE_CONFIG_PARAM "VoIpPlugin" + +/** This class represents the top of the configuration hierarchy for the generator. */ +class VoIpConfigTopObject : public Object +{ +public: + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + VoIpConfig m_config; +}; + +typedef boost::shared_ptr VoIpConfigTopObjectRef; + + +#endif + diff --git a/orkaudio/audiocaptureplugins/voip/g711.c b/orkaudio/audiocaptureplugins/voip/g711.c new file mode 100644 index 0000000..7317dbb --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/g711.c @@ -0,0 +1,285 @@ +/* + * This source code is a product of Sun Microsystems, Inc. and is provided + * for unrestricted use. Users may copy or modify this source code without + * charge. + * + * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING + * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun source code is provided with no support and without any obligation on + * the part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ + +#include "g711.h" + +/* + * g711.c + * + * u-law, A-law and linear PCM conversions. + */ +#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ +#define QUANT_MASK (0xf) /* Quantization field mask. */ +#define NSEGS (8) /* Number of A-law segments. */ +#define SEG_SHIFT (4) /* Left shift for segment number. */ +#define SEG_MASK (0x70) /* Segment field mask. */ + +static short seg_end[8] = {0xFF, 0x1FF, 0x3FF, 0x7FF, + 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF}; + +/* copy from CCITT G.711 specifications */ +unsigned char _u2a[128] = { /* u- to A-law conversions */ + 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, + 25, 27, 29, 31, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, + 46, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, + 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128}; + +unsigned char _a2u[128] = { /* A- to u-law conversions */ + 1, 3, 5, 7, 9, 11, 13, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 32, 33, 33, 34, 34, 35, 35, + 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 48, 49, 49, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 64, + 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 79, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127}; + +static int +search( + int val, + short *table, + int size) +{ + int i; + + for (i = 0; i < size; i++) { + if (val <= *table++) + return (i); + } + return (size); +} + +/* + * linear2alaw() - Convert a 16-bit linear PCM value to 8-bit A-law + * + * linear2alaw() accepts an 16-bit integer and encodes it as A-law data. + * + * Linear Input Code Compressed Code + * ------------------------ --------------- + * 0000000wxyza 000wxyz + * 0000001wxyza 001wxyz + * 000001wxyzab 010wxyz + * 00001wxyzabc 011wxyz + * 0001wxyzabcd 100wxyz + * 001wxyzabcde 101wxyz + * 01wxyzabcdef 110wxyz + * 1wxyzabcdefg 111wxyz + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ +unsigned char +linear2alaw( + int pcm_val) /* 2's complement (16-bit range) */ +{ + int mask; + int seg; + unsigned char aval; + + if (pcm_val >= 0) { + mask = 0xD5; /* sign (7th) bit = 1 */ + } else { + mask = 0x55; /* sign bit = 0 */ + pcm_val = -pcm_val - 8; + } + + /* Convert the scaled magnitude to segment number. */ + seg = search(pcm_val, seg_end, 8); + + /* Combine the sign, segment, and quantization bits. */ + + if (seg >= 8) /* out of range, return maximum value. */ + return (0x7F ^ mask); + else { + aval = seg << SEG_SHIFT; + if (seg < 2) + aval |= (pcm_val >> 4) & QUANT_MASK; + else + aval |= (pcm_val >> (seg + 3)) & QUANT_MASK; + return (aval ^ mask); + } +} + +/* + * alaw2linear() - Convert an A-law value to 16-bit linear PCM + * + */ +int +alaw2linear( + unsigned char a_val) +{ + int t; + int seg; + + a_val ^= 0x55; + + t = (a_val & QUANT_MASK) << 4; + seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; + switch (seg) { + case 0: + t += 8; + break; + case 1: + t += 0x108; + break; + default: + t += 0x108; + t <<= seg - 1; + } + return ((a_val & SIGN_BIT) ? t : -t); +} + +#define BIAS (0x84) /* Bias for linear code. */ + +/* + * linear2ulaw() - Convert a linear PCM value to u-law + * + * In order to simplify the encoding process, the original linear magnitude + * is biased by adding 33 which shifts the encoding range from (0 - 8158) to + * (33 - 8191). The result can be seen in the following encoding table: + * + * Biased Linear Input Code Compressed Code + * ------------------------ --------------- + * 00000001wxyza 000wxyz + * 0000001wxyzab 001wxyz + * 000001wxyzabc 010wxyz + * 00001wxyzabcd 011wxyz + * 0001wxyzabcde 100wxyz + * 001wxyzabcdef 101wxyz + * 01wxyzabcdefg 110wxyz + * 1wxyzabcdefgh 111wxyz + * + * Each biased linear code has a leading 1 which identifies the segment + * number. The value of the segment number is equal to 7 minus the number + * of leading 0's. The quantization interval is directly available as the + * four bits wxyz. * The trailing bits (a - h) are ignored. + * + * Ordinarily the complement of the resulting code word is used for + * transmission, and so the code word is complemented before it is returned. + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ +unsigned char +linear2ulaw( + int pcm_val) /* 2's complement (16-bit range) */ +{ + int mask; + int seg; + unsigned char uval; + + /* Get the sign and the magnitude of the value. */ + if (pcm_val < 0) { + pcm_val = BIAS - pcm_val; + mask = 0x7F; + } else { + pcm_val += BIAS; + mask = 0xFF; + } + + /* Convert the scaled magnitude to segment number. */ + seg = search(pcm_val, seg_end, 8); + + /* + * Combine the sign, segment, quantization bits; + * and complement the code word. + */ + if (seg >= 8) /* out of range, return maximum value. */ + return (0x7F ^ mask); + else { + uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF); + return (uval ^ mask); + } + +} + +/* + * ulaw2linear() - Convert a u-law value to 16-bit linear PCM + * + * First, a biased linear code is derived from the code word. An unbiased + * output can then be obtained by subtracting 33 from the biased code. + * + * Note that this function expects to be passed the complement of the + * original code word. This is in keeping with ISDN conventions. + */ +int +ulaw2linear( + unsigned char u_val) +{ + int t; + + /* Complement to obtain normal u-law value. */ + u_val = ~u_val; + + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = ((u_val & QUANT_MASK) << 3) + BIAS; + t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; + + return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); +} + +/* A-law to u-law conversion */ +unsigned char +alaw2ulaw( + unsigned char aval) +{ + aval &= 0xff; + return ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : + (0x7F ^ _a2u[aval ^ 0x55])); +} + +/* u-law to A-law conversion */ +unsigned char +ulaw2alaw( + unsigned char uval) +{ + uval &= 0xff; + return ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : + (0x55 ^ (_u2a[0x7F ^ uval] - 1))); +} diff --git a/orkaudio/audiocaptureplugins/voip/g711.h b/orkaudio/audiocaptureplugins/voip/g711.h new file mode 100644 index 0000000..f15df4d --- /dev/null +++ b/orkaudio/audiocaptureplugins/voip/g711.h @@ -0,0 +1,21 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __G711_H__ +#define __G711_H__ + +int ulaw2linear(unsigned char u_val); +int alaw2linear(unsigned char a_val); + +#endif + diff --git a/orkaudio/audiofile/AudioFile.cpp b/orkaudio/audiofile/AudioFile.cpp new file mode 100644 index 0000000..377963b --- /dev/null +++ b/orkaudio/audiofile/AudioFile.cpp @@ -0,0 +1,58 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "AudioFile.h" +#include "ace/OS_NS_unistd.h" + +void AudioFile::Open(fileOpenModeEnum mode, bool stereo , int sampleRate) +{ + Open(m_filename, mode, stereo, sampleRate); +} + + +void AudioFile::RecursiveMkdir(CStdString& path) +{ + int position = 0; + bool done = false; + while (!done) + { + position = path.Find('/', position+1); + if (position == -1) + { + done = true; + } + else + { + CStdString level = path.Left(position); + ACE_OS::mkdir((PCSTR)level); + } + } +} + +void AudioFile::MoveOrig() +{ + CStdString newName = m_filename + ".orig"; + if (ACE_OS::rename((PCSTR)m_filename, (PCSTR)newName) == 0) + { + m_filename = newName; + } + else + { + throw(CStdString("AudioFile::MoveOrig: could not rename file:" + m_filename)); + } +} + +void AudioFile::Delete() +{ + ACE_OS::unlink((PCSTR)m_filename); +} diff --git a/orkaudio/audiofile/AudioFile.h b/orkaudio/audiofile/AudioFile.h new file mode 100644 index 0000000..cd7d6f6 --- /dev/null +++ b/orkaudio/audiofile/AudioFile.h @@ -0,0 +1,69 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __AUDIOFILE_H__ +#define __AUDIOFILE_H__ + +#include "boost/shared_ptr.hpp" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_sys_stat.h" + +#include "StdString.h" +#include "AudioCapture.h" + + +/** Base class for all file accessor classes. */ +class AudioFile +{ +public: + typedef enum {READ = 0, WRITE = 1} fileOpenModeEnum; + + /** Open audio file for reading or writing. + Filename should include path information but not extension (which is automatically appended) + If the underlying format does not support stereo, data is transparently read from two files in read mode + or two files are transparently written to in write mode */ + virtual void Open(CStdString& filename, fileOpenModeEnum mode, bool stereo = false, int sampleRate = 8000) = 0; + /** Same as above but uses the intenal filename */ + void Open(fileOpenModeEnum mode, bool stereo = false, int sampleRate = 8000); + /** Explicitely close the underlying file(s). This is also done automatically by the destructor */ + virtual void Close() = 0; + + /** Writes a chunk of audio to disk. + If stereo capture, this represents the local party */ + virtual void WriteChunk(AudioChunkRef chunkRef) = 0; + /** Writes a chunk of audio from the remote pary to disk (if stereo capture) + //virtual bool WriteRemoteChunk(AudioChunkRef chunkRef) = 0; + /** Reads a chunk of audio stereo-wise + If underlying storage is mono, remoteChunk will be NULL + ReadChunkStereo guarantees that local and remote chunks returned are in sync */ + //virtual bool ReadChunkStereo(AudioChunkRef& chunk, AudioChunkRef& remoteChunk) = 0; + /** Reads a chunk of audio mono-wise + If underlying file is stereo, ReadChunkMono merges the two streams in a synchronized manner and returns the result */ + virtual int ReadChunkMono(AudioChunkRef& chunk) = 0; + + /** Move the file to a new name including ".orig" suffix */ + void MoveOrig(); + void Delete(); + virtual CStdString GetExtension() = 0; + + static void RecursiveMkdir(CStdString& path); +protected: + CStdString m_filename; + fileOpenModeEnum m_mode; + int m_numChunksWritten; +}; + +typedef boost::shared_ptr AudioFileRef; + +#endif + diff --git a/orkaudio/audiofile/LibSndFileFile.cpp b/orkaudio/audiofile/LibSndFileFile.cpp new file mode 100644 index 0000000..cc5bf82 --- /dev/null +++ b/orkaudio/audiofile/LibSndFileFile.cpp @@ -0,0 +1,123 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "LibSndFileFile.h" + +LibSndFileFile::LibSndFileFile(int fileFormat) +{ + m_fileInfo.format = fileFormat; + m_fileInfo.frames = 0; + m_fileInfo.samplerate = 0; + m_fileInfo.channels = 0; + m_fileInfo.sections = 0; + m_fileInfo.seekable = 0; + m_pFile = NULL; + m_numChunksWritten = 0; + m_mode = READ; +} + +LibSndFileFile::~LibSndFileFile() +{ + Close(); +} + +void LibSndFileFile::Open(CStdString& filename, fileOpenModeEnum mode, bool stereo, int sampleRate) +{ + if(!m_filename.Equals(filename)) + { + m_filename = filename + ".wav"; + } + m_mode = mode; + stereo ? m_fileInfo.channels = 2 : m_fileInfo.channels = 1; + m_fileInfo.samplerate = sampleRate; + + if( (mode==WRITE) && !sf_format_check(&m_fileInfo)) + { + throw(CStdString("libsndfile: Selected output format not supported")); + } + + RecursiveMkdir(m_filename); + + int sndFileMode; + mode == READ ? sndFileMode = SFM_READ : sndFileMode = SFM_WRITE; + m_pFile = sf_open((PCSTR)m_filename, sndFileMode, &m_fileInfo); + + if(!m_pFile) + { + throw(CStdString("sf_open failed, audio file could not be created:"+ m_filename)); + } +} + +void LibSndFileFile::WriteChunk(AudioChunkRef chunkRef) +{ + if (m_pFile) + { + + if( chunkRef->m_encoding == AudioChunk::AlawAudio || chunkRef->m_encoding == AudioChunk::UlawAudio) + { + if(sf_write_raw(m_pFile, chunkRef->m_pBuffer, chunkRef->GetNumSamples()) != chunkRef->GetNumSamples()) + { + CStdString numChunksWrittenString = IntToString(m_numChunksWritten); + throw(CStdString("sf_write_raw failed, audio file " + m_filename + " could not be written after " + numChunksWrittenString + " chunks written")); + } + } + else if (chunkRef->m_encoding == AudioChunk::PcmAudio) + { + if(sf_write_short(m_pFile, (short*)chunkRef->m_pBuffer, chunkRef->GetNumSamples()) != chunkRef->GetNumSamples()) + { + CStdString numChunksWrittenString = IntToString(m_numChunksWritten); + throw(CStdString("sf_write_short failed, audio file " + m_filename + " could not be written after " + numChunksWrittenString + " chunks written")); + } + } + m_numChunksWritten++; + } + else + { + throw(CStdString("Write attempt on unopened file:")+ m_filename); + } +} + +int LibSndFileFile::ReadChunkMono(AudioChunkRef& chunk) +{ + unsigned int numRead = 0; + if (m_pFile) + { + chunk.reset(new AudioChunk()); + short temp[8000]; + numRead = sf_read_short(m_pFile, temp, 8000); + chunk->SetBuffer(temp, sizeof(short)*numRead, AudioChunk::PcmAudio); + } + else + { + throw(CStdString("Read attempt on unopened file:")+ m_filename); + } + return numRead; +} + + +void LibSndFileFile::Close() +{ + if (m_pFile) + { + sf_close(m_pFile); + m_pFile = NULL; + } +} + +CStdString LibSndFileFile::GetExtension() +{ + return ".wav"; +} diff --git a/orkaudio/audiofile/LibSndFileFile.h b/orkaudio/audiofile/LibSndFileFile.h new file mode 100644 index 0000000..e0516a8 --- /dev/null +++ b/orkaudio/audiofile/LibSndFileFile.h @@ -0,0 +1,46 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __LIBSNDFILEFILE_H__ +#define __LIBSNDFILEFILE_H__ + + +#include "StdString.h" +#include "AudioCapture.h" +#include "sndfile.h" +#include "AudioFile.h" + + +/** file accessor class for all file types supported by the libsndfile library. + The library can be found at http://www.mega-nerd.com/libsndfile/ +*/ +class LibSndFileFile : public AudioFile +{ +public: + LibSndFileFile(int fileFormat); // fileFormat is described at http://www.mega-nerd.com/libsndfile/api.html + ~LibSndFileFile(); + + void Open(CStdString& filename, fileOpenModeEnum mode, bool stereo = false, int sampleRate = 8000); + void Close(); + + void WriteChunk(AudioChunkRef chunkRef); + int ReadChunkMono(AudioChunkRef& chunk); + + CStdString GetExtension(); +private: + SF_INFO m_fileInfo; + SNDFILE* m_pFile; +}; + +#endif + diff --git a/orkaudio/audiofile/Makefile.am b/orkaudio/audiofile/Makefile.am new file mode 100644 index 0000000..d6bddad --- /dev/null +++ b/orkaudio/audiofile/Makefile.am @@ -0,0 +1,6 @@ +METASOURCES = AUTO +noinst_LTLIBRARIES = libaudiofile.la +libaudiofile_la_SOURCES = AudioFile.cpp LibSndFileFile.cpp PcmFile.cpp +AM_CPPFLAGS = -D_REENTRANT +libaudiofile_la_LIBADD = +INCLUDES = -I@top_srcdir@ -I../../orkbasecxx diff --git a/orkaudio/audiofile/PcmFile.cpp b/orkaudio/audiofile/PcmFile.cpp new file mode 100644 index 0000000..93f4743 --- /dev/null +++ b/orkaudio/audiofile/PcmFile.cpp @@ -0,0 +1,100 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "PcmFile.h" + +PcmFile::PcmFile() +{ + m_stream = NULL; + m_mode = READ; + m_numChunksWritten = 0; +} + +PcmFile::~PcmFile() +{ + Close(); +} + + +void PcmFile::Close() +{ + if(m_stream) + { + ACE_OS::fclose(m_stream); + m_stream = NULL; + } +} + +void PcmFile::WriteChunk(AudioChunkRef chunkRef) +{ + unsigned int numWritten = 0; + if (m_stream) + { + numWritten = ACE_OS::fwrite(chunkRef->m_pBuffer, sizeof(short), chunkRef->GetNumSamples(), m_stream); + } + else + { + throw(CStdString("Write attempt on unopened file:")+ m_filename); + } + + if (numWritten != chunkRef->GetNumSamples()) + { + throw(CStdString("Could not write to file:")+ m_filename); + } +} + +int PcmFile::ReadChunkMono(AudioChunkRef& chunkRef) +{ + unsigned int numRead = 0; + if (m_stream) + { + chunkRef.reset(new AudioChunk()); + short temp[PCM_FILE_DEFAULT_CHUNK_NUM_SAMPLES]; + numRead = ACE_OS::fread(temp, sizeof(short), PCM_FILE_DEFAULT_CHUNK_NUM_SAMPLES, m_stream); + chunkRef->SetBuffer(temp, sizeof(short)*numRead, AudioChunk::PcmAudio); + } + else + { + throw(CStdString("Read attempt on unopened file:")+ m_filename); + } + return numRead; +} + + +void PcmFile::Open(CStdString& filename, fileOpenModeEnum mode, bool stereo, int sampleRate) +{ + if(!m_filename.Equals(filename)) + { + m_filename = filename + ".pcm"; + } + m_stream = NULL; + m_mode = mode; + if (mode == READ) + { + m_stream = ACE_OS::fopen((PCSTR)m_filename, "rb"); + } + else + { + RecursiveMkdir(m_filename); + m_stream = ACE_OS::fopen((PCSTR)m_filename, "wb"); + } + if(!m_stream) + { + throw(CStdString("Could not open file: ") + m_filename); + } +} + +CStdString PcmFile::GetExtension() +{ + return ".pcm"; +} diff --git a/orkaudio/audiofile/PcmFile.h b/orkaudio/audiofile/PcmFile.h new file mode 100644 index 0000000..91c1325 --- /dev/null +++ b/orkaudio/audiofile/PcmFile.h @@ -0,0 +1,41 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __PCMFILE_H__ +#define __PCMFILE_H__ + +#include "audiofile/AudioFile.h" + +#define PCM_FILE_DEFAULT_CHUNK_NUM_SAMPLES 8000 + +/** File class for raw 16 bit signed PCM output */ +class PcmFile : public AudioFile +{ +public: + PcmFile(); + ~PcmFile(); + + void Open(CStdString& filename, fileOpenModeEnum mode, bool stereo = false, int sampleRate = 8000); + void Close(); + + void WriteChunk(AudioChunkRef chunkRef); + int ReadChunkMono(AudioChunkRef& chunkRef); + + CStdString GetExtension(); +protected: + + FILE* m_stream; +}; + +#endif + diff --git a/orkaudio/config-template.xml b/orkaudio/config-template.xml new file mode 100644 index 0000000..f0132a7 --- /dev/null +++ b/orkaudio/config-template.xml @@ -0,0 +1,24 @@ + + + + hostname + true + 1000 + audiocaptureplugins/ + Generator.dll + gsm + + no + false + 10 + + \Device\NPF_{2FEDB9F0-F584-48A8-B164-117965F80986} + + 10.0.0.102 + + + 1 + 5 + sine.8KHz.pcm.wav + + \ No newline at end of file diff --git a/orkaudio/config.guess b/orkaudio/config.guess new file mode 100644 index 0000000..182e141 --- /dev/null +++ b/orkaudio/config.guess @@ -0,0 +1 @@ +link /usr/share/libtool/config.guess \ No newline at end of file diff --git a/orkaudio/config.sub b/orkaudio/config.sub new file mode 100644 index 0000000..ea4beb2 --- /dev/null +++ b/orkaudio/config.sub @@ -0,0 +1 @@ +link /usr/share/libtool/config.sub \ No newline at end of file diff --git a/orkaudio/configure.in b/orkaudio/configure.in new file mode 100644 index 0000000..b92725d --- /dev/null +++ b/orkaudio/configure.in @@ -0,0 +1,10 @@ +AC_INIT(configure.in) + +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(orkaudio, 0.1) + +AC_LANG_CPLUSPLUS +AC_PROG_CXX +AM_PROG_LIBTOOL + +AC_OUTPUT(Makefile messages/Makefile audiofile/Makefile audiocaptureplugins/Makefile audiocaptureplugins/generator/Makefile audiocaptureplugins/voip/Makefile) diff --git a/orkaudio/install-sh b/orkaudio/install-sh new file mode 100644 index 0000000..36f96f3 --- /dev/null +++ b/orkaudio/install-sh @@ -0,0 +1,276 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd=$cpprog + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "$0: no input file specified" >&2 + exit 1 +else + : +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d "$dst" ]; then + instcmd=: + chmodcmd="" + else + instcmd=$mkdirprog + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f "$src" ] || [ -d "$src" ] + then + : + else + echo "$0: $src does not exist" >&2 + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "$0: no destination specified" >&2 + exit 1 + else + : + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d "$dst" ] + then + dst=$dst/`basename "$src"` + else + : + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' + ' +IFS="${IFS-$defaultIFS}" + +oIFS=$IFS +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS=$oIFS + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp=$pathcomp$1 + shift + + if [ ! -d "$pathcomp" ] ; + then + $mkdirprog "$pathcomp" + else + : + fi + + pathcomp=$pathcomp/ +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd "$dst" && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename "$dst"` + else + dstfile=`basename "$dst" $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename "$dst"` + else + : + fi + +# Make a couple of temp file names in the proper directory. + + dsttmp=$dstdir/#inst.$$# + rmtmp=$dstdir/#rm.$$# + +# Trap to clean up temp files at exit. + + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap '(exit $?); exit' 1 2 13 15 + +# Move or copy the file name to the temp name + + $doit $instcmd "$src" "$dsttmp" && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && + +# Now remove or move aside any old file at destination location. We try this +# two ways since rm can't unlink itself on some systems and the destination +# file might be busy for other reasons. In this case, the final cleanup +# might fail but the new file should still install successfully. + +{ + if [ -f "$dstdir/$dstfile" ] + then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || + $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || + { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi +} && + +# Now rename the file to the real destination. + + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + +fi && + +# The final little trick to "correctly" pass the exit status to the exit trap. + +{ + (exit 0); exit +} diff --git a/orkaudio/logging-template.properties b/orkaudio/logging-template.properties new file mode 100644 index 0000000..b441d54 --- /dev/null +++ b/orkaudio/logging-template.properties @@ -0,0 +1,43 @@ +# This is an example configuration file for the Oreka orkaudio capture service logging --> +# Copy this to logging.properties and modify according to needs --> + +# console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n + +# main logfile +log4j.appender.A1=org.apache.log4j.RollingFileAppender +log4j.appender.A1.File=orkaudio.log +log4j.appender.A1.MaxFileSize=5000KB +log4j.appender.A1.MaxBackupIndex=2 +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n + +# messages logfile +log4j.appender.messages=org.apache.log4j.RollingFileAppender +log4j.appender.messages.File=messages.log +log4j.appender.messages.MaxFileSize=5000KB +log4j.appender.messages.MaxBackupIndex=2 +log4j.appender.messages.layout=org.apache.log4j.PatternLayout +log4j.appender.messages.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n + +#tapelist logfile +log4j.appender.tapelist=org.apache.log4j.RollingFileAppender +log4j.appender.tapelist.File=tapelist.log +log4j.appender.tapelist.MaxFileSize=5000KB +log4j.appender.tapelist.MaxBackupIndex=2 +log4j.appender.tapelist.layout=org.apache.log4j.PatternLayout +log4j.appender.tapelist.layout.ConversionPattern=%m%n + + +# Set root logger level to DEBUG +log4j.rootLogger=INFO, A1, stdout +log4j.logger.reporting=INFO, messages +log4j.logger.tapelist=INFO, tapelist +log4j.logger.rtpringbuffer=INFO +log4j.logger.voip=INFO +log4j.logger.sipsessions=INFO +log4j.logger.sipsession=DEBUG +log4j.logger.sipextraction=DEBUG diff --git a/orkaudio/ltmain.sh b/orkaudio/ltmain.sh new file mode 100644 index 0000000..7404ae3 --- /dev/null +++ b/orkaudio/ltmain.sh @@ -0,0 +1 @@ +link /usr/share/libtool/ltmain.sh \ No newline at end of file diff --git a/orkaudio/messages/CaptureMsg.cpp b/orkaudio/messages/CaptureMsg.cpp new file mode 100644 index 0000000..f013e1f --- /dev/null +++ b/orkaudio/messages/CaptureMsg.cpp @@ -0,0 +1,84 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "Utils.h" +#include "CaptureMsg.h" +//#include "LogManager.h" +#include "CapturePluginProxy.h" + +#define CAPTURE_CLASS "capture" +#define CAPTURE_RESPONSE_CLASS "captureresponse" +#define CAPTURE_STATE_PARAM "state" +#define COMMENT_PARAM "comment" + +void CaptureResponseMsg::Define(Serializer* s) +{ + s->BoolValue(SUCCESS_PARAM, m_success); + s->StringValue(COMMENT_PARAM, m_comment); +} + +CStdString CaptureResponseMsg::GetClassName() +{ + return CStdString(CAPTURE_RESPONSE_CLASS); +} + +ObjectRef CaptureResponseMsg::NewInstance() +{ + return ObjectRef(new CaptureResponseMsg); +} + +//=============================== + +void CaptureMsg::Define(Serializer* s) +{ + CStdString captureClass(CAPTURE_CLASS); + s->StringValue(OBJECT_TYPE_TAG, captureClass, true); + s->StringValue(CAPTURE_PORT_PARAM, m_capturePort, true); + s->EnumValue(CAPTURE_STATE_PARAM, (int&)m_eventType, CaptureEvent::EventTypeToEnum, CaptureEvent::EventTypeToString, true); +} + + +CStdString CaptureMsg::GetClassName() +{ + return CStdString(CAPTURE_CLASS); +} + +ObjectRef CaptureMsg::NewInstance() +{ + return ObjectRef(new CaptureMsg); +} + +ObjectRef CaptureMsg::Process() +{ + CaptureResponseMsg* msg = new CaptureResponseMsg; + ObjectRef ref(msg); + + if(m_eventType == CaptureEvent::EtStart) + { + CapturePluginProxySingleton::instance()->StartCapture(m_capturePort); + msg->m_success = true; + } + else if(m_eventType == CaptureEvent::EtStop) + { + CapturePluginProxySingleton::instance()->StopCapture(m_capturePort); + msg->m_success = true; + } + else + { + msg->m_success = false; + msg->m_comment = CAPTURE_STATE_PARAM; + msg->m_comment += " needs to be start or stop"; + } + return ref; +} + diff --git a/orkaudio/messages/CaptureMsg.h b/orkaudio/messages/CaptureMsg.h new file mode 100644 index 0000000..782f70f --- /dev/null +++ b/orkaudio/messages/CaptureMsg.h @@ -0,0 +1,51 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __CAPTUREMSG_H__ +#define __CAPTUREMSG_H__ + +#include "messages/SyncMessage.h" +#include "messages/AsyncMessage.h" +#include "AudioCapture.h" + + +class CaptureResponseMsg : public AsyncMessage +{ +public: + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + bool m_success; + CStdString m_comment; +}; + +class CaptureMsg : public SyncMessage +{ +public: + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + ObjectRef Process(); + + CaptureEvent::EventTypeEnum m_eventType; + CStdString m_capturePort; +}; + +#endif + diff --git a/orkaudio/messages/DeleteTapeMsg.cpp b/orkaudio/messages/DeleteTapeMsg.cpp new file mode 100644 index 0000000..9dc8dae --- /dev/null +++ b/orkaudio/messages/DeleteTapeMsg.cpp @@ -0,0 +1,60 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "DeleteTapeMsg.h" +#include "messages/AsyncMessage.h" + +#define DELETE_TAPE_CLASS "deletetape" + +void DeleteTapeMsg::Define(Serializer* s) +{ + CStdString deleteTapeClass(DELETE_TAPE_CLASS); + s->StringValue(OBJECT_TYPE_TAG, deleteTapeClass, true); + s->StringValue(FILENAME_PARAM, m_filename, true); +} + + +CStdString DeleteTapeMsg::GetClassName() +{ + return CStdString(DELETE_TAPE_CLASS); +} + +ObjectRef DeleteTapeMsg::NewInstance() +{ + return ObjectRef(new DeleteTapeMsg); +} + +ObjectRef DeleteTapeMsg::Process() +{ + SimpleResponseMsg* msg = new SimpleResponseMsg; + ObjectRef ref(msg); + + // Check that the audio file to delete is actually an audio file + if(m_filename.Find('/') != -1 && (m_filename.Find(".pcm") != -1 || m_filename.Find(".wav") != -1 )) + { + if (ACE_OS::unlink((PCSTR)m_filename) == -1) + { + msg->m_success = false; + msg->m_comment = "could not delete file"; + } + + } + else + { + msg->m_success = false; + msg->m_comment = "filename not valid"; + } + + return ref; +} + diff --git a/orkaudio/messages/DeleteTapeMsg.h b/orkaudio/messages/DeleteTapeMsg.h new file mode 100644 index 0000000..33fb9ae --- /dev/null +++ b/orkaudio/messages/DeleteTapeMsg.h @@ -0,0 +1,33 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __DELETETAPEMSG_H__ +#define __DELETETAPEMSG_H__ + +#include "messages/SyncMessage.h" + +class DeleteTapeMsg : public SyncMessage +{ +public: + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + ObjectRef Process(); + + CStdString m_filename; +}; + +#endif + diff --git a/orkaudio/messages/Makefile.am b/orkaudio/messages/Makefile.am new file mode 100644 index 0000000..2367e4b --- /dev/null +++ b/orkaudio/messages/Makefile.am @@ -0,0 +1,7 @@ +METASOURCES = AUTO +noinst_LTLIBRARIES = libmessages.la +libmessages_la_SOURCES = CaptureMsg.cpp DeleteTapeMsg.cpp PingMsg.cpp \ + TapeMsg.cpp TestMsg.cpp +AM_CPPFLAGS = -D_REENTRANT +libmessages_la_LIBADD = -L../../orkbasecxx/ -lorkbase +INCLUDES = -I@top_srcdir@ -I../../orkbasecxx diff --git a/orkaudio/messages/PingMsg.cpp b/orkaudio/messages/PingMsg.cpp new file mode 100644 index 0000000..1f90bbe --- /dev/null +++ b/orkaudio/messages/PingMsg.cpp @@ -0,0 +1,60 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "PingMsg.h" + +#define PING_CLASS "ping" +#define PING_RESPONSE_CLASS "pingresponse" + +void PingResponseMsg::Define(Serializer* s) +{ + s->BoolValue(SUCCESS_PARAM, m_success); +} + +CStdString PingResponseMsg::GetClassName() +{ + return CStdString(PING_RESPONSE_CLASS); +} + +ObjectRef PingResponseMsg::NewInstance() +{ + return ObjectRef(new PingResponseMsg); +} + +//=============================== + +void PingMsg::Define(Serializer* s) +{ + CStdString pingClass(PING_CLASS); + s->StringValue(OBJECT_TYPE_TAG, pingClass, true); +} + + +CStdString PingMsg::GetClassName() +{ + return CStdString(PING_CLASS); +} + +ObjectRef PingMsg::NewInstance() +{ + return ObjectRef(new PingMsg); +} + +ObjectRef PingMsg::Process() +{ + PingResponseMsg* msg = new PingResponseMsg; + ObjectRef ref(msg); + msg->m_success = true; + return ref; +} + diff --git a/orkaudio/messages/PingMsg.h b/orkaudio/messages/PingMsg.h new file mode 100644 index 0000000..21b659a --- /dev/null +++ b/orkaudio/messages/PingMsg.h @@ -0,0 +1,46 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __PINGMSG_H__ +#define __PINGMSG_H__ + +#include "messages/SyncMessage.h" +#include "messages/AsyncMessage.h" + + +class PingResponseMsg : public AsyncMessage +{ +public: + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + bool m_success; +}; + +class PingMsg : public SyncMessage +{ +public: + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + ObjectRef Process(); +}; + +#endif + diff --git a/orkaudio/messages/TapeMsg.cpp b/orkaudio/messages/TapeMsg.cpp new file mode 100644 index 0000000..86c86b4 --- /dev/null +++ b/orkaudio/messages/TapeMsg.cpp @@ -0,0 +1,56 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "Utils.h" +#include "TapeMsg.h" +#include "ConfigManager.h" + +TapeMsg::TapeMsg() +{ + // Here is where default values are set + m_timestamp = 0; + m_direction = CaptureEvent::DirectionToString(CaptureEvent::DirUnkn); + m_duration = 0; + m_serviceName = CONFIG.m_serviceName; +} + +void TapeMsg::Define(Serializer* s) +{ + CStdString tapeMessageName(TAPE_MESSAGE_NAME); + s->StringValue(OBJECT_TYPE_TAG, tapeMessageName, true); + s->StringValue(STAGE_PARAM, m_stage, true); + s->StringValue(CAPTURE_PORT_PARAM, m_capturePort, true); + s->IntValue(TIMESTAMP_PARAM, (int&)m_timestamp, true); + s->StringValue(FILENAME_PARAM, m_fileName, true); + s->StringValue(LOCALPARTY_PARAM, m_localParty); + s->StringValue(LOCALENTRYPOINT_PARAM, m_localEntryPoint); + s->StringValue(REMOTEPARTY_PARAM, m_remoteParty); + s->StringValue(DIRECTION_PARAM, m_direction); + s->IntValue(DURATION_PARAM, m_duration); + s->StringValue(SERVICE_PARAM, m_serviceName); +} + +void TapeMsg::Validate() +{ +} + +CStdString TapeMsg::GetClassName() +{ + return CStdString(TAPE_MESSAGE_NAME); +} + +ObjectRef TapeMsg::NewInstance() +{ + return ObjectRef(new TapeMsg); +} + diff --git a/orkaudio/messages/TapeMsg.h b/orkaudio/messages/TapeMsg.h new file mode 100644 index 0000000..d127c6d --- /dev/null +++ b/orkaudio/messages/TapeMsg.h @@ -0,0 +1,58 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __TAPEMSG_H__ +#define __TAPEMSG_H__ + +#include "messages/SyncMessage.h" +#include "AudioTape.h" + +#define TAPE_MESSAGE_NAME "tape" +#define FILENAME_PARAM "filename" +#define STAGE_PARAM "stage" +#define LOCALPARTY_PARAM "localparty" +#define REMOTEPARTY_PARAM "remoteparty" +#define DIRECTION_PARAM "direction" +#define LOCALENTRYPOINT_PARAM "localentrypoint" +#define DURATION_PARAM "duration" +#define SERVICE_PARAM "service" + +class TapeMsg : public SyncMessage +{ +public: + TapeMsg(); + + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + CStdString m_stage; + time_t m_timestamp; + CStdString m_fileName; + CStdString m_capturePort; + CStdString m_localParty; + CStdString m_localEntryPoint; + CStdString m_remoteParty; + CStdString m_direction; + CStdString m_loginString; + int m_duration; + CStdString m_serviceName; +}; + +typedef boost::shared_ptr TapeMsgRef; + +#endif + diff --git a/orkaudio/messages/TestMsg.cpp b/orkaudio/messages/TestMsg.cpp new file mode 100644 index 0000000..68e2f3e --- /dev/null +++ b/orkaudio/messages/TestMsg.cpp @@ -0,0 +1,53 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "Utils.h" +#include "TestMsg.h" + +TestMsg::TestMsg() +{ + // Here is where default values are set + m_timestamp = 0; +} + +void TestMsg::Define(Serializer* s) +{ + CStdString testMessageName("test"); + s->StringValue("test", testMessageName, true); + s->StringValue(STAGE_PARAM, m_stage, true); + s->StringValue(CAPTURE_PORT_PARAM, m_capturePort, true); + s->IntValue(TIMESTAMP_PARAM, (int&)m_timestamp, true); + s->StringValue(FILENAME_PARAM, m_fileName, true); + + s->StringValue(LOCALPARTY_PARAM, m_localParty); + s->StringValue(LOCALENTRYPOINT_PARAM, m_localEntryPoint); + s->StringValue(REMOTEPARTY_PARAM, m_remoteParty); + s->StringValue(DIRECTION_PARAM, m_direction); + s->CsvValue("csv", m_csv); + s->DateValue("date", m_time); +} + +void TestMsg::Validate() +{ +} + +CStdString TestMsg::GetClassName() +{ + return CStdString("test"); +} + +ObjectRef TestMsg::NewInstance() +{ + return ObjectRef(new TestMsg); +} + diff --git a/orkaudio/messages/TestMsg.h b/orkaudio/messages/TestMsg.h new file mode 100644 index 0000000..13aed71 --- /dev/null +++ b/orkaudio/messages/TestMsg.h @@ -0,0 +1,55 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __TESTMSG_H__ +#define __TESTMSG_H__ + +#include +#include "messages/SyncMessage.h" + +#define FILENAME_PARAM "filename" +#define STAGE_PARAM "stage" +#define LOCALPARTY_PARAM "localparty" +#define REMOTEPARTY_PARAM "remoteparty" +#define DIRECTION_PARAM "direction" +#define LOCALENTRYPOINT_PARAM "localentrypoint" + +class TestMsg : public SyncMessage +{ +public: + TestMsg(); + + void Define(Serializer* s); + void Validate(); + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + CStdString m_stage; + time_t m_timestamp; + CStdString m_fileName; + CStdString m_capturePort; + CStdString m_localParty; + CStdString m_localEntryPoint; + CStdString m_remoteParty; + CStdString m_direction; + CStdString m_loginString; + std::list m_csv; + time_t m_time; +}; + +typedef boost::shared_ptr TestMsgRef; + +#endif + diff --git a/orkaudio/missing b/orkaudio/missing new file mode 100644 index 0000000..6a37006 --- /dev/null +++ b/orkaudio/missing @@ -0,0 +1,336 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. +# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# 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, 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing 0.4 - GNU automake" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. + You can get \`$1Help2man' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequirements for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 diff --git a/orkaudio/mkinstalldirs b/orkaudio/mkinstalldirs new file mode 100644 index 0000000..d2d5f21 --- /dev/null +++ b/orkaudio/mkinstalldirs @@ -0,0 +1,111 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman +# Created: 1993-05-16 +# Public domain + +errstatus=0 +dirmode="" + +usage="\ +Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." + +# process command line arguments +while test $# -gt 0 ; do + case $1 in + -h | --help | --h*) # -h for help + echo "$usage" 1>&2 + exit 0 + ;; + -m) # -m PERM arg + shift + test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } + dirmode=$1 + shift + ;; + --) # stop option processing + shift + break + ;; + -*) # unknown option + echo "$usage" 1>&2 + exit 1 + ;; + *) # first non-opt arg + break + ;; + esac +done + +for file +do + if test -d "$file"; then + shift + else + break + fi +done + +case $# in + 0) exit 0 ;; +esac + +case $dirmode in + '') + if mkdir -p -- . 2>/dev/null; then + echo "mkdir -p -- $*" + exec mkdir -p -- "$@" + fi + ;; + *) + if mkdir -m "$dirmode" -p -- . 2>/dev/null; then + echo "mkdir -m $dirmode -p -- $*" + exec mkdir -m "$dirmode" -p -- "$@" + fi + ;; +esac + +for file +do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d + do + pathcomp="$pathcomp$d" + case $pathcomp in + -*) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + else + if test ! -z "$dirmode"; then + echo "chmod $dirmode $pathcomp" + lasterr="" + chmod "$dirmode" "$pathcomp" || lasterr=$? + + if test ! -z "$lasterr"; then + errstatus=$lasterr + fi + fi + fi + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# End: +# mkinstalldirs ends here diff --git a/orkbasecxx/AudioCapture.cpp b/orkbasecxx/AudioCapture.cpp new file mode 100644 index 0000000..3178f2e --- /dev/null +++ b/orkbasecxx/AudioCapture.cpp @@ -0,0 +1,201 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "Utils.h" +#include "math.h" +#include "AudioCapture.h" + + +AudioChunk::AudioChunk() +{ + m_encoding = UnknownAudio; + m_timestamp = 0; + m_sequenceNumber = 0; + m_numBytes = 0; + m_pBuffer = NULL; + m_sampleRate = 8000; +} + +AudioChunk::~AudioChunk() +{ + if(m_pBuffer) + { + free(m_pBuffer); + } +} + +void AudioChunk::SetBuffer(void* pBuffer, size_t numBytes, AudioEncodingEnum encoding, unsigned int timestamp, unsigned int sequenceNumber) +{ + if(m_pBuffer) + { + free(m_pBuffer); + m_numBytes = 0; + } + if(numBytes && pBuffer) + { + m_pBuffer = malloc(numBytes); + if (!m_pBuffer) + { + CStdString numBytesString = IntToString(numBytes); + throw("AudioChunk::AudioChunk: could not malloc a buffer of size:" + numBytesString); + } + else + { + m_numBytes = numBytes; + memcpy(m_pBuffer, pBuffer, numBytes); + m_encoding = encoding; + m_timestamp = timestamp; + m_sequenceNumber = sequenceNumber; + } + } +} + +int AudioChunk::GetNumSamples() +{ + switch(m_encoding) + { + case PcmAudio: + return m_numBytes/2; + case AlawAudio: case UlawAudio: + return m_numBytes; + default: + throw(CStdString("AudioChunk::GetNumSamples: unknown encoding")); + } +} + +double AudioChunk::GetDurationSec() +{ + int i = 0; + return ((double)GetNumSamples())/((double)m_sampleRate); +} + + +double AudioChunk::ComputeRms() +{ + double rmsValue = 0; + if(m_encoding == PcmAudio) + { + for(int i=0; i AudioChunkRef; + +class DLL_IMPORT_EXPORT CaptureEvent +{ +public: + CaptureEvent(); + +#define DIR_IN "in" +#define DIR_OUT "out" +#define DIR_UNKN "unkn" + typedef enum { + DirIn = 0, + DirOut = 1, + DirUnkn = 2 + } DirectionEnum; + static CStdString DirectionToString(int); + static int DirectionToEnum(CStdString& dir); + +#define ET_UNKNOWN "unknown" +#define ET_START "start" +#define ET_STOP "stop" +#define ET_DIRECTION "direction" +#define ET_REMOTEPARTY "remoteparty" +#define ET_LOCALPARTY "localparty" +#define ET_LOCALENTRYPOINT "localentrypoint" +#define ET_KEYVALUE "keyvalue" +#define ET_INVALID "invalid" + typedef enum + { + EtUnknown = 0, + EtStart = 1, + EtStop = 2, + EtDirection = 3, + EtRemoteParty = 4, + EtLocalParty = 5, + EtLocalEntryPoint = 6, + EtKeyValue = 7, + EtInvalid = 8 + } EventTypeEnum; + static CStdString EventTypeToString(int eventTypeEnum); + static int EventTypeToEnum(CStdString&); + + time_t m_timestamp; + EventTypeEnum m_type; + CStdString m_key; + CStdString m_value; +}; + +typedef boost::shared_ptr CaptureEventRef; +#endif + diff --git a/orkbasecxx/BUILD.txt b/orkbasecxx/BUILD.txt new file mode 100644 index 0000000..70f9ba3 --- /dev/null +++ b/orkbasecxx/BUILD.txt @@ -0,0 +1,2 @@ + +To build this, please see ../BUILD_C++.txt \ No newline at end of file diff --git a/orkbasecxx/Makefile.am b/orkbasecxx/Makefile.am new file mode 100644 index 0000000..b660bf6 --- /dev/null +++ b/orkbasecxx/Makefile.am @@ -0,0 +1,14 @@ +# not a GNU package. You can remove this line, if +# have all needed files, that a GNU package needs +AUTOMAKE_OPTIONS = foreign 1.4 + + +lib_LTLIBRARIES = liborkbase.la +liborkbase_la_LDFLAGS = +liborkbase_la_SOURCES = OrkBase.cpp Object.cpp ObjectFactory.cpp \ + OrkClient.cpp AudioCapture.cpp +#INCLUDES = -I/projects/ext/xmlrpc++/xmlrpc++0.7/src +SUBDIRS = messages serializers +liborkbase_la_LIBADD = $(top_builddir)/serializers/libserializers.la \ + $(top_builddir)/messages/libmessages.la +AM_CXXFLAGS = -D_REENTRANT diff --git a/orkbasecxx/Makefile.cvs b/orkbasecxx/Makefile.cvs new file mode 100644 index 0000000..d160702 --- /dev/null +++ b/orkbasecxx/Makefile.cvs @@ -0,0 +1,8 @@ +default: all + +all: + aclocal + autoheader + automake + autoconf + diff --git a/orkbasecxx/Object.cpp b/orkbasecxx/Object.cpp new file mode 100644 index 0000000..66ceeb9 --- /dev/null +++ b/orkbasecxx/Object.cpp @@ -0,0 +1,54 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "serializers/SingleLineSerializer.h" +#include "serializers/DomSerializer.h" +#include "serializers/UrlSerializer.h" +#include "Object.h" + + +CStdString Object::SerializeSingleLine() +{ + SingleLineSerializer serializer(this); + return serializer.Serialize(); +} + +void Object::DeSerializeSingleLine(CStdString& input) +{ + SingleLineSerializer serializer(this); + serializer.DeSerialize(input); +} + +void Object::SerializeDom(XERCES_CPP_NAMESPACE::DOMDocument* doc) +{ + DomSerializer serializer(this); + serializer.Serialize(doc); +} + +void Object::DeSerializeDom(DOMNode* doc) +{ + DomSerializer serializer(this); + serializer.DeSerialize(doc); +} + +CStdString Object::SerializeUrl() +{ + UrlSerializer serializer(this); + return serializer.Serialize(); +} + +void Object::DeSerializeUrl(CStdString& input) +{ + UrlSerializer serializer(this); + serializer.DeSerialize(input); +} diff --git a/orkbasecxx/Object.h b/orkbasecxx/Object.h new file mode 100644 index 0000000..ba8128e --- /dev/null +++ b/orkbasecxx/Object.h @@ -0,0 +1,56 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __OBJECT_H__ +#define __OBJECT_H__ + +#include "OrkBase.h" +#include "boost/shared_ptr.hpp" +#include "xercesc/dom/DOMNode.hpp" + +class Serializer; +class Object; + +using namespace XERCES_CPP_NAMESPACE; + +typedef boost::shared_ptr ObjectRef; + +#define OBJECT_TYPE_TAG "type" + +/** An Object is the equivalent of a Java Object +*/ +class DLL_IMPORT_EXPORT Object +{ +public: + virtual void Define(Serializer* s) = 0; + virtual void Validate() = 0; + + CStdString SerializeSingleLine(); + void DeSerializeSingleLine(CStdString& input); + + void SerializeDom(XERCES_CPP_NAMESPACE::DOMDocument* doc); + void DeSerializeDom(DOMNode* doc); + + CStdString SerializeUrl(); + void DeSerializeUrl(CStdString& input); + + virtual CStdString GetClassName() = 0; + virtual ObjectRef NewInstance() = 0; + + virtual ObjectRef Process() = 0; +}; + + + +#endif + diff --git a/orkbasecxx/ObjectFactory.cpp b/orkbasecxx/ObjectFactory.cpp new file mode 100644 index 0000000..173d581 --- /dev/null +++ b/orkbasecxx/ObjectFactory.cpp @@ -0,0 +1,44 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "ObjectFactory.h" + + +void ObjectFactory::Initialize() +{ + ; +} + +ObjectRef ObjectFactory::NewInstance(CStdString& className) +{ + std::map::iterator pair; + pair = m_classes.find(className); + + if (pair == m_classes.end()) + { + return ObjectRef(); // Empty + } + else + { + return pair->second; + } +} + +void ObjectFactory::RegisterObject(ObjectRef& objRef) +{ + m_classes.insert(std::make_pair(objRef->GetClassName(), objRef)); +} + + diff --git a/orkbasecxx/ObjectFactory.h b/orkbasecxx/ObjectFactory.h new file mode 100644 index 0000000..52f61b7 --- /dev/null +++ b/orkbasecxx/ObjectFactory.h @@ -0,0 +1,39 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __OBJECTFACTORY_H__ +#define __OBJECTFACTORY_H__ + +#include "ace/Singleton.h" +#include +#include "StdString.h" +#include "Object.h" + +/** The ObjectFactory can be used to instanciate Objects based on class name. + All existing Objects must be registered to the ObjectFactory at startup. +*/ +class DLL_IMPORT_EXPORT ObjectFactory +{ +public: + void Initialize(); + ObjectRef NewInstance(CStdString& className); + + void RegisterObject(ObjectRef&); +private: + std::map m_classes; +}; + +typedef ACE_Singleton ObjectFactorySingleton; + +#endif + diff --git a/orkbasecxx/OrkBase.cpp b/orkbasecxx/OrkBase.cpp new file mode 100644 index 0000000..98d7d1b --- /dev/null +++ b/orkbasecxx/OrkBase.cpp @@ -0,0 +1,27 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +// Defines the entry point for the DLL application. +// + +//#include "stdafx.h" +/* +BOOL APIENTRY DllMain( HANDLE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + return TRUE; +} +*/ + diff --git a/orkbasecxx/OrkBase.dsp b/orkbasecxx/OrkBase.dsp new file mode 100644 index 0000000..36c004f --- /dev/null +++ b/orkbasecxx/OrkBase.dsp @@ -0,0 +1,330 @@ +# Microsoft Developer Studio Project File - Name="OrkBase" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=OrkBase - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "OrkBase.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "OrkBase.mak" CFG="OrkBase - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "OrkBase - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "OrkBase - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "BUILD_ORKBASE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /FD /c +# SUBTRACT CPP /YX /Yc /Yu +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 xerces-c_2.lib log4cxx.lib ace.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"C:\devExt\ACE_wrappers\lib" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\lib" +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Cmds=copy Release\OrkBase.dll ..\OrkAudio\OrkBase.dll +# End Special Build Tool + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "BUILD_ORKBASE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /FD /GZ /c +# SUBTRACT CPP /YX /Yc /Yu +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 xerces-c_2D.lib log4cxx.lib aced.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /map /debug /machine:I386 /out:"Debug/OrkBaseD.dll" /pdbtype:sept /libpath:"C:\devExt\ACE_wrappers\lib" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\lib" +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Cmds=copy Debug\OrkBaseD.dll ..\OrkAudio\OrkBaseD.dll +# End Special Build Tool + +!ENDIF + +# Begin Target + +# Name "OrkBase - Win32 Release" +# Name "OrkBase - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Group "Serializers" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Serializers\DomSerializer.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Serializers\DomSerializer.h +# End Source File +# Begin Source File + +SOURCE=.\Serializers\Serializer.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Serializers\Serializer.h +# End Source File +# Begin Source File + +SOURCE=.\Serializers\SingleLineSerializer.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Serializers\SingleLineSerializer.h +# End Source File +# Begin Source File + +SOURCE=.\Serializers\UrlSerializer.cpp +# End Source File +# Begin Source File + +SOURCE=.\Serializers\UrlSerializer.h +# End Source File +# Begin Source File + +SOURCE=.\Serializers\XmlRpcSerializer.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Serializers\XmlRpcSerializer.h +# End Source File +# End Group +# Begin Group "Messages" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Messages\AsyncMessage.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Messages\AsyncMessage.h +# End Source File +# Begin Source File + +SOURCE=.\Messages\Message.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Messages\Message.h +# End Source File +# Begin Source File + +SOURCE=.\Messages\SyncMessage.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Messages\SyncMessage.h +# End Source File +# End Group +# Begin Source File + +SOURCE=.\AudioCapture.cpp +# End Source File +# Begin Source File + +SOURCE=.\AudioCapture.h +# End Source File +# Begin Source File + +SOURCE=.\Object.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Object.h +# End Source File +# Begin Source File + +SOURCE=.\ObjectFactory.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\ObjectFactory.h +# End Source File +# Begin Source File + +SOURCE=.\OrkBase.cpp + +!IF "$(CFG)" == "OrkBase - Win32 Release" + +!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug" + +# SUBTRACT CPP /YX /Yc /Yu + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\OrkBase.h +# End Source File +# Begin Source File + +SOURCE=.\OrkClient.cpp +# End Source File +# Begin Source File + +SOURCE=.\OrkClient.h +# End Source File +# Begin Source File + +SOURCE=.\StdString.h +# End Source File +# Begin Source File + +SOURCE=.\Utils.h +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\ReadMe.txt +# End Source File +# End Target +# End Project diff --git a/orkbasecxx/OrkBase.dsw b/orkbasecxx/OrkBase.dsw new file mode 100644 index 0000000..b9c8f99 --- /dev/null +++ b/orkbasecxx/OrkBase.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "OrkBase"=.\OrkBase.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/orkbasecxx/OrkBase.h b/orkbasecxx/OrkBase.h new file mode 100644 index 0000000..95f1ef6 --- /dev/null +++ b/orkbasecxx/OrkBase.h @@ -0,0 +1,26 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#ifdef WIN32 + #ifdef BUILD_ORKBASE + #define DLL_IMPORT_EXPORT __declspec( dllexport ) + #else + #define DLL_IMPORT_EXPORT __declspec( dllimport ) + #endif +#else + #define DLL_IMPORT_EXPORT +#endif + +#include "StdString.h" diff --git a/orkbasecxx/OrkClient.cpp b/orkbasecxx/OrkClient.cpp new file mode 100644 index 0000000..900656d --- /dev/null +++ b/orkbasecxx/OrkClient.cpp @@ -0,0 +1,132 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "Utils.h" +#include "OrkClient.h" +#include "ace/INET_Addr.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_Stream.h" + +#ifdef WIN32 + #define IOV_TYPE char* +#else + #define IOV_TYPE void* +#endif + +bool OrkHttpClient::ExecuteUrl(CStdString& request, CStdString& response, CStdString& hostname, int tcpPort, int timeout) +{ + ACE_SOCK_Connector connector; + ACE_SOCK_Stream peer; + ACE_INET_Addr peer_addr; + ACE_Time_Value aceTimeout (timeout); + + char szTcpPort[10]; + sprintf(szTcpPort, "%d", tcpPort); + iovec iov[8]; + iov[0].iov_base = (IOV_TYPE)"GET "; + iov[0].iov_len = 4; // Length of "GET ". + iov[1].iov_base = (PSTR)(PCSTR)request; + iov[1].iov_len = request.size(); + iov[2].iov_base = (IOV_TYPE)" HTTP/1.0\r\n"; + iov[2].iov_len = 11; + iov[3].iov_base = (IOV_TYPE)"Host: "; + iov[3].iov_len = 6; + iov[4].iov_base = (PSTR)(PCSTR)hostname; + iov[4].iov_len = hostname.size(); + iov[5].iov_base = (IOV_TYPE)":"; + iov[5].iov_len = 1; + iov[6].iov_base = szTcpPort; + iov[6].iov_len = strlen(szTcpPort); + iov[7].iov_base = (IOV_TYPE)"\r\n\r\n"; + iov[7].iov_len = 4; + + if (peer_addr.set (tcpPort, (PCSTR)hostname) == -1) + { + return false; + } + else if (connector.connect (peer, peer_addr, &aceTimeout) == -1) + { + if (errno == ETIME) + { + } + return false; + } + else if (peer.sendv_n (iov, 8, &aceTimeout) == -1) + { + return false; + } + + ssize_t numReceived = 0; +#define BUFSIZE 4096 + char buf [BUFSIZE]; + + CStdString header; + bool gotHeader = false; + while ( (numReceived = peer.recv (buf, BUFSIZE, &aceTimeout)) > 0 ) + { + for(int i=0; i 4 && + header.GetAt(headerSize-1) == '\n' && + header.GetAt(headerSize-2) == '\r' && + header.GetAt(headerSize-3) == '\n' && + header.GetAt(headerSize-4) == '\r' ) + { + gotHeader = true; + } + } + else + { + // extract content + response += buf[i]; + } + } + } + if(numReceived < 0) + { + return false; + } + if(header.size() <= 0 || response.size() <= 0) + { + return false; + } + if( header.GetAt(10) != '2' && + header.GetAt(11) != '0' && + header.GetAt(12) != '0' && + header.GetAt(13) != ' ' && + header.GetAt(14) != 'O' && + header.GetAt(15) != 'K' ) + { + return false; + } + return true; +} + +bool OrkHttpSingleLineClient::Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout) +{ + CStdString requestString = "/" + serviceName + "/command?"; + requestString += request.SerializeUrl(); + CStdString responseString; + if (ExecuteUrl(requestString, responseString, hostname, tcpPort, timeout)) + { + response.DeSerializeSingleLine(responseString); + return true; + } + return false; +} + diff --git a/orkbasecxx/OrkClient.h b/orkbasecxx/OrkClient.h new file mode 100644 index 0000000..26e59a1 --- /dev/null +++ b/orkbasecxx/OrkClient.h @@ -0,0 +1,43 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __ORKCLIENT_H__ +#define __ORKCLIENT_H__ + +#include "messages/SyncMessage.h" +#include "messages/AsyncMessage.h" + +/** Abstract base class for all clients. */ +class DLL_IMPORT_EXPORT OrkClient +{ +public: + virtual bool Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout = 5) = 0; +}; + +/** Abstract base class for all clients based on http. */ +class DLL_IMPORT_EXPORT OrkHttpClient : public OrkClient +{ +public: + virtual bool Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout = 5) = 0; + bool ExecuteUrl(CStdString& request, CStdString& response, CStdString& hostname, int tcpPort, int timeout = 5); +protected: +}; + +/** Client that uses a HTTP URL request and receives the response back in the SingleLine format. */ +class DLL_IMPORT_EXPORT OrkHttpSingleLineClient : public OrkHttpClient +{ +public: + bool Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout = 5); +}; + +#endif diff --git a/orkbasecxx/StdString.h b/orkbasecxx/StdString.h new file mode 100644 index 0000000..0743e16 --- /dev/null +++ b/orkbasecxx/StdString.h @@ -0,0 +1,3747 @@ +#ifdef WIN32 +#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning +#pragma warning( disable: 4018 ) // signed/unsigned mismatch +#endif + + + +// ============================================================================= +// FILE: StdString.h +// AUTHOR: Joe O'Leary (with outside help noted in comments) +// REMARKS: +// This header file declares the CStdStr template. This template derives +// the Standard C++ Library basic_string<> template and add to it the +// the following conveniences: +// - The full MFC CString set of functions (including implicit cast) +// - writing to/reading from COM IStream interfaces +// - Functional objects for use in STL algorithms +// +// From this template, we intstantiate two classes: CStdStringA and +// CStdStringW. The name "CStdString" is just a #define of one of these, +// based upone the _UNICODE macro setting +// +// This header also declares our own version of the MFC/ATL UNICODE-MBCS +// conversion macros. Our version looks exactly like the Microsoft's to +// facilitate portability. +// +// NOTE: +// If you you use this in an MFC or ATL build, you should include either +// afx.h or atlbase.h first, as appropriate. +// +// PEOPLE WHO HAVE CONTRIBUTED TO THIS CLASS: +// +// Several people have helped me iron out problems and othewise improve +// this class. OK, this is a long list but in my own defense, this code +// has undergone two major rewrites. Many of the improvements became +// necessary after I rewrote the code as a template. Others helped me +// improve the CString facade. +// +// Anyway, these people are (in chronological order): +// +// - Pete the Plumber (???) +// - Julian Selman +// - Chris (of Melbsys) +// - Dave Plummer +// - John C Sipos +// - Chris Sells +// - Nigel Nunn +// - Fan Xia +// - Matthew Williams +// - Carl Engman +// - Mark Zeren +// - Craig Watson +// - Rich Zuris +// - Karim Ratib +// - Chris Conti +// - Baptiste Lepilleur +// - Greg Pickles +// - Jim Cline +// - Jeff Kohn +// - Todd Heckel +// - Ullrich Pollähne +// - Joe Vitaterna +// - Joe Woodbury +// - Aaron (no last name) +// - Joldakowski (???) +// - Scott Hathaway +// - Eric Nitzche +// - Pablo Presedo +// - Farrokh Nejadlotfi +// - Jason Mills +// - Igor Kholodov +// - Mike Crusader +// - John James +// - Wang Haifeng +// - Tim Dowty +// - Arnt Witteveen +// - Glen Maynard +// - Paul DeMarco +// - Bagira (full name?) +// - Ronny Schulz +// - Jakko Van Hunen +// - Charles G +// +// REVISION HISTORY +// 2003-JUL-10 - Thanks to Charles G for making me realize my 'FmtArg' fixes +// had inadvertently broken the DLL-export code (which is +// normally commented out. I had to move it up higher. Also +// this helped me catch a bug in ssicoll that would prevent +// compilation, otherwise. +// +// 2003-MAR-14 - Thanks to Jakko Van Hunen for pointing out a copy-and-paste +// bug in one of the overloads of FmtArg. +// +// 2003-MAR-10 - Thanks to Ronny Schulz for (twice!) sending me some changes +// to help CStdString build on SGI and for pointing out an +// error in placement of my preprocessor macros for ssfmtmsg. +// +// 2002-NOV-26 - Thanks to Bagira for pointing out that my implementation of +// SpanExcluding was not properly handling the case in which +// the string did NOT contain any of the given characters +// +// 2002-OCT-21 - Many thanks to Paul DeMarco who was invaluable in helping me +// get this code working with Borland's free compiler as well +// as the Dev-C++ compiler (available free at SourceForge). +// +// 2002-SEP-13 - Thanks to Glen Maynard who helped me get rid of some loud +// but harmless warnings that were showing up on g++. Glen +// also pointed out that some pre-declarations of FmtArg<> +// specializations were unnecessary (and no good on G++) +// +// 2002-JUN-26 - Thanks to Arnt Witteveen for pointing out that I was using +// static_cast<> in a place in which I should have been using +// reinterpret_cast<> (the ctor for unsigned char strings). +// That's what happens when I don't unit-test properly! +// Arnt also noticed that CString was silently correcting the +// 'nCount' argument to Left() and Right() where CStdString was +// not (and crashing if it was bad). That is also now fixed! +// +// 2002-FEB-25 - Thanks to Tim Dowty for pointing out (and giving me the fix +// for) a conversion problem with non-ASCII MBCS characters. +// CStdString is now used in my favorite commercial MP3 player! +// +// 2001-DEC-06 - Thanks to Wang Haifeng for spotting a problem in one of the +// assignment operators (for _bstr_t) that would cause compiler +// errors when refcounting protection was turned off. +// +// 2001-NOV-27 - Remove calls to operator!= which involve reverse_iterators +// due to a conflict with the rel_ops operator!=. Thanks to +// John James for pointing this out. +// +// 2001-OCT-29 - Added a minor range checking fix for the Mid function to +// make it as forgiving as CString's version is. Thanks to +// Igor Kholodov for noticing this. +// - Added a specialization of std::swap for CStdString. Thanks +// to Mike Crusader for suggesting this! It's commented out +// because you're not supposed to inject your own code into the +// 'std' namespace. But if you don't care about that, it's +// there if you want it +// - Thanks to Jason Mills for catching a case where CString was +// more forgiving in the Delete() function than I was. +// +// 2001-JUN-06 - I was violating the Standard name lookup rules stated +// in [14.6.2(3)]. None of the compilers I've tried so +// far apparently caught this but HP-UX aCC 3.30 did. The +// fix was to add 'this->' prefixes in many places. +// Thanks to Farrokh Nejadlotfi for this! +// +// 2001-APR-27 - StreamLoad was calculating the number of BYTES in one +// case, not characters. Thanks to Pablo Presedo for this. +// +// 2001-FEB-23 - Replace() had a bug which caused infinite loops if the +// source string was empty. Fixed thanks to Eric Nitzsche. +// +// 2001-FEB-23 - Scott Hathaway was a huge help in providing me with the +// ability to build CStdString on Sun Unix systems. He +// sent me detailed build reports about what works and what +// does not. If CStdString compiles on your Unix box, you +// can thank Scott for it. +// +// 2000-DEC-29 - Joldakowski noticed one overload of Insert failed to do a +// range check as CString's does. Now fixed -- thanks! +// +// 2000-NOV-07 - Aaron pointed out that I was calling static member +// functions of char_traits via a temporary. This was not +// technically wrong, but it was unnecessary and caused +// problems for poor old buggy VC5. Thanks Aaron! +// +// 2000-JUL-11 - Joe Woodbury noted that the CString::Find docs don't match +// what the CString::Find code really ends up doing. I was +// trying to match the docs. Now I match the CString code +// - Joe also caught me truncating strings for GetBuffer() calls +// when the supplied length was less than the current length. +// +// 2000-MAY-25 - Better support for STLPORT's Standard library distribution +// - Got rid of the NSP macro - it interfered with Koenig lookup +// - Thanks to Joe Woodbury for catching a TrimLeft() bug that +// I introduced in January. Empty strings were not getting +// trimmed +// +// 2000-APR-17 - Thanks to Joe Vitaterna for pointing out that ReverseFind +// is supposed to be a const function. +// +// 2000-MAR-07 - Thanks to Ullrich Pollähne for catching a range bug in one +// of the overloads of assign. +// +// 2000-FEB-01 - You can now use CStdString on the Mac with CodeWarrior! +// Thanks to Todd Heckel for helping out with this. +// +// 2000-JAN-23 - Thanks to Jim Cline for pointing out how I could make the +// Trim() function more efficient. +// - Thanks to Jeff Kohn for prompting me to find and fix a typo +// in one of the addition operators that takes _bstr_t. +// - Got rid of the .CPP file - you only need StdString.h now! +// +// 1999-DEC-22 - Thanks to Greg Pickles for helping me identify a problem +// with my implementation of CStdString::FormatV in which +// resulting string might not be properly NULL terminated. +// +// 1999-DEC-06 - Chris Conti pointed yet another basic_string<> assignment +// bug that MS has not fixed. CStdString did nothing to fix +// it either but it does now! The bug was: create a string +// longer than 31 characters, get a pointer to it (via c_str()) +// and then assign that pointer to the original string object. +// The resulting string would be empty. Not with CStdString! +// +// 1999-OCT-06 - BufferSet was erasing the string even when it was merely +// supposed to shrink it. Fixed. Thanks to Chris Conti. +// - Some of the Q172398 fixes were not checking for assignment- +// to-self. Fixed. Thanks to Baptiste Lepilleur. +// +// 1999-AUG-20 - Improved Load() function to be more efficient by using +// SizeOfResource(). Thanks to Rich Zuris for this. +// - Corrected resource ID constructor, again thanks to Rich. +// - Fixed a bug that occurred with UNICODE characters above +// the first 255 ANSI ones. Thanks to Craig Watson. +// - Added missing overloads of TrimLeft() and TrimRight(). +// Thanks to Karim Ratib for pointing them out +// +// 1999-JUL-21 - Made all calls to GetBuf() with no args check length first. +// +// 1999-JUL-10 - Improved MFC/ATL independence of conversion macros +// - Added SS_NO_REFCOUNT macro to allow you to disable any +// reference-counting your basic_string<> impl. may do. +// - Improved ReleaseBuffer() to be as forgiving as CString. +// Thanks for Fan Xia for helping me find this and to +// Matthew Williams for pointing it out directly. +// +// 1999-JUL-06 - Thanks to Nigel Nunn for catching a very sneaky bug in +// ToLower/ToUpper. They should call GetBuf() instead of +// data() in order to ensure the changed string buffer is not +// reference-counted (in those implementations that refcount). +// +// 1999-JUL-01 - Added a true CString facade. Now you can use CStdString as +// a drop-in replacement for CString. If you find this useful, +// you can thank Chris Sells for finally convincing me to give +// in and implement it. +// - Changed operators << and >> (for MFC CArchive) to serialize +// EXACTLY as CString's do. So now you can send a CString out +// to a CArchive and later read it in as a CStdString. I have +// no idea why you would want to do this but you can. +// +// 1999-JUN-21 - Changed the CStdString class into the CStdStr template. +// - Fixed FormatV() to correctly decrement the loop counter. +// This was harmless bug but a bug nevertheless. Thanks to +// Chris (of Melbsys) for pointing it out +// - Changed Format() to try a normal stack-based array before +// using to _alloca(). +// - Updated the text conversion macros to properly use code +// pages and to fit in better in MFC/ATL builds. In other +// words, I copied Microsoft's conversion stuff again. +// - Added equivalents of CString::GetBuffer, GetBufferSetLength +// - new sscpy() replacement of CStdString::CopyString() +// - a Trim() function that combines TrimRight() and TrimLeft(). +// +// 1999-MAR-13 - Corrected the "NotSpace" functional object to use _istpace() +// instead of _isspace() Thanks to Dave Plummer for this. +// +// 1999-FEB-26 - Removed errant line (left over from testing) that #defined +// _MFC_VER. Thanks to John C Sipos for noticing this. +// +// 1999-FEB-03 - Fixed a bug in a rarely-used overload of operator+() that +// caused infinite recursion and stack overflow +// - Added member functions to simplify the process of +// persisting CStdStrings to/from DCOM IStream interfaces +// - Added functional objects (e.g. StdStringLessNoCase) that +// allow CStdStrings to be used as keys STL map objects with +// case-insensitive comparison +// - Added array indexing operators (i.e. operator[]). I +// originally assumed that these were unnecessary and would be +// inherited from basic_string. However, without them, Visual +// C++ complains about ambiguous overloads when you try to use +// them. Thanks to Julian Selman to pointing this out. +// +// 1998-FEB-?? - Added overloads of assign() function to completely account +// for Q172398 bug. Thanks to "Pete the Plumber" for this +// +// 1998-FEB-?? - Initial submission +// +// COPYRIGHT: +// 2002 Joseph M. O'Leary. This code is 100% free. Use it anywhere you +// want. Rewrite it, restructure it, whatever. If you can write software +// that makes money off of it, good for you. I kinda like capitalism. +// Please don't blame me if it causes your $30 billion dollar satellite +// explode in orbit. If you redistribute it in any form, I'd appreciate it +// if you would leave this notice here. +// +// If you find any bugs, please let me know: +// +// jmoleary@earthlink.net +// http://www.joeo.net +// +// The latest version of this code should always be available at the +// following link: +// +// http://www.joeo.net/code/StdString.zip +// ============================================================================= + +// Avoid multiple inclusion the VC++ way, +// Turn off browser references +// Turn off unavoidable compiler warnings + +#if defined(_MSC_VER) && (_MSC_VER > 1100) + #pragma once + #pragma component(browser, off, references, "CStdString") + #pragma warning (disable : 4290) // C++ Exception Specification ignored + #pragma warning (disable : 4127) // Conditional expression is constant + #pragma warning (disable : 4097) // typedef name used as synonym for class name +#endif + +// Borland warnings to turn off + +#ifdef __BORLANDC__ + #pragma option push -w-inl +// #pragma warn -inl // Turn off inline function warnings +#endif + +#ifndef STDSTRING_H +#define STDSTRING_H + +// MACRO: SS_UNSIGNED +// ------------------ +// This macro causes the addition of a constructor and assignment operator +// which take unsigned characters. CString has such functions and in order +// to provide maximum CString-compatability, this code needs them as well. +// In practice you will likely never need these functions... + +//#define SS_UNSIGNED + +#ifdef SS_ALLOW_UNSIGNED_CHARS + #define SS_UNSIGNED +#endif + +// MACRO: SS_SAFE_FORMAT +// --------------------- +// This macro provides limited compatability with a questionable CString +// "feature". You can define it in order to avoid a common problem that +// people encounter when switching from CString to CStdString. +// +// To illustrate the problem -- With CString, you can do this: +// +// CString sName("Joe"); +// CString sTmp; +// sTmp.Format("My name is %s", sName); // WORKS! +// +// However if you were to try this with CStdString, your program would +// crash. +// +// CStdString sName("Joe"); +// CStdString sTmp; +// sTmp.Format("My name is %s", sName); // CRASHES! +// +// You must explicitly call c_str() or cast the object to the proper type +// +// sTmp.Format("My name is %s", sName.c_str()); // WORKS! +// sTmp.Format("My name is %s", static_cast(sName));// WORKS! +// sTmp.Format("My name is %s", (PCSTR)sName);// WORKS! +// +// This is because it is illegal to pass anything but a POD type as a +// variadic argument to a variadic function (i.e. as one of the "..." +// arguments). The type const char* is a POD type. The type CStdString +// is not. Of course, neither is the type CString, but CString lets you do +// it anyway due to the way they laid out the class in binary. I have no +// control over this in CStdString since I derive from whatever +// implementation of basic_string is available. +// +// However if you have legacy code (which does this) that you want to take +// out of the MFC world and you don't want to rewrite all your calls to +// Format(), then you can define this flag and it will no longer crash. +// +// Note however that this ONLY works for Format(), not sprintf, fprintf, +// etc. If you pass a CStdString object to one of those functions, your +// program will crash. Not much I can do to get around this, short of +// writing substitutes for those functions as well. + +#define SS_SAFE_FORMAT // use new template style Format() function + + +// MACRO: SS_NO_IMPLICIT_CAST +// -------------------------- +// Some people don't like the implicit cast to const char* (or rather to +// const CT*) that CStdString (and MFC's CString) provide. That was the +// whole reason I created this class in the first place, but hey, whatever +// bakes your cake. Just #define this macro to get rid of the the implicit +// cast. + +//#define SS_NO_IMPLICIT_CAST // gets rid of operator const CT*() + + +// MACRO: SS_NO_REFCOUNT +// --------------------- +// turns off reference counting at the assignment level. Only needed +// for the version of basic_string<> that comes with Visual C++ versions +// 6.0 or earlier, and only then in some heavily multithreaded scenarios. +// Uncomment it if you feel you need it. + +#define SS_NO_REFCOUNT + +// MACRO: SS_WIN32 +// --------------- +// When this flag is set, we are building code for the Win32 platform and +// may use Win32 specific functions (such as LoadString). This gives us +// a couple of nice extras for the code. +// +// Obviously, Microsoft's is not the only compiler available for Win32 out +// there. So I can't just check to see if _MSC_VER is defined to detect +// if I'm building on Win32. So for now, if you use MS Visual C++ or +// Borland's compiler, I turn this on. Otherwise you may turn it on +// yourself, if you prefer +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WIN32) + #define SS_WIN32 +#endif + +// MACRO: SS_ANSI +// -------------- +// When this macro is defined, the code attempts only to use ANSI/ISO +// standard library functions to do it's work. It will NOT attempt to use +// any Win32 of Visual C++ specific functions -- even if they are +// available. You may define this flag yourself to prevent any Win32 +// of VC++ specific functions from being called. + +// If we're not on Win32, we MUST use an ANSI build + +#ifndef SS_WIN32 + #if !defined(SS_NO_ANSI) + #define SS_ANSI + #endif +#endif + +// MACRO: SS_ALLOCA +// ---------------- +// Some implementations of the Standard C Library have a non-standard +// function known as alloca(). This functions allows one to allocate a +// variable amount of memory on the stack. It comes in very useful for +// the ASCII/MBCS conversion macros. +// +// Here we attempt to determine automatically if alloca() is available on +// this platform. If so we define SS_ALLOCA to be the name of the alloca +// function. If SS_ALLOCA is undefined later on, then the conversion +// macros will not be compiled. +// +// You may prevent SS_ALLOCA + + + +// Avoid legacy code screw up: if _UNICODE is defined, UNICODE must be as well + +#if defined (_UNICODE) && !defined (UNICODE) + #define UNICODE +#endif +#if defined (UNICODE) && !defined (_UNICODE) + #define _UNICODE +#endif + +// ----------------------------------------------------------------------------- +// MIN and MAX. The Standard C++ template versions go by so many names (at +// at least in the MS implementation) that you never know what's available +// ----------------------------------------------------------------------------- +template +inline const Type& SSMIN(const Type& arg1, const Type& arg2) +{ + return arg2 < arg1 ? arg2 : arg1; +} +template +inline const Type& SSMAX(const Type& arg1, const Type& arg2) +{ + return arg2 > arg1 ? arg2 : arg1; +} + +// If they have not #included W32Base.h (part of my W32 utility library) then +// we need to define some stuff. Otherwise, this is all defined there. + +#if !defined(W32BASE_H) + + // If they want us to use only standard C++ stuff (no Win32 stuff) + + #ifdef SS_ANSI + + // On Win32 we have TCHAR.H so just include it. This is NOT violating + // the spirit of SS_ANSI as we are not calling any Win32 functions here. + + #ifdef SS_WIN32 + + #include + #include + #ifndef STRICT + #define STRICT + #endif + + // ... but on non-Win32 platforms, we must #define the types we need. + + #else + + typedef const char* PCSTR; + typedef char* PSTR; + typedef const wchar_t* PCWSTR; + typedef wchar_t* PWSTR; + #ifdef UNICODE + typedef wchar_t TCHAR; + #else + typedef char TCHAR; + #endif + typedef wchar_t OLECHAR; + + #endif // #ifndef _WIN32 + + + // Make sure ASSERT and verify are defined using only ANSI stuff + + #ifndef ASSERT + #include + #define ASSERT(f) assert((f)) + #endif + #ifndef VERIFY + #ifdef _DEBUG + #define VERIFY(x) ASSERT((x)) + #else + #define VERIFY(x) x + #endif + #endif + + #else // ...else SS_ANSI is NOT defined + + #include + #include + #ifndef STRICT + #define STRICT + #endif + + // Make sure ASSERT and verify are defined + + #ifndef ASSERT + #include + #define ASSERT(f) _ASSERTE((f)) + #endif + #ifndef VERIFY + #ifdef _DEBUG + #define VERIFY(x) ASSERT((x)) + #else + #define VERIFY(x) x + #endif + #endif + + #endif // #ifdef SS_ANSI + + #ifndef UNUSED + #define UNUSED(x) x + #endif + +#endif // #ifndef W32BASE_H + +// Standard headers needed + +#include // basic_string +#include // for_each, etc. +#include // for StdStringLessNoCase, et al +#include // for various facets + +// If this is a recent enough version of VC include comdef.h, so we can write +// member functions to deal with COM types & compiler support classes e.g. _bstr_t + +#if defined (_MSC_VER) && (_MSC_VER >= 1100) + #include + #define SS_INC_COMDEF // signal that we #included MS comdef.h file + #define STDSTRING_INC_COMDEF + #define SS_NOTHROW __declspec(nothrow) +#else + #define SS_NOTHROW +#endif + +#ifndef TRACE + #define TRACE_DEFINED_HERE + #define TRACE +#endif + +// Microsoft defines PCSTR, PCWSTR, etc, but no PCTSTR. I hate to use the +// versions with the "L" in front of them because that's a leftover from Win 16 +// days, even though it evaluates to the same thing. Therefore, Define a PCSTR +// as an LPCTSTR. + +#if !defined(PCTSTR) && !defined(PCTSTR_DEFINED) + typedef const TCHAR* PCTSTR; + #define PCTSTR_DEFINED +#endif + +#if !defined(PCOLESTR) && !defined(PCOLESTR_DEFINED) + typedef const OLECHAR* PCOLESTR; + #define PCOLESTR_DEFINED +#endif + +#if !defined(POLESTR) && !defined(POLESTR_DEFINED) + typedef OLECHAR* POLESTR; + #define POLESTR_DEFINED +#endif + +#if !defined(PCUSTR) && !defined(PCUSTR_DEFINED) + typedef const unsigned char* PCUSTR; + typedef unsigned char* PUSTR; + #define PCUSTR_DEFINED +#endif + + +// SGI compiler 7.3 doesnt know these types - oh and btw, remember to use +// -LANG:std in the CXX Flags +#if defined(__sgi) + typedef unsigned long DWORD; + typedef void * LPCVOID; +#endif + + +// SS_USE_FACET macro and why we need it: +// +// Since I'm a good little Standard C++ programmer, I use locales. Thus, I +// need to make use of the use_facet<> template function here. Unfortunately, +// this need is complicated by the fact the MS' implementation of the Standard +// C++ Library has a non-standard version of use_facet that takes more +// arguments than the standard dictates. Since I'm trying to write CStdString +// to work with any version of the Standard library, this presents a problem. +// +// The upshot of this is that I can't do 'use_facet' directly. The MS' docs +// tell me that I have to use a macro, _USE() instead. Since _USE obviously +// won't be available in other implementations, this means that I have to write +// my OWN macro -- SS_USE_FACET -- that evaluates either to _USE or to the +// standard, use_facet. +// +// If you are having trouble with the SS_USE_FACET macro, in your implementation +// of the Standard C++ Library, you can define your own version of SS_USE_FACET. +#ifndef schMSG + #define schSTR(x) #x + #define schSTR2(x) schSTR(x) + #define schMSG(desc) message(__FILE__ "(" schSTR2(__LINE__) "):" #desc) +#endif + +#ifndef SS_USE_FACET + // STLPort #defines a macro (__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) for + // all MSVC builds, erroneously in my opinion. It causes problems for + // my SS_ANSI builds. In my code, I always comment out that line. You'll + // find it in \stlport\config\stl_msvc.h + #if defined(__SGI_STL_PORT) && (__SGI_STL_PORT >= 0x400 ) + #if defined(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && defined(_MSC_VER) + #ifdef SS_ANSI + #pragma schMSG(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS defined!!) + #endif + #endif + #define SS_USE_FACET(loc, fac) std::use_facet(loc) + #elif defined(_MSC_VER ) + #define SS_USE_FACET(loc, fac) std::_USE(loc, fac) + + // ...and + #elif defined(_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE) + #define SS_USE_FACET(loc, fac) std::use_facet(loc, (fac*)0) + #else + #define SS_USE_FACET(loc, fac) std::use_facet(loc) + #endif +#endif + +// ============================================================================= +// UNICODE/MBCS conversion macros. Made to work just like the MFC/ATL ones. +// ============================================================================= + +#include // Added to Std Library with Amendment #1. + +// First define the conversion helper functions. We define these regardless of +// any preprocessor macro settings since their names won't collide. + +// Not sure if we need all these headers. I believe ANSI says we do. + +#include +#include +#include +#include +#include +#ifndef va_start + #include +#endif + +// StdCodeCvt - made to look like Win32 functions WideCharToMultiByte +// and MultiByteToWideChar but uses locales in SS_ANSI +// builds + +#if defined (SS_ANSI) || !defined (SS_WIN32) + + typedef std::codecvt SSCodeCvt; + + + inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars, + const std::locale& loc=std::locale()) + { + ASSERT(0 != pA); + ASSERT(0 != pW); + pW[0] = '\0'; + PCSTR pBadA = 0; + PWSTR pBadW = 0; + SSCodeCvt::result res = SSCodeCvt::ok; + const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt); + SSCodeCvt::state_type st= { 0 }; + res = conv.in(st, + pA, pA + nChars, pBadA, + pW, pW + nChars, pBadW); + ASSERT(SSCodeCvt::ok == res); + return pW; + } + inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars, + const std::locale& loc=std::locale()) + { + return StdCodeCvt(pW, (PCSTR)pA, nChars, loc); + } + + inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars, + const std::locale& loc=std::locale()) + { + ASSERT(0 != pA); + ASSERT(0 != pW); + pA[0] = '\0'; + PSTR pBadA = 0; + PCWSTR pBadW = 0; + SSCodeCvt::result res = SSCodeCvt::ok; + const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt); + SSCodeCvt::state_type st= { 0 }; + res = conv.out(st, + pW, pW + nChars, pBadW, + pA, pA + nChars, pBadA); + ASSERT(SSCodeCvt::ok == res); + return pA; + } + inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars, + const std::locale& loc=std::locale()) + { + return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, loc); + } + +#else // ...or are we doing things assuming win32 and Visual C++? + + #include // needed for _alloca + + inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars, UINT acp=CP_ACP) + { + ASSERT(0 != pA); + ASSERT(0 != pW); + pW[0] = '\0'; + MultiByteToWideChar(acp, 0, pA, -1, pW, nChars); + return pW; + } + inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars, UINT acp=CP_ACP) + { + return StdCodeCvt(pW, (PCSTR)pA, nChars, acp); + } + + inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP) + { + ASSERT(0 != pA); + ASSERT(0 != pW); + pA[0] = '\0'; + WideCharToMultiByte(acp, 0, pW, -1, pA, nChars, 0, 0); + return pA; + } + inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP) + { + return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, acp); + } + +#endif +// Unicode/MBCS conversion macros are only available on implementations of +// the "C" library that have the non-standard _alloca function. As far as I +// know that's only Microsoft's though I've hear that the function exits +// elsewhere. + +#if defined(SS_ALLOCA) && !defined SS_NO_CONVERSION + + #include // needed for _alloca + + + // Define our conversion macros to look exactly like Microsoft's to + // facilitate using this stuff both with and without MFC/ATL + + #ifdef _CONVERSION_USES_THREAD_LOCALE + #ifndef _DEBUG + #define SSCVT int _cvt; _cvt; UINT _acp=GetACP(); \ + _acp; PCWSTR _pw; _pw; PCSTR _pa; _pa + #else + #define SSCVT int _cvt = 0; _cvt; UINT _acp=GetACP();\ + _acp; PCWSTR _pw=0; _pw; PCSTR _pa=0; _pa + #endif + #else + #ifndef _DEBUG + #define SSCVT int _cvt; _cvt; UINT _acp=CP_ACP; _acp;\ + PCWSTR _pw; _pw; PCSTR _pa; _pa + #else + #define SSCVT int _cvt = 0; _cvt; UINT _acp=CP_ACP; \ + _acp; PCWSTR _pw=0; _pw; PCSTR _pa=0; _pa + #endif + #endif + + #ifdef _CONVERSION_USES_THREAD_LOCALE + #define SSA2W(pa) (\ + ((_pa = pa) == 0) ? 0 : (\ + _cvt = (sslen(_pa)+1),\ + StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt, _acp))) + #define SSW2A(pw) (\ + ((_pw = pw) == 0) ? 0 : (\ + _cvt = (sslen(_pw)+1)*2,\ + StdW2AHelper((LPSTR) _alloca(_cvt), _pw, _cvt, _acp))) + #else + #define SSA2W(pa) (\ + ((_pa = pa) == 0) ? 0 : (\ + _cvt = (sslen(_pa)+1),\ + StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt))) + #define SSW2A(pw) (\ + ((_pw = pw) == 0) ? 0 : (\ + _cvt = (sslen(_pw)+1)*2,\ + StdCodeCvt((LPSTR) _alloca(_cvt), _pw, _cvt))) + #endif + + #define SSA2CW(pa) ((PCWSTR)SSA2W((pa))) + #define SSW2CA(pw) ((PCSTR)SSW2A((pw))) + + #ifdef UNICODE + #define SST2A SSW2A + #define SSA2T SSA2W + #define SST2CA SSW2CA + #define SSA2CT SSA2CW + inline PWSTR SST2W(PTSTR p) { return p; } + inline PTSTR SSW2T(PWSTR p) { return p; } + inline PCWSTR SST2CW(PCTSTR p) { return p; } + inline PCTSTR SSW2CT(PCWSTR p) { return p; } + #else + #define SST2W SSA2W + #define SSW2T SSW2A + #define SST2CW SSA2CW + #define SSW2CT SSW2CA + inline PSTR SST2A(PTSTR p) { return p; } + inline PTSTR SSA2T(PSTR p) { return p; } + inline PCSTR SST2CA(PCTSTR p) { return p; } + inline PCTSTR SSA2CT(PCSTR p) { return p; } + #endif // #ifdef UNICODE + + #if defined(UNICODE) + // in these cases the default (TCHAR) is the same as OLECHAR + inline PCOLESTR SST2COLE(PCTSTR p) { return p; } + inline PCTSTR SSOLE2CT(PCOLESTR p) { return p; } + inline POLESTR SST2OLE(PTSTR p) { return p; } + inline PTSTR SSOLE2T(POLESTR p) { return p; } + #elif defined(OLE2ANSI) + // in these cases the default (TCHAR) is the same as OLECHAR + inline PCOLESTR SST2COLE(PCTSTR p) { return p; } + inline PCTSTR SSOLE2CT(PCOLESTR p) { return p; } + inline POLESTR SST2OLE(PTSTR p) { return p; } + inline PTSTR SSOLE2T(POLESTR p) { return p; } + #else + //CharNextW doesn't work on Win95 so we use this + #define SST2COLE(pa) SSA2CW((pa)) + #define SST2OLE(pa) SSA2W((pa)) + #define SSOLE2CT(po) SSW2CA((po)) + #define SSOLE2T(po) SSW2A((po)) + #endif + + #ifdef OLE2ANSI + #define SSW2OLE SSW2A + #define SSOLE2W SSA2W + #define SSW2COLE SSW2CA + #define SSOLE2CW SSA2CW + inline POLESTR SSA2OLE(PSTR p) { return p; } + inline PSTR SSOLE2A(POLESTR p) { return p; } + inline PCOLESTR SSA2COLE(PCSTR p) { return p; } + inline PCSTR SSOLE2CA(PCOLESTR p){ return p; } + #else + #define SSA2OLE SSA2W + #define SSOLE2A SSW2A + #define SSA2COLE SSA2CW + #define SSOLE2CA SSW2CA + inline POLESTR SSW2OLE(PWSTR p) { return p; } + inline PWSTR SSOLE2W(POLESTR p) { return p; } + inline PCOLESTR SSW2COLE(PCWSTR p) { return p; } + inline PCWSTR SSOLE2CW(PCOLESTR p){ return p; } + #endif + + // Above we've defined macros that look like MS' but all have + // an 'SS' prefix. Now we need the real macros. We'll either + // get them from the macros above or from MFC/ATL. + + #if defined (USES_CONVERSION) + + #define _NO_STDCONVERSION // just to be consistent + + #else + + #ifdef _MFC_VER + + #include + #define _NO_STDCONVERSION // just to be consistent + + #else + + #define USES_CONVERSION SSCVT + #define A2CW SSA2CW + #define W2CA SSW2CA + #define T2A SST2A + #define A2T SSA2T + #define T2W SST2W + #define W2T SSW2T + #define T2CA SST2CA + #define A2CT SSA2CT + #define T2CW SST2CW + #define W2CT SSW2CT + #define ocslen sslen + #define ocscpy sscpy + #define T2COLE SST2COLE + #define OLE2CT SSOLE2CT + #define T2OLE SST2COLE + #define OLE2T SSOLE2CT + #define A2OLE SSA2OLE + #define OLE2A SSOLE2A + #define W2OLE SSW2OLE + #define OLE2W SSOLE2W + #define A2COLE SSA2COLE + #define OLE2CA SSOLE2CA + #define W2COLE SSW2COLE + #define OLE2CW SSOLE2CW + + #endif // #ifdef _MFC_VER + #endif // #ifndef USES_CONVERSION +#endif // #ifndef SS_NO_CONVERSION + +// Define ostring - generic name for std::basic_string + +#if !defined(ostring) && !defined(OSTRING_DEFINED) + typedef std::basic_string ostring; + #define OSTRING_DEFINED +#endif + +// StdCodeCvt when there's no conversion to be done +inline PSTR StdCodeCvt(PSTR pDst, PCSTR pSrc, int nChars) +{ + if ( nChars > 0 ) + { + pDst[0] = '\0'; + std::basic_string::traits_type::copy(pDst, pSrc, nChars); +// std::char_traits::copy(pDst, pSrc, nChars); + if ( nChars > 0 ) + pDst[nChars] = '\0'; + } + + return pDst; +} +inline PSTR StdCodeCvt(PSTR pDst, PCUSTR pSrc, int nChars) +{ + return StdCodeCvt(pDst, (PCSTR)pSrc, nChars); +} +inline PUSTR StdCodeCvt(PUSTR pDst, PCSTR pSrc, int nChars) +{ + return (PUSTR)StdCodeCvt((PSTR)pDst, pSrc, nChars); +} + +inline PWSTR StdCodeCvt(PWSTR pDst, PCWSTR pSrc, int nChars) +{ + if ( nChars > 0 ) + { + pDst[0] = '\0'; + std::basic_string::traits_type::copy(pDst, pSrc, nChars); +// std::char_traits::copy(pDst, pSrc, nChars); + if ( nChars > 0 ) + pDst[nChars] = '\0'; + } + + return pDst; +} + + +// Define tstring -- generic name for std::basic_string + +#if !defined(tstring) && !defined(TSTRING_DEFINED) + typedef std::basic_string tstring; + #define TSTRING_DEFINED +#endif + +// a very shorthand way of applying the fix for KB problem Q172398 +// (basic_string assignment bug) + +#if defined ( _MSC_VER ) && ( _MSC_VER < 1200 ) + #define Q172398(x) (x).erase() +#else + #define Q172398(x) +#endif + +// ============================================================================= +// INLINE FUNCTIONS ON WHICH CSTDSTRING RELIES +// +// Usually for generic text mapping, we rely on preprocessor macro definitions +// to map to string functions. However the CStdStr<> template cannot use +// macro-based generic text mappings because its character types do not get +// resolved until template processing which comes AFTER macro processing. In +// other words, UNICODE is of little help to us in the CStdStr template +// +// Therefore, to keep the CStdStr declaration simple, we have these inline +// functions. The template calls them often. Since they are inline (and NOT +// exported when this is built as a DLL), they will probably be resolved away +// to nothing. +// +// Without these functions, the CStdStr<> template would probably have to broken +// out into two, almost identical classes. Either that or it would be a huge, +// convoluted mess, with tons of "if" statements all over the place checking the +// size of template parameter CT. +// +// In several cases, you will see two versions of each function. One version is +// the more portable, standard way of doing things, while the other is the +// non-standard, but often significantly faster Visual C++ way. +// ============================================================================= + +// If they defined SS_NO_REFCOUNT, then we must convert all assignments + +#ifdef SS_NO_REFCOUNT + #define SSREF(x) (x).c_str() +#else + #define SSREF(x) (x) +#endif + +// ----------------------------------------------------------------------------- +// sslen: strlen/wcslen wrappers +// ----------------------------------------------------------------------------- +template inline int sslen(const CT* pT) +{ + return 0 == pT ? 0 : std::basic_string::traits_type::length(pT); +// return 0 == pT ? 0 : std::char_traits::length(pT); +} +inline SS_NOTHROW int sslen(const std::string& s) +{ + return s.length(); +} +inline SS_NOTHROW int sslen(const std::wstring& s) +{ + return s.length(); +} + +// ----------------------------------------------------------------------------- +// sstolower/sstoupper -- convert characters to upper/lower case +// ----------------------------------------------------------------------------- +template +inline CT sstolower(const CT& t, const std::locale& loc = std::locale()) +{ + return std::tolower(t, loc); +} +template +inline CT sstoupper(const CT& t, const std::locale& loc = std::locale()) +{ + return std::toupper(t, loc); +} + +// ----------------------------------------------------------------------------- +// ssasn: assignment functions -- assign "sSrc" to "sDst" +// ----------------------------------------------------------------------------- +typedef std::string::size_type SS_SIZETYPE; // just for shorthand, really +typedef std::string::pointer SS_PTRTYPE; +typedef std::wstring::size_type SW_SIZETYPE; +typedef std::wstring::pointer SW_PTRTYPE; + +inline void ssasn(std::string& sDst, const std::string& sSrc) +{ + if ( sDst.c_str() != sSrc.c_str() ) + { + sDst.erase(); + sDst.assign(SSREF(sSrc)); + } +} +inline void ssasn(std::string& sDst, PCSTR pA) +{ + // Watch out for NULLs, as always. + + if ( 0 == pA ) + { + sDst.erase(); + } + + // If pA actually points to part of sDst, we must NOT erase(), but + // rather take a substring + + else if ( pA >= sDst.c_str() && pA <= sDst.c_str() + sDst.size() ) + { + sDst =sDst.substr(static_cast(pA-sDst.c_str())); + } + + // Otherwise (most cases) apply the assignment bug fix, if applicable + // and do the assignment + + else + { + Q172398(sDst); + sDst.assign(pA); + } +} +inline void ssasn(std::string& sDst, const std::wstring& sSrc) +{ + int nLen = sSrc.size(); + sDst.resize(nLen * sizeof(wchar_t) + 1); + StdCodeCvt(const_cast(sDst.data()), sSrc.c_str(), nLen); + sDst.resize(nLen); + //sDst.resize(sslen(sDst.c_str())); +} +inline void ssasn(std::string& sDst, PCWSTR pW) +{ + int nLen = sslen(pW); + sDst.resize(nLen * sizeof(wchar_t) + 1); + StdCodeCvt(const_cast(sDst.data()), pW, nLen); + sDst.resize(nLen); + //sDst.resize(sslen(sDst.c_str())); +} +inline void ssasn(std::string& sDst, const int nNull) +{ + UNUSED(nNull); + ASSERT(nNull==0); + sDst.assign(""); +} +inline void ssasn(std::wstring& sDst, const std::wstring& sSrc) +{ + if ( sDst.c_str() != sSrc.c_str() ) + { + sDst.erase(); + sDst.assign(SSREF(sSrc)); + } +} +inline void ssasn(std::wstring& sDst, PCWSTR pW) +{ + // Watch out for NULLs, as always. + + if ( 0 == pW ) + { + sDst.erase(); + } + + // If pW actually points to part of sDst, we must NOT erase(), but + // rather take a substring + + else if ( pW >= sDst.c_str() && pW <= sDst.c_str() + sDst.size() ) + { + sDst = sDst.substr(static_cast(pW-sDst.c_str())); + } + + // Otherwise (most cases) apply the assignment bug fix, if applicable + // and do the assignment + + else + { + Q172398(sDst); + sDst.assign(pW); + } +} +#undef StrSizeType +inline void ssasn(std::wstring& sDst, const std::string& sSrc) +{ + int nLen = sSrc.size(); + sDst.resize(nLen+1); + StdCodeCvt(const_cast(sDst.data()), sSrc.c_str(), nLen+1); + sDst.resize(sslen(sDst.c_str())); +} +inline void ssasn(std::wstring& sDst, PCSTR pA) +{ + int nLen = sslen(pA); + sDst.resize(nLen+1); + StdCodeCvt(const_cast(sDst.data()), pA, nLen+1); + sDst.resize(sslen(sDst.c_str())); +} +inline void ssasn(std::wstring& sDst, const int nNull) +{ + UNUSED(nNull); + ASSERT(nNull==0); + sDst.assign(L""); +} + + +// ----------------------------------------------------------------------------- +// ssadd: string object concatenation -- add second argument to first +// ----------------------------------------------------------------------------- +inline void ssadd(std::string& sDst, const std::wstring& sSrc) +{ + int nSrcLen = sSrc.size(); + int nDstLen = sDst.size(); + int nEndLen = nSrcLen + nDstLen; + sDst.resize(nEndLen + 1); + StdCodeCvt(const_cast(sDst.data()+nDstLen), sSrc.c_str(), nSrcLen); + sDst.resize(nEndLen); +} +inline void ssadd(std::string& sDst, const std::string& sSrc) +{ + if ( &sDst == &sSrc ) + sDst.reserve(2*sDst.size()); + + sDst.append(sSrc.c_str()); +} +inline void ssadd(std::string& sDst, PCWSTR pW) +{ + int nSrcLen = sslen(pW); + int nDstLen = sDst.size(); + int nEndLen = nSrcLen + nDstLen; + sDst.resize(nEndLen + 1); + StdCodeCvt(const_cast(sDst.data()+nDstLen), pW, nSrcLen+1); + sDst.resize(nEndLen); +} +inline void ssadd(std::string& sDst, PCSTR pA) +{ + if ( pA ) + { + // If the string being added is our internal string or a part of our + // internal string, then we must NOT do any reallocation without + // first copying that string to another object (since we're using a + // direct pointer) + + if ( pA >= sDst.c_str() && pA <= sDst.c_str()+sDst.length()) + { + if ( sDst.capacity() <= sDst.size()+sslen(pA) ) + sDst.append(std::string(pA)); + else + sDst.append(pA); + } + else + { + sDst.append(pA); + } + } +} +inline void ssadd(std::wstring& sDst, const std::wstring& sSrc) +{ + if ( &sDst == &sSrc ) + sDst.reserve(2*sDst.size()); + + sDst.append(sSrc.c_str()); +} +inline void ssadd(std::wstring& sDst, const std::string& sSrc) +{ + int nSrcLen = sSrc.size(); + int nDstLen = sDst.size(); + int nEndLen = nSrcLen + nDstLen; + sDst.resize(nEndLen+1); + StdCodeCvt(const_cast(sDst.data()+nDstLen), sSrc.c_str(), nSrcLen+1); + sDst.resize(nEndLen); +} +inline void ssadd(std::wstring& sDst, PCSTR pA) +{ + int nSrcLen = sslen(pA); + int nDstLen = sDst.size(); + int nEndLen = nSrcLen + nDstLen; + sDst.resize(nEndLen + 1); + StdCodeCvt(const_cast(sDst.data()+nDstLen), pA, nSrcLen+1); + sDst.resize(nEndLen); +} +inline void ssadd(std::wstring& sDst, PCWSTR pW) +{ + if ( pW ) + { + // If the string being added is our internal string or a part of our + // internal string, then we must NOT do any reallocation without + // first copying that string to another object (since we're using a + // direct pointer) + + if ( pW >= sDst.c_str() && pW <= sDst.c_str()+sDst.length()) + { + if ( sDst.capacity() <= sDst.size()+sslen(pW) ) + sDst.append(std::wstring(pW)); + else + sDst.append(pW); + } + else + { + sDst.append(pW); + } + } +} + + +// ----------------------------------------------------------------------------- +// ssicmp: comparison (case insensitive ) +// ----------------------------------------------------------------------------- +template +inline int ssicmp(const CT* pA1, const CT* pA2) +{ + std::locale loc; + const std::ctype& ct = SS_USE_FACET(loc, std::ctype); + CT f; + CT l; + + do + { + f = ct.tolower(*(pA1++)); + l = ct.tolower(*(pA2++)); + } while ( (f) && (f == l) ); + + return (int)(f - l); +} + +// ----------------------------------------------------------------------------- +// ssupr/sslwr: Uppercase/Lowercase conversion functions +// ----------------------------------------------------------------------------- + +template +inline void sslwr(CT* pT, size_t nLen) +{ + SS_USE_FACET(std::locale(), std::ctype).tolower(pT, pT+nLen); +} +template +inline void ssupr(CT* pT, size_t nLen) +{ + SS_USE_FACET(std::locale(), std::ctype).toupper(pT, pT+nLen); +} + + +// ----------------------------------------------------------------------------- +// vsprintf/vswprintf or _vsnprintf/_vsnwprintf equivalents. In standard +// builds we can't use _vsnprintf/_vsnwsprintf because they're MS extensions. +// ----------------------------------------------------------------------------- +#if defined(SS_ANSI) || !defined(_MSC_VER) + + // Borland's headers put some ANSI "C" functions in the 'std' namespace. + // Promote them to the global namespace so we can use them here. + + #if defined(__BORLANDC__) + using std::vsprintf; + using std::vswprintf; + #endif + + inline int ssvsprintf(PSTR pA, size_t /*nCount*/, PCSTR pFmtA, va_list vl) + { + return vsprintf(pA, pFmtA, vl); + } + inline int ssvsprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl) + { + // JMO: Some distributions of the "C" have a version of vswprintf that + // takes 3 arguments (e.g. Microsoft, Borland, GNU). Others have a + // version which takes 4 arguments (an extra "count" argument in the + // second position. The best stab I can take at this so far is that if + // you are NOT running with MS, Borland, or GNU, then I'll assume you + // have the version that takes 4 arguments. + // + // I'm sure that these checks don't catch every platform correctly so if + // you get compiler errors on one of the lines immediately below, it's + // probably because your implemntation takes a different number of + // arguments. You can comment out the offending line (and use the + // alternate version) or you can figure out what compiler flag to check + // and add that preprocessor check in. Regardless, if you get an error + // on these lines, I'd sure like to hear from you about it. + // + // Thanks to Ronny Schulz for the SGI-specific checks here. + +// #if !defined(__MWERKS__) && !defined(__SUNPRO_CC_COMPAT) && !defined(__SUNPRO_CC) + #if !defined(_MSC_VER) \ + && !defined (__BORLANDC__) \ + && !defined(__sgi) + + return vswprintf(pW, nCount, pFmtW, vl); + + // suddenly with the current SGI 7.3 compiler there is no such function as + // vswprintf and the substitute needs explicit casts to compile + + #elif defined(__sgi) + + nCount; + return vsprintf( (char *)pW, (char *)pFmtW, vl); + + #else + + nCount; + return vswprintf(pW, pFmtW, vl); + + #endif + + } +#else + inline int ssnprintf(PSTR pA, size_t nCount, PCSTR pFmtA, va_list vl) + { + return _vsnprintf(pA, nCount, pFmtA, vl); + } + inline int ssnprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl) + { + return _vsnwprintf(pW, nCount, pFmtW, vl); + } +#endif + + + +// ----------------------------------------------------------------------------- +// ssload: Type safe, overloaded ::LoadString wrappers +// There is no equivalent of these in non-Win32-specific builds. However, I'm +// thinking that with the message facet, there might eventually be one +// ----------------------------------------------------------------------------- +#if defined (SS_WIN32) && !defined(SS_ANSI) + inline int ssload(HMODULE hInst, UINT uId, PSTR pBuf, int nMax) + { + return ::LoadStringA(hInst, uId, pBuf, nMax); + } + inline int ssload(HMODULE hInst, UINT uId, PWSTR pBuf, int nMax) + { + return ::LoadStringW(hInst, uId, pBuf, nMax); + } +#endif + + +// ----------------------------------------------------------------------------- +// sscoll/ssicoll: Collation wrappers +// Note -- with MSVC I have reversed the arguments order here because the +// functions appear to return the opposite of what they should +// ----------------------------------------------------------------------------- +template +inline int sscoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2) +{ + const std::collate& coll = + SS_USE_FACET(std::locale(), std::collate); + + return coll.compare(sz2, sz2+nLen2, sz1, sz1+nLen1); +} +template +inline int ssicoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2) +{ + const std::locale loc; + const std::collate& coll = SS_USE_FACET(loc, std::collate); + + // Some implementations seem to have trouble using the collate<> + // facet typedefs so we'll just default to basic_string and hope + // that's what the collate facet uses (which it generally should) + +// std::collate::string_type s1(sz1); +// std::collate::string_type s2(sz2); + const std::basic_string sEmpty; + std::basic_string s1(sz1 ? sz1 : sEmpty.c_str()); + std::basic_string s2(sz2 ? sz2 : sEmpty.c_str()); + + sslwr(const_cast(s1.c_str()), nLen1); + sslwr(const_cast(s2.c_str()), nLen2); + return coll.compare(s2.c_str(), s2.c_str()+nLen2, + s1.c_str(), s1.c_str()+nLen1); +} + + +// ----------------------------------------------------------------------------- +// ssfmtmsg: FormatMessage equivalents. Needed because I added a CString facade +// Again -- no equivalent of these on non-Win32 builds but their might one day +// be one if the message facet gets implemented +// ----------------------------------------------------------------------------- +#if defined (SS_WIN32) && !defined(SS_ANSI) + inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId, + DWORD dwLangId, PSTR pBuf, DWORD nSize, + va_list* vlArgs) + { + return FormatMessageA(dwFlags, pSrc, dwMsgId, dwLangId, + pBuf, nSize,vlArgs); + } + inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId, + DWORD dwLangId, PWSTR pBuf, DWORD nSize, + va_list* vlArgs) + { + return FormatMessageW(dwFlags, pSrc, dwMsgId, dwLangId, + pBuf, nSize,vlArgs); + } +#else +#endif + + + +// FUNCTION: sscpy. Copies up to 'nMax' characters from pSrc to pDst. +// ----------------------------------------------------------------------------- +// FUNCTION: sscpy +// inline int sscpy(PSTR pDst, PCSTR pSrc, int nMax=-1); +// inline int sscpy(PUSTR pDst, PCSTR pSrc, int nMax=-1) +// inline int sscpy(PSTR pDst, PCWSTR pSrc, int nMax=-1); +// inline int sscpy(PWSTR pDst, PCWSTR pSrc, int nMax=-1); +// inline int sscpy(PWSTR pDst, PCSTR pSrc, int nMax=-1); +// +// DESCRIPTION: +// This function is very much (but not exactly) like strcpy. These +// overloads simplify copying one C-style string into another by allowing +// the caller to specify two different types of strings if necessary. +// +// The strings must NOT overlap +// +// "Character" is expressed in terms of the destination string, not +// the source. If no 'nMax' argument is supplied, then the number of +// characters copied will be sslen(pSrc). A NULL terminator will +// also be added so pDst must actually be big enough to hold nMax+1 +// characters. The return value is the number of characters copied, +// not including the NULL terminator. +// +// PARAMETERS: +// pSrc - the string to be copied FROM. May be a char based string, an +// MBCS string (in Win32 builds) or a wide string (wchar_t). +// pSrc - the string to be copied TO. Also may be either MBCS or wide +// nMax - the maximum number of characters to be copied into szDest. Note +// that this is expressed in whatever a "character" means to pDst. +// If pDst is a wchar_t type string than this will be the maximum +// number of wchar_ts that my be copied. The pDst string must be +// large enough to hold least nMaxChars+1 characters. +// If the caller supplies no argument for nMax this is a signal to +// the routine to copy all the characters in pSrc, regardless of +// how long it is. +// +// RETURN VALUE: none +// ----------------------------------------------------------------------------- +template +inline int sscpycvt(CT1* pDst, const CT2* pSrc, int nChars) +{ + StdCodeCvt(pDst, pSrc, nChars); + pDst[SSMAX(nChars, 0)] = '\0'; + return nChars; +} + +template +inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax, int nLen) +{ + return sscpycvt(pDst, pSrc, SSMIN(nMax, nLen)); +} +template +inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax) +{ + return sscpycvt(pDst, pSrc, SSMIN(nMax, sslen(pSrc))); +} +template +inline int sscpy(CT1* pDst, const CT2* pSrc) +{ + return sscpycvt(pDst, pSrc, sslen(pSrc)); +} +template +inline int sscpy(CT1* pDst, const std::basic_string& sSrc, int nMax) +{ + return sscpycvt(pDst, sSrc.c_str(), SSMIN(nMax, (int)sSrc.length())); +} +template +inline int sscpy(CT1* pDst, const std::basic_string& sSrc) +{ + return sscpycvt(pDst, sSrc.c_str(), (int)sSrc.length()); +} + +#ifdef SS_INC_COMDEF + template + inline int sscpy(CT1* pDst, const _bstr_t& bs, int nMax) + { + return sscpycvt(pDst, static_cast(bs), + SSMIN(nMax, static_cast(bs.length()))); + } + template + inline int sscpy(CT1* pDst, const _bstr_t& bs) + { + return sscpy(pDst, bs, static_cast(bs.length())); + } +#endif + + +// ----------------------------------------------------------------------------- +// Functional objects for changing case. They also let you pass locales +// ----------------------------------------------------------------------------- + +#ifdef SS_ANSI + template + struct SSToUpper : public std::binary_function + { + inline CT operator()(const CT& t, const std::locale& loc) const + { + return sstoupper(t, loc); + } + }; + template + struct SSToLower : public std::binary_function + { + inline CT operator()(const CT& t, const std::locale& loc) const + { + return sstolower(t, loc); + } + }; +#endif + +// This struct is used for TrimRight() and TrimLeft() function implementations. +//template +//struct NotSpace : public std::unary_function +//{ +// const std::locale& loc; +// inline NotSpace(const std::locale& locArg) : loc(locArg) {} +// inline bool operator() (CT t) { return !std::isspace(t, loc); } +//}; +template +struct NotSpace : public std::unary_function +{ + + // DINKUMWARE BUG: + // Note -- using std::isspace in a COM DLL gives us access violations + // because it causes the dynamic addition of a function to be called + // when the library shuts down. Unfortunately the list is maintained + // in DLL memory but the function is in static memory. So the COM DLL + // goes away along with the function that was supposed to be called, + // and then later when the DLL CRT shuts down it unloads the list and + // tries to call the long-gone function. + // This is DinkumWare's implementation problem. Until then, we will + // use good old isspace and iswspace from the CRT unless they + // specify SS_ANSI + + const std::locale loc; + NotSpace(const std::locale& locArg=std::locale()) : loc(locArg) {} + bool operator() (CT t) const { return !std::isspace(t, loc); } +}; + + + + +// Now we can define the template (finally!) +// ============================================================================= +// TEMPLATE: CStdStr +// template class CStdStr : public std::basic_string +// +// REMARKS: +// This template derives from basic_string and adds some MFC CString- +// like functionality +// +// Basically, this is my attempt to make Standard C++ library strings as +// easy to use as the MFC CString class. +// +// Note that although this is a template, it makes the assumption that the +// template argument (CT, the character type) is either char or wchar_t. +// ============================================================================= + +//#define CStdStr _SS // avoid compiler warning 4786 + +// template ARG& FmtArg(ARG& arg) { return arg; } +// PCSTR FmtArg(const std::string& arg) { return arg.c_str(); } +// PCWSTR FmtArg(const std::wstring& arg) { return arg.c_str(); } + +template +struct FmtArg +{ + explicit FmtArg(const ARG& arg) : a_(arg) {} + const ARG& Val() const { return a_; } + const ARG& a_; +private: + FmtArg& operator=(const FmtArg&) { return *this; } +}; + +template +class CStdStr : public std::basic_string +{ + // Typedefs for shorter names. Using these names also appears to help + // us avoid some ambiguities that otherwise arise on some platforms + + typedef typename std::basic_string MYBASE; // my base class + typedef CStdStr MYTYPE; // myself + typedef typename MYBASE::const_pointer PCMYSTR; // PCSTR or PCWSTR + typedef typename MYBASE::pointer PMYSTR; // PSTR or PWSTR + typedef typename MYBASE::iterator MYITER; // my iterator type + typedef typename MYBASE::const_iterator MYCITER; // you get the idea... + typedef typename MYBASE::reverse_iterator MYRITER; + typedef typename MYBASE::size_type MYSIZE; + typedef typename MYBASE::value_type MYVAL; + typedef typename MYBASE::allocator_type MYALLOC; + +public: + + // shorthand conversion from PCTSTR to string resource ID + #define _TRES(pctstr) (LOWORD((DWORD)(pctstr))) + + // CStdStr inline constructors + CStdStr() + { + } + + CStdStr(const MYTYPE& str) : MYBASE(SSREF(str)) + { + } + + CStdStr(const std::string& str) + { + ssasn(*this, SSREF(str)); + } + + CStdStr(const std::wstring& str) + { + ssasn(*this, SSREF(str)); + } + + CStdStr(PCMYSTR pT, MYSIZE n) : MYBASE(pT, n) + { + } + +#ifdef SS_UNSIGNED + CStdStr(PCUSTR pU) + { + *this = reinterpret_cast(pU); + } +#endif + + CStdStr(PCSTR pA) + { + #ifdef SS_ANSI + *this = pA; + #else + if ( 0 != HIWORD(pA) ) + *this = pA; + else if ( 0 != pA && !Load(_TRES(pA)) ) + TRACE(_T("Can't load string %u\n"), _TRES(pA)); + #endif + } + + CStdStr(PCWSTR pW) + { + #ifdef SS_ANSI + *this = pW; + #else + if ( 0 != HIWORD(pW) ) + *this = pW; + else if ( 0 != pW && !Load(_TRES(pW)) ) + TRACE(_T("Can't load string %u\n"), _TRES(pW)); + #endif + } + + CStdStr(MYCITER first, MYCITER last) + : MYBASE(first, last) + { + } + + CStdStr(MYSIZE nSize, MYVAL ch, const MYALLOC& al=MYALLOC()) + : MYBASE(nSize, ch, al) + { + } + + #ifdef SS_INC_COMDEF + CStdStr(const _bstr_t& bstr) + { + if ( bstr.length() > 0 ) + this->append(static_cast(bstr), bstr.length()); + } + #endif + + // CStdStr inline assignment operators -- the ssasn function now takes care + // of fixing the MSVC assignment bug (see knowledge base article Q172398). + MYTYPE& operator=(const MYTYPE& str) + { + ssasn(*this, str); + return *this; + } + + MYTYPE& operator=(const std::string& str) + { + ssasn(*this, str); + return *this; + } + + MYTYPE& operator=(const std::wstring& str) + { + ssasn(*this, str); + return *this; + } + + MYTYPE& operator=(PCSTR pA) + { + ssasn(*this, pA); + return *this; + } + + MYTYPE& operator=(PCWSTR pW) + { + ssasn(*this, pW); + return *this; + } + +#ifdef SS_UNSIGNED + MYTYPE& operator=(PCUSTR pU) + { + ssasn(*this, reinterpret_cast(pU)): + return *this; + } +#endif + + MYTYPE& operator=(CT t) + { + Q172398(*this); + this->assign(1, t); + return *this; + } + + #ifdef SS_INC_COMDEF + MYTYPE& operator=(const _bstr_t& bstr) + { + if ( bstr.length() > 0 ) + { + this->assign(static_cast(bstr), bstr.length()); + return *this; + } + else + { + this->erase(); + return *this; + } + } + #endif + + + // Overloads also needed to fix the MSVC assignment bug (KB: Q172398) + // *** Thanks to Pete The Plumber for catching this one *** + // They also are compiled if you have explicitly turned off refcounting + #if ( defined(_MSC_VER) && ( _MSC_VER < 1200 ) ) || defined(SS_NO_REFCOUNT) + + MYTYPE& assign(const MYTYPE& str) + { + ssasn(*this, str); + return *this; + } + + MYTYPE& assign(const MYTYPE& str, MYSIZE nStart, MYSIZE nChars) + { + // This overload of basic_string::assign is supposed to assign up to + // or the NULL terminator, whichever comes first. Since we + // are about to call a less forgiving overload (in which + // must be a valid length), we must adjust the length here to a safe + // value. Thanks to Ullrich Pollähne for catching this bug + + nChars = SSMIN(nChars, str.length() - nStart); + + // Watch out for assignment to self + + if ( this == &str ) + { + MYTYPE strTemp(str.c_str()+nStart, nChars); + MYBASE::assign(strTemp); + } + else + { + Q172398(*this); + MYBASE::assign(str.c_str()+nStart, nChars); + } + return *this; + } + + MYTYPE& assign(const MYBASE& str) + { + ssasn(*this, str); + return *this; + } + + MYTYPE& assign(const MYBASE& str, MYSIZE nStart, MYSIZE nChars) + { + // This overload of basic_string::assign is supposed to assign up to + // or the NULL terminator, whichever comes first. Since we + // are about to call a less forgiving overload (in which + // must be a valid length), we must adjust the length here to a safe + // value. Thanks to Ullrich Pollähne for catching this bug + + nChars = SSMIN(nChars, str.length() - nStart); + + // Watch out for assignment to self + + if ( this == &str ) // watch out for assignment to self + { + MYTYPE strTemp(str.c_str() + nStart, nChars); + MYBASE::assign(strTemp); + } + else + { + Q172398(*this); + MYBASE::assign(str.c_str()+nStart, nChars); + } + return *this; + } + + MYTYPE& assign(const CT* pC, MYSIZE nChars) + { + // Q172398 only fix -- erase before assigning, but not if we're + // assigning from our own buffer + + #if defined ( _MSC_VER ) && ( _MSC_VER < 1200 ) + if ( !this->empty() && + ( pC < this->data() || pC > this->data() + this->capacity() ) ) + { + this->erase(); + } + #endif + Q172398(*this); + MYBASE::assign(pC, nChars); + return *this; + } + + MYTYPE& assign(MYSIZE nChars, MYVAL val) + { + Q172398(*this); + MYBASE::assign(nChars, val); + return *this; + } + + MYTYPE& assign(const CT* pT) + { + return this->assign(pT, MYBASE::traits_type::length(pT)); + } + + MYTYPE& assign(MYCITER iterFirst, MYCITER iterLast) + { + #if defined ( _MSC_VER ) && ( _MSC_VER < 1200 ) + // Q172398 fix. don't call erase() if we're assigning from ourself + if ( iterFirst < this->begin() || + iterFirst > this->begin() + this->size() ) + { + this->erase() + } + #endif + this->replace(this->begin(), this->end(), iterFirst, iterLast); + return *this; + } + #endif + + + // ------------------------------------------------------------------------- + // CStdStr inline concatenation. + // ------------------------------------------------------------------------- + MYTYPE& operator+=(const MYTYPE& str) + { + ssadd(*this, str); + return *this; + } + + MYTYPE& operator+=(const std::string& str) + { + ssadd(*this, str); + return *this; + } + + MYTYPE& operator+=(const std::wstring& str) + { + ssadd(*this, str); + return *this; + } + + MYTYPE& operator+=(PCSTR pA) + { + ssadd(*this, pA); + return *this; + } + + MYTYPE& operator+=(PCWSTR pW) + { + ssadd(*this, pW); + return *this; + } + + MYTYPE& operator+=(CT t) + { + this->append(1, t); + return *this; + } + #ifdef SS_INC_COMDEF // if we have _bstr_t, define a += for it too. + MYTYPE& operator+=(const _bstr_t& bstr) + { + return this->operator+=(static_cast(bstr)); + } + #endif + + + // ------------------------------------------------------------------------- + // Case changing functions + // ------------------------------------------------------------------------- + + MYTYPE& ToUpper() + { + // Strictly speaking, this would be about the most portable way + + // std::transform(begin(), + // end(), + // begin(), + // std::bind2nd(SSToUpper(), std::locale())); + + // But practically speaking, this works faster + + if ( !empty() ) + ssupr(GetBuf(), this->size()); + + return *this; + } + + + + MYTYPE& ToLower() + { + // Strictly speaking, this would be about the most portable way + + // std::transform(begin(), + // end(), + // begin(), + // std::bind2nd(SSToLower(), std::locale())); + + // But practically speaking, this works faster + + if ( !empty() ) + sslwr(GetBuf(), this->size()); + + return *this; + } + + + + MYTYPE& Normalize() + { + return Trim().ToLower(); + } + + + // ------------------------------------------------------------------------- + // CStdStr -- Direct access to character buffer. In the MS' implementation, + // the at() function that we use here also calls _Freeze() providing us some + // protection from multithreading problems associated with ref-counting. + // In VC 7 and later, of course, the ref-counting stuff is gone. + // ------------------------------------------------------------------------- + + CT* GetBuf(int nMinLen=-1) + { + if ( static_cast(size()) < nMinLen ) + this->resize(static_cast(nMinLen)); + + return this->empty() ? const_cast(this->data()) : &(this->at(0)); + } + + CT* SetBuf(int nLen) + { + nLen = ( nLen > 0 ? nLen : 0 ); + if ( this->capacity() < 1 && nLen == 0 ) + this->resize(1); + + this->resize(static_cast(nLen)); + return const_cast(this->data()); + } + void RelBuf(int nNewLen=-1) + { + this->resize(static_cast(nNewLen > -1 ? nNewLen : + sslen(this->c_str()))); + } + + void BufferRel() { RelBuf(); } // backwards compatability + CT* Buffer() { return GetBuf(); } // backwards compatability + CT* BufferSet(int nLen) { return SetBuf(nLen);}// backwards compatability + + bool Equals(const CT* pT, bool bUseCase=false) const + { // get copy, THEN compare (thread safe) + return bUseCase ? this->compare(pT) == 0 : + ssicmp(MYTYPE(*this).c_str(), pT) == 0; + } + + // ------------------------------------------------------------------------- + // FUNCTION: CStdStr::Load + // REMARKS: + // Loads string from resource specified by nID + // + // PARAMETERS: + // nID - resource Identifier. Purely a Win32 thing in this case + // + // RETURN VALUE: + // true if successful, false otherwise + // ------------------------------------------------------------------------- + +#ifndef SS_ANSI + + bool Load(UINT nId, HMODULE hModule=NULL) + { + bool bLoaded = false; // set to true of we succeed. + + #ifdef _MFC_VER // When in Rome (or MFC land)... + + CString strRes; + bLoaded = FALSE != strRes.LoadString(nId); + if ( bLoaded ) + *this = strRes; + + #else // otherwise make our own hackneyed version of CString's Load + + // Get the resource name and module handle + + if ( NULL == hModule ) + hModule = GetResourceHandle(); + + PCTSTR szName = MAKEINTRESOURCE((nId>>4)+1); // lifted + DWORD dwSize = 0; + + // No sense continuing if we can't find the resource + + HRSRC hrsrc = ::FindResource(hModule, szName, RT_STRING); + + if ( NULL == hrsrc ) + { + TRACE(_T("Cannot find resource %d: 0x%X"), nId, ::GetLastError()); + } + else if ( 0 == (dwSize = ::SizeofResource(hModule, hrsrc) / sizeof(CT))) + { + TRACE(_T("Cant get size of resource %d 0x%X\n"),nId,GetLastError()); + } + else + { + bLoaded = 0 != ssload(hModule, nId, GetBuf(dwSize), dwSize); + ReleaseBuffer(); + } + + #endif // #ifdef _MFC_VER + + if ( !bLoaded ) + TRACE(_T("String not loaded 0x%X\n"), ::GetLastError()); + + return bLoaded; + } + +#endif // #ifdef SS_ANSI + + // ------------------------------------------------------------------------- + // FUNCTION: CStdStr::Format + // void _cdecl Formst(CStdStringA& PCSTR szFormat, ...) + // void _cdecl Format(PCSTR szFormat); + // + // DESCRIPTION: + // This function does sprintf/wsprintf style formatting on CStdStringA + // objects. It looks a lot like MFC's CString::Format. Some people + // might even call this identical. Fortunately, these people are now + // dead... heh heh. + // + // PARAMETERS: + // nId - ID of string resource holding the format string + // szFormat - a PCSTR holding the format specifiers + // argList - a va_list holding the arguments for the format specifiers. + // + // RETURN VALUE: None. + // ------------------------------------------------------------------------- + // formatting (using wsprintf style formatting) + + // If they want a Format() function that safely handles string objects + // without casting + +#ifdef SS_SAFE_FORMAT + + // Question: Joe, you wacky coder you, why do you have so many overloads + // of the Format() function + // Answer: One reason only - CString compatability. In short, by making + // the Format() function a template this way, I can do strong typing + // and allow people to pass CStdString arguments as fillers for + // "%s" format specifiers without crashing their program! The downside + // is that I need to overload on the number of arguments. If you are + // passing more arguments than I have listed below in any of my + // overloads, just add another one. + // + // Yes, yes, this is really ugly. In essence what I am doing here is + // protecting people from a bad (and incorrect) programming practice + // that they should not be doing anyway. I am protecting them from + // themselves. Why am I doing this? Well, if you had any idea the + // number of times I've been emailed by people about this + // "incompatability" in my code, you wouldn't ask. + + void Fmt(const CT* szFmt, ...) + { + va_list argList; + va_start(argList, szFmt); + FormatV(szFmt, argList); + va_end(argList); + } + +#ifndef SS_ANSI + + void Format(UINT nId) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + this->swap(strFmt); + } + template + void Format(UINT nId, const A1& v) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + Fmt(strFmt, FmtArg(v).Val()); + } + template + void Format(UINT nId, const A1& v1, const A2& v2) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val()); + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(),FmtArg(v5).Val(), + FmtArg(v6).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(),FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(),FmtArg(v10).Val(),FmtArg(v11).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(), FmtArg(v13).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(), FmtArg(v13).Val(),FmtArg(v14).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14, const A15& v15) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(),FmtArg(v13).Val(),FmtArg(v14).Val(), + FmtArg(v15).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14, const A15& v15, + const A16& v16) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(),FmtArg(v13).Val(),FmtArg(v14).Val(), + FmtArg(v15).Val(), FmtArg(v16).Val()); + } + } + template + void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14, const A15& v15, + const A16& v16, const A17& v17) + { + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + { + Fmt(strFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(),FmtArg(v13).Val(),FmtArg(v14).Val(), + FmtArg(v15).Val(),FmtArg(v16).Val(),FmtArg(v17).Val()); + } + } + +#endif // #ifndef SS_ANSI + + // ...now the other overload of Format: the one that takes a string literal + + void Format(const CT* szFmt) + { + *this = szFmt; + } + template + void Format(const CT* szFmt, A1 v) + { + Fmt(szFmt, FmtArg(v).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(),FmtArg(v10).Val(),FmtArg(v11).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(), FmtArg(v13).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(), FmtArg(v13).Val(),FmtArg(v14).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14, const A15& v15) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(),FmtArg(v13).Val(),FmtArg(v14).Val(), + FmtArg(v15).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14, const A15& v15, + const A16& v16) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(),FmtArg(v13).Val(),FmtArg(v14).Val(), + FmtArg(v15).Val(), FmtArg(v16).Val()); + } + template + void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3, + const A4& v4, const A5& v5, const A6& v6, const A7& v7, + const A8& v8, const A9& v9, const A10& v10, const A11& v11, + const A12& v12, const A13& v13, const A14& v14, const A15& v15, + const A16& v16, const A17& v17) + { + Fmt(szFmt, FmtArg(v1).Val(), FmtArg(v2).Val(), + FmtArg(v3).Val(), FmtArg(v4).Val(), FmtArg(v5).Val(), + FmtArg(v6).Val(), FmtArg(v7).Val(), FmtArg(v8).Val(), + FmtArg(v9).Val(), FmtArg(v10).Val(),FmtArg(v11).Val(), + FmtArg(v12).Val(),FmtArg(v13).Val(),FmtArg(v14).Val(), + FmtArg(v15).Val(),FmtArg(v16).Val(),FmtArg(v17).Val()); + } + +#else // #ifdef SS_SAFE_FORMAT + + +#ifndef SS_ANSI + + void Format(UINT nId, ...) + { + va_list argList; + va_start(argList, nId); + va_start(argList, nId); + + MYTYPE strFmt; + if ( strFmt.Load(nId) ) + FormatV(strFmt, argList); + + va_end(argList); + } + +#endif // #ifdef SS_ANSI + + void Format(const CT* szFmt, ...) + { + va_list argList; + va_start(argList, szFmt); + FormatV(szFmt, argList); + va_end(argList); + } + +#endif // #ifdef SS_SAFE_FORMAT + + void AppendFormat(const CT* szFmt, ...) + { + va_list argList; + va_start(argList, szFmt); + AppendFormatV(szFmt, argList); + va_end(argList); + } + + #define MAX_FMT_TRIES 5 // #of times we try + #define FMT_BLOCK_SIZE 2048 // # of bytes to increment per try + #define BUFSIZE_1ST 256 + #define BUFSIZE_2ND 512 + #define STD_BUF_SIZE 1024 + + // an efficient way to add formatted characters to the string. You may only + // add up to STD_BUF_SIZE characters at a time, though + void AppendFormatV(const CT* szFmt, va_list argList) + { + CT szBuf[STD_BUF_SIZE]; + #ifdef SS_ANSI + int nLen = ssvsprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList); + #else + int nLen = ssnprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList); + #endif + if ( 0 < nLen ) + this->append(szBuf, nLen); + } + + // ------------------------------------------------------------------------- + // FUNCTION: FormatV + // void FormatV(PCSTR szFormat, va_list, argList); + // + // DESCRIPTION: + // This function formats the string with sprintf style format-specs. + // It makes a general guess at required buffer size and then tries + // successively larger buffers until it finds one big enough or a + // threshold (MAX_FMT_TRIES) is exceeded. + // + // PARAMETERS: + // szFormat - a PCSTR holding the format of the output + // argList - a Microsoft specific va_list for variable argument lists + // + // RETURN VALUE: + // ------------------------------------------------------------------------- + + void FormatV(const CT* szFormat, va_list argList) + { + #ifdef SS_ANSI + + int nLen = sslen(szFormat) + STD_BUF_SIZE; + ssvsprintf(GetBuffer(nLen), nLen-1, szFormat, argList); + ReleaseBuffer(); + + #else + + CT* pBuf = NULL; + int nChars = 1; + int nUsed = 0; + size_type nActual = 0; + int nTry = 0; + + do + { + // Grow more than linearly (e.g. 512, 1536, 3072, etc) + + nChars += ((nTry+1) * FMT_BLOCK_SIZE); + pBuf = reinterpret_cast(_alloca(sizeof(CT)*nChars)); + nUsed = ssnprintf(pBuf, nChars-1, szFormat, argList); + + // Ensure proper NULL termination. + + nActual = nUsed == -1 ? nChars-1 : SSMIN(nUsed, nChars-1); + pBuf[nActual+1]= '\0'; + + + } while ( nUsed < 0 && nTry++ < MAX_FMT_TRIES ); + + // assign whatever we managed to format + + this->assign(pBuf, nActual); + + #endif + } + + + // ------------------------------------------------------------------------- + // CString Facade Functions: + // + // The following methods are intended to allow you to use this class as a + // drop-in replacement for CString. + // ------------------------------------------------------------------------- + #ifdef SS_WIN32 + BSTR AllocSysString() const + { + ostring os; + ssasn(os, *this); + return ::SysAllocString(os.c_str()); + } + #endif + + int Collate(PCMYSTR szThat) const + { + return sscoll(this->c_str(), this->length(), szThat, sslen(szThat)); + } + + int CollateNoCase(PCMYSTR szThat) const + { + return ssicoll(this->c_str(), this->length(), szThat, sslen(szThat)); + } + + int Compare(PCMYSTR szThat) const + { + return this->compare(szThat); + } + + int CompareNoCase(PCMYSTR szThat) const + { + return ssicmp(this->c_str(), szThat); + } + + int Delete(int nIdx, int nCount=1) + { + if ( nIdx < 0 ) + nIdx = 0; + + if ( nIdx < GetLength() ) + this->erase(static_cast(nIdx), static_cast(nCount)); + + return GetLength(); + } + + void Empty() + { + this->erase(); + } + + int Find(CT ch) const + { + MYSIZE nIdx = this->find_first_of(ch); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + + int Find(PCMYSTR szSub) const + { + MYSIZE nIdx = this->find(szSub); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + + int Find(CT ch, int nStart) const + { + // CString::Find docs say add 1 to nStart when it's not zero + // CString::Find code doesn't do that however. We'll stick + // with what the code does + + MYSIZE nIdx = this->find_first_of(ch, static_cast(nStart)); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + + int Find(PCMYSTR szSub, int nStart) const + { + // CString::Find docs say add 1 to nStart when it's not zero + // CString::Find code doesn't do that however. We'll stick + // with what the code does + + MYSIZE nIdx = this->find(szSub, static_cast(nStart)); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + + int FindOneOf(PCMYSTR szCharSet) const + { + MYSIZE nIdx = this->find_first_of(szCharSet); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + +#ifndef SS_ANSI + void FormatMessage(PCMYSTR szFormat, ...) throw(std::exception) + { + va_list argList; + va_start(argList, szFormat); + PMYSTR szTemp; + if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER, + szFormat, 0, 0, + reinterpret_cast(&szTemp), 0, &argList) == 0 || + szTemp == 0 ) + { + throw std::runtime_error("out of memory"); + } + *this = szTemp; + LocalFree(szTemp); + va_end(argList); + } + + void FormatMessage(UINT nFormatId, ...) throw(std::exception) + { + MYTYPE sFormat; + VERIFY(sFormat.LoadString(nFormatId) != 0); + va_list argList; + va_start(argList, nFormatId); + PMYSTR szTemp; + if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER, + sFormat, 0, 0, + reinterpret_cast(&szTemp), 0, &argList) == 0 || + szTemp == 0) + { + throw std::runtime_error("out of memory"); + } + *this = szTemp; + LocalFree(szTemp); + va_end(argList); + } +#endif + + + // ------------------------------------------------------------------------- + // GetXXXX -- Direct access to character buffer + // ------------------------------------------------------------------------- + CT GetAt(int nIdx) const + { + return this->at(static_cast(nIdx)); + } + + CT* GetBuffer(int nMinLen=-1) + { + return GetBuf(nMinLen); + } + + CT* GetBufferSetLength(int nLen) + { + return BufferSet(nLen); + } + + // GetLength() -- MFC docs say this is the # of BYTES but + // in truth it is the number of CHARACTERs (chars or wchar_ts) + int GetLength() const + { + return static_cast(this->length()); + } + + + int Insert(int nIdx, CT ch) + { + if ( static_cast(nIdx) > this->size() -1 ) + this->append(1, ch); + else + this->insert(static_cast(nIdx), 1, ch); + + return GetLength(); + } + int Insert(int nIdx, PCMYSTR sz) + { + if ( nIdx >= this->size() ) + this->append(sz, sslen(sz)); + else + this->insert(static_cast(nIdx), sz); + + return GetLength(); + } + + bool IsEmpty() const + { + return this->empty(); + } + + MYTYPE Left(int nCount) const + { + // Range check the count. + + nCount = SSMAX(0, SSMIN(nCount, static_cast(this->size()))); + return this->substr(0, static_cast(nCount)); + } + +#ifndef SS_ANSI + bool LoadString(UINT nId) + { + return this->Load(nId); + } +#endif + + void MakeLower() + { + ToLower(); + } + + void MakeReverse() + { + std::reverse(this->begin(), this->end()); + } + + void MakeUpper() + { + ToUpper(); + } + + MYTYPE Mid(int nFirst ) const + { + return Mid(nFirst, size()-nFirst); + } + + MYTYPE Mid(int nFirst, int nCount) const + { + // CString does range checking here. Since we're trying to emulate it, + // we must check too. + + if ( nFirst < 0 ) + nFirst = 0; + if ( nCount < 0 ) + nCount = 0; + + if ( nFirst + nCount > size() ) + nCount = size() - nFirst; + + if ( nFirst > size() ) + return MYTYPE(); + + ASSERT(nFirst >= 0); + ASSERT(nFirst + nCount <= size()); + + return this->substr(static_cast(nFirst), + static_cast(nCount)); + } + + void ReleaseBuffer(int nNewLen=-1) + { + RelBuf(nNewLen); + } + + int Remove(CT ch) + { + MYSIZE nIdx = 0; + int nRemoved = 0; + while ( (nIdx=this->find_first_of(ch)) != MYBASE::npos ) + { + this->erase(nIdx, 1); + nRemoved++; + } + return nRemoved; + } + + int Replace(CT chOld, CT chNew) + { + int nReplaced = 0; + for ( MYITER iter=this->begin(); iter != this->end(); iter++ ) + { + if ( *iter == chOld ) + { + *iter = chNew; + nReplaced++; + } + } + return nReplaced; + } + + int Replace(PCMYSTR szOld, PCMYSTR szNew) + { + int nReplaced = 0; + MYSIZE nIdx = 0; + MYSIZE nOldLen = sslen(szOld); + if ( 0 == nOldLen ) + return 0; + + static const CT ch = CT(0); + MYSIZE nNewLen = sslen(szNew); + PCMYSTR szRealNew = szNew == 0 ? &ch : szNew; + + while ( (nIdx=this->find(szOld, nIdx)) != MYBASE::npos ) + { + replace(this->begin()+nIdx, this->begin()+nIdx+nOldLen, szRealNew); + nReplaced++; + nIdx += nNewLen; + } + return nReplaced; + } + + int ReverseFind(CT ch) const + { + MYSIZE nIdx = this->find_last_of(ch); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + + // ReverseFind overload that's not in CString but might be useful + int ReverseFind(PCMYSTR szFind, MYSIZE pos=MYBASE::npos) const + { + MYSIZE nIdx = this->rfind(0 == szFind ? MYTYPE() : szFind, pos); + return static_cast(MYBASE::npos == nIdx ? -1 : nIdx); + } + + MYTYPE Right(int nCount) const + { + // Range check the count. + + nCount = SSMAX(0, SSMIN(nCount, static_cast(this->size()))); + return this->substr(this->size()-static_cast(nCount)); + } + + void SetAt(int nIndex, CT ch) + { + ASSERT(this->size() > static_cast(nIndex)); + this->at(static_cast(nIndex)) = ch; + } + +#ifndef SS_ANSI + BSTR SetSysString(BSTR* pbstr) const + { + ostring os; + ssasn(os, *this); + if ( !::SysReAllocStringLen(pbstr, os.c_str(), os.length()) ) + throw std::runtime_error("out of memory"); + + ASSERT(*pbstr != 0); + return *pbstr; + } +#endif + + MYTYPE SpanExcluding(PCMYSTR szCharSet) const + { + MYSIZE pos = this->find_first_of(szCharSet); + return pos == MYBASE::npos ? *this : Left(pos); + } + + MYTYPE SpanIncluding(PCMYSTR szCharSet) const + { + MYSIZE pos = this->find_first_not_of(szCharSet); + return pos == MYBASE::npos ? *this : Left(pos); + } + +#if !defined(UNICODE) && !defined(SS_ANSI) + + // CString's OemToAnsi and AnsiToOem functions are available only in + // Unicode builds. However since we're a template we also need a + // runtime check of CT and a reinterpret_cast to account for the fact + // that CStdStringW gets instantiated even in non-Unicode builds. + + void AnsiToOem() + { + if ( sizeof(CT) == sizeof(char) && !empty() ) + { + ::CharToOem(reinterpret_cast(this->c_str()), + reinterpret_cast(GetBuf())); + } + else + { + ASSERT(false); + } + } + + void OemToAnsi() + { + if ( sizeof(CT) == sizeof(char) && !empty() ) + { + ::OemToChar(reinterpret_cast(this->c_str()), + reinterpret_cast(GetBuf())); + } + else + { + ASSERT(false); + } + } + +#endif + + + // ------------------------------------------------------------------------- + // Trim and its variants + // ------------------------------------------------------------------------- + MYTYPE& Trim() + { + return TrimLeft().TrimRight(); + } + + MYTYPE& TrimLeft() + { + this->erase(this->begin(), + std::find_if(this->begin(), this->end(), NotSpace())); + + return *this; + } + + MYTYPE& TrimLeft(CT tTrim) + { + this->erase(0, this->find_first_not_of(tTrim)); + return *this; + } + + MYTYPE& TrimLeft(PCMYSTR szTrimChars) + { + this->erase(0, this->find_first_not_of(szTrimChars)); + return *this; + } + + MYTYPE& TrimRight() + { + // NOTE: When comparing reverse_iterators here (MYRITER), I avoid using + // operator!=. This is because namespace rel_ops also has a template + // operator!= which conflicts with the global operator!= already defined + // for reverse_iterator in the header . + // Thanks to John James for alerting me to this. + + MYRITER it = std::find_if(this->rbegin(), this->rend(), NotSpace()); + if ( !(this->rend() == it) ) + this->erase(this->rend() - it); + + this->erase(!(it == this->rend()) ? this->find_last_of(*it) + 1 : 0); + return *this; + } + + MYTYPE& TrimRight(CT tTrim) + { + MYSIZE nIdx = this->find_last_not_of(tTrim); + this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx); + return *this; + } + + MYTYPE& TrimRight(PCMYSTR szTrimChars) + { + MYSIZE nIdx = this->find_last_not_of(szTrimChars); + this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx); + return *this; + } + + void FreeExtra() + { + MYTYPE mt; + this->swap(mt); + if ( !mt.empty() ) + this->assign(mt.c_str(), mt.size()); + } + + // I have intentionally not implemented the following CString + // functions. You cannot make them work without taking advantage + // of implementation specific behavior. However if you absolutely + // MUST have them, uncomment out these lines for "sort-of-like" + // their behavior. You're on your own. + +// CT* LockBuffer() { return GetBuf(); }// won't really lock +// void UnlockBuffer(); { } // why have UnlockBuffer w/o LockBuffer? + + // Array-indexing operators. Required because we defined an implicit cast + // to operator const CT* (Thanks to Julian Selman for pointing this out) + CT& operator[](int nIdx) + { + return MYBASE::operator[](static_cast(nIdx)); + } + + const CT& operator[](int nIdx) const + { + return MYBASE::operator[](static_cast(nIdx)); + } + + CT& operator[](unsigned int nIdx) + { + return MYBASE::operator[](static_cast(nIdx)); + } + + const CT& operator[](unsigned int nIdx) const + { + return MYBASE::operator[](static_cast(nIdx)); + } + +#ifndef SS_NO_IMPLICIT_CAST + operator const CT*() const + { + return this->c_str(); + } +#endif + + // IStream related functions. Useful in IPersistStream implementations + +#ifdef SS_INC_COMDEF + + // struct SSSHDR - useful for non Std C++ persistence schemes. + typedef struct SSSHDR + { + BYTE byCtrl; + ULONG nChars; + } SSSHDR; // as in "Standard String Stream Header" + + #define SSSO_UNICODE 0x01 // the string is a wide string + #define SSSO_COMPRESS 0x02 // the string is compressed + + // ------------------------------------------------------------------------- + // FUNCTION: StreamSize + // REMARKS: + // Returns how many bytes it will take to StreamSave() this CStdString + // object to an IStream. + // ------------------------------------------------------------------------- + ULONG StreamSize() const + { + // Control header plus string + ASSERT(this->size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR)); + return (this->size() * sizeof(CT)) + sizeof(SSSHDR); + } + + // ------------------------------------------------------------------------- + // FUNCTION: StreamSave + // REMARKS: + // Saves this CStdString object to a COM IStream. + // ------------------------------------------------------------------------- + HRESULT StreamSave(IStream* pStream) const + { + ASSERT(size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR)); + HRESULT hr = E_FAIL; + ASSERT(pStream != 0); + SSSHDR hdr; + hdr.byCtrl = sizeof(CT) == 2 ? SSSO_UNICODE : 0; + hdr.nChars = this->size(); + + + if ( FAILED(hr=pStream->Write(&hdr, sizeof(SSSHDR), 0)) ) + TRACE(_T("StreamSave: Cannot write control header, ERR=0x%X\n"),hr); + else if ( empty() ) + ; // nothing to write + else if ( FAILED(hr=pStream->Write(this->c_str(), this->size()*sizeof(CT), 0)) ) + TRACE(_T("StreamSave: Cannot write string to stream 0x%X\n"), hr); + + return hr; + } + + + // ------------------------------------------------------------------------- + // FUNCTION: StreamLoad + // REMARKS: + // This method loads the object from an IStream. + // ------------------------------------------------------------------------- + HRESULT StreamLoad(IStream* pStream) + { + ASSERT(pStream != 0); + SSSHDR hdr; + HRESULT hr = E_FAIL; + + if ( FAILED(hr=pStream->Read(&hdr, sizeof(SSSHDR), 0)) ) + { + TRACE(_T("StreamLoad: Cant read control header, ERR=0x%X\n"), hr); + } + else if ( hdr.nChars > 0 ) + { + ULONG nRead = 0; + PMYSTR pMyBuf = BufferSet(hdr.nChars); + + // If our character size matches the character size of the string + // we're trying to read, then we can read it directly into our + // buffer. Otherwise, we have to read into an intermediate buffer + // and convert. + + if ( (hdr.byCtrl & SSSO_UNICODE) != 0 ) + { + ULONG nBytes = hdr.nChars * sizeof(wchar_t); + if ( sizeof(CT) == sizeof(wchar_t) ) + { + if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) ) + TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr); + } + else + { + PWSTR pBufW = reinterpret_cast(_alloca((nBytes)+1)); + if ( FAILED(hr=pStream->Read(pBufW, nBytes, &nRead)) ) + TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr); + else + sscpy(pMyBuf, pBufW, hdr.nChars); + } + } + else + { + ULONG nBytes = hdr.nChars * sizeof(char); + if ( sizeof(CT) == sizeof(char) ) + { + if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) ) + TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr); + } + else + { + PSTR pBufA = reinterpret_cast(_alloca(nBytes)); + if ( FAILED(hr=pStream->Read(pBufA, hdr.nChars, &nRead)) ) + TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr); + else + sscpy(pMyBuf, pBufA, hdr.nChars); + } + } + } + else + { + this->erase(); + } + return hr; + } +#endif // #ifdef SS_INC_COMDEF + +#ifndef SS_ANSI + + // SetResourceHandle/GetResourceHandle. In MFC builds, these map directly + // to AfxSetResourceHandle and AfxGetResourceHandle. In non-MFC builds they + // point to a single static HINST so that those who call the member + // functions that take resource IDs can provide an alternate HINST of a DLL + // to search. This is not exactly the list of HMODULES that MFC provides + // but it's better than nothing. + +#ifdef _MFC_VER + static void SetResourceHandle(HMODULE hNew) + { + AfxSetResourceHandle(hNew); + } + static HMODULE GetResourceHandle() + { + return AfxGetResourceHandle(); + } +#else + static void SetResourceHandle(HMODULE hNew) + { + SSResourceHandle() = hNew; + } + static HMODULE GetResourceHandle() + { + return SSResourceHandle(); + } +#endif + + + template + MYTYPE operator+(const CStdStr& s2) + { + MYTYPE strRet(SSREF(*this)); + strRet += s2.c_str(); + return strRet; + } + + +#endif +}; + + + +// ----------------------------------------------------------------------------- +// CStdStr friend addition functions defined as inline +// ----------------------------------------------------------------------------- +template +inline +CStdStr operator+(const CStdStr& str1, const CStdStr& str2) +{ + CStdStr strRet(SSREF(str1)); + strRet.append(str2); + return strRet; +} + +template +inline +CStdStr operator+(const CStdStr& str, CT t) +{ + // this particular overload is needed for disabling reference counting + // though it's only an issue from line 1 to line 2 + + CStdStr strRet(SSREF(str)); // 1 + strRet.append(1, t); // 2 + return strRet; +} + +template +inline +CStdStr operator+(const CStdStr& str, PCSTR pA) +{ + return CStdStr(str) + CStdStr(pA); +} + +template +inline +CStdStr operator+(PCSTR pA, const CStdStr& str) +{ + CStdStr strRet(pA); + strRet.append(str); + return strRet; +} + +template +inline +CStdStr operator+(const CStdStr& str, PCWSTR pW) +{ + return CStdStr(SSREF(str)) + CStdStr(pW); +} + +template +inline +CStdStr operator+(PCWSTR pW, const CStdStr& str) +{ + CStdStr strRet(pW); + strRet.append(str); + return strRet; +} + +#ifdef SS_INC_COMDEF + template + inline + CStdStr operator+(const _bstr_t& bstr, const CStdStr& str) + { + return static_cast(bstr) + str; + } + + template + inline + CStdStr operator+(const CStdStr& str, const _bstr_t& bstr) + { + return str + static_cast(bstr); + } +#endif + +// ----------------------------------------------------------------------------- +// HOW TO EXPORT CSTDSTRING FROM A DLL +// +// If you want to export CStdStringA and CStdStringW from a DLL, then all you +// need to +// 1. make sure that all components link to the same DLL version +// of the CRT (not the static one). +// 2. Uncomment the 3 lines of code below +// 3. #define 2 macros per the instructions in MS KnowledgeBase +// article Q168958. The macros are: +// +// MACRO DEFINTION WHEN EXPORTING DEFINITION WHEN IMPORTING +// ----- ------------------------ ------------------------- +// SSDLLEXP (nothing, just #define it) extern +// SSDLLSPEC __declspec(dllexport) __declspec(dllimport) +// +// Note that these macros must be available to ALL clients who want to +// link to the DLL and use the class. If they +// ----------------------------------------------------------------------------- +//#pragma warning(disable:4231) // non-standard extension ("extern template") +// SSDLLEXP template class SSDLLSPEC CStdStr; +// SSDLLEXP template class SSDLLSPEC CStdStr; + +// ============================================================================= +// END OF CStdStr INLINE FUNCTION DEFINITIONS +// ============================================================================= + +// Now typedef our class names based upon this humongous template + +typedef CStdStr CStdStringA; // a better std::string +typedef CStdStr CStdStringW; // a better std::wstring +typedef CStdStr CStdStringO; // almost always CStdStringW + + +// New-style format function is a template + +#ifdef SS_SAFE_FORMAT + +template<> +struct FmtArg +{ + explicit FmtArg(const CStdStringA& arg) : a_(arg) {} + PCSTR Val() const { return a_.c_str(); } + const CStdStringA& a_; +private: + FmtArg& operator=(const FmtArg&) { return *this; } +}; +template<> +struct FmtArg +{ + explicit FmtArg(const CStdStringW& arg) : a_(arg) {} + PCWSTR Val() const { return a_.c_str(); } + const CStdStringW& a_; +private: + FmtArg& operator=(const FmtArg&) { return *this; } +}; + +template<> +struct FmtArg +{ + explicit FmtArg(const std::string& arg) : a_(arg) {} + PCSTR Val() const { return a_.c_str(); } + const std::string& a_; +private: + FmtArg& operator=(const FmtArg&) { return *this; } +}; +template<> +struct FmtArg +{ + explicit FmtArg(const std::wstring& arg) : a_(arg) {} + PCWSTR Val() const { return a_.c_str(); } + const std::wstring& a_; +private: + FmtArg& operator=(const FmtArg&) {return *this;} +}; +#endif // #ifdef SS_SAFEFORMAT + +#ifndef SS_ANSI + // SSResourceHandle: our MFC-like resource handle + inline HMODULE& SSResourceHandle() + { + static HMODULE hModuleSS = GetModuleHandle(0); + return hModuleSS; + } +#endif + + + + +// In MFC builds, define some global serialization operators +// Special operators that allow us to serialize CStdStrings to CArchives. +// Note that we use an intermediate CString object in order to ensure that +// we use the exact same format. + +#ifdef _MFC_VER + inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringA& strA) + { + CString strTemp = strA; + return ar << strTemp; + } + inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringW& strW) + { + CString strTemp = strW; + return ar << strTemp; + } + + inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringA& strA) + { + CString strTemp; + ar >> strTemp; + strA = strTemp; + return ar; + } + inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringW& strW) + { + CString strTemp; + ar >> strTemp; + strW = strTemp; + return ar; + } +#endif // #ifdef _MFC_VER -- (i.e. is this MFC?) + + + +// ----------------------------------------------------------------------------- +// GLOBAL FUNCTION: WUFormat +// CStdStringA WUFormat(UINT nId, ...); +// CStdStringA WUFormat(PCSTR szFormat, ...); +// +// REMARKS: +// This function allows the caller for format and return a CStdStringA +// object with a single line of code. +// ----------------------------------------------------------------------------- +#ifdef SS_ANSI +#else + inline CStdStringA WUFormatA(UINT nId, ...) + { + va_list argList; + va_start(argList, nId); + + CStdStringA strFmt; + CStdStringA strOut; + if ( strFmt.Load(nId) ) + strOut.FormatV(strFmt, argList); + + va_end(argList); + return strOut; + } + inline CStdStringA WUFormatA(PCSTR szFormat, ...) + { + va_list argList; + va_start(argList, szFormat); + CStdStringA strOut; + strOut.FormatV(szFormat, argList); + va_end(argList); + return strOut; + } + + inline CStdStringW WUFormatW(UINT nId, ...) + { + va_list argList; + va_start(argList, nId); + + CStdStringW strFmt; + CStdStringW strOut; + if ( strFmt.Load(nId) ) + strOut.FormatV(strFmt, argList); + + va_end(argList); + return strOut; + } + inline CStdStringW WUFormatW(PCWSTR szwFormat, ...) + { + va_list argList; + va_start(argList, szwFormat); + CStdStringW strOut; + strOut.FormatV(szwFormat, argList); + va_end(argList); + return strOut; + } +#endif // #ifdef SS_ANSI + +#ifdef SS_WIN32 + // ------------------------------------------------------------------------- + // FUNCTION: WUSysMessage + // CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID); + // CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID); + // + // DESCRIPTION: + // This function simplifies the process of obtaining a string equivalent + // of a system error code returned from GetLastError(). You simply + // supply the value returned by GetLastError() to this function and the + // corresponding system string is returned in the form of a CStdStringA. + // + // PARAMETERS: + // dwError - a DWORD value representing the error code to be translated + // dwLangId - the language id to use. defaults to english. + // + // RETURN VALUE: + // a CStdStringA equivalent of the error code. Currently, this function + // only returns either English of the system default language strings. + // ------------------------------------------------------------------------- + #define SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT) + inline CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID) + { + CHAR szBuf[512]; + + if ( 0 != ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, + dwLangId, szBuf, 511, NULL) ) + return WUFormatA("%s (0x%X)", szBuf, dwError); + else + return WUFormatA("Unknown error (0x%X)", dwError); + } + inline CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID) + { + WCHAR szBuf[512]; + + if ( 0 != ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, + dwLangId, szBuf, 511, NULL) ) + return WUFormatW(L"%s (0x%X)", szBuf, dwError); + else + return WUFormatW(L"Unknown error (0x%X)", dwError); + } +#endif + +// Define TCHAR based friendly names for some of these functions + +#ifdef UNICODE + #define CStdString CStdStringW + #define WUSysMessage WUSysMessageW + #define WUFormat WUFormatW +#else + #define CStdString CStdStringA + #define WUSysMessage WUSysMessageA + #define WUFormat WUFormatA +#endif + +// ...and some shorter names for the space-efficient + +#define WUSysMsg WUSysMessage +#define WUSysMsgA WUSysMessageA +#define WUSysMsgW WUSysMessageW +#define WUFmtA WUFormatA +#define WUFmtW WUFormatW +#define WUFmt WUFormat +#define WULastErrMsg() WUSysMessage(::GetLastError()) +#define WULastErrMsgA() WUSysMessageA(::GetLastError()) +#define WULastErrMsgW() WUSysMessageW(::GetLastError()) + + +// ----------------------------------------------------------------------------- +// FUNCTIONAL COMPARATORS: +// REMARKS: +// These structs are derived from the std::binary_function template. They +// give us functional classes (which may be used in Standard C++ Library +// collections and algorithms) that perform case-insensitive comparisons of +// CStdString objects. This is useful for maps in which the key may be the +// proper string but in the wrong case. +// ----------------------------------------------------------------------------- +#define StdStringLessNoCaseW SSLNCW // avoid VC compiler warning 4786 +#define StdStringEqualsNoCaseW SSENCW +#define StdStringLessNoCaseA SSLNCA +#define StdStringEqualsNoCaseA SSENCA + +#ifdef UNICODE + #define StdStringLessNoCase SSLNCW + #define StdStringEqualsNoCase SSENCW +#else + #define StdStringLessNoCase SSLNCA + #define StdStringEqualsNoCase SSENCA +#endif + +struct StdStringLessNoCaseW + : std::binary_function +{ + inline + bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const + { return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; } +}; +struct StdStringEqualsNoCaseW + : std::binary_function +{ + inline + bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const + { return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; } +}; +struct StdStringLessNoCaseA + : std::binary_function +{ + inline + bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const + { return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; } +}; +struct StdStringEqualsNoCaseA + : std::binary_function +{ + inline + bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const + { return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; } +}; + +// If we had to define our own version of TRACE above, get rid of it now + +#ifdef TRACE_DEFINED_HERE + #undef TRACE + #undef TRACE_DEFINED_HERE +#endif + + +// These std::swap specializations come courtesy of Mike Crusader. + +//namespace std +//{ +// inline void swap(CStdStringA& s1, CStdStringA& s2) throw() +// { +// s1.swap(s2); +// } +// template<> +// inline void swap(CStdStringW& s1, CStdStringW& s2) throw() +// { +// s1.swap(s2); +// } +//} + +// Turn back on any Borland warnings we turned off. + +#ifdef __BORLANDC__ + #pragma option pop // Turn back on inline function warnings +// #pragma warn +inl // Turn back on inline function warnings +#endif + +#endif // #ifndef STDSTRING_H + diff --git a/orkbasecxx/Utils.h b/orkbasecxx/Utils.h new file mode 100644 index 0000000..8d41a10 --- /dev/null +++ b/orkbasecxx/Utils.h @@ -0,0 +1,93 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __UTILS_H__ +#define __UTILS_H__ + +#include "ace/Guard_T.h" // For some reason, this include must always come before the StdString include + // otherwise it gives the following compile error: + // error C2039: 'TryEnterCriticalSection' : is not a member of '`global namespace'' + // If seeing this error somewhere, the remedy is to #include "Utils.h" first +#include "ace/Thread_Mutex.h" +#include "StdString.h" + +#include "OrkBase.h" + +inline CStdString IntToString(int integer) +{ + CStdString ret; + ret.Format("%d", integer); + return ret; +} + +inline int StringToInt(CStdString& value) +{ + char* errorLocation = NULL; + PCSTR szValue = (PCSTR)value; + int intValue = strtol(szValue, &errorLocation, 10); + if(*errorLocation != '\0') + throw CStdString(CStdString("StringToInt: invalid integer:") + value); + return intValue; +} + +inline CStdString DoubleToString(double value) +{ + CStdString ret; + ret.Format("%f", value); + return ret; +} + +inline double StringToDouble(CStdString& value) +{ + char* errorLocation = NULL; + PCSTR szValue = (PCSTR)value; + double doubleValue = strtod(szValue, &errorLocation); + if(errorLocation == szValue) + throw CStdString(CStdString("StringToDouble: invalid double:") + value); + return doubleValue; +} + +inline CStdString BaseName(CStdString& path) +{ + CStdString result; + int lastSeparatorPosition = path.ReverseFind('/'); + if(lastSeparatorPosition == -1) + { + lastSeparatorPosition = path.ReverseFind('\\'); + } + if(lastSeparatorPosition != -1 && path.GetLength()>3) + { + result = path.Right(path.GetLength() - lastSeparatorPosition - 1); + } + return result; +} + +inline CStdString StripFileExtension(CStdString& filename) +{ + CStdString result; + int extensionPosition = filename.ReverseFind('.'); + if (extensionPosition != -1) + { + result = filename.Left(extensionPosition); + } + else + { + result = filename; + } + return result; +} + +typedef ACE_Guard MutexSentinel; + +#endif + diff --git a/orkbasecxx/config.guess b/orkbasecxx/config.guess new file mode 100644 index 0000000..182e141 --- /dev/null +++ b/orkbasecxx/config.guess @@ -0,0 +1 @@ +link /usr/share/libtool/config.guess \ No newline at end of file diff --git a/orkbasecxx/config.sub b/orkbasecxx/config.sub new file mode 100644 index 0000000..ea4beb2 --- /dev/null +++ b/orkbasecxx/config.sub @@ -0,0 +1 @@ +link /usr/share/libtool/config.sub \ No newline at end of file diff --git a/orkbasecxx/configure.in b/orkbasecxx/configure.in new file mode 100644 index 0000000..fae8c6e --- /dev/null +++ b/orkbasecxx/configure.in @@ -0,0 +1,10 @@ +AC_INIT(configure.in) + +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(orkbase, 0.1) + +AC_LANG_CPLUSPLUS +AC_PROG_CXX +AM_PROG_LIBTOOL + +AC_OUTPUT(Makefile messages/Makefile serializers/Makefile) diff --git a/orkbasecxx/install-sh b/orkbasecxx/install-sh new file mode 100644 index 0000000..36f96f3 --- /dev/null +++ b/orkbasecxx/install-sh @@ -0,0 +1,276 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd=$cpprog + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "$0: no input file specified" >&2 + exit 1 +else + : +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d "$dst" ]; then + instcmd=: + chmodcmd="" + else + instcmd=$mkdirprog + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f "$src" ] || [ -d "$src" ] + then + : + else + echo "$0: $src does not exist" >&2 + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "$0: no destination specified" >&2 + exit 1 + else + : + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d "$dst" ] + then + dst=$dst/`basename "$src"` + else + : + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' + ' +IFS="${IFS-$defaultIFS}" + +oIFS=$IFS +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS=$oIFS + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp=$pathcomp$1 + shift + + if [ ! -d "$pathcomp" ] ; + then + $mkdirprog "$pathcomp" + else + : + fi + + pathcomp=$pathcomp/ +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd "$dst" && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename "$dst"` + else + dstfile=`basename "$dst" $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename "$dst"` + else + : + fi + +# Make a couple of temp file names in the proper directory. + + dsttmp=$dstdir/#inst.$$# + rmtmp=$dstdir/#rm.$$# + +# Trap to clean up temp files at exit. + + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap '(exit $?); exit' 1 2 13 15 + +# Move or copy the file name to the temp name + + $doit $instcmd "$src" "$dsttmp" && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && + +# Now remove or move aside any old file at destination location. We try this +# two ways since rm can't unlink itself on some systems and the destination +# file might be busy for other reasons. In this case, the final cleanup +# might fail but the new file should still install successfully. + +{ + if [ -f "$dstdir/$dstfile" ] + then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || + $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || + { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi +} && + +# Now rename the file to the real destination. + + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + +fi && + +# The final little trick to "correctly" pass the exit status to the exit trap. + +{ + (exit 0); exit +} diff --git a/orkbasecxx/ltmain.sh b/orkbasecxx/ltmain.sh new file mode 100644 index 0000000..7404ae3 --- /dev/null +++ b/orkbasecxx/ltmain.sh @@ -0,0 +1 @@ +link /usr/share/libtool/ltmain.sh \ No newline at end of file diff --git a/orkbasecxx/messages/AsyncMessage.cpp b/orkbasecxx/messages/AsyncMessage.cpp new file mode 100644 index 0000000..e32cb50 --- /dev/null +++ b/orkbasecxx/messages/AsyncMessage.cpp @@ -0,0 +1,46 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "AsyncMessage.h" + +//void AsyncMessage::send(XmlRpc::XmlRpcClient& c) +//{ +// ; +//} + +#define SIMPLERESPONSE_CLASS "simpleresponse" +#define SUCCESS_PARAM "sucess" +#define SUCCESS_DEFAULT true +#define COMMENT_PARAM "comment" + +SimpleResponseMsg::SimpleResponseMsg() +{ + m_success = false; +} + + +void SimpleResponseMsg::Define(Serializer* s) +{ + s->BoolValue(SUCCESS_PARAM, m_success); + s->StringValue(COMMENT_PARAM, m_comment); +} + +CStdString SimpleResponseMsg::GetClassName() +{ + return CStdString(SIMPLERESPONSE_CLASS); +} + +ObjectRef SimpleResponseMsg::NewInstance() +{ + return ObjectRef(new SimpleResponseMsg); +} diff --git a/orkbasecxx/messages/AsyncMessage.h b/orkbasecxx/messages/AsyncMessage.h new file mode 100644 index 0000000..bbdb313 --- /dev/null +++ b/orkbasecxx/messages/AsyncMessage.h @@ -0,0 +1,48 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __ASYNCMESSAGE_H__ +#define __ASYNCMESSAGE_H__ + +//#include "XmlRpc.h" +#include "Message.h" + +/** An AsyncMessage is an asynchronous message ("fire and forget"). + It can also be the response to a synchronous message. +*/ +class DLL_IMPORT_EXPORT AsyncMessage : public Message +{ +//public: +// void send(XmlRpc::XmlRpcClient& c); +}; + +/** A SimpleResponseMsg is used as a response when commands can just succeed or fail. + Additionally, there is textual comment field e.g. for error messages. +*/ +class DLL_IMPORT_EXPORT SimpleResponseMsg : public AsyncMessage +{ +public: + SimpleResponseMsg(); + void Define(Serializer* s); + inline void Validate() {}; + + CStdString GetClassName(); + ObjectRef NewInstance(); + inline ObjectRef Process() {return ObjectRef();}; + + bool m_success; + CStdString m_comment; +}; + +#endif + diff --git a/orkbasecxx/messages/Makefile.am b/orkbasecxx/messages/Makefile.am new file mode 100644 index 0000000..0465da7 --- /dev/null +++ b/orkbasecxx/messages/Makefile.am @@ -0,0 +1,8 @@ +METASOURCES = AUTO +noinst_LTLIBRARIES = libmessages.la +libmessages_la_SOURCES = AsyncMessage.cpp AsyncMessage.h Message.cpp Message.h\ + SyncMessage.cpp SyncMessage.h + +#libmessages_la_LIBADD = -L/projects/ext/xmlrpc++/xmlrpc++0.7/ -lXmlRpc +INCLUDES = -I@top_srcdir@ +AM_CXXFLAGS = -D_REENTRANT diff --git a/orkbasecxx/messages/Message.cpp b/orkbasecxx/messages/Message.cpp new file mode 100644 index 0000000..ad6e533 --- /dev/null +++ b/orkbasecxx/messages/Message.cpp @@ -0,0 +1,41 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning + +#include "serializers/XmlRpcSerializer.h" +#include "Message.h" + + +char Message::m_hostname[HOSTNAME_BUF_LEN] = ""; + +Message::Message() +{ + m_creationTime = time(NULL); + ACE_OS::hostname(m_hostname, HOSTNAME_BUF_LEN); +} + + +bool Message::InvokeXmlRpc(CStdString& hostname, int tcpPort) +{ +/* + XmlRpcSerializer serializer(this); + return serializer.Invoke(hostname, tcpPort); + //serializerRef.reset(new XmlRpcSerializer(this)); + //serializerRef->Invoke(hostname, tcpPort); +*/ + return true; +} + diff --git a/orkbasecxx/messages/Message.h b/orkbasecxx/messages/Message.h new file mode 100644 index 0000000..1ecceb6 --- /dev/null +++ b/orkbasecxx/messages/Message.h @@ -0,0 +1,55 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __MESSAGE_H__ +#define __MESSAGE_H__ + +//#ifdef WIN32 +#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning +#pragma warning( disable: 4018 ) // signed/unsigned mismatch +//#endif + +#include "OrkBase.h" +#include "ace/OS_NS_time.h" +#include "ace/OS_NS_unistd.h" + +#include "serializers/Serializer.h" +#include "Object.h" + +#define HOSTNAME_BUF_LEN 40 + +#define TIMESTAMP_PARAM "timestamp" +#define CAPTURE_PORT_PARAM "captureport" +#define FILENAME_PARAM "filename" + +#define SUCCESS_PARAM "sucess" +#define SUCCESS_DEFAULT true + +/** A Message is an Object that is meant to be sent to a remote server. +*/ +class DLL_IMPORT_EXPORT Message : public Object +{ +public: + Message(); + + bool InvokeXmlRpc(CStdString& hostname, int tcpport); +protected: + time_t m_creationTime; + bool m_sent; + static char m_hostname[HOSTNAME_BUF_LEN]; +}; + +typedef boost::shared_ptr MessageRef; + +#endif + diff --git a/orkbasecxx/messages/SyncMessage.cpp b/orkbasecxx/messages/SyncMessage.cpp new file mode 100644 index 0000000..b49fd64 --- /dev/null +++ b/orkbasecxx/messages/SyncMessage.cpp @@ -0,0 +1,14 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "SyncMessage.h" diff --git a/orkbasecxx/messages/SyncMessage.h b/orkbasecxx/messages/SyncMessage.h new file mode 100644 index 0000000..598ffe3 --- /dev/null +++ b/orkbasecxx/messages/SyncMessage.h @@ -0,0 +1,31 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#pragma warning( disable: 4786 ) + +#ifndef __SYNCMESSAGE_H__ +#define __SYNCMESSAGE_H__ + + +#include "Message.h" + +/** A SyncMessage is a synchronous message that needs an immediate answer from the remote server. + The response should be an AsyncMessage +*/ +class DLL_IMPORT_EXPORT SyncMessage : public Message +{ +public: +}; + +#endif + diff --git a/orkbasecxx/missing b/orkbasecxx/missing new file mode 100644 index 0000000..6a37006 --- /dev/null +++ b/orkbasecxx/missing @@ -0,0 +1,336 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. +# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# 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, 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing 0.4 - GNU automake" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. + You can get \`$1Help2man' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequirements for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 diff --git a/orkbasecxx/mkinstalldirs b/orkbasecxx/mkinstalldirs new file mode 100644 index 0000000..d2d5f21 --- /dev/null +++ b/orkbasecxx/mkinstalldirs @@ -0,0 +1,111 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman +# Created: 1993-05-16 +# Public domain + +errstatus=0 +dirmode="" + +usage="\ +Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." + +# process command line arguments +while test $# -gt 0 ; do + case $1 in + -h | --help | --h*) # -h for help + echo "$usage" 1>&2 + exit 0 + ;; + -m) # -m PERM arg + shift + test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } + dirmode=$1 + shift + ;; + --) # stop option processing + shift + break + ;; + -*) # unknown option + echo "$usage" 1>&2 + exit 1 + ;; + *) # first non-opt arg + break + ;; + esac +done + +for file +do + if test -d "$file"; then + shift + else + break + fi +done + +case $# in + 0) exit 0 ;; +esac + +case $dirmode in + '') + if mkdir -p -- . 2>/dev/null; then + echo "mkdir -p -- $*" + exec mkdir -p -- "$@" + fi + ;; + *) + if mkdir -m "$dirmode" -p -- . 2>/dev/null; then + echo "mkdir -m $dirmode -p -- $*" + exec mkdir -m "$dirmode" -p -- "$@" + fi + ;; +esac + +for file +do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d + do + pathcomp="$pathcomp$d" + case $pathcomp in + -*) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + else + if test ! -z "$dirmode"; then + echo "chmod $dirmode $pathcomp" + lasterr="" + chmod "$dirmode" "$pathcomp" || lasterr=$? + + if test ! -z "$lasterr"; then + errstatus=$lasterr + fi + fi + fi + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# End: +# mkinstalldirs ends here diff --git a/orkbasecxx/serializers/DomSerializer.cpp b/orkbasecxx/serializers/DomSerializer.cpp new file mode 100644 index 0000000..348819e --- /dev/null +++ b/orkbasecxx/serializers/DomSerializer.cpp @@ -0,0 +1,157 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "xercesc/util/XMLString.hpp" +#include +#include +#include +#include +#include +#include +#include + +#include "DomSerializer.h" + +void DomSerializer::ObjectValue(const char* key, Object& value, bool required) +{ + if (m_deSerialize == true) + { + GetObject(key, value, required); + } + else + { + AddObject(key, value); + } +} + +void DomSerializer::GetString(const char* key, CStdString& value, bool required) +{ + // Find the right node + DOMNode* stringNode = FindElementByName(m_node, CStdString(key)); + + if(stringNode) + { + // Now, the string associated to element should be the first child (text element) + DOMNode* textNode = stringNode->getFirstChild(); + if (textNode && textNode->getNodeType() == DOMNode::TEXT_NODE) + { + value = XMLStringToLocal(textNode->getNodeValue()); + } + } + else if (required) + { + throw(CStdString("DomSerializer::GetString: required parameter missing:") + key); + } +} + +void DomSerializer::GetObject(const char* key, Object& value, bool required) +{ + // Find the node corresponding to the object wanting to be populated + DOMNode* objectNode = FindElementByName(m_node, CStdString(key)); + + // Create a new serializer and affect it to this object + if (objectNode) + { + DomSerializer serializer(&value); + serializer.DeSerialize(objectNode); + } + else if (required) + { + throw(CStdString("DomSerializer::GetObject: required node missing:") + key); + } +} + +void DomSerializer::AddObject(const char* key, Object& value) +{ + ; +} + +void DomSerializer::AddString(const char* key, CStdString& value) +{ + DOMElement* newElem = m_document->createElement(XStr(key).unicodeForm()); + m_node->appendChild(newElem); + + DOMText* newText = m_document->createTextNode(XStr((PCSTR)value).unicodeForm()); + newElem->appendChild(newText); +} + +void DomSerializer::Serialize(XERCES_CPP_NAMESPACE::DOMDocument* doc) +{ + if(doc) + { + m_document = doc; + m_node = m_document->getDocumentElement(); + m_deSerialize = false; // Set Serialize mode + m_object->Define(this); + } + else + { + throw(CStdString("DomSerializer::Serialize: input DOM document is NULL")); + } +} + +void DomSerializer::DeSerialize(DOMNode* node) +{ + m_node = node; + m_deSerialize = true; // Set DeSerialize mode + m_object->Define(this); + m_object->Validate(); +} + +CStdString DomSerializer::XMLStringToLocal(const XMLCh* const toTranscode) +{ + char* szResult = XMLString::transcode(toTranscode); + CStdString result = szResult; + XMLString::release(&szResult); + return result; +} + +DOMNode* DomSerializer::FindElementByName(DOMNode *node, CStdString name) +{ + DOMNode *child = node->getFirstChild(); + while(child) + { + if (XMLStringToLocal(child->getNodeName()) == name && child->getNodeType() == DOMNode::ELEMENT_NODE) + { + return child; + } + child = child->getNextSibling(); + } + return NULL; +} + +CStdString DomSerializer::DomNodeToString(DOMNode* node) +{ + CStdString output; + + DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(XStr("LS").unicodeForm()); + DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter(); + // set user specified output encoding + //theSerializer->setEncoding(gOutputEncoding); + theSerializer->setFeature(XStr("format-pretty-print").unicodeForm(), true); + + XMLFormatTarget *myFormTarget; + myFormTarget = new MemBufFormatTarget (); + theSerializer->writeNode(myFormTarget, *node); + + output = (char *)((MemBufFormatTarget*)myFormTarget)->getRawBuffer(); + + // Clean up + delete theSerializer; + // + // Filter, formatTarget and error handler + // are NOT owned by the serializer. + delete myFormTarget; + + return output; +} diff --git a/orkbasecxx/serializers/DomSerializer.h b/orkbasecxx/serializers/DomSerializer.h new file mode 100644 index 0000000..4190d59 --- /dev/null +++ b/orkbasecxx/serializers/DomSerializer.h @@ -0,0 +1,81 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __DOMSERIALIZER_H__ +#define __DOMSERIALIZER_H__ + +#include "Serializer.h" +#include "Object.h" + +#include "xercesc/dom/DOMNode.hpp" +#include "xercesc/util/XMLString.hpp" + +using namespace XERCES_CPP_NAMESPACE; + +/** Serializer class for Document Object Model. + This class allows a nested object to be serialized or deserialized + to or from a xerces DOM object. +*/ +class DLL_IMPORT_EXPORT DomSerializer : public Serializer +{ +public: + DomSerializer(Object* object) : Serializer(object){}; + + void ObjectValue(const char* key, Object& value, bool required = false); + + void AddInt(const char* key, int value); + void AddString(const char* key, CStdString& value); + void AddObject(const char* key, Object& value); + void Serialize(XERCES_CPP_NAMESPACE::DOMDocument* node); + + void GetString(const char* key, CStdString& value, bool required = false); + void GetObject(const char* key, Object& value, bool required = false); + void DeSerialize(DOMNode* node); + + static CStdString XMLStringToLocal(const XMLCh* const toTranscode); + static XMLCh* LocalStringToXML(CStdString& toTranscode); + + DOMNode* FindElementByName(DOMNode *node, CStdString name); + + static CStdString DomNodeToString(DOMNode *); +protected: + DOMNode* m_node; + XERCES_CPP_NAMESPACE::DOMDocument* m_document; +}; + +/** Container for xerces unicode string initialized with char* string */ +class DLL_IMPORT_EXPORT XStr +{ +public : + inline XStr(const char* const toTranscode) + { + fUnicodeForm = XMLString::transcode(toTranscode); + } + + inline ~XStr() + { + XMLString::release(&fUnicodeForm); + } + + inline const XMLCh* unicodeForm() const + { + return fUnicodeForm; + } + +private : + XMLCh* fUnicodeForm; +}; + + +#endif + diff --git a/orkbasecxx/serializers/Makefile.am b/orkbasecxx/serializers/Makefile.am new file mode 100644 index 0000000..33bd167 --- /dev/null +++ b/orkbasecxx/serializers/Makefile.am @@ -0,0 +1,10 @@ +METASOURCES = AUTO +noinst_LTLIBRARIES = libserializers.la +libserializers_la_SOURCES = DomSerializer.cpp DomSerializer.h Serializer.cpp\ + Serializer.h SingleLineSerializer.cpp SingleLineSerializer.h\ + UrlSerializer.cpp UrlSerializer.h XmlRpcSerializer.cpp\ + XmlRpcSerializer.h +#libserializers_la_LIBADD = -L/projects/ext/xmlrpc++/xmlrpc++0.7/ -lXmlRpc +INCLUDES = -I@top_srcdir@ + +AM_CXXFLAGS = -D_REENTRANT diff --git a/orkbasecxx/serializers/Serializer.cpp b/orkbasecxx/serializers/Serializer.cpp new file mode 100644 index 0000000..8e571ed --- /dev/null +++ b/orkbasecxx/serializers/Serializer.cpp @@ -0,0 +1,312 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#define _WINSOCKAPI_ // prevents the inclusion of winsock.h + +#include "ace/OS_NS_time.h" +#include "Object.h" +#include "Serializer.h" +#include "Utils.h" + +using namespace XERCES_CPP_NAMESPACE; + +Serializer::Serializer(Object* object) +{ + m_object = object; +} + +void Serializer::IntValue(const char* key, int& value, bool required) +{ + if (m_deSerialize == true) + { + GetInt(key, value, required); + } + else + { + AddInt(key, value); + } +} + +void Serializer::DoubleValue(const char* key, double& value, bool required) +{ + if (m_deSerialize == true) + { + GetDouble(key, value, required); + } + else + { + AddDouble(key, value); + } +} + +void Serializer::BoolValue(const char* key, bool& value, bool required) +{ + if (m_deSerialize == true) + { + GetBool(key, value, required); + } + else + { + AddBool(key, value); + } +} + +void Serializer::StringValue(const char* key, CStdString& value, bool required) +{ + if (m_deSerialize == true) + { + GetString(key, value, required); + } + else + { + AddString(key, value); + } +} + +void Serializer::EnumValue(const char* key, int& value, StringToEnumFunction toEnum, EnumToStringFunction toString, bool required) +{ + if (m_deSerialize == true) + { + GetEnum(key, value, toEnum, required); + } + else + { + AddEnum(key, value, toString); + } +} + +void Serializer::CsvValue(const char* key, std::list& value, bool required) +{ + if (m_deSerialize == true) + { + GetCsv(key, value, required); + } + else + { + AddCsv(key, value); + } +} + +void Serializer::DateValue(const char* key, time_t& value, bool required) +{ + if (m_deSerialize == true) + { + GetDate(key, value, required); + } + else + { + AddDate(key, value); + } +} + + +//===================================== +void Serializer::AddInt(const char* key, int value) +{ + CStdString valueString = IntToString(value); + AddString(key, valueString); +} + +void Serializer::AddDouble(const char* key, double value) +{ + CStdString valueString = DoubleToString(value); + AddString(key, valueString); +} + +void Serializer::AddBool(const char* key, bool value) +{ + if(value) + { + CStdString trueString("true"); + AddString(key, trueString); + } + else + { + CStdString falseString("false"); + AddString(key, falseString); + } +} + +void Serializer::AddEnum(const char* key, int value, EnumToStringFunction function) +{ + if(!function) + { + throw(CStdString("Serializer: wrong enumerated type conversion function for parameter:") + key); + } + else + { + CStdString valueString = function(value); + AddString(key, valueString); + } +} + +void Serializer::AddCsv(const char* key, std::list& value) +{ + CStdString csvString; + bool first = true; + for(std::list::iterator it = value.begin(); it!=value.end(); it++) + { + if(!first) + { + csvString += ","; + } + first = false; + csvString += *it; + } + AddString(key, csvString); +} + +void Serializer::AddDate(const char* key, time_t value) +{ + struct tm date; + ACE_OS::localtime_r(&value ,&date); + int month = date.tm_mon + 1; // january=0, decembre=11 + int year = date.tm_year + 1900; + CStdString dateString; + dateString.Format("%.4d-%.2d-%.2d_%.2d-%.2d-%.2d", year, month, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec); + AddString(key, dateString); +} + + +//==================================================================== +void Serializer::GetInt(const char* key, int&value, bool required) +{ + CStdString stringValue; + GetString(key, stringValue, required); + if(!stringValue.IsEmpty()) + { + value = StringToInt(stringValue); + } +} + +void Serializer::GetDouble(const char* key, double&value, bool required) +{ + CStdString stringValue; + GetString(key, stringValue, required); + if(!stringValue.IsEmpty()) + { + value = StringToDouble(stringValue); + } +} + +void Serializer::GetBool(const char* key, bool&value, bool required) +{ + CStdString stringValue; + GetString(key, stringValue, required); + stringValue.ToLower(); + if( stringValue == "true" || stringValue == "yes" || stringValue == "1" ) + { + value = true; + } + else if( stringValue == "false" || stringValue == "no" || stringValue == "0" ) + { + value = false; + } + else if( stringValue.IsEmpty() ) + { + ; // do not touch default value + } + else + { + throw(CStdString("Serializer: Invalid boolean value:") + stringValue + " for parameter:" + key); + } +} + +void Serializer::GetEnum(const char* key, int& value, StringToEnumFunction function, bool required) +{ + if(!function) + { + throw(CStdString("Serializer: missing enumerated type conversion function for parameter:") + key); + } + else + { + CStdString enumStringValue; + GetString(key, enumStringValue, required); + if (!enumStringValue.IsEmpty()) + { + value = function(enumStringValue); + } + } + +} + +void Serializer::GetCsv(const char* key, std::list& value, bool required) +{ + CStdString stringValue; + stringValue.Trim(); + CStdString element; + bool first = true; + GetString(key, stringValue, required); + for(int i=0; i::iterator it = m_map.find(CStdString(key)); + if (it != m_map.end()) + { + value = it->second; + } + else if (required == true) + { + throw CStdString(CStdString("Serializer::GetString: required parameter missing:") + key); + } +} + +void KeyValueSerializer::ObjectValue(const char* key, Object& value, bool required) +{ + throw CStdString(CStdString("KeyValueSerializer::ObjectValue: Nested objects not allowed for key-value serializers")); +} + diff --git a/orkbasecxx/serializers/Serializer.h b/orkbasecxx/serializers/Serializer.h new file mode 100644 index 0000000..a63af1a --- /dev/null +++ b/orkbasecxx/serializers/Serializer.h @@ -0,0 +1,86 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __SERIALIZER_H__ +#define __SERIALIZER_H__ + +#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning + +#include "OrkBase.h" +#include +#include +#include "boost/shared_ptr.hpp" + +typedef int (*StringToEnumFunction)(CStdString&); +typedef CStdString (*EnumToStringFunction)(int); + +class Object; + +/** Base class for serializing Objects. +*/ +class DLL_IMPORT_EXPORT Serializer +{ +public: + Serializer(Object* object); + + void IntValue(const char* key, int& value, bool required = false); + void DoubleValue(const char* key, double& value, bool required = false); + void StringValue(const char* key, CStdString& value, bool required = false); + void BoolValue(const char* key, bool& value, bool required = false); + void EnumValue(const char* key, int& value, StringToEnumFunction, EnumToStringFunction, bool required = false); + virtual void ObjectValue(const char* key, Object& value, bool required = false) = 0; + void CsvValue(const char* key, std::list& value, bool required = false); + void DateValue(const char* key, time_t& value, bool required = false); + + void AddInt(const char* key, int value); + void AddDouble(const char* key, double value); + void AddBool(const char* key, bool value); + void AddEnum(const char* key, int value, EnumToStringFunction); + void AddCsv(const char* key, std::list& value); + void AddDate(const char* key, time_t value); + virtual void AddString(const char* key, CStdString& value) = 0; + + void GetInt(const char* key, int& value, bool required = false); + void GetDouble(const char* key, double& value, bool required = false); + void GetBool(const char* key, bool& value, bool required = false); + void GetEnum(const char* key, int& value, StringToEnumFunction, bool required = false); + void GetCsv(const char* key, std::list& value, bool required = false); + void GetDate(const char* key, time_t& value, bool required = false); + virtual void GetString(const char* key, CStdString& value, bool required = false) = 0; + +protected: + + Object* m_object; + bool m_deSerialize; +}; + +typedef boost::shared_ptr SerializerRef; + +/** Base class for all Key-Value pair based serializers. +*/ +class DLL_IMPORT_EXPORT KeyValueSerializer : public Serializer +{ +public: + KeyValueSerializer(Object* object) : Serializer(object), m_numParams(0){}; + + void ObjectValue(const char* key, Object& value, bool required = false); + + void GetString(const char* key, CStdString& value, bool required = false); + +protected: + int m_numParams; + std::map m_map; +}; + +#endif + diff --git a/orkbasecxx/serializers/SingleLineSerializer.cpp b/orkbasecxx/serializers/SingleLineSerializer.cpp new file mode 100644 index 0000000..11b60d9 --- /dev/null +++ b/orkbasecxx/serializers/SingleLineSerializer.cpp @@ -0,0 +1,203 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "ace/OS_NS_ctype.h" +#include "Utils.h" +#include "SingleLineSerializer.h" + + +void SingleLineSerializer::AddString(const char* key, CStdString& value) +{ + CStdString pair; + CStdString escapedValue; + EscapeSingleLine(value, escapedValue); + pair.Format("%s=%s ", key, (PCSTR)escapedValue); + m_output += pair; +} + +CStdString SingleLineSerializer::Serialize() +{ + m_deSerialize = false; // Set Serialize mode + m_object->Define(this); + return m_output; +} + +typedef enum {SingleLineStartState, SingleLineKeyState, SingleLineValueState, SingleLineErrorState} SingleLineState; + +void SingleLineSerializer::DeSerialize(CStdString& input) +{ + // read string and extract values into map + SingleLineState state = SingleLineStartState; + CStdString key; + CStdString value; + // #### Additionally, errorDescription should be converted to Exceptions + CStdString errorDescription; + + input.Trim(); + + for(int i=0; iDefine(this); + m_object->Validate(); +} + +// Escape the space, colon and percent characters for serializing to Key-Value-Pair text +void SingleLineSerializer::EscapeSingleLine(CStdString& in, CStdString& out) +{ + for(int i=0; i equalsPostion) + { + result = input.Mid(equalsPostion+1, spacePostion-equalsPostion-1); + } + else + { + result = input.Mid(equalsPostion+1, input.GetLength() - equalsPostion - 1); + } + } + result.ToLower(); + return result; +} + diff --git a/orkbasecxx/serializers/SingleLineSerializer.h b/orkbasecxx/serializers/SingleLineSerializer.h new file mode 100644 index 0000000..62ada27 --- /dev/null +++ b/orkbasecxx/serializers/SingleLineSerializer.h @@ -0,0 +1,44 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __SINGLELINESERIALIZER_H__ +#define __SINGLELINESERIALIZER_H__ + +#include "messages/Message.h" +#include "serializers/Serializer.h" + +/** Serializer that generates and parses objects to and from a single line of text. + key-value pairs are separated by spaces. + key and values are separated by equal signs. + example: message=doit what=run +*/ +class DLL_IMPORT_EXPORT SingleLineSerializer : public KeyValueSerializer +{ +public: + SingleLineSerializer(Object* object) : KeyValueSerializer(object){}; + + void AddString(const char* key, CStdString& value); + CStdString Serialize(); + + void DeSerialize(CStdString& input); + + void EscapeSingleLine(CStdString& in, CStdString& out); + void UnEscapeSingleLine(CStdString& in, CStdString& out); + + static CStdString FindClass(CStdString& input); +private: + CStdString m_output; +}; + +#endif + diff --git a/orkbasecxx/serializers/UrlSerializer.cpp b/orkbasecxx/serializers/UrlSerializer.cpp new file mode 100644 index 0000000..1f33c18 --- /dev/null +++ b/orkbasecxx/serializers/UrlSerializer.cpp @@ -0,0 +1,161 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "ace/OS_NS_ctype.h" +#include "Utils.h" +#include "UrlSerializer.h" + + +void UrlSerializer::AddString(const char* key, CStdString& value) +{ + CStdString pair; + CStdString escapedValue; + EscapeUrl(value, escapedValue); + pair.Format("%s=%s&", key, (PCSTR)escapedValue); + m_output += pair; +} + +CStdString UrlSerializer::Serialize() +{ + m_deSerialize = false; // Set Serialize mode + m_object->Define(this); + return m_output; +} + +typedef enum {UrlStartState, UrlKeyState, UrlValueState, UrlErrorState} UrlState; + +void UrlSerializer::DeSerialize(CStdString& input) +{ + // read string and extract values into map + UrlState state = UrlStartState; + CStdString key; + CStdString value; + CStdString errorDescription; + + input.Trim(); + input.ToLower(); + + for(int i=0; iDefine(this); + m_object->Validate(); +} + +// Escape the space, colon and percent characters for serializing to Key-Value-Pair text +void UrlSerializer::EscapeUrl(CStdString& in, CStdString& out) +{ + //####### fixme, need unescaping + out = in; +} + +// Unescape the space, colon and percent characters for serializing to Key-Value-Pair text +void UrlSerializer::UnEscapeUrl(CStdString& in, CStdString& out) +{ + // ###### fixme, need escaping + out = in; +} + +CStdString UrlSerializer::FindClass(CStdString& input) +{ + CStdString result; + int equalsPostion = input.Find('='); + if (equalsPostion != -1) + { + int ampersandPostion = input.Find('&'); + if (ampersandPostion > equalsPostion) + { + // there is at least one parameter + result = input.Mid(equalsPostion+1, ampersandPostion-equalsPostion-1); + } + else + { + // there is no parameter + result = input.Mid(equalsPostion+1, input.GetLength() - equalsPostion - 1); + } + } + result.ToLower(); + return result; +} \ No newline at end of file diff --git a/orkbasecxx/serializers/UrlSerializer.h b/orkbasecxx/serializers/UrlSerializer.h new file mode 100644 index 0000000..5c2ce21 --- /dev/null +++ b/orkbasecxx/serializers/UrlSerializer.h @@ -0,0 +1,44 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __URLSERIALIZER_H__ +#define __URLSERIALIZER_H__ + +#include "messages/Message.h" +#include "serializers/Serializer.h" + +/** Serializer that generates and parses URLs from and to objects. + key-value pairs are separated by ampersands + keys and values are separated by equal signs + example: message=doit&what=run +*/ +class DLL_IMPORT_EXPORT UrlSerializer : public KeyValueSerializer +{ +public: + UrlSerializer(Object* object) : KeyValueSerializer(object){}; + + void AddString(const char* key, CStdString& value); + CStdString Serialize(); + + void DeSerialize(CStdString& input); + + void EscapeUrl(CStdString& in, CStdString& out); + void UnEscapeUrl(CStdString& in, CStdString& out); + + static CStdString FindClass(CStdString& input); +private: + CStdString m_output; +}; + +#endif + diff --git a/orkbasecxx/serializers/XmlRpcSerializer.cpp b/orkbasecxx/serializers/XmlRpcSerializer.cpp new file mode 100644 index 0000000..b9ffd88 --- /dev/null +++ b/orkbasecxx/serializers/XmlRpcSerializer.cpp @@ -0,0 +1,47 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/* +#include "XmlRpcSerializer.h" + +#define XMLRPC_METHOD_NAME "exec" + + +void XmlRpcSerializer::AddInt(const char* key, int value) +{ + XmlRpcValue pair; + pair[0] = key; + pair[1] = value; + m_array[m_numParams++] = pair; +} + +void XmlRpcSerializer::AddString(const char* key, CStdString& value) +{ + XmlRpcValue pair; + pair[0] = key; + pair[1] = (PCSTR)value; + m_array[m_numParams++] = pair; +} + +bool XmlRpcSerializer::Invoke(CStdString& hostname, int tcpPort) +{ + m_object->Define(this); + m_hostname = hostname; + m_tcpPort = tcpPort; + m_params[0] = m_array; + XmlRpcClient client(m_hostname, m_tcpPort); + client.execute(XMLRPC_METHOD_NAME, m_params, m_ret); + client.close(); + return m_ret.valid(); +} +*/ diff --git a/orkbasecxx/serializers/XmlRpcSerializer.h b/orkbasecxx/serializers/XmlRpcSerializer.h new file mode 100644 index 0000000..07bb59f --- /dev/null +++ b/orkbasecxx/serializers/XmlRpcSerializer.h @@ -0,0 +1,45 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#ifndef __XMLRPCSERIALIZER_H__ +#define __XMLRPCSERIALIZER_H__ +/* +#include "XmlRpc.h" +#include "messages/Message.h" +#include "serializers/Serializer.h" + +using namespace XmlRpc; +*/ +/** Serializer that generates and parses XMLRPC parameters from and to objects. +*/ +/* +class DLL_IMPORT_EXPORT XmlRpcSerializer : public KeyValueSerializer +{ +public: + //XmlRpcSerializer(Message* message, CStdString& hostname, int tcpPort); + XmlRpcSerializer(Object* object) : KeyValueSerializer(object){}; + + void AddInt(const char* key, int value); + void AddString(const char* key, CStdString& value); + + bool Invoke(CStdString& hostname, int tcpPort); +private: + CStdString m_hostname; + int m_tcpPort; + XmlRpcValue m_params; + XmlRpcValue m_array; + XmlRpcValue m_ret; +}; +*/ +#endif + diff --git a/orkbasej/.classpath b/orkbasej/.classpath new file mode 100644 index 0000000..2c1efe8 --- /dev/null +++ b/orkbasej/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/orkbasej/.project b/orkbasej/.project new file mode 100644 index 0000000..41bc85d --- /dev/null +++ b/orkbasej/.project @@ -0,0 +1,17 @@ + + + orkbasej + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/orkbasej/build.xml b/orkbasej/build.xml new file mode 100644 index 0000000..8dfad7f --- /dev/null +++ b/orkbasej/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +---------------------------------------------------+ + | | + | R U N N I N G H I B E R N A T E D O C L E T | + | | + +---------------------------------------------------+ + + + + + + + + + + + \ No newline at end of file diff --git a/orkbasej/java/hsqldb.hbm.template.xml b/orkbasej/java/hsqldb.hbm.template.xml new file mode 100644 index 0000000..c3c6f12 --- /dev/null +++ b/orkbasej/java/hsqldb.hbm.template.xml @@ -0,0 +1,17 @@ + + + + + true + create-drop + org.hibernate.cache.HashtableCacheProvider + true + org.hibernate.dialect.HSQLDialect + jdbc:hsqldb:mem:test + + sa + org.hsqldb.jdbcDriver + + diff --git a/orkbasej/java/log4j.template.properties b/orkbasej/java/log4j.template.properties new file mode 100644 index 0000000..af9e970 --- /dev/null +++ b/orkbasej/java/log4j.template.properties @@ -0,0 +1,40 @@ +### stdout ### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +### logfile ### +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=c:\oreka\oreka.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +# HUB is a socket hub appender +#log4j.appender.HUB=org.apache.log4j.net.SocketHubAppender +#log4j.appender.HUB.layout=org.apache.log4j.PatternLayout +#log4j.appender.HUB.layout.ConversionPattern=[cc]%d{MMM-dd HH:mm:ss} %-14.14c{1}- %m%n +#log4j.appender.HUB.port=9000 + +log4j.rootLogger=info, file, stdout + +################# +### Hibernate logging +log4j.logger.org.hibernate=info +#log4j.logger.org.hibernate=debug +### log just the SQL +#log4j.logger.org.hibernate.SQL=debug +### log JDBC bind parameters ### +log4j.logger.org.hibernate.type=info +#log4j.logger.org.hibernate.type=debug +### log schema export/update ### +log4j.logger.org.hibernate.tool.hbm2ddl=info +### log HQL parse trees +#log4j.logger.org.hibernate.hql=debug +### log cache activity ### +#log4j.logger.org.hibernate.cache=debug +### log JDBC resource acquisition +#log4j.logger.org.hibernate.jdbc=debug +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace diff --git a/orkbasej/java/mysql.hbm.template.xml b/orkbasej/java/mysql.hbm.template.xml new file mode 100644 index 0000000..353f5cc --- /dev/null +++ b/orkbasej/java/mysql.hbm.template.xml @@ -0,0 +1,35 @@ + + + + + org.hibernate.dialect.MySQLMyISAMDialect + com.mysql.jdbc.Driver + jdbc:mysql://localhost/test + mypassword + root + 1 + + update + true + + + + + + + + + true + true 1, false 0, yes 'Y', no 'N' + hibernate.test + pool1 + 8 + true + 1 + org.hibernate.cache.HashtableCacheProvider + true + true + + diff --git a/orkbasej/java/net/sf/oreka/Cycle.java b/orkbasej/java/net/sf/oreka/Cycle.java new file mode 100644 index 0000000..1d48893 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/Cycle.java @@ -0,0 +1,16 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public enum Cycle {permanent, hourly, daily, weekly, monthly, unknown} diff --git a/orkbasej/java/net/sf/oreka/Direction.java b/orkbasej/java/net/sf/oreka/Direction.java new file mode 100644 index 0000000..4a828af --- /dev/null +++ b/orkbasej/java/net/sf/oreka/Direction.java @@ -0,0 +1,16 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public enum Direction {IN, OUT, ALL, UNKN} diff --git a/orkbasej/java/net/sf/oreka/HibernateManager.java b/orkbasej/java/net/sf/oreka/HibernateManager.java new file mode 100644 index 0000000..806f5ba --- /dev/null +++ b/orkbasej/java/net/sf/oreka/HibernateManager.java @@ -0,0 +1,67 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka; + +import java.io.File; + +import net.sf.oreka.persistent.Domain; +import net.sf.oreka.persistent.LoginString; +import net.sf.oreka.persistent.RecPort; +import net.sf.oreka.persistent.RecPortFace; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.RecSession; +import net.sf.oreka.persistent.RecTape; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.persistent.User; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; + + +public class HibernateManager { + + private static SessionFactory sessionFactory = null; + + public static void configure(String filename) throws Exception { + + File configFile = new File(filename); + + AnnotationConfiguration config = new AnnotationConfiguration(); + config.configure(configFile); + + config.addAnnotatedClass(RecProgram.class); + config.addAnnotatedClass(RecSession.class); + config.addAnnotatedClass(RecSegment.class); + config.addAnnotatedClass(RecTape.class); + config.addAnnotatedClass(User.class); + config.addAnnotatedClass(LoginString.class); + config.addAnnotatedClass(Domain.class); + config.addAnnotatedClass(Service.class); + config.addAnnotatedClass(RecPort.class); + config.addAnnotatedClass(RecPortFace.class); + sessionFactory = config.buildSessionFactory(); + } + + public static Session getSession() throws Exception { + if (sessionFactory == null) { + throw new OrkException("HibernateManager.getSession: application must configure hibernate before using it."); + } + return sessionFactory.openSession(); + } +} diff --git a/orkbasej/java/net/sf/oreka/OrkException.java b/orkbasej/java/net/sf/oreka/OrkException.java new file mode 100644 index 0000000..9ec3076 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkException.java @@ -0,0 +1,22 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public class OrkException extends Exception { + + public OrkException(String message) + { + super(message); + } +} diff --git a/orkbasej/java/net/sf/oreka/OrkObject.java b/orkbasej/java/net/sf/oreka/OrkObject.java new file mode 100644 index 0000000..5469001 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkObject.java @@ -0,0 +1,23 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +import net.sf.oreka.serializers.*; + +public interface OrkObject { + + public String getOrkClassName(); + public void define(OrkSerializer serializer) throws OrkException; + public void validate(); +} diff --git a/orkbasej/java/net/sf/oreka/OrkObjectFactory.java b/orkbasej/java/net/sf/oreka/OrkObjectFactory.java new file mode 100644 index 0000000..79c2734 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkObjectFactory.java @@ -0,0 +1,66 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; +/** + * The ObjectFactory can be used to instanciate Objects based on class name. + * All existing Objects must be registered to the ObjectFactory at startup. + */ +public class OrkObjectFactory { + + static OrkObjectFactory instance = null; + java.util.HashMap classes; + + private OrkObjectFactory() + { + classes = new java.util.HashMap(); + } + + public static OrkObjectFactory instance() + { + if(instance == null) + { + instance = new OrkObjectFactory(); + } + return instance; + } + + public OrkObject newOrkObject(String className) throws OrkException + { + className = className.toLowerCase(); + OrkObject classObject = classes.get(className); + OrkObject newInstance = null; + if(classObject != null) + { + try + { + newInstance = classObject.getClass().newInstance(); + } + catch (Exception e) + { + throw new OrkException("OrkObjectFactory: Could not instanciate:" + className); + } + } + else + { + throw new OrkException("OrkObjectFactory: class does not exist:" + className); + } + return newInstance; + } + + public void registerOrkObject(OrkObject object) + { + classes.put(object.getOrkClassName(), object); + } + +} diff --git a/orkbasej/java/net/sf/oreka/OrkTest.java b/orkbasej/java/net/sf/oreka/OrkTest.java new file mode 100644 index 0000000..c08ec1e --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkTest.java @@ -0,0 +1,123 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.messages.test.TestNestedMessage; +import net.sf.oreka.messages.test.TestSubMessage; +import net.sf.oreka.serializers.DomSerializer; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class OrkTest { + + enum MyEnum {one, two, three}; + enum MyEnum2 {four, five, six}; + + + + + public static void main(String args[]) throws Exception + { + /* Enums + MyEnum toto = MyEnum.three; + MyEnum2 titi = MyEnum2.six; + + Enum grrrr = toto; + System.out.printf("%s", grrrr.name()); + grrrr = titi; + System.out.printf("%s", grrrr.name()); + + Class aClass = titi.getClass(); + grrrr = Enum.valueOf(aClass, "five"); + + System.out.printf("%s", grrrr.name()); + */ + /* Reflection + Class myClass = Class.forName("java.lang.String"); + Object myObj = myClass.newInstance(); + String boum = (String)myObj; + */ + /* + TestMessage msg = new TestMessage(); + SingleLineSerializer ser = new SingleLineSerializer(); + String serialized = ser.serialize(msg); + System.out.println(serialized); + */ + /* + Class toto = null; + toto = TestMessage.class; + + System.out.println(toto.toString()); + + java.util.ArrayList al = new java.util.ArrayList(); + al.add(toto); + + java.util.HashMap hm = new java.util.HashMap(); + hm.put(toto, toto); + */ + +// TestMessage toto = new TestMessage(); +// +// OrkObjectFactory.instance().RegisterOrkObject(toto); +// OrkObject obj = OrkObjectFactory.instance().newOrkObject("test"); +// +// TestMessage msg = (TestMessage)obj; +// msg.setIntParm(5); +// msg.setStringParm("henri"); +// +// SingleLineSerializer ser = new SingleLineSerializer(); +// ser.setClassKey("message"); +// String serialized = ser.serialize(msg); +// System.out.println(serialized); +// +// OrkObject obj2 = ser.deSerialize(serialized); +// String str = ser.serialize(obj2); +// System.out.println(str); + + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); +// InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream ("net/sf/oreka/TestMessage.xml"); +// +// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); +// DocumentBuilder builder = factory.newDocumentBuilder(); +// //Document doc = builder.parse("c:/toto.xml"); +// Document doc = builder.parse(is); +// +// DomSerializer ser = new DomSerializer(); +// OrkObject obj = ser.deSerialize(doc.getFirstChild()); + + TestMessage msg = new TestMessage(); + DomSerializer ser = new DomSerializer(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.newDocument(); + + Element el = doc.createElement("nob"); + doc.appendChild(el); + +// System.out.println(DomSerializer.NodeToString(doc)); + + ser.serialize(doc, el, msg); + System.out.println(DomSerializer.NodeToString(doc)); + + TestNestedMessage tnm = new TestNestedMessage(); + TestSubMessage tsm = tnm.getSubMsg(); + + + } +} diff --git a/orkbasej/java/net/sf/oreka/ServiceClass.java b/orkbasej/java/net/sf/oreka/ServiceClass.java new file mode 100644 index 0000000..6e8abde --- /dev/null +++ b/orkbasej/java/net/sf/oreka/ServiceClass.java @@ -0,0 +1,16 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public enum ServiceClass {unkn, audio, cti} diff --git a/orkbasej/java/net/sf/oreka/messages/AsyncMessage.java b/orkbasej/java/net/sf/oreka/messages/AsyncMessage.java new file mode 100644 index 0000000..7cfa9f5 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/AsyncMessage.java @@ -0,0 +1,18 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +public abstract class AsyncMessage extends Message { + +} diff --git a/orkbasej/java/net/sf/oreka/messages/Message.java b/orkbasej/java/net/sf/oreka/messages/Message.java new file mode 100644 index 0000000..72dfaad --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/Message.java @@ -0,0 +1,19 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +import net.sf.oreka.*; + +public abstract class Message implements OrkObject { +} diff --git a/orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java b/orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java new file mode 100644 index 0000000..2da9131 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java @@ -0,0 +1,56 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +import net.sf.oreka.OrkException; +import net.sf.oreka.serializers.OrkSerializer; + +public class SimpleResponseMessage extends AsyncMessage { + + boolean success = false; + String comment = ""; + + public void define(OrkSerializer serializer) throws OrkException { + + success = serializer.booleanValue("success", success, true); + comment = serializer.stringValue("comment", comment, false); + } + + public String getOrkClassName() { + + return "simpleresponse"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + +} diff --git a/orkbasej/java/net/sf/oreka/messages/SyncMessage.java b/orkbasej/java/net/sf/oreka/messages/SyncMessage.java new file mode 100644 index 0000000..0aae393 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/SyncMessage.java @@ -0,0 +1,19 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +public abstract class SyncMessage extends Message { + + public abstract AsyncMessage process(); +} diff --git a/orkbasej/java/net/sf/oreka/messages/test/TestMessage.java b/orkbasej/java/net/sf/oreka/messages/test/TestMessage.java new file mode 100644 index 0000000..6ac8fea --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/test/TestMessage.java @@ -0,0 +1,97 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages.test; + +import net.sf.oreka.*; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.serializers.*; + +public class TestMessage extends SyncMessage +{ + static final String orkObjectClass = "test"; + + public enum TestEnum {value1, value2, value3}; + + String stringParm = ""; + int intParm = 0; + double doubleParm = 0.0; + boolean boolParm = false; + TestEnum enumParm = TestEnum.value1; + + public String getOrkClassName() + { + return orkObjectClass; + } + + public void define(OrkSerializer serializer) throws OrkException + { + //serializer.stringValue("command", orkObjectClass, true); + intParm = serializer.intValue("intParm", intParm, true); + doubleParm = serializer.doubleValue("doubleParm", doubleParm, false); + stringParm = serializer.stringValue("stringParm", stringParm, false); + boolParm = serializer.booleanValue("boolParm", boolParm, false); + enumParm = (TestEnum)serializer.enumValue("enumParm", enumParm, false); + } + + public void validate() + { + ; + } + + public AsyncMessage process() + { + return null; + } + + public int getIntParm() { + return intParm; + } + + public void setIntParm(int intParm) { + this.intParm = intParm; + } + + public String getStringParm() { + return stringParm; + } + + public void setStringParm(String stringParm) { + this.stringParm = stringParm; + } + + public boolean isBoolParm() { + return boolParm; + } + + public void setBoolParm(boolean boolParm) { + this.boolParm = boolParm; + } + + public double getDoubleParm() { + return doubleParm; + } + + public void setDoubleParm(double doubleParm) { + this.doubleParm = doubleParm; + } + + public TestEnum getEnumParm() { + return enumParm; + } + + public void setEnumParm(TestEnum enumParm) { + this.enumParm = enumParm; + } +} diff --git a/orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java b/orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java new file mode 100644 index 0000000..c949652 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java @@ -0,0 +1,108 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages.test; + +import net.sf.oreka.*; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.serializers.*; + +public class TestNestedMessage extends SyncMessage +{ + static final String orkObjectClass = "testnested"; + + public enum TestEnum {value1, value2, value3}; + + String stringParm = ""; + int intParm = 0; + double doubleParm = 0.0; + boolean boolParm = false; + TestEnum enumParm = TestEnum.value1; + TestSubMessage subMsg = new TestSubMessage(); + + + public String getOrkClassName() + { + return orkObjectClass; + } + + public void define(OrkSerializer serializer) throws OrkException + { + //serializer.stringValue("command", orkObjectClass, true); + intParm = serializer.intValue("intParm", intParm, true); + doubleParm = serializer.doubleValue("doubleParm", doubleParm, false); + stringParm = serializer.stringValue("stringParm", stringParm, false); + boolParm = serializer.booleanValue("boolParm", boolParm, false); + enumParm = (TestEnum)serializer.enumValue("enumParm", enumParm, false); + subMsg = (TestSubMessage)serializer.objectValue("testsub", subMsg, false); + } + + public void validate() + { + ; + } + + public AsyncMessage process() + { + return null; + } + + public int getIntParm() { + return intParm; + } + + public void setIntParm(int intParm) { + this.intParm = intParm; + } + + public String getStringParm() { + return stringParm; + } + + public void setStringParm(String stringParm) { + this.stringParm = stringParm; + } + + public boolean isBoolParm() { + return boolParm; + } + + public void setBoolParm(boolean boolParm) { + this.boolParm = boolParm; + } + + public double getDoubleParm() { + return doubleParm; + } + + public void setDoubleParm(double doubleParm) { + this.doubleParm = doubleParm; + } + + public TestEnum getEnumParm() { + return enumParm; + } + + public void setEnumParm(TestEnum enumParm) { + this.enumParm = enumParm; + } + + public TestSubMessage getSubMsg() { + return subMsg; + } + + public void setSubMsg(TestSubMessage subMsg) { + this.subMsg = subMsg; + } +} \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java b/orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java new file mode 100644 index 0000000..919e995 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java @@ -0,0 +1,57 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages.test; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.serializers.OrkSerializer; + +public class TestSubMessage implements OrkObject { + + String stringSubParm = ""; + int intSubParm = 0; + + public void define(OrkSerializer serializer) throws OrkException { + + stringSubParm = serializer.stringValue("stringsubparm",stringSubParm,false); + intSubParm = serializer.intValue("intsubparm", intSubParm, false); + } + + public String getOrkClassName() { + + return "testsub"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + + public int getIntSubParm() { + return intSubParm; + } + + public void setIntSubParm(int intSubParm) { + this.intSubParm = intSubParm; + } + + public String getStringSubParm() { + return stringSubParm; + } + + public void setStringSubParm(String stringSubParm) { + this.stringSubParm = stringSubParm; + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java b/orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java new file mode 100644 index 0000000..e75217a --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java @@ -0,0 +1,59 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + + +@Entity +public class AnnotatedTestClass { + + public enum TestEnum{value1, value2}; + + long Id; + TestEnum myEnum; + + String firstname; + String lastname; + public String getFirstname() { + return firstname; + } + public void setFirstname(String firstname) { + this.firstname = firstname; + } + @Id(generate=GeneratorType.AUTO) + public long getId() { + return Id; + } + public void setId(long id) { + Id = id; + } + public String getLastname() { + return lastname; + } + public void setLastname(String lastname) { + this.lastname = lastname; + } + + @Column(columnDefinition="varchar(255)") + public TestEnum getMyEnum() { + return myEnum; + } + public void setMyEnum(TestEnum myEnum) { + this.myEnum = myEnum; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java b/orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java new file mode 100644 index 0000000..6b15796 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java @@ -0,0 +1,316 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + + + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.AnnotationConfiguration; +//import org.hibernate.tool.hbm2ddl.SchemaExport; +//import org.hibernate.ScrollableResults; + +public class AnnotationsTest { + + /** Creates a new instance of TestHibernate */ + public AnnotationsTest() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + +// Service srv1 = new Service(); +// srv1.setHostname("aoum"); +// +// srv1.setServiceClass(Service.ServiceClass.unkn); +// +// Method method = null; +// Object[] values = null; +// try { +// Class myClass = Service.ServiceClass.class; +// method = myClass.getDeclaredMethod( "values", new Class[0] ); +// values = (Object[]) method.invoke(null, new Object[0] ); +// } +// catch (Exception e) { +// int i = 0; +// } + +// if(true) {return;} + +// Date date = new Date(); +// long mili = date.getTime(); +// int sec = (int)(mili/1000); +// long mili2 = (long)sec*1000; +// Date date2 = new Date(mili2); + + AnnotationConfiguration config = (AnnotationConfiguration)new AnnotationConfiguration(); +// .setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect") +// .setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver") +// .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test") +// .setProperty("hibernate.connection.username", "sa") +// .setProperty("hibernate.connection.password", "") +// .setProperty("hibernate.connection.pool_size", "1") +// .setProperty("hibernate.connection.autocommit", "true") +// .setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider") +// .setProperty("hibernate.hbm2ddl.auto", "create-drop") +// .setProperty("hibernate.show_sql", "true"); +// config.configure("mysql.hbm.xml"); + config.configure("hsqldb.hbm.xml"); + + config.addAnnotatedClass(AnnotatedTestClass.class); + config.addAnnotatedClass(RecProgram.class); + config.addAnnotatedClass(RecSession.class); + config.addAnnotatedClass(RecSegment.class); + config.addAnnotatedClass(RecTape.class); + config.addAnnotatedClass(User.class); + config.addAnnotatedClass(LoginString.class); + config.addAnnotatedClass(Domain.class); + config.addAnnotatedClass(Service.class); + config.addAnnotatedClass(RecPort.class); + config.addAnnotatedClass(RecPortFace.class); + + SessionFactory sessions = config.buildSessionFactory(); + Session session = sessions.openSession(); + + Transaction tx = null; + + try { + /* + SchemaExport export = new SchemaExport(config); + export.setOutputFile("c:\\schema.sql"); + export.create(true,false); + */ + + // single insert +// tx = session.beginTransaction(); +// AnnotatedTestClass obj = new AnnotatedTestClass(); +// obj.setMyEnum(TestEnum.value2); +// session.save(obj); +// tx.commit(); + + // insert +// for (int i=0; i<100 ; i++) +// { +// tx = session.beginTransaction(); +// Domain obj = new Domain(); +// session.save(obj); +// tx.commit(); +// } + + /* + // iterator select + Iterator documents = session.createQuery( + "from Documents doc join doc.car") + .list() + .iterator(); + + while ( documents.hasNext() ) { + Object[] row = (Object[]) documents.next(); + Documents doc = (Documents)row[0]; + Car car = (Car)row[1]; + + //Documents doc = (Documents)documents.next(); + + System.out.println(doc.getId() + " " + car.getId()); + } + */ + /* + // scrollable select + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment intr join intr.RecSession").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment doc = (RecSegment)scrollDocs.get(0); + RecSession car = (RecSession)scrollDocs.get(1); + System.out.println(doc.getId() + " " + car.getId()); + } + */ + + /* + // many to many insert + tx = session.beginTransaction(); + + RecProgram prog1 = new RecProgram(); + RecProgram prog2 = new RecProgram(); + RecSegment seg = new RecSegment(); + + HashSet programs = new HashSet(); + programs.add(prog1); + programs.add(prog2); + seg.setRecPrograms(programs); + + session.save(prog1); + session.save(prog2); + session.save(seg); + tx.commit(); + */ + /* + // Many to many select + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment as seg join seg.recPrograms as prg where prg.id=2").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment seg = (RecSegment)scrollDocs.get(0); + RecProgram prg = (RecProgram)scrollDocs.get(1); + System.out.println(seg.getId() + " " + prg.getId()); + } + */ + + /* + // one to many create + tx = session.beginTransaction(); + + RecProgram prog = new RecProgram(); + User user = new User(); + prog.setTargetUser(user); + + session.save(user); + session.save(prog); + tx.commit(); + */ + /* + // one to many select + ScrollableResults scrollDocs = session.createQuery( + "from RecProgram as prg join prg.targetUser as tgt").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecProgram prg = (RecProgram)scrollDocs.get(0); + User tgt = (User)scrollDocs.get(1); + System.out.println(prg.getId() + " " + tgt.getId()); + } + */ + + // multi-session stuff +// tx = session.beginTransaction(); +// RecTape obj = new RecTape(); +// Service srv = new Service(); +// obj.setService(srv); +// srv.setName("service1"); +// session.save(srv); +// session.save(obj); +// tx.commit(); +// session.close(); +// +// session = sessions.openSession(); +// tx = session.beginTransaction(); +// obj = new RecTape(); +// obj.setService(srv); +// session.save(obj); +// tx.commit(); +// session.close(); + +// tx = session.beginTransaction(); +// //Service.retrieveByName("toto", session); +// RecSegment seg = new RecSegment(); +// seg.setLoginString("too"); +// seg.setDuration(56); +// seg.setDirection(Direction.in); +// seg.setRemoteParty("135"); +// session.save(seg); +// +// java.util.List recSegments = session.createQuery( +// "from RecSegment as seg where seg.remoteParty = :rp") +// .setString("rp", "135") +// .list(); +// if (recSegments.size() > 0) { +// RecSegment result = (RecSegment)recSegments.get(0); +// System.out.println(result.getLoginString() + " " + result.getDirection().name()); +// } + + // enum stuff +// tx = session.beginTransaction(); +// //Service.retrieveByName("toto", session); +// Service srv = new Service(); +// srv.setHostname("aoum"); +// srv.setServiceClass(ServiceClass.audio); +// session.save(srv); +// +// java.util.List services = session.createQuery( +// "from Service as srv where srv.hostname = :rp") +// .setString("rp", "aoum") +// .list(); +// if (services.size() > 0) { +// Service result = (Service)services.get(0); +// System.out.println(result.getHostname() + result.getServiceClass().name()); +// } + + + +// tx = session.beginTransaction(); +// +// Iterator portFaces = session.createQuery( +// "from RecPortFace") +// .list() +// .iterator(); + + tx = session.beginTransaction(); + System.out.println("hello"); + RecSegment seg = new RecSegment(); + GregorianCalendar cal = new GregorianCalendar(); + Date now = cal.getTime(); + seg.setTimestamp(now); + session.save(seg); + + GregorianCalendar cal2 = new GregorianCalendar(); + cal2.setTimeInMillis(cal.getTimeInMillis() + 1000); + + Iterator segments = session.createQuery( + "from RecSegment as seg where seg.timestamp= :date") + //.setDate("date", now) + //.setDate("date2", new Date(time+10000000)) + .setCalendar("date", cal) + .list() + .iterator(); + if(segments.hasNext()) { + RecSegment seg2 = (RecSegment)segments.next(); + System.out.println("db timestamp:" + seg2.getTimestamp().getTime() + " my:" + now.getTime()); + } + else { + System.out.println("fail"); + } + + } + catch ( HibernateException he ) { + if ( tx != null ) tx.rollback(); + throw he; + } + finally { + session.close(); + } + } + +} \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/persistent/Domain.java b/orkbasej/java/net/sf/oreka/persistent/Domain.java new file mode 100644 index 0000000..edb463d --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/Domain.java @@ -0,0 +1,91 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +/** + * @hibernate.class + */ +@Entity +public class Domain { + + private int id; + private String name = ""; + private String description = ""; + + /** + * + */ + public Domain() { + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the description. + */ + public String getDescription() { + return description; + } + + + /** + * @param description The description to set. + */ + public void setDescription(String description) { + this.description = description; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the name. + */ + public String getName() { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java new file mode 100644 index 0000000..2554a70 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java @@ -0,0 +1,195 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import org.hibernate.cfg.Configuration; +import org.hibernate.SessionFactory; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.HibernateException; +//import org.hibernate.tool.hbm2ddl.SchemaExport; +//import org.hibernate.ScrollableResults; + +public class HbnXmlTest { + + /** Creates a new instance of TestHibernate */ + public HbnXmlTest() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + Configuration config = new Configuration() + .configure("mysql.hbm.xml"); + + config.addClass(HbnXmlTestClass.class); + SessionFactory sessions = config.buildSessionFactory(); + Session session = sessions.openSession(); + + Transaction tx = null; + + try { + /* + SchemaExport export = new SchemaExport(config); + export.setOutputFile("c:\\schema.sql"); + export.create(true,false); + */ + + for (int i=0; i<100 ; i++) + { + tx = session.beginTransaction(); + + HbnXmlTestClass obj = new HbnXmlTestClass(); + + session.save(obj); + tx.commit(); + } + + + // insert + /* + for (int i=0; i<100 ; i++) + { + tx = session.beginTransaction(); + + RecSession RecSession = new RecSession(); + RecSession.setDuration(i); + + + RecSegment intr1 = new RecSegment(); + intr1.setRecSession(RecSession); + intr1.setLocalParty(i + " " + 1); + intr1.setDuration(23); + RecSegment intr2 = new RecSegment(); + intr2.setRecSession(RecSession); + intr2.setLocalParty(i + " " + 2); + intr2.setDuration(45); + + session.save(RecSession); + session.save(intr1); + session.save(intr2); + tx.commit(); + } +*/ + /* + // iterator select + Iterator documents = session.createQuery( + "from Documents doc join doc.car") + .list() + .iterator(); + + while ( documents.hasNext() ) { + Object[] row = (Object[]) documents.next(); + Documents doc = (Documents)row[0]; + Car car = (Car)row[1]; + + //Documents doc = (Documents)documents.next(); + + System.out.println(doc.getId() + " " + car.getId()); + } + */ + /* + // scrollable select + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment intr join intr.RecSession").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment doc = (RecSegment)scrollDocs.get(0); + RecSession car = (RecSession)scrollDocs.get(1); + System.out.println(doc.getId() + " " + car.getId()); + } + */ + + /* + // many to many insert + tx = session.beginTransaction(); + + RecProgram prog1 = new RecProgram(); + RecProgram prog2 = new RecProgram(); + RecSegment seg = new RecSegment(); + + HashSet programs = new HashSet(); + programs.add(prog1); + programs.add(prog2); + seg.setRecPrograms(programs); + + session.save(prog1); + session.save(prog2); + session.save(seg); + tx.commit(); + */ + + // Many to many select + /* + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment as seg join seg.recPrograms as prg where prg.id=2").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment seg = (RecSegment)scrollDocs.get(0); + RecProgram prg = (RecProgram)scrollDocs.get(1); + System.out.println(seg.getId() + " " + prg.getId()); + } + */ + + /* + // one to one create + tx = session.beginTransaction(); + + RecProgram prog = new RecProgram(); + User user = new User(); + prog.setTargetUser(user); + + session.save(user); + session.save(prog); + tx.commit(); + */ + /* + // one to one select + ScrollableResults scrollDocs = session.createQuery( + "from RecProgram as prg join prg.targetUser as tgt").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecProgram prg = (RecProgram)scrollDocs.get(0); + User tgt = (User)scrollDocs.get(1); + System.out.println(prg.getId() + " " + tgt.getId()); + } + */ + } + catch ( HibernateException he ) { + if ( tx != null ) tx.rollback(); + throw he; + } + finally { + session.close(); + } + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java new file mode 100644 index 0000000..8706455 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java @@ -0,0 +1,62 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +/** + * @hibernate.class + */ +public class HbnXmlTestClass { + + long Id; + String firstname = ""; + String lastname = ""; + + /** + * @hibernate.property + * not-null="true" + * @return Returns the filename. + */ + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the filename. + */ + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * @hibernate.id + * generator-class="native" + */ + public long getId() { + return Id; + } + + public void setId(long id) { + Id = id; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/LoginString.java b/orkbasej/java/net/sf/oreka/persistent/LoginString.java new file mode 100644 index 0000000..ad44057 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/LoginString.java @@ -0,0 +1,114 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +/** + * @hibernate.class + */ +@Entity +public class LoginString { + + private int id; + private String loginString; + private User user; + private Domain domain; + + /** + * @hibernate.many-to-one + * @return Returns the domain. + */ + @ManyToOne + public Domain getDomain() { + return domain; + } + + + /** + * @param domain The domain to set. + */ + public void setDomain(Domain domain) { + this.domain = domain; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the loginString. + */ + public String getLoginString() { + return loginString; + } + + + /** + * @param loginString The loginString to set. + */ + public void setLoginString(String loginString) { + this.loginString = loginString; + } + + + /** + * @hibernate.many-to-one + * @return Returns the user. + */ + @ManyToOne + public User getUser() { + return user; + } + + + /** + * @param user The user to set. + */ + public void setUser(User user) { + this.user = user; + } + + + /** + * + */ + public LoginString() { + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecPort.java b/orkbasej/java/net/sf/oreka/persistent/RecPort.java new file mode 100644 index 0000000..9886bdc --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecPort.java @@ -0,0 +1,33 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +@Entity +public class RecPort { + + private int id; + + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecPortFace.java b/orkbasej/java/net/sf/oreka/persistent/RecPortFace.java new file mode 100644 index 0000000..2824926 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecPortFace.java @@ -0,0 +1,49 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class RecPortFace { + + private RecPort recPort; + private Service service; + private String name; + + @Id + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + @ManyToOne + public RecPort getRecPort() { + return recPort; + } + public void setRecPort(RecPort recPort) { + this.recPort = recPort; + } + @ManyToOne + public Service getService() { + return service; + } + public void setService(Service service) { + this.service = service; + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecProgram.java b/orkbasej/java/net/sf/oreka/persistent/RecProgram.java new file mode 100644 index 0000000..48d8bdb --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecProgram.java @@ -0,0 +1,516 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import java.util.Collection; +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import net.sf.oreka.Cycle; +import net.sf.oreka.Direction; + +/** + * @hibernate.class + */ +@Entity +public class RecProgram { + + private int id; + private String name = ""; + private String description = ""; + private boolean discarded = false; + private Date timestamp; + private User owner; + private boolean active = true; + private Direction direction = Direction.ALL; + private int minDuration = 0; + private int maxDuration = 0; + private double randomPercent = 0.0; + private Cycle cycle = Cycle.permanent; + private int startDay = 0; + private int stopDay = 0; + private Date startTime; + private Date stopTime; + private int recPerCycle = 0; + private int recordedSoFar = 0; + private String localParty = ""; + private String remoteParty = ""; + private int keepForHours = 0; + private User targetUser; + private RecPort targetPort; + + //private Set RecSegments; + private Collection recSegments; + + /** + * @hibernate.set + * lazy="true" + * table="PrgToSeg" + * @hibernate.collection-key + * column="RecProgram" + * @hibernate.collection-many-to-many + * column="RecSegment" + * class="net.sf.oreka.persistent.RecSegment" + * @return Returns the recSegments. + */ + @ManyToMany +// ( +// targetEntity="net.sf.oreka.persistent.RecSegment" +// ) + @JoinTable( + table=@Table(name="ProgToSeg"), + joinColumns={@JoinColumn(name="ProgId")}, + inverseJoinColumns={@JoinColumn(name="SegId")} + ) + public Collection getRecSegments() { + return recSegments; + } + + + /** + * @param recSegments The recSegments to set. + */ + public void setRecSegments(Collection recSegments) { + this.recSegments = recSegments; + } + + + public RecProgram () { + direction = Direction.ALL; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the active. + */ + public boolean isActive() { + return active; + } + + + /** + * @param active The active to set. + */ + public void setActive(boolean active) { + this.active = active; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the cycle. + */ + public Cycle getCycle() { + return cycle; + } + + + /** + * @param cycle The cycle to set. + */ + public void setCycle(Cycle cycle) { + this.cycle = cycle; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the description. + */ + public String getDescription() { + return description; + } + + + /** + * @param description The description to set. + */ + public void setDescription(String description) { + this.description = description; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the direction. + */ + public Direction getDirection() { + return direction; + } + + + /** + * @param direction The direction to set. + */ + public void setDirection(Direction direction) { + this.direction = direction; + } + + + /** + * @return Returns the discarded. + */ + public boolean isDiscarded() { + return discarded; + } + + + /** + * @param discarded The discarded to set. + */ + public void setDiscarded(boolean discarded) { + this.discarded = discarded; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the keepForHours. + */ + public int getKeepForHours() { + return keepForHours; + } + + + /** + * @param keepForHours The keepForHours to set. + */ + public void setKeepForHours(int keepForHours) { + this.keepForHours = keepForHours; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the maxDuration. + */ + public int getMaxDuration() { + return maxDuration; + } + + + /** + * @param maxDuration The maxDuration to set. + */ + public void setMaxDuration(int maxDuration) { + this.maxDuration = maxDuration; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the minDuration. + */ + public int getMinDuration() { + return minDuration; + } + + + /** + * @param minDuration The minDuration to set. + */ + public void setMinDuration(int minDuration) { + this.minDuration = minDuration; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the name. + */ + public String getName() { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the randomPercent. + */ + public double getRandomPercent() { + return randomPercent; + } + + + /** + * @param randomPercent The randomPercent to set. + */ + public void setRandomPercent(double randomPercent) { + this.randomPercent = randomPercent; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the recordedSoFar. + */ + public int getRecordedSoFar() { + return recordedSoFar; + } + + + /** + * @param recordedSoFar The recordedSoFar to set. + */ + public void setRecordedSoFar(int recordedSoFar) { + this.recordedSoFar = recordedSoFar; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the recPerCycle. + */ + public int getRecPerCycle() { + return recPerCycle; + } + + + /** + * @param recPerCycle The recPerCycle to set. + */ + public void setRecPerCycle(int recPerCycle) { + this.recPerCycle = recPerCycle; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the remoteParty. + */ + public String getRemoteParty() { + return remoteParty; + } + + + /** + * @param remoteParty The remoteParty to set. + */ + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the startDay. + */ + public int getStartDay() { + return startDay; + } + + + /** + * @param startDay The startDay to set. + */ + public void setStartDay(int startDay) { + this.startDay = startDay; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the startTime. + */ + public Date getStartTime() { + return startTime; + } + + + /** + * @param startTime The startTime to set. + */ + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the stopDay. + */ + public int getStopDay() { + return stopDay; + } + + + /** + * @param stopDay The stopDay to set. + */ + public void setStopDay(int stopDay) { + this.stopDay = stopDay; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the stopTime. + */ + public Date getStopTime() { + return stopTime; + } + + + /** + * @param stopTime The stopTime to set. + */ + public void setStopTime(Date stopTime) { + this.stopTime = stopTime; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the targetPort. + */ + @OneToOne + public RecPort getTargetPort() { + return targetPort; + } + + + /** + * @param targetPort The targetPort to set. + */ + public void setTargetPort(RecPort targetPort) { + this.targetPort = targetPort; + } + + /** + * @hibernate.many-to-one + * @return Returns the targetUser. + */ + @ManyToOne + public User getTargetUser() { + return targetUser; + } + + + + /** + * @param targetUser The targetUser to set. + */ + public void setTargetUser(User targetUser) { + this.targetUser = targetUser; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the timestamp. + */ + public Date getTimestamp() { + return timestamp; + } + + + /** + * @param timestamp The timestamp to set. + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + + /** + * @hibernate.many-to-one + * @return Returns the owner. + */ + @ManyToOne + public User getOwner() { + return owner; + } + + + + /** + * @param owner The owner to set. + */ + public void setOwner(User owner) { + this.owner = owner; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecSegment.java b/orkbasej/java/net/sf/oreka/persistent/RecSegment.java new file mode 100644 index 0000000..716de5b --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecSegment.java @@ -0,0 +1,321 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +import net.sf.oreka.Direction; + +/** + * @hibernate.class + */ +@Entity +public class RecSegment { + + private int id; + private RecSession recSession; + private long recSessionOffset; + private RecTape recTape; + private long recTapeOffset; + private Date timestamp = new Date(0); + private long duration; + private String localParty = ""; + private String localEntryPoint = ""; + private String remoteParty = ""; + private Direction direction;; + private User user; + private String loginString = ""; + private RecPort port; + //private java.util.Set RecPrograms; + private Collection recPrograms; + + public RecSegment() { + direction = Direction.UNKN; + recPrograms = new ArrayList(); + } + + /** + * @hibernate.property + * + * @hibernate.column + * name="direction" + * index="direction" + * not-null="true" + * @return Returns the direction. + */ + public Direction getDirection() { + return direction; + } + + /** + * @param direction The direction to set. + */ + public void setDirection(Direction direction) { + this.direction = direction; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the duration. + */ + public long getDuration() { + return duration; + } + + /** + * @param duration The duration to set. + */ + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @hibernate.id + * generator-class="native" + * @hibernate.collection-many-to-many + * column="RecSegmentId" + * class="RecProgram" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @hibernate.property + * + * @hibernate.column + * name="localParty" + * index="localParty" + * not-null="true" + * + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the loginString. + */ + public String getLoginString() { + return loginString; + } + + /** + * @param loginString The loginString to set. + */ + public void setLoginString(String loginString) { + this.loginString = loginString; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the remoteParty. + */ + public String getRemoteParty() { + return remoteParty; + } + + /** + * @param remoteParty The remoteParty to set. + */ + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the RecTapeOffset. + */ + public long getRecTapeOffset() { + return recTapeOffset; + } + + /** + * @param RecTapeOffset The RecTapeOffset to set. + */ + public void setRecTapeOffset(long recTapeOffset) { + this.recTapeOffset = recTapeOffset; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the timestamp. + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * @param timestamp The timestamp to set. + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + /** + * @hibernate.many-to-one + * @return Returns the RecSession. + */ + @ManyToOne + public RecSession getRecSession() { + return recSession; + } + + /** + * @param RecSession The RecSession to set. + */ + public void setRecSession(RecSession recSession) { + this.recSession = recSession; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the RecSessionOffset. + */ + public long getRecSessionOffset() { + return recSessionOffset; + } + + /** + * @param RecSessionOffset The RecSessionOffset to set. + */ + public void setRecSessionOffset(long recSessionOffset) { + this.recSessionOffset = recSessionOffset; + } + + /** + * @hibernate.many-to-one + * @return Returns the recTape. + */ + @ManyToOne + public RecTape getRecTape() { + return recTape; + } + + + /** + * @param recTape The recTape to set. + */ + public void setRecTape(RecTape recTape) { + this.recTape = recTape; + } + + /** + * @hibernate.set + * lazy="true" + * table="PrgToSeg" + * @hibernate.collection-key + * column="RecSegment" + * @hibernate.collection-many-to-many + * column="RecProgram" + * class="net.sf.oreka.persistent.RecProgram" + * @return Returns the recPrograms. + */ + @ManyToMany + @JoinTable( + table=@Table(name="ProgToSeg"), + joinColumns={@JoinColumn(name="SegId")}, + inverseJoinColumns={@JoinColumn(name="ProgId")} + ) + public Collection getRecPrograms() { + return recPrograms; + } + + + /** + * @param recPrograms The recPrograms to set. + */ + public void setRecPrograms(Collection recPrograms) { + this.recPrograms = recPrograms; + } + + /** + * @hibernate.many-to-one + * @return Returns the user. + */ + @ManyToOne + public User getUser() { + return user; + } + + + /** + * @param user The user to set. + */ + public void setUser(User user) { + this.user = user; + } + + public String getLocalEntryPoint() { + return localEntryPoint; + } + + public void setLocalEntryPoint(String localEntryPoint) { + this.localEntryPoint = localEntryPoint; + } + + @Transient + public long getStopTime() { + return timestamp.getTime() + duration; + } + + @OneToOne + public RecPort getPort() { + return port; + } + + public void setPort(RecPort port) { + this.port = port; + } + + + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecSession.java b/orkbasej/java/net/sf/oreka/persistent/RecSession.java new file mode 100644 index 0000000..214f678 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecSession.java @@ -0,0 +1,79 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.Transient; + +/** + * @hibernate.class + */ +@Entity +public class RecSession { + private int id; + private Date timestamp = new Date(0); + private long duration; + + /** + * @hibernate.property + * not-null="true" + * @return + */ + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @hibernate.id + * generator-class="native" + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + public void setId(int id) { + this.id = id; + } + + /** + * @hibernate.property + * @return + */ + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + @Transient + public long getStopTime() { + return timestamp.getTime() + duration; + } + + public void setStopTime(long stopTime) { + duration = stopTime - timestamp.getTime(); + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecTape.java b/orkbasej/java/net/sf/oreka/persistent/RecTape.java new file mode 100644 index 0000000..d5f6d73 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecTape.java @@ -0,0 +1,249 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Transient; + +import net.sf.oreka.Direction; + +/** + * @hibernate.class + */ +@Entity +public class RecTape { + + private int id; + private Date timestamp = new Date(0); + private long duration; + private String filename = ""; + private Service service; + private String localParty = ""; + private String localEntryPoint = ""; + private String remoteParty = ""; + private Direction direction; + private RecPort port; + private Date expiryTimestamp = new Date(0); + + public RecTape() + { + // Defaults + direction = Direction.UNKN; + } + + /** + * @hibernate.property + * @hibernate.column + * name="direction" + * index="direction" + * not-null="true" + * @return Returns the direction. + */ + public Direction getDirection() { + return direction; + } + + /** + * @param direction The direction to set. + */ + public void setDirection(Direction direction) { + this.direction = direction; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the duration. + */ + public long getDuration() { + return duration; + } + + /** + * @param duration The duration to set. + */ + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the expiryTimestamp. + */ + public Date getExpiryTimestamp() { + return expiryTimestamp; + } + + /** + * @param expiryTimestamp The expiryTimestamp to set. + */ + public void setExpiryTimestamp(Date expiryTimestamp) { + this.expiryTimestamp = expiryTimestamp; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the filename. + */ + public String getFilename() { + return filename; + } + + /** + * @param filename The filename to set. + */ + public void setFilename(String filename) { + this.filename = filename; + } + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the port. + */ + @OneToOne + public RecPort getPort() { + return port; + } + + /** + * @param port The port to set. + */ + public void setPort(RecPort port) { + this.port = port; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the remoteParty. + */ + public String getRemoteParty() { + return remoteParty; + } + + /** + * @param remoteParty The remoteParty to set. + */ + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the timestamp. + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * @param timestamp The timestamp to set. + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + /** + * @hibernate.many-to-one + * @return Returns the service. + */ + @ManyToOne + public Service getService() { + return service; + } + + + /** + * @param server The service to set. + */ + public void setService(Service service) { + this.service = service; + } + + public String getLocalEntryPoint() { + return localEntryPoint; + } + + public void setLocalEntryPoint(String localEntryPoint) { + this.localEntryPoint = localEntryPoint; + } + + @Transient + public long getStopTime() { + return timestamp.getTime() + duration; + } + + @Transient + public String getUrl() { + + if(service != null) { + return service.getFileServeProtocol() + "://" + + service.getHostname() + ":" + service.getFileServeTcpPort() + + "/" + service.getFileServePath() + "/" + filename; + } + else { + return ""; + } + } + + @Transient + public String getPlayUrl() { + + return "javascript:play('" + getUrl() + "')"; + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/Service.java b/orkbasej/java/net/sf/oreka/persistent/Service.java new file mode 100644 index 0000000..361676a --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/Service.java @@ -0,0 +1,172 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +import net.sf.oreka.ServiceClass; + +/** + * @hibernate.class + */ +@Entity +public class Service { + + private int id; + private String name = ""; + private String hostname = ""; + private int tcpPort = 0; + private String fileServeProtocol = ""; + private int fileServeTcpPort = 0; + private String fileServePath = ""; + private ServiceClass serviceClass; + private boolean recordMaster = false; + + /** + * + */ + public Service() { + serviceClass = ServiceClass.unkn; + } + + /** + * + * @hibernate.property + * not-null="true" + * @return Returns the fileServePath. + */ + public String getFileServePath() { + return fileServePath; + } + + + /** + * @param fileServePath The fileServePath to set. + */ + public void setFileServePath(String fileServePath) { + this.fileServePath = fileServePath; + } + + public int getFileServeTcpPort() { + return fileServeTcpPort; + } + + public void setFileServeTcpPort(int fileServeTcpPort) { + this.fileServeTcpPort = fileServeTcpPort; + } + + public int getTcpPort() { + return tcpPort; + } + + public void setTcpPort(int tcpPort) { + this.tcpPort = tcpPort; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the fileServeProtocol. + */ + public String getFileServeProtocol() { + return fileServeProtocol; + } + + + /** + * @param fileServeProtocol The fileServeProtocol to set. + */ + public void setFileServeProtocol(String fileServeProtocol) { + this.fileServeProtocol = fileServeProtocol; + } + + + /** + * @hibernate.property + * unique="true" + * not-null="true" + * @return Returns the gUID. + */ + public String getName() { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the hostname. + */ + public String getHostname() { + return hostname; + } + + + /** + * @param hostname The hostname to set. + */ + public void setHostname(String hostname) { + this.hostname = hostname; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + public ServiceClass getServiceClass() { + return serviceClass; + } + + public void setServiceClass(ServiceClass serviceClass) { + this.serviceClass = serviceClass; + } + + public boolean isRecordMaster() { + return recordMaster; + } + + public void setRecordMaster(boolean cdrMaster) { + this.recordMaster = cdrMaster; + } + + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/User.java b/orkbasej/java/net/sf/oreka/persistent/User.java new file mode 100644 index 0000000..5d78760 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/User.java @@ -0,0 +1,133 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +/** + * @hibernate.class + */ +@Entity +public class User { + + private int id; + private String password = ""; + private String firstname = ""; + private String lastname = ""; + private String email = ""; + + /** + * @hibernate.property + * not-null="true" + * @return Returns the email. + */ + public String getEmail() { + return email; + } + + + /** + * @param email The email to set. + */ + public void setEmail(String email) { + this.email = email; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the firstname. + */ + public String getFirstname() { + return firstname; + } + + + /** + * @param firstname The firstname to set. + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + @Id(generate=GeneratorType.AUTO) + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the lastname. + */ + public String getLastname() { + return lastname; + } + + + /** + * @param lastname The lastname to set. + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the password. + */ + public String getPassword() { + return password; + } + + + /** + * @param password The password to set. + */ + public void setPassword(String password) { + this.password = password; + } + + + /** + * + */ + public User() { + } + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/DomSerializer.java b/orkbasej/java/net/sf/oreka/serializers/DomSerializer.java new file mode 100644 index 0000000..ac64a13 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/DomSerializer.java @@ -0,0 +1,186 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + + + +package net.sf.oreka.serializers; + + +import java.io.ByteArrayOutputStream; + +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.Text; + +public class DomSerializer extends OrkSerializer { + + Node node = null; + Document document = null; + + public OrkObject deSerialize(Node node) throws OrkException + { + if (node == null) + { + throw (new OrkException("DomSerializer: null node was passed in")); + } + this.node = node; + deserialize = true; // Set DeSerialize mode + OrkObject obj = OrkObjectFactory.instance().newOrkObject(node.getNodeName()); + obj.define(this); + obj.validate(); + return obj; + } + + public void serialize(Document document, Node node, OrkObject object) throws OrkException { + + if (node == null) { + throw ( new OrkException("DomSerializer: passed DOM node is null")); + } + if (document == null) { + throw ( new OrkException("DomSerializer: passed DOM document is null")); + } + this.document = document; + this.node = node; + + deserialize = false; // Set Serialize mode + object.define(this); + } + + @Override + public void addClassName(String value) { + // TODO Auto-generated method stub + + } + + @Override + void addString(String key, String value) { + + Element newElem = document.createElement(key); + node.appendChild(newElem); + + Text newText = document.createTextNode(value); + newElem.appendChild(newText); + } + + @Override + String getString(String key, String oldValue, boolean required) throws OrkException { + + String value = null; + + // Find the right node + Node stringNode = findElementByName(node, key); + + if(stringNode != null) + { + // Now, the string associated to element should be the first child (text element) + Node textNode = stringNode.getFirstChild(); + if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) { + value = textNode.getNodeValue().trim(); + } + } + if (value == null) { + if (required) { + throw(new OrkException("DomSerializer::GetString: required parameter missing:" + key)); + } + value = oldValue; + } + return value; + } + + @Override + public OrkObject objectValue(String key, OrkObject value, boolean required) throws OrkException { + + if (deserialize) { + return getObject(key, value, required); + } + else { + addObject(key, value); + return value; + } + } + + void addObject(String key, OrkObject value) throws OrkException { + + Element newElem = document.createElement(key); + node.appendChild(newElem); + DomSerializer ser = new DomSerializer(); + ser.serialize(document, newElem, value); + } + + OrkObject getObject(String key, OrkObject oldValue, boolean required) throws OrkException { + + OrkObject value = null; + + // Find the node corresponding to the object wanting to be populated + Node objectNode = findElementByName(node, key); + + // Create a new serializer and affect it to this object + if (objectNode != null) + { + DomSerializer serializer = new DomSerializer(); + value = serializer.deSerialize(objectNode); + } + if (value == null) { + if (required) { + throw(new OrkException("DomSerializer.getObject: required node missing:" + key)); + } + value = oldValue; + } + return value; + } + + public Node findElementByName(Node node, String name) + { + Node child = node.getFirstChild(); + while(child != null) + { + if (child.getNodeName().equalsIgnoreCase(name) && child.getNodeType() == Node.ELEMENT_NODE) + { + return child; + } + child = child.getNextSibling(); + } + return null; + } + + public static String NodeToString(Node node) { + + String result = null; + TransformerFactory xformerFactory = TransformerFactory.newInstance(); + try { + Transformer xformer = xformerFactory.newTransformer(); + xformer.setOutputProperty("indent", "yes"); + ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); + Result output = new StreamResult(byteArray); + DOMSource source = new DOMSource(node); + xformer.transform(source,output); + result = byteArray.toString(); + } + catch (Exception e) { + ; + } + return result; + } + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java b/orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java new file mode 100644 index 0000000..bc65819 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java @@ -0,0 +1,47 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import java.util.HashMap; + +import net.sf.oreka.*; + +public abstract class KeyValueSerializer extends OrkSerializer +{ + HashMap map; + + KeyValueSerializer() + { + map = new HashMap(); + } + + String getString(String key, String oldValue, boolean required) throws OrkException + { + String value = map.get(key.toLowerCase()); + if (value == null) + { + if (required == true) + { + throw (new OrkException("Serializer.GetString: required parameter missing:" + key)); + } + value = oldValue; + } + return value; + } + + public OrkObject objectValue(String key, OrkObject value, boolean required) throws OrkException + { + throw (new OrkException("KeyValueSerializer.objectValue: Nested objects not allowed for key-value serializers")); + } +} diff --git a/orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java b/orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java new file mode 100644 index 0000000..f4b0d54 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java @@ -0,0 +1,239 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import net.sf.oreka.*; + +/** + * + * Base class for all serializers. + * Serializers have to implement their own serialize and deserialize methods + * since the data can be read from and written to many different formats + * + * Enum and Boolean value are case insensitive (all enum values must be defined + * lower case in the project, otherwise they won't be recognized at all) + * + */ +public abstract class OrkSerializer { + + boolean deserialize = false; + String classKey = "class"; + + public void setClassKey(String classKey) + { + this.classKey = classKey; + } + + public int intValue(String key, int value, boolean required) throws OrkException + { + if (deserialize) + { + return getInt(key, value, required); + } + else + { + addInt(key, value); + return value; + } + } + + public double doubleValue(String key, double value, boolean required) throws OrkException + { + if (deserialize) + { + return getDouble(key, value, required); + } + else + { + addDouble(key, value); + return value; + } + } + + public String stringValue(String key, String value, boolean required ) throws OrkException + { + if (deserialize) + { + return getString(key, value, required); + } + else + { + addString(key, value); + return value; + } + } + + public boolean booleanValue(String key, boolean value, boolean required ) throws OrkException + { + if (deserialize) + { + return getBoolean(key, value, required); + } + else + { + addBoolean(key, value); + return value; + } + } + + public Enum enumValue(String key, Enum value, boolean required ) throws OrkException + { + if (deserialize) + { + return getEnum(key, value, required); + } + else + { + addEnum(key, value); + return value; + } + } + + public abstract OrkObject objectValue(String key, OrkObject value, boolean required ) throws OrkException; + + public abstract void addClassName(String value); + + void addInt(String key, int value) + { + String valueString = String.valueOf(value); + addString(key, valueString); + } + + void addDouble(String key, double value) + { + String valueString = String.valueOf(value); + addString(key, valueString); + } + + void addBoolean(String key, boolean value) + { + if(value) + { + addString(key, "true"); + } + else + { + addString(key, "false"); + } + } + + void addEnum(String key, Enum value) + { + addString(key, value.name()); + } + + abstract void addString(String key, String value); + + int getInt(String key, int oldValue, boolean required) throws OrkException + { + int value = 0; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + try + { + value = Integer.valueOf(stringValue); + } + catch (Exception e) + { + throw (new OrkException("Serializer: value:" + stringValue + " not an int for key:" + key)); + } + } + return value; + } + + double getDouble(String key, double oldValue, boolean required) throws OrkException + { + double value = 0.0; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + try + { + value = Double.valueOf(stringValue); + } + catch (Exception e) + { + throw (new OrkException("Serializer: value:" + stringValue + " not a double for key:" + key)); + } + } + return value; + } + + boolean getBoolean(String key, boolean oldValue, boolean required) throws OrkException + { + boolean value; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + stringValue = stringValue.toLowerCase(); + + if( stringValue.equals("true") || stringValue.equals("yes") || stringValue.equals("1") ) + { + value = true; + } + else if( stringValue.equals("false") || stringValue.equals("no") || stringValue.equals("0") ) + { + value = false; + } + else + { + throw(new OrkException("Serializer: Invalid boolean value:" + stringValue + " for key:" + key)); + } + } + return value; + } + + Enum getEnum(String key, Enum oldValue, boolean required) throws OrkException + { + Enum value = null; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + stringValue = stringValue.toLowerCase(); + Class valueClass = oldValue.getClass(); + try + { + value = Enum.valueOf(valueClass, stringValue); + } + catch (IllegalArgumentException e) + { + throw (new OrkException("Serializer: Invalid enum value:" + stringValue + " for parameter:" + key)); + } + } + return value; + } + + abstract String getString(String key, String oldValue, boolean required ) throws OrkException; +} diff --git a/orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java b/orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java new file mode 100644 index 0000000..8eded74 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java @@ -0,0 +1,79 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import javax.servlet.http.*; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; + +public class ServletRequestSerializer extends OrkSerializer { + + HttpServletRequest request = null; + final String classMarker = "cmd"; + + public OrkObject deSerialize(HttpServletRequest request) throws OrkException + { + this.request = request; + deserialize = true; // Set DeSerialize mode + + // Instanciate the right object + String classMarker2 = (String)request.getParameterNames().nextElement(); + String orkClass = null; + if(classMarker2 != null) + { + orkClass = request.getParameter(classMarker2); + } + if(orkClass == null) { + throw (new OrkException("ServletRequestSerializer.deSerialize: where is the command in:" + request.getQueryString())); + } + + OrkObject obj = OrkObjectFactory.instance().newOrkObject(orkClass.toLowerCase()); + obj.define(this); + obj.validate(); + return obj; + } + + @Override + public void addClassName(String value) { + ; // not needed, this serializer is only a de-serializer + } + + @Override + void addString(String key, String value) { + ; // not needed, this serializer is only a de-serializer + } + + @Override + String getString(String key, String oldValue, boolean required) throws OrkException { + String value = request.getParameter(key); + if(value == null) { + if (required) { + throw (new OrkException("ServletRequestSerializer.getString: parameter not found:" + key)); + } + else { + value = oldValue; + } + } + return value; + } + + @Override + public OrkObject objectValue(String key, OrkObject value, boolean required) throws OrkException { + throw (new OrkException("ServletRequestSerializer.objectValue: Nested objects not allowed")); + } + + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java b/orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java new file mode 100644 index 0000000..44f2fe3 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java @@ -0,0 +1,231 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; + +/** + * Serializer that generates and parses objects to and from a single line of text. + * key-value pairs are separated by spaces. + * key and values are separated by equal signs. + * example: message=doit what=run + */ +public class SingleLineSerializer extends KeyValueSerializer +{ + StringBuffer output; + + public String serialize(OrkObject input) throws OrkException + { + output = new StringBuffer(); + deserialize = false; // Set Serialize mode + addClassName(input.getOrkClassName()); + input.define(this); + return output.toString(); + } + + enum SingleLineState {StartState, KeyState, ValueState}; + + public OrkObject deSerialize(String input) throws OrkException + { + // read string and extract values into map + input = input.trim(); + + SingleLineState state = SingleLineState.StartState; + + StringBuffer key = new StringBuffer(); + StringBuffer value = new StringBuffer(); + String firstValue = null; + + for(int i=0; i 0) + { + // Add pair to key-value map + map.put(key.toString().toLowerCase(), unEscapeSingleLine(value.toString())); + if (firstValue == null) + { + firstValue = value.toString().toLowerCase(); + } + key = new StringBuffer(); + value = new StringBuffer(); + } + } + } + + deserialize = true; // Set DeSerialize mode + + OrkObject obj = OrkObjectFactory.instance().newOrkObject(firstValue); + obj.define(this); + obj.validate(); + return obj; + } + + public void addClassName(String value) + { + addString(classKey, value); + } + + void addString(String key, String value) + { + String pair; + String escapedValue = escapeSingleLine(value); + pair = key + "=" + escapedValue + " "; + output.append(pair); + } + + /** + * Finds the Object Class from a serialized string. + * i.e. for a serialized object of the form: + * message=dosomething when=now + * it returns "dosomething" + * + * @param input + * @return + */ + /* + static String findClass(String input) + { + String result = ""; + int equalsPosition = input.indexOf("="); + if (equalsPosition != -1) + { + int spacePostion = input.indexOf(" "); + if (spacePostion > equalsPosition) + { + result = input.substring(equalsPosition+1, spacePostion-1); + } + else + { + result = input.substring(equalsPosition+1, input.length() - 1); + } + } + return result.toLowerCase(); + } + */ + + String escapeSingleLine(String in) + { + StringBuffer out = new StringBuffer(); + for(int i=0; i parameters = new Hashtable(); + + public void setParameter(String key, String value) { + parameters.put(key, value); + } + + public String getParameter(String key) { + return (String)this.parameters.get(key); + } + + public Enumeration getParameterNames(){ + return this.parameters.elements(); + } + + public Cookie[] getCookies() {return null;} + public String getMethod(){return null;} + public String getRequestURI(){return null;} + public String getServletPath(){return null;} + public String getPathInfo(){return null;} + public String getPathTranslated(){return null;} + public String getQueryString(){return null;} + public String getRemoteUser(){return null;} + public String getAuthType(){return null;} + public String getHeader(String name){return null;} + public int getIntHeader(String name){return 0;} + public long getDateHeader(String name){return 0;} + public Enumeration getHeaderNames(){return null;} + public HttpSession getSession(boolean create){return null;} + public String getRequestedSessionId(){return null;} + public boolean isRequestedSessionIdValid(){return false;} + public boolean isRequestedSessionIdFromCookie(){return false;} + public boolean isRequestedSessionIdFromUrl(){return false;} + public int getContentLength(){return 0;} + public String getContentType(){return null;} + public String getProtocol(){return null;} + public String getScheme(){return null;} + public String getServerName(){return null;} + public int getServerPort(){return 0;} + public String getRemoteAddr(){return null;} + public String getRemoteHost(){return null;} + public String getRealPath(String path){return null;} + public ServletInputStream getInputStream() throws IOException{return null;} + public String[] getParameterValues(String name){return null;} + public Enumeration getAttributeNames(){return null;} + public Object getAttribute(String name){return null;} + public HttpSession getSession(){return null;} + public BufferedReader getReader() throws IOException{return null;} + public String getCharacterEncoding(){return null;} + public void setAttribute(String name, Object o) {} + public boolean isRequestedSessionIdFromURL() {return false;} + + public String getContextPath() { + // TODO Auto-generated method stub + return null; + } + + public Enumeration getHeaders(String arg0) { + // TODO Auto-generated method stub + return null; + } + + public StringBuffer getRequestURL() { + // TODO Auto-generated method stub + return null; + } + + public Principal getUserPrincipal() { + // TODO Auto-generated method stub + return null; + } + + public boolean isUserInRole(String arg0) { + // TODO Auto-generated method stub + return false; + } + + public String getLocalAddr() { + // TODO Auto-generated method stub + return null; + } + + public Locale getLocale() { + // TODO Auto-generated method stub + return null; + } + + public Enumeration getLocales() { + // TODO Auto-generated method stub + return null; + } + + public String getLocalName() { + // TODO Auto-generated method stub + return null; + } + + public int getLocalPort() { + // TODO Auto-generated method stub + return 0; + } + + public Map getParameterMap() { + // TODO Auto-generated method stub + return null; + } + + public int getRemotePort() { + // TODO Auto-generated method stub + return 0; + } + + public RequestDispatcher getRequestDispatcher(String arg0) { + // TODO Auto-generated method stub + return null; + } + + public boolean isSecure() { + // TODO Auto-generated method stub + return false; + } + + public void removeAttribute(String arg0) { + // TODO Auto-generated method stub + + } + + public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java b/orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java new file mode 100644 index 0000000..08260fb --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.serializers.ServletRequestSerializer; + +public class ServletRequestSerializerTest extends TestCase { + + public static void main (String[] args) { + junit.textui.TestRunner.run (suite()); + } + protected void setUp() { + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); + } + public static Test suite() { + return new TestSuite(ServletRequestSerializerTest.class); + } + + public void testSerializeBasic() throws Exception + { + NullHttpServletRequest req = new NullHttpServletRequest(); + ServletRequestSerializer ser = new ServletRequestSerializer(); + req.setParameter("cmd", "test"); + req.setParameter("intParm", "45"); + OrkObject obj = ser.deSerialize(req); + assertTrue(((TestMessage)obj).getIntParm() == 45); + } +} diff --git a/orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java b/orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java new file mode 100644 index 0000000..5520626 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java @@ -0,0 +1,172 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers.test; + +import junit.framework.*; +import net.sf.oreka.*; +import net.sf.oreka.messages.*; +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.serializers.SingleLineSerializer; + +public class SingleLineSerializerTest extends TestCase +{ + public static void main (String[] args) { + junit.textui.TestRunner.run (suite()); + } + protected void setUp() { + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); + } + public static Test suite() { + return new TestSuite(SingleLineSerializerTest.class); + } + + public void testSerializeBasic() throws Exception + { + String output = null; + + TestMessage msg = new TestMessage(); + SingleLineSerializer ser = new SingleLineSerializer(); + + msg.setIntParm(6); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("intparm=6") != -1); + + msg.setIntParm(-5); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("intparm=-5") != -1); + + msg.setDoubleParm(7.7); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("doubleparm=7.7") != -1); + + msg.setBoolParm(true); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("boolparm=true") != -1); + + msg.setStringParm("hello"); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("stringparm=hello") != -1); + } + + public void testDeSerializeBasic() throws Exception + { + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test intparm=3"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.getIntParm() == 3); + + input = "class=test doubleparm=-14.6"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.getDoubleParm() == -14.6); + + input = "class=test boolparm=yes"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + } + + public void testDeSerializeBoolean() throws Exception + { + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test intparm=78 boolparm=no"; + msg = (TestMessage)ser.deSerialize(input); + assertFalse(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=0"; + msg = (TestMessage)ser.deSerialize(input); + assertFalse(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=false"; + msg = (TestMessage)ser.deSerialize(input); + assertFalse(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=true"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=yes"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=1"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=asdf"; + boolean threw = false; + try { + msg = (TestMessage)ser.deSerialize(input); + } + catch (OrkException e) { + threw = true; + } + assertTrue(threw); + } + + public void testDeSerializeRequired() throws Exception + { + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test"; + boolean threw = false; + try { + msg = (TestMessage)ser.deSerialize(input); + } + catch (OrkException e) { + threw = true; + } + assertTrue(threw); + } + + public void testEnum() throws Exception + { + // deserialize + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test intparm=78 enumparm=value2"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.getEnumParm() == TestMessage.TestEnum.value2); + + input = "class=test intparm=78 enumparm=garbage"; + boolean threw = false; + try { + msg = (TestMessage)ser.deSerialize(input); + } + catch (OrkException e) { + threw = true; + } + assertTrue(threw); + + // serialize + String output = null; + msg.setEnumParm(TestMessage.TestEnum.value3); + output = ser.serialize(msg); + assertTrue(output.toLowerCase().indexOf("enumparm=value3") != -1); + } + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml b/orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml new file mode 100644 index 0000000..20347c4 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml @@ -0,0 +1,5 @@ + + + 546 + + \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml b/orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml new file mode 100644 index 0000000..0309449 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml @@ -0,0 +1,6 @@ + + 546 + + hello + + \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/test/FillDatabase.java b/orkbasej/java/net/sf/oreka/test/FillDatabase.java new file mode 100644 index 0000000..849af3c --- /dev/null +++ b/orkbasej/java/net/sf/oreka/test/FillDatabase.java @@ -0,0 +1,118 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.test; + +import java.util.Date; + +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.persistent.LoginString; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.RecTape; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.persistent.User; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class FillDatabase { + + public static void main(String args[]) throws Exception + { + HibernateManager.configure("c:/oreka/test/mysql.hbm.xml"); + + Session hbnSession = HibernateManager.getSession(); + Transaction tx = hbnSession.beginTransaction(); + + Service service = new Service(); + service.setFileServePath(""); + service.setFileServeProtocol("http"); + service.setFileServeTcpPort(8080); + service.setHostname("localhost"); + service.setRecordMaster(true); + service.setName("orkaudio1"); + hbnSession.save(service); + + User user = new User(); + user.setFirstname("salisse"); + LoginString ls = new LoginString(); + ls.setUser(user); + ls.setLoginString("1973"); + hbnSession.save(user); + hbnSession.save(ls); + + // create program that does not filter anything + RecProgram prog1 = new RecProgram(); + hbnSession.save(prog1); + + // Create a bunch of segments + String lastParty = "123-234-5678"; + java.util.Random generator = new java.util.Random(); + for(int i=0; i<500; i++) { + RecSegment seg = new RecSegment(); + RecTape tape = new RecTape(); + + tape.setService(service); + tape.setFilename("f1.mp3"); + + Date date = new Date(new Date().getTime() - 600000 +(i*1000)); + seg.setTimestamp(date); + tape.setTimestamp(date); + + String randomString = "" + generator.nextInt(); + randomString = randomString.replace("-", "a"); + seg.setLocalParty(randomString); + seg.setRemoteParty(lastParty); + lastParty = randomString; + + float randomDirection = generator.nextFloat(); + if(randomDirection > .5){ + seg.setDirection(Direction.IN); + } + else { + seg.setDirection(Direction.OUT); + } + + long duration = (long)(generator.nextFloat()*60.0); + seg.setDuration(duration); + tape.setDuration(duration+1); + + seg.setRecTape(tape); + hbnSession.save(tape); + hbnSession.save(seg); + } + +// StringBuffer queryString = new StringBuffer("from RecSegment as seg "); +// Query query = hbnSession.createQuery(queryString.toString()); +// +// ScrollableResults scrollDocs = query.scroll(); +// scrollDocs.first(); +// +// while (scrollDocs.get()!= null) +// { +// RecSegment seg = (RecSegment)scrollDocs.get(0); +// //RecTape tape = (RecTape)scrollDocs.get(1); +// //RecTape tape = new RecTape(); +// System.out.println(seg.getId()); +// scrollDocs.next(); +// } + + tx.commit(); + hbnSession.close(); + + System.out.println("Done"); + } + +} diff --git a/orktrack/.classpath b/orktrack/.classpath new file mode 100644 index 0000000..b24e059 --- /dev/null +++ b/orktrack/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/orktrack/.project b/orktrack/.project new file mode 100644 index 0000000..92ab63c --- /dev/null +++ b/orktrack/.project @@ -0,0 +1,18 @@ + + + orktrack + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + com.sysdeo.eclipse.tomcat.tomcatnature + + diff --git a/orktrack/context/WEB-INF/web.xml b/orktrack/context/WEB-INF/web.xml new file mode 100644 index 0000000..e7515f7 --- /dev/null +++ b/orktrack/context/WEB-INF/web.xml @@ -0,0 +1,39 @@ + + + + orktrack + + Log4jConfigFile + c:/oreka/orktrack/log4j.properties + + + ConfigFile + c:/oreka/orktrack/orktrack.config.xml + + + HibernateConfigFile + c:/oreka/orktrack/mysql.hbm.xml + + + redirect + org.apache.tapestry.RedirectFilter + + + redirect + / + + + net.sf.oreka.orktrack.ContextListener + + + command + net.sf.oreka.orktrack.CommandServlet + 1 + + + command + /command + + diff --git a/orktrack/deploy-template.xml b/orktrack/deploy-template.xml new file mode 100644 index 0000000..c882b36 --- /dev/null +++ b/orktrack/deploy-template.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${remove.result} + + + + + + + + + + + + + + + + + + ${install.result} + + + + + + diff --git a/orktrack/orktrack.config.xml b/orktrack/orktrack.config.xml new file mode 100644 index 0000000..f294a54 --- /dev/null +++ b/orktrack/orktrack.config.xml @@ -0,0 +1,3 @@ + + yes + \ No newline at end of file diff --git a/orktrack/src/net/sf/oreka/orktrack/CommandServlet.java b/orktrack/src/net/sf/oreka/orktrack/CommandServlet.java new file mode 100644 index 0000000..cf8fc1a --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/CommandServlet.java @@ -0,0 +1,115 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObjectFactory; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SimpleResponseMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.serializers.ServletRequestSerializer; +import net.sf.oreka.serializers.SingleLineSerializer; + +import org.apache.log4j.Logger; + +public class CommandServlet extends HttpServlet { + + static Logger logger = Logger.getLogger(CommandServlet.class); + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException + { + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); + + ServletRequestSerializer ser = new ServletRequestSerializer(); + + try { + SyncMessage obj = (SyncMessage)ser.deSerialize(request); + AsyncMessage rsp = obj.process(); + SingleLineSerializer ser2 = new SingleLineSerializer(); + PrintWriter out = response.getWriter(); + out.println(ser2.serialize(rsp)); + } + catch (Exception e) { + SimpleResponseMessage rsp = new SimpleResponseMessage(); + rsp.setComment(e.getMessage()); + rsp.setSuccess(false); + SingleLineSerializer ser2 = new SingleLineSerializer(); + PrintWriter out = response.getWriter(); + try { + out.println(ser2.serialize(rsp)); + } + catch (OrkException ae) { + out.println("Error:" + ae.getMessage()); + } + } + +// SingleLineSerializer ser2 = new SingleLineSerializer(); +// try { +// OrkObject obj = ser.deSerialize(request); +// response.setContentType("text/html"); +// PrintWriter out = response.getWriter(); +// out.println(""); +// out.println(""); +// out.println("Sucess"); +// out.println(""); +// out.println(""); +// out.println("

"); +// out.println(ser2.serialize(obj)); +// out.println("

"); +// out.println(""); +// out.println(""); +// } +// catch (OrkException e) { +// response.setContentType("text/html"); +// PrintWriter out = response.getWriter(); +// out.println(""); +// out.println(""); +// out.println("Error"); +// out.println(""); +// out.println(""); +// out.println("

"); +// out.println(e.getMessage()); +// out.println("

"); +// out.println(""); +// out.println(""); +// } + +// logger.log(Level.INFO, request.getPathInfo()); +// logger.log(Level.INFO, request.getRequestURL()); +// logger.log(Level.INFO, request.getQueryString()); +// logger.log(Level.INFO, request.getParameter("toto")); +// logger.log(Level.INFO, request.getParameter("titi")); +// +// response.setContentType("text/html"); +// PrintWriter out = response.getWriter(); +// out.println(""); +// out.println(""); +// out.println("Hello World!"); +// out.println(""); +// out.println(""); +// out.println("

Hello World!

"); +// out.println(""); +// out.println(""); + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/ConfigManager.java b/orktrack/src/net/sf/oreka/orktrack/ConfigManager.java new file mode 100644 index 0000000..1ac9039 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/ConfigManager.java @@ -0,0 +1,86 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.orktrack; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import net.sf.oreka.OrkException; +import net.sf.oreka.serializers.DomSerializer; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; + +/** + * This singleton class manages all application configuration parameters + */ +public class ConfigManager { + + static ConfigManager configManager = null; + + Logger log = null; + OrkTrackConfig config = null; + + private ConfigManager() { + config = new OrkTrackConfig(); + log = LogManager.getInstance().getConfigLogger(); + } + + public static ConfigManager getInstance() + { + if (configManager == null) + { + configManager = new ConfigManager(); + } + return configManager; + } + + public void load(String filename) { + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + try { + File file = new File(filename); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputStream is = new FileInputStream(file); + Document doc = builder.parse(is); + DomSerializer ser = new DomSerializer(); + config = (OrkTrackConfig)ser.deSerialize(doc.getFirstChild()); + } + catch (OrkException e) { + log.error("ConfigManager.load: deserialization error:" + e.getMessage()); + } + catch (FileNotFoundException e) { + log.error("ConfigManager.load config file does not exist:" + filename + " check your web.xml"); + } + catch (Exception e) { + log.error("ConfigManager.load: exception:" + e.getMessage()); + } + } + + public OrkTrackConfig getConfig() { + return config; + } + + public void setConfig(OrkTrackConfig config) { + this.config = config; + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/ContextListener.java b/orktrack/src/net/sf/oreka/orktrack/ContextListener.java new file mode 100644 index 0000000..b8bf558 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/ContextListener.java @@ -0,0 +1,90 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.log4j.Logger; + +public class ContextListener implements ServletContextListener { + + Logger log = LogManager.getInstance().getContextLogger(); + + public void contextDestroyed(ServletContextEvent arg0) { + + log.info(OrkTrack.APP_NAME + " shutting down."); + } + + public void contextInitialized(ServletContextEvent servletContextEvent) { + + ServletContext context = servletContextEvent.getServletContext(); + String log4jConfigFile = context.getInitParameter("Log4jConfigFile"); + +// boolean complainAboutLog4jConfigFile = false; +// if (log4jConfigFile != null) { +// LogManager.getInstance().configure(log4jConfigFile); +// } +// else { +// complainAboutLog4jConfigFile = true; +// } + if (log4jConfigFile == null) { + System.out.println("Log4jConfigFile context-param missing in web.xml"); + } + +// log.info("========================================"); +// log.info(OrkTrack.APP_NAME + " starting ..."); + +// if(complainAboutLog4jConfigFile) { +// log.warn("contextInitialized: Log4jConfigFile context-param missing in web.xml"); +// } + + // Register all OrkObjects +// OrkObjectFactory.instance().registerOrkObject(new OrkTrackConfig()); + + String configFile = context.getInitParameter("ConfigFile"); +// if (configFile != null) { +// ConfigManager.getInstance().load(configFile); +// } +// else { +// log.error("contextInitialized: ConfigFile context-param missing in web.xml"); +// } + if (configFile == null) { + System.out.println("ConfigFile context-param missing in web.xml"); + } + + String hibernateConfigFile = context.getInitParameter("HibernateConfigFile"); +// if (hibernateConfigFile != null) { +// try { +// HibernateManager.configure(hibernateConfigFile); +// } +// catch (Exception e) { +// log.error("contextInitialized: Error configuring Hibernate:" + e.getMessage()); +// } +// } +// else { +// log.error("contextInitialized: HibernateConfigFile context-param missing in web.xml"); +// } + if (hibernateConfigFile == null) { + System.out.println("HibernateConfigFile context-param missing in web.xml"); + } + + //PortManager.instance().initialize(); + + OrkTrack.initialize(log4jConfigFile, hibernateConfigFile, configFile); + } + + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/LogManager.java b/orktrack/src/net/sf/oreka/orktrack/LogManager.java new file mode 100644 index 0000000..1c5be27 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/LogManager.java @@ -0,0 +1,126 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.io.File; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +/** + * This singleton class manages all application log4j loggers + */ +public class LogManager { + + static LogManager logManager = null; + + Logger rootLogger = null; + Logger configLogger = null; + Logger contextLogger = null; + Logger portLogger = null; + Logger userLogger = null; + + private LogManager() + { + rootLogger = Logger.getRootLogger(); + rootLogger.setLevel(Level.INFO); + configLogger = Logger.getLogger("config"); + contextLogger = Logger.getLogger("context"); + portLogger = Logger.getLogger("port"); + userLogger = Logger.getLogger("user"); + + BasicConfigurator.configure(); // in case there is no properties file + } + + public static LogManager getInstance() + { + if (logManager == null) + { + logManager = new LogManager(); + } + return logManager; + } + + public void configure(String filename) { + + // Check wether filename is valid + File file = new File(filename); + if (file.exists()) { + // Attempt to configure log4j + PropertyConfigurator.configure(filename); + } + else { + configLogger.warn("Log4j properties file does not exist:" + filename + " check your web.xml"); + } + } + + /** + * @return Returns the rootLogger. + */ + public Logger getRootLogger() { + return rootLogger; + } + + + /** + * @param rootLogger The rootLogger to set. + */ + public void setRootLogger(Logger rootLogger) { + this.rootLogger = rootLogger; + } + + /** + * @return Returns the configLogger. + */ + public Logger getConfigLogger() { + return configLogger; + } + + + /** + * @param configLogger The configLogger to set. + */ + public void setConfigLogger(Logger configLogger) { + this.configLogger = configLogger; + } + + public Logger getContextLogger() { + return contextLogger; + } + + public void setContextLogger(Logger contextLogger) { + this.contextLogger = contextLogger; + } + + public Logger getPortLogger() { + return portLogger; + } + + public void setPortLogger(Logger portLogger) { + this.portLogger = portLogger; + } + + public Logger getUserLogger() { + return userLogger; + } + + public void setUserLogger(Logger userLogger) { + this.userLogger = userLogger; + } + + + +} \ No newline at end of file diff --git a/orktrack/src/net/sf/oreka/orktrack/OrkTest.java b/orktrack/src/net/sf/oreka/orktrack/OrkTest.java new file mode 100644 index 0000000..b1750b3 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/OrkTest.java @@ -0,0 +1,24 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import org.apache.log4j.Logger; + +public class OrkTest { + + public static void main(String args[]) throws Exception + { + Logger log = LogManager.getInstance().getContextLogger(); + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/OrkTrack.java b/orktrack/src/net/sf/oreka/orktrack/OrkTrack.java new file mode 100644 index 0000000..5bd8a9c --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/OrkTrack.java @@ -0,0 +1,74 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.orktrack; + +import net.sf.oreka.OrkObjectFactory; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.orktrack.messages.MetadataMessage; +import net.sf.oreka.orktrack.messages.TapeMessage; +import net.sf.oreka.orktrack.messages.UserStateMessage; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + + + +public class OrkTrack { + + public static final String APP_NAME = "OrkTrack"; + + public OrkTrack() { + + LogManager.getInstance().getConfigLogger().log(Level.INFO, "Entering OrkTrack"); + } + + public static void initialize(String log4jConfigFile, String hibernateConfigFile, String configFile) { + + LogManager.getInstance().configure(log4jConfigFile); + Logger log = LogManager.getInstance().getRootLogger(); + log.info("========================================"); + log.info(OrkTrack.APP_NAME + " starting ..."); + + // Register all OrkObjects + OrkObjectFactory.instance().registerOrkObject(new OrkTrackConfig()); + OrkObjectFactory.instance().registerOrkObject(new MetadataMessage()); + OrkObjectFactory.instance().registerOrkObject(new TapeMessage()); + OrkObjectFactory.instance().registerOrkObject(new UserStateMessage()); + + ConfigManager.getInstance().load(configFile); + + try { + HibernateManager.configure(hibernateConfigFile); + } + catch (Exception e) { + log.error("OrkTrack.initialize: Error configuring Hibernate:" + e.getMessage()); + } + + ServiceManager.initialize(); + PortManager.instance().initialize(); + ProgramManager.instance().load(); + } + + public static void main(String[] args) + { + //System.out.println("hello"); + //RecSegment seg = new RecSegment(); + //System.out.println(seg.getDuration()); + OrkTrack orkTrack = new OrkTrack(); + } + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/OrkTrackConfig.java b/orktrack/src/net/sf/oreka/orktrack/OrkTrackConfig.java new file mode 100644 index 0000000..24d0489 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/OrkTrackConfig.java @@ -0,0 +1,46 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.serializers.OrkSerializer; + +public class OrkTrackConfig implements OrkObject { + + boolean ctiDriven = false; + + public void define(OrkSerializer serializer) throws OrkException { + + ctiDriven = serializer.booleanValue("ctidriven", ctiDriven, true); + } + + public String getOrkClassName() { + return "orktrackconfig"; + } + + public void validate() { + + } + + public boolean isCtiDriven() { + return ctiDriven; + } + + public void setCtiDriven(boolean ctiDriven) { + this.ctiDriven = ctiDriven; + } + + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/Port.java b/orktrack/src/net/sf/oreka/orktrack/Port.java new file mode 100644 index 0000000..5831841 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/Port.java @@ -0,0 +1,274 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; + +import net.sf.oreka.orktrack.messages.MetadataMessage; +import net.sf.oreka.orktrack.messages.TapeMessage; +import net.sf.oreka.persistent.RecPort; +import net.sf.oreka.persistent.RecPortFace; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.RecTape; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.persistent.User; + +import org.apache.log4j.Logger; +import org.hibernate.Session; + +public class Port { + + public ArrayList portFaces = new ArrayList(); + private RecPort recPort = null; + private TapeMessage lastTapeMessage = null; + private MetadataMessage lastMetadataMessage = null; + private User user = null; + + private LinkedList recSegments = new LinkedList (); + private LinkedList recTapes = new LinkedList (); + + Logger log = null; + + public Port(RecPort recPort) { + this.recPort = recPort; + log = LogManager.getInstance().portLogger; + } + + private synchronized void addTapeToLocalCache(RecTape tape) { + + if (recTapes.size() > 50) { + recTapes.removeLast(); + } + recTapes.addFirst(tape); + } + + private synchronized void addSegmentToLocalCache(RecSegment seg) { + + if (recSegments.size() > 50) { + recSegments.removeLast(); + } + recSegments.addFirst(seg); + } + + private boolean areTogether(RecTape tape, RecSegment seg) { + + boolean result = false; + long segStartTime = seg.getTimestamp().getTime(); + long tapeStartTime = tape.getTimestamp().getTime(); + long segStopTime = segStartTime + seg.getDuration(); + long tapeStopTime = tapeStartTime + tape.getDuration(); + + if( segStartTime > tapeStartTime || + (tapeStartTime - segStartTime) < 3000 ) { + + if ( segStopTime < tapeStopTime || + (segStopTime-tapeStopTime) < 3000 ) { + + result = true; + } + } + return result; + } + + private void joinTogether(RecTape tape, RecSegment seg, Session hbnSession) { + + seg.setRecTape(tape); + seg.setRecTapeOffset(seg.getTimestamp().getTime() - tape.getTimestamp().getTime()); + hbnSession.save(seg); + } + + private synchronized void findAndAssociateTape(RecSegment segment, Session hbnSession) { + + // Iterate over tapes and find the ones corresponding to this segment + Iterator it = recTapes.iterator(); + boolean foundOne = false; + boolean done = false; + while (it.hasNext() && !done) { + RecTape tape = it.next(); + if (areTogether(tape, segment)) { + joinTogether(tape, segment, hbnSession); + log.info("#" + recPort.getId() + ": associating segment:" + segment.getId() + " with tape:" + tape.getId()); + foundOne = true; + } + else { + if (foundOne) { + done = true; + } + } + } + } + + private synchronized void findAndAssociateSegment(RecTape tape, Session hbnSession) { + + // Iterate over segments and find the ones corresponding to this tape + Iterator it = recSegments.iterator(); + boolean foundOne = false; + boolean done = false; + while (it.hasNext() && !done) { + RecSegment segment = it.next(); + if (areTogether(tape, segment)) { + joinTogether(tape, segment, hbnSession); + log.info("#" + recPort.getId() + ": associating segment:" + segment.getId() + " with tape:" + tape.getId()); + foundOne = true; + } + else { + if (foundOne) { + done = true; + } + } + } + } + + public void notifyMetadataMessage(MetadataMessage metadataMessage, Session hbnSession, Service srv) { + + long duration = 0; + Date startDate = null; + + if (metadataMessage.getStage() == TapeMessage.CaptureStage.start) { + lastMetadataMessage = metadataMessage; + } + else if (metadataMessage.getStage() == TapeMessage.CaptureStage.stop) { + + if (lastMetadataMessage != null) { + duration = ((long)metadataMessage.getTimestamp() - (long)lastMetadataMessage.getTimestamp())*1000; + startDate = new Date((long)lastMetadataMessage.getTimestamp()*1000); + } + } + else if (metadataMessage.getStage() == TapeMessage.CaptureStage.complete) { + duration = (long)metadataMessage.getDuration()*1000; + startDate = new Date(metadataMessage.getTimestamp()*1000); + } + + if (startDate != null) { + + if (srv.isRecordMaster()) { + // create segment + RecSegment recSegment = new RecSegment(); + recSegment.setTimestamp(startDate); + recSegment.setDirection(metadataMessage.getDirection()); + recSegment.setDuration(duration); + recSegment.setLocalParty(metadataMessage.getLocalParty()); + recSegment.setLocalEntryPoint(metadataMessage.getLocalEntryPoint()); + recSegment.setRecSessionOffset(0); + recSegment.setPort(recPort); + + if(metadataMessage.getLocalParty() != "") { + User user = UserManager.instance().getByLoginString(metadataMessage.getLocalParty(), hbnSession); + recSegment.setUser(user); + } + + // is this retained by a program ? + if (ProgramManager.instance().filterSegmentAgainstAllPrograms(recSegment, hbnSession)) { + // Try to find associated tape and link it to this + addSegmentToLocalCache(recSegment); + findAndAssociateTape(recSegment, hbnSession); + hbnSession.save(recSegment); + log.info("#" + metadataMessage.getCapturePort() + ": written segment " + recSegment.getId()); + } + else { + log.info("#" + metadataMessage.getCapturePort() + ": metadata message discarded"); + } + } + } + } + + public void notifyTapeMessage(TapeMessage tapeMessage, Session hbnSession, Service srv) { + + if (tapeMessage.getStage() == TapeMessage.CaptureStage.start) { + lastTapeMessage = tapeMessage; + } + else { + // Tape stop + if (lastTapeMessage == null) { + log.warn("Port: notifyTapeMessage: stop without a previous tape message"); + } + else if (lastTapeMessage.getStage() != TapeMessage.CaptureStage.start) { + log.warn("Port: notifyTapeMessage: stop without a start"); + } + else if (tapeMessage.getStage() == TapeMessage.CaptureStage.stop){ + boolean generateSegment = false; + if (portFaces.size() == 1 || srv.isRecordMaster()) { + generateSegment = true; + } + + TapeMessage startMessage = lastTapeMessage; + TapeMessage stopMessage = tapeMessage; + long duration = (stopMessage.getTimestamp() - startMessage.getTimestamp())*1000; + long date = ((long)startMessage.getTimestamp()) * 1000; + Date timestamp = new Date(date); + + // create a new tape record + RecTape recTape = new RecTape(); + recTape.setDirection(stopMessage.getDirection()); + recTape.setDuration(duration); + recTape.setExpiryTimestamp(new Date()); + recTape.setFilename(stopMessage.getFilename()); + recTape.setLocalParty(stopMessage.getLocalParty()); + recTape.setPort(recPort); + recTape.setRemoteParty(stopMessage.getRemoteParty()); + recTape.setTimestamp(timestamp); + recTape.setService(srv); + hbnSession.save(recTape); + log.info("#" + tapeMessage.getCapturePort() + ": written tape " + recTape.getId()); + + if (generateSegment) { + RecSegment recSegment = new RecSegment(); + recSegment.setTimestamp(timestamp); + recSegment.setDirection(stopMessage.getDirection()); + recSegment.setDuration(duration); + recSegment.setLocalParty(stopMessage.getLocalParty()); + recSegment.setLocalEntryPoint(stopMessage.getLocalEntryPoint()); + recSegment.setRecTape(recTape); + recSegment.setPort(recPort); + + if(stopMessage.getLocalParty() != "") { + User user = UserManager.instance().getByLoginString(stopMessage.getLocalParty(), hbnSession); + recSegment.setUser(user); + } + if (ProgramManager.instance().filterSegmentAgainstAllPrograms(recSegment, hbnSession)) { + hbnSession.save(recSegment); + log.info("#" + tapeMessage.getCapturePort() + ": written segment " + recSegment.getId()); + } + else { + log.info("#" + tapeMessage.getCapturePort() + ": tape message discarded"); } + } + else { + // segments are generated by metadata messages + addTapeToLocalCache(recTape); + findAndAssociateSegment(recTape, hbnSession); + } + } + } + } + + public RecPort getRecPort() { + return recPort; + } + + public void setRecPort(RecPort recPort) { + this.recPort = recPort; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/PortManager.java b/orktrack/src/net/sf/oreka/orktrack/PortManager.java new file mode 100644 index 0000000..09c18e9 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/PortManager.java @@ -0,0 +1,166 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import net.sf.oreka.HibernateManager; +import net.sf.oreka.persistent.RecPort; +import net.sf.oreka.persistent.RecPortFace; +import net.sf.oreka.persistent.Service; + +import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** Singleton class that manages activity on all capture ports */ +public class PortManager { + + HashMap portById = new HashMap(); + HashMap portByName = new HashMap(); + + static PortManager portManager = null; + Logger log = null; + + private PortManager () { + log = LogManager.getInstance().portLogger; + } + + public static PortManager instance() { + if (portManager == null) { + portManager = new PortManager(); + } + return portManager; + } + + public Port getPort(String name) { + return portByName.get(name); + } + + public Port getAndCreatePort(String name, Session hbnSession, Service service) { + + Port port = portByName.get(name); + if (port == null) { + + port = createPort(name, hbnSession, service); + } + return port; + } + + public synchronized Port createPort(String name, Session hbnSession, Service service) { + + RecPort recPort = null; + + RecPortFace portFace = (RecPortFace)hbnSession.get(RecPortFace.class, name); + if (portFace == null) { + portFace = new RecPortFace(); + portFace.setName(name); + portFace.setRecPort(recPort); + portFace.setService(service); + + recPort = new RecPort(); + portFace.setRecPort(recPort); + } + else { + portFace.setRecPort(recPort); + portFace.setService(service); + recPort = portFace.getRecPort(); + } + + hbnSession.save(recPort); + hbnSession.save(portFace); + + log.info("created port:" + recPort.getId() + " with face:" + name); + + Port port = new Port(recPort); + port.portFaces.add(portFace); + portById.put(recPort.getId(), port); + portByName.put(portFace.getName(), port); + return port; + } + + // for testing purposes + public void addPort(String face1, String face2, Session hbnSession) { + + RecPort recPort = new RecPort(); + Port port = new Port(recPort); + RecPortFace portFace1 = new RecPortFace(); + portFace1.setName(face1); + portFace1.setRecPort(recPort); + RecPortFace portFace2 = new RecPortFace(); + portFace2.setName(face2); + portFace2.setRecPort(recPort); + + hbnSession.save(recPort); + hbnSession.save(portFace1); + hbnSession.save(portFace2); + + port.portFaces.add(portFace1); + port.portFaces.add(portFace2); + portByName.put(face1, port); + portByName.put(face2, port); + portById.put(1, port); + } + + public void initialize() { + + try { + Session session = HibernateManager.getSession(); + Transaction tx = session.beginTransaction(); + + Iterator portFaces = session.createQuery( + "from RecPortFace") + .list() + .iterator(); + + while ( portFaces.hasNext() ) { + RecPortFace portFace = (RecPortFace)portFaces.next(); + + int portId = portFace.getRecPort().getId(); + Port port = portById.get(portId); + if(port == null) { + RecPort recPort = (RecPort)session.get(RecPort.class, portId); + if (recPort != null) { + port = new Port(recPort); + portById.put(portId, port); + } + } + port.portFaces.add(portFace); + portByName.put(portFace.getName(), port); + } + tx.commit(); + session.close(); + } + catch (Exception e) { + log.warn("HibernateManager.initialize: could not initialize", e); + } + } + + public RecPort getRecPortByFace(String face, Session hbnSession) { + RecPort port = null; + List ports = hbnSession.createQuery( + "from RecPortFace as pf join pf.recPort as p where pf.name=:face") + .setString("face", face) + .list(); + if (ports.size() > 0) { + Object[] row = (Object[])ports.get(0); + if (row.length > 1) { + port = (RecPort)row[1]; + } + } + return port; + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/ProgramManager.java b/orktrack/src/net/sf/oreka/orktrack/ProgramManager.java new file mode 100644 index 0000000..6b8a54c --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/ProgramManager.java @@ -0,0 +1,158 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.util.ArrayList; +import java.util.List; + +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; + +import org.apache.log4j.Logger; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class ProgramManager { + + private Logger log = null; + + private static ProgramManager programManager = null; + private ArrayList recPrograms = new ArrayList(); + + private ProgramManager() { + log = LogManager.getInstance().getPortLogger();; + } + + public static ProgramManager instance() { + + if (programManager == null) { + programManager = new ProgramManager(); + } + return programManager; + } + + public void load() { + + Session hbnSession = null; + Transaction tx = null; + + try { + hbnSession = HibernateManager.getSession(); + tx = hbnSession.beginTransaction(); + + List progs = hbnSession.createQuery( + "from RecProgram as prg where prg.active=:active and prg.discarded=:discarded") + .setBoolean("active", true) + .setBoolean("discarded", false) + .list(); + + recPrograms = new ArrayList(progs); + tx.commit(); + } + catch (Exception e) { + log.error("Could not load programs", e); + } + finally { + hbnSession.close(); + } + } + + public void addProgram(RecProgram prog) { + + recPrograms.add(prog); + } + + public boolean filterSegmentAgainstAllPrograms(RecSegment seg, Session hbnSession) { + + boolean result = false; + // Iterate over programs + ArrayList progs = recPrograms; + for(int i=0; i 0 && + (seg.getDuration() > (prog.getMaxDuration()*1000))) { + drop = true; + } + + if ( !drop && prog.getMinDuration() > 0 && + (seg.getDuration() < (prog.getMinDuration()*1000))) { + drop = true; + } + + if (!drop && prog.getRandomPercent() != 0.0) { + double randomNumber = java.lang.Math.random(); + if (randomNumber > prog.getRandomPercent()) { + drop = true; + } + } + + if ( !drop && prog.getLocalParty().length() > 0 && + (!seg.getLocalParty().equals(prog.getLocalParty())) ) { + drop = true; + } + + if ( !drop && prog.getRemoteParty().length() > 0 && + (!seg.getRemoteParty().equals(prog.getRemoteParty())) ) { + drop = true; + } + + if ( !drop && + (prog.getTargetUser() != null) && + (seg.getUser().getId() != prog.getTargetUser().getId()) ) { + drop = true; + } + + if ( !drop && + (prog.getTargetPort() != null) && + (seg.getPort().getId() != prog.getTargetPort().getId()) ) { + drop = true; + } + + if ( !drop && + prog.getRecordedSoFar() < prog.getRecPerCycle() ) + drop = true; + + if(drop == false) { + // All criteria have passed, the segment is accepted by the program + prog.setRecordedSoFar(prog.getRecordedSoFar() + 1); + hbnSession.update(prog); + seg.getRecPrograms().add(prog); + result = true; + } + return result; + } + + public void filterTime() { + ; + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/ServiceManager.java b/orktrack/src/net/sf/oreka/orktrack/ServiceManager.java new file mode 100644 index 0000000..b29c13e --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/ServiceManager.java @@ -0,0 +1,54 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.util.List; + +import net.sf.oreka.persistent.Service; + +import org.apache.log4j.Logger; +import org.hibernate.Session; + +public class ServiceManager { + + static Logger log = null; + + static void initialize() { + log = LogManager.getInstance().getPortLogger(); + } + + public static Service retrieveOrCreate(String name, Session hbnSession) { + Service service = retrieveByName(name, hbnSession); + if (service == null) { + log.info("Creating service:" + name); + service = new Service(); + service.setName(name); + hbnSession.save(service); + } + return service; + } + + public static Service retrieveByName(String name, Session hbnSession) { + + Service service = null; + List services = hbnSession.createQuery( + "from Service as srv where srv.name=:name") + .setString("name", name) + .list(); + if (services.size() > 0) { + service = (Service)services.get(0); + } + return service; + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/UserManager.java b/orktrack/src/net/sf/oreka/orktrack/UserManager.java new file mode 100644 index 0000000..4c5ce02 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/UserManager.java @@ -0,0 +1,66 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack; + +import java.util.HashMap; +import java.util.List; + +import net.sf.oreka.persistent.User; + +import org.apache.log4j.Logger; +import org.hibernate.Session; + +public class UserManager { + + private static Logger log = null; + private static UserManager userManager = null; + + private HashMap userLocations = new HashMap(); + + private UserManager() { + log = LogManager.getInstance().getUserLogger(); + } + + public static UserManager instance() { + + if(userManager == null) { + userManager = new UserManager(); + } + return userManager; + } + + public User getByLoginString(String loginString, Session hbnSession) { + + User user = null; + List users = hbnSession.createQuery( + "from LoginString as ls join ls.user as usr where ls.loginString=:loginstring") + .setString("loginstring", loginString) + .list(); + if (users.size() > 0) { + Object[] row = (Object[])users.get(0); + if (row.length > 1) { + user = (User)row[1]; + } + } + return user; + } + + public synchronized void setUserLocation(User user, Port port) { + userLocations.put(user, port); + } + + public synchronized Port getUserLocation(User user) { + return userLocations.get(user); + } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/messages/MetadataMessage.java b/orktrack/src/net/sf/oreka/orktrack/messages/MetadataMessage.java new file mode 100644 index 0000000..d6a2062 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/messages/MetadataMessage.java @@ -0,0 +1,207 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack.messages; + +import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Transaction; + +import net.sf.oreka.OrkException; +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SimpleResponseMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.orktrack.LogManager; +import net.sf.oreka.orktrack.Port; +import net.sf.oreka.orktrack.PortManager; +import net.sf.oreka.orktrack.ServiceManager; +import net.sf.oreka.orktrack.messages.TapeMessage.CaptureStage; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.serializers.OrkSerializer; +import net.sf.oreka.serializers.SingleLineSerializer; + +public class MetadataMessage extends SyncMessage { + + Logger log = null; + + CaptureStage stage = CaptureStage.unkn; + int timestamp = 0; + int duration = 0; + String capturePort = ""; + String localParty = ""; + String localEntryPoint = ""; + String remoteParty = ""; + Direction direction = Direction.UNKN; + String loginString = ""; + String service = ""; + + public MetadataMessage() { + log = LogManager.getInstance().getPortLogger(); + } + + @Override + public AsyncMessage process() { + + SimpleResponseMessage response = new SimpleResponseMessage(); + Session session = null; + Transaction tx = null; + try { + session = HibernateManager.getSession(); + tx = session.beginTransaction(); + boolean success = false; + + SingleLineSerializer ser = new SingleLineSerializer(); + log.info("Message: " + ser.serialize(this)); + + Service service = ServiceManager.retrieveByName(this.service, session); + + if (service != null) { + Port port = PortManager.instance().getAndCreatePort(this.getCapturePort(), session, service); + port.notifyMetadataMessage(this, session, service); + success = true; + } + else { + response.setComment("service:" + this.service + " does not exist"); + log.error("MetadataMessage.process: service" + this.service + " does not exist"); + } + + response.setSuccess(success); + if (success) {tx.commit();} + else {tx.rollback();} + } + catch (Exception e) { + if (tx != null) {tx.rollback();} + log.error("TapeMessage.process: ", e); + response.setSuccess(false); + response.setComment(e.getMessage()); + } + finally { + if(session != null) {session.close();} + } + return response; + } + + public void define(OrkSerializer serializer) throws OrkException { + + stage = (CaptureStage)serializer.enumValue("stage", stage, true); + timestamp = serializer.intValue("timestamp", timestamp, true); + duration = serializer.intValue("duration", duration, false); + capturePort = serializer.stringValue("capturePort", capturePort, true); + localParty = serializer.stringValue("localParty", localParty, false); + localEntryPoint = serializer.stringValue("localEntryPoint", localEntryPoint, false); + remoteParty = serializer.stringValue("remoteParty", remoteParty, false); + direction = (Direction)serializer.enumValue("direction", direction, false); + loginString = serializer.stringValue("loginString", loginString, false); + service = serializer.stringValue("service", service, true); + } + + public String getOrkClassName() { + return "metadata"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + + public String getCapturePort() { + return capturePort; + } + + public void setCapturePort(String capturePort) { + this.capturePort = capturePort; + } + + public Direction getDirection() { + return direction; + } + + public void setDirection(Direction direction) { + this.direction = direction; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public String getLocalEntryPoint() { + return localEntryPoint; + } + + public void setLocalEntryPoint(String localEntryPoint) { + this.localEntryPoint = localEntryPoint; + } + + public String getLocalParty() { + return localParty; + } + + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + public Logger getLog() { + return log; + } + + public void setLog(Logger log) { + this.log = log; + } + + public String getLoginString() { + return loginString; + } + + public void setLoginString(String loginString) { + this.loginString = loginString; + } + + public String getRemoteParty() { + return remoteParty; + } + + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + public String getService() { + return service; + } + + public void setService(String service) { + this.service = service; + } + + public CaptureStage getStage() { + return stage; + } + + public void setStage(CaptureStage stage) { + this.stage = stage; + } + + public int getTimestamp() { + return timestamp; + } + + public void setTimestamp(int timestamp) { + this.timestamp = timestamp; + } + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/messages/TapeMessage.java b/orktrack/src/net/sf/oreka/orktrack/messages/TapeMessage.java new file mode 100644 index 0000000..12c66b2 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/messages/TapeMessage.java @@ -0,0 +1,202 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack.messages; + +import net.sf.oreka.OrkException; +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SimpleResponseMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.orktrack.LogManager; +import net.sf.oreka.orktrack.Port; +import net.sf.oreka.orktrack.PortManager; +import net.sf.oreka.orktrack.ServiceManager; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.serializers.OrkSerializer; +import net.sf.oreka.serializers.SingleLineSerializer; + +import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class TapeMessage extends SyncMessage { + + public enum CaptureStage {start , stop, complete, unkn}; + + Logger log = null; + + CaptureStage stage = CaptureStage.unkn; + int timestamp = 0; + int duration = 0; + String filename = ""; + String capturePort = ""; + String localParty = ""; + String localEntryPoint = ""; + String remoteParty = ""; + Direction direction = Direction.UNKN; + String loginString = ""; + String service = ""; + + public TapeMessage() { + log = LogManager.getInstance().getPortLogger(); + } + + public String getService() { + return service; + } + + public void setService(String service) { + this.service = service; + } + + @Override + public AsyncMessage process() { + + SimpleResponseMessage response = new SimpleResponseMessage(); + Session session = null; + Transaction tx = null; + + try { + session = HibernateManager.getSession(); + tx = session.beginTransaction(); + + SingleLineSerializer ser = new SingleLineSerializer(); + log.info("Message: " + ser.serialize(this)); + + Service service = ServiceManager.retrieveOrCreate(this.service, session); + + Port port = PortManager.instance().getAndCreatePort(this.getCapturePort(), session, service); + port.notifyTapeMessage(this, session, service); + + response.setSuccess(true); + tx.commit(); + } + catch (Exception e) { + if (tx != null) {tx.rollback();} + log.error("TapeMessage.process: ", e); + response.setSuccess(false); + response.setComment(e.getMessage()); + } + finally { + if(session != null) {session.close();} + } + return response; + } + + public void define(OrkSerializer serializer) throws OrkException { + + stage = (CaptureStage)serializer.enumValue("stage", stage, true); + timestamp = serializer.intValue("timestamp", timestamp, true); + duration = serializer.intValue("duration", duration, true); + filename = serializer.stringValue("filename", filename, true); + capturePort = serializer.stringValue("capturePort", capturePort, true); + localParty = serializer.stringValue("localParty", localParty, false); + localEntryPoint = serializer.stringValue("localEntryPoint", localEntryPoint, false); + remoteParty = serializer.stringValue("remoteParty", remoteParty, false); + direction = (Direction)serializer.enumValue("direction", direction, false); + loginString = serializer.stringValue("loginString", loginString, false); + service = serializer.stringValue("service", service, true); + } + + public String getOrkClassName() { + return "tape"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + + public String getCapturePort() { + return capturePort; + } + + public void setCapturePort(String capturePort) { + this.capturePort = capturePort; + } + + public Direction getDirection() { + return direction; + } + + public void setDirection(Direction direction) { + this.direction = direction; + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getLocalEntryPoint() { + return localEntryPoint; + } + + public void setLocalEntryPoint(String localEntryPoint) { + this.localEntryPoint = localEntryPoint; + } + + public String getLocalParty() { + return localParty; + } + + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + public String getLoginString() { + return loginString; + } + + public void setLoginString(String loginString) { + this.loginString = loginString; + } + + public String getRemoteParty() { + return remoteParty; + } + + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + public CaptureStage getStage() { + return stage; + } + + public void setStage(CaptureStage stage) { + this.stage = stage; + } + + public int getTimestamp() { + return timestamp; + } + + public void setTimestamp(int timestamp) { + this.timestamp = timestamp; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/messages/UserStateMessage.java b/orktrack/src/net/sf/oreka/orktrack/messages/UserStateMessage.java new file mode 100644 index 0000000..9800e24 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/messages/UserStateMessage.java @@ -0,0 +1,119 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack.messages; + +import net.sf.oreka.OrkException; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SimpleResponseMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.orktrack.LogManager; +import net.sf.oreka.orktrack.Port; +import net.sf.oreka.orktrack.PortManager; +import net.sf.oreka.orktrack.UserManager; +import net.sf.oreka.persistent.User; +import net.sf.oreka.serializers.OrkSerializer; + +import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class UserStateMessage extends SyncMessage { + + public enum UserState {login, logout, unkn}; + + private Logger log = null; + + private UserState userState = UserState.unkn; + private String loginString = ""; + private String recPort = ""; + + public UserStateMessage() { + log = LogManager.getInstance().getPortLogger(); + } + + @Override + public AsyncMessage process() { + + SimpleResponseMessage response = new SimpleResponseMessage(); + + Session hbnSession = null; + Transaction tx = null; + try { + String comment = ""; + boolean success = false; + hbnSession = HibernateManager.getSession(); + tx = hbnSession.beginTransaction(); + // find out user + User user = UserManager.instance().getByLoginString(loginString, hbnSession); + if (user == null) { + comment = "Could not find user for login string:" + loginString; + log.warn(comment); + } + else { + // find out port + Port port = PortManager.instance().getPort(recPort); + if (port == null) { + comment = "Could not find port for face:" + recPort; + log.warn(comment); + } + else { + if(userState == UserState.login) { + port.setUser(user); + UserManager.instance().setUserLocation(user, port); + log.info("user:" + loginString + " logging onto:" + recPort); + } + else if (userState == UserState.logout) { + port.setUser(null); + UserManager.instance().setUserLocation(user, null); + log.info("user:" + loginString + " logging out of:" + recPort); + } + success = true; + } + } + + response.setComment(comment); + response.setSuccess(success); + tx.commit(); + } + catch (Exception e) { + if (tx != null) {tx.rollback();} + log.error("TapeMessage.process: ", e); + response.setSuccess(false); + response.setComment(e.getMessage()); + } + finally { + if(hbnSession != null) {hbnSession.close();} + } + + return response; + } + + public void define(OrkSerializer serializer) throws OrkException { + + userState = (UserState)serializer.enumValue("userstate", userState, true); + loginString = serializer.stringValue("loginstring", loginString, true); + recPort = serializer.stringValue("recport", recPort, true); + } + + public String getOrkClassName() { + return "userstate"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + +} diff --git a/orktrack/src/net/sf/oreka/orktrack/test/PortTest.java b/orktrack/src/net/sf/oreka/orktrack/test/PortTest.java new file mode 100644 index 0000000..2c16784 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/test/PortTest.java @@ -0,0 +1,307 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack.test; + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.orktrack.OrkTrack; +import net.sf.oreka.orktrack.PortManager; +import net.sf.oreka.orktrack.ProgramManager; +import net.sf.oreka.orktrack.ServiceManager; +import net.sf.oreka.orktrack.messages.MetadataMessage; +import net.sf.oreka.orktrack.messages.TapeMessage; +import net.sf.oreka.persistent.LoginString; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.RecTape; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.persistent.User; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class PortTest extends TestCase { + + public static void main (String[] args) { + junit.textui.TestRunner.run (suite()); + } + protected void setUp() throws Exception { + OrkTrack.initialize("C:/oreka/log4j.properties", "C:/oreka/hsqldb.hbm.xml", "C:/oreka/orktrack.config.xml"); + } + public static Test suite() { + return new TestSuite(PortTest.class); + } + +// === commented out because touches private elements +// public void testAreTogether() { +// +// Port port = new Port(); +// +// long now = new Date().getTime(); +// RecTape tape = new RecTape(); +// tape.setTimestamp(new Date(now)); +// tape.setDuration(10000); +// +// RecSegment seg = new RecSegment(); +// seg.setTimestamp(new Date(now)); +// seg.setDuration(10000); +// +// assertTrue(port.areTogether(tape, seg)); +// +// tape.setTimestamp(new Date(now-2000)); +// assertTrue(port.areTogether(tape, seg)); +// +// tape.setTimestamp(new Date(now-4000)); +// assertFalse(port.areTogether(tape, seg)); +// +// tape.setTimestamp(new Date(now)); +// seg.setDuration(12000); +// assertTrue(port.areTogether(tape, seg)); +// +// seg.setDuration(14000); +// assertFalse(port.areTogether(tape, seg)); +// +// tape.setTimestamp(new Date(now)); +// tape.setDuration(10000); +// seg.setTimestamp(new Date(now+5000)); +// seg.setDuration(5000); +// assertTrue(port.areTogether(tape, seg)); +// +// seg.setDuration(8000); +// assertFalse(port.areTogether(tape, seg)); +// +// } + +//=== commented out because touches private elements +// public void testFindAndAssociateTape() throws Exception { +// +// Session hbnSession = HibernateManager.getSession(); +// Transaction tx = hbnSession.beginTransaction(); +// +// // case 1, a segment arrives after a tape +// Port port = new Port(); +// RecTape tape1 = new RecTape(); // older tape +// RecTape tape2 = new RecTape(); // newer tape +// RecTape fooTape = new RecTape(); // this is the one +// long now = new Date().getTime(); +// fooTape.setTimestamp(new Date(now)); +// tape1.setTimestamp(new Date(now-10000)); +// tape2.setTimestamp(new Date(now+10000)); +// fooTape.setDuration(10000); +// tape1.setDuration(10000); +// tape2.setDuration(10000); +// +// port.recTapes.addFirst(tape1); +// port.recTapes.addFirst(fooTape); +// port.recTapes.addFirst(tape2); +// +// RecSegment seg = new RecSegment(); +// seg.setTimestamp(new Date(now)); +// seg.setDuration(5000); +// port.findAndAssociateTape(seg, hbnSession); +// +// assertTrue(seg.getRecTape() == fooTape); +// assertTrue(seg.getRecTapeOffset() == 0); +// +// // case 2, a second segment arrives and is part of the same tape +// RecSegment seg2 = new RecSegment(); +// seg2.setTimestamp(new Date(now+4000)); +// seg2.setDuration(5000); +// port.findAndAssociateTape(seg2, hbnSession); +// +// assertTrue(seg2.getRecTape() == fooTape); +// assertTrue(seg2.getRecTapeOffset() == 4000); +// +// hbnSession.close(); +// } + +// public void testTapeMessage() throws Exception { +// +// // Generate start and stop messages +// TapeMessage startMsg = new TapeMessage(); +// startMsg.setCapturePort("port1"); +// startMsg.setService("service1"); +// startMsg.setStage(TapeMessage.CaptureStage.start); +// long startTime = new Date().getTime(); +// int startTimestamp = (int)(startTime/1000); +// startMsg.setTimestamp(startTimestamp); +// +// startMsg.process(); +// +// TapeMessage stopMsg = new TapeMessage(); +// stopMsg.setCapturePort("port1"); +// stopMsg.setDirection(Direction.in); +// stopMsg.setFilename("test.wav"); +// stopMsg.setLocalEntryPoint("dnis1"); +// stopMsg.setLocalParty("9833"); +// stopMsg.setRemoteParty("514-425-5678"); +// stopMsg.setService("service1"); +// stopMsg.setStage(TapeMessage.CaptureStage.stop); +// stopMsg.setTimestamp(startTimestamp + 10); +// +// stopMsg.process(); +// +// // verify database entities. +// Session hbnSession = HibernateManager.getSession(); +// Transaction tx = hbnSession.beginTransaction(); +// long time = ((long)startTimestamp)*1000; +// GregorianCalendar cal = new GregorianCalendar(); +// cal.setTimeInMillis(time); +// +// RecSegment seg = null; +// Iterator segments = hbnSession.createQuery( +// "from RecSegment as seg where seg.timestamp=:date") +// .setCalendar("date", cal) +// .list() +// .iterator(); +// if(segments.hasNext()) { +// seg = (RecSegment)segments.next(); +// assertTrue(seg.getLocalParty().equals("9833")); +// +// RecTape tape = seg.getRecTape(); +// assertTrue(tape.getFilename().equals("test.wav")); +// } +// else { +// fail(); +// } +// tx.commit(); +// hbnSession.close(); +// } + + public void testTapeAndMetadataMessage() throws Exception { + + Session hbnSession = HibernateManager.getSession(); + Transaction tx = hbnSession.beginTransaction(); + Service recService = ServiceManager.retrieveOrCreate("recservice", hbnSession); + Service ctiService = ServiceManager.retrieveOrCreate("ctiservice", hbnSession); + ctiService.setRecordMaster(true); + hbnSession.save(recService); + + User user = new User(); + user.setFirstname("salisse"); + LoginString ls = new LoginString(); + ls.setUser(user); + ls.setLoginString("1973"); + hbnSession.save(user); + hbnSession.save(ls); + + PortManager.instance().addPort("recport", "ctiport", hbnSession); + + // create program that does not filter anything + RecProgram prog1 = new RecProgram(); + hbnSession.save(prog1); + ProgramManager.instance().addProgram(prog1); + + tx.commit(); + hbnSession.close(); + + + + // Generate tape start and stop messages + TapeMessage startMsg = new TapeMessage(); + startMsg.setCapturePort("recport"); + startMsg.setService("recservice"); + startMsg.setStage(TapeMessage.CaptureStage.start); + long startTime = new Date().getTime(); + int startTimestamp = (int)(startTime/1000); + startMsg.setTimestamp(startTimestamp); + + startMsg.process(); + + TapeMessage stopMsg = new TapeMessage(); + stopMsg.setCapturePort("recport"); + stopMsg.setService("recservice"); + stopMsg.setDirection(Direction.IN); + stopMsg.setFilename("test.wav"); + stopMsg.setLocalEntryPoint("dnis1"); + stopMsg.setLocalParty("9833"); + stopMsg.setRemoteParty("514-425-5678"); + stopMsg.setStage(TapeMessage.CaptureStage.stop); + stopMsg.setTimestamp(startTimestamp + 10); + + stopMsg.process(); + + // Generate metadata start and stop messages + MetadataMessage mdStartMsg = new MetadataMessage(); + mdStartMsg.setStage(TapeMessage.CaptureStage.start); + mdStartMsg.setTimestamp(startTimestamp + 3); + mdStartMsg.setCapturePort("ctiport"); + mdStartMsg.setService("ctiservice"); + + mdStartMsg.process(); + + MetadataMessage mdStopMsg = new MetadataMessage(); + mdStopMsg.setStage(TapeMessage.CaptureStage.stop); + mdStopMsg.setLocalParty("1973"); + mdStopMsg.setTimestamp(startTimestamp + 5); + mdStopMsg.setCapturePort("ctiport"); + mdStopMsg.setService("ctiservice"); + + mdStopMsg.process(); + + // verify database entities. + hbnSession = HibernateManager.getSession(); + tx = hbnSession.beginTransaction(); + long time = ((long)(startTimestamp+3))*1000; + GregorianCalendar cal = new GregorianCalendar(); + cal.setTimeInMillis(time); + + RecSegment seg = null; + Iterator segments = hbnSession.createQuery( + "from RecSegment as seg where seg.timestamp=:date") + .setCalendar("date", cal) + .list() + .iterator(); + if(segments.hasNext()) { + seg = (RecSegment)segments.next(); + assertTrue(seg.getLocalParty().equals("1973")); + assertTrue(seg.getRecTapeOffset() == 3000); + + RecTape tape = seg.getRecTape(); + assertTrue(tape.getFilename().equals("test.wav")); + + User user2 = seg.getUser(); + assertTrue(user.getId() == user2.getId()); + } + else { + fail(); + } + tx.commit(); + hbnSession.close(); + } + +// public void testUserManager() throws Exception { +// +// Session hbnSession = HibernateManager.getSession(); +// Transaction tx = hbnSession.beginTransaction(); +// User user = new User(); +// user.setFirstname("salisse"); +// LoginString ls = new LoginString(); +// ls.setUser(user); +// ls.setLoginString("4568"); +// hbnSession.save(user); +// hbnSession.save(ls); +// User user2 = UserManager.getByLoginString("4568", hbnSession); +// assertTrue(user.getFirstname().equals(user2.getFirstname())); +// tx.commit(); +// hbnSession.close(); +// } +} diff --git a/orktrack/src/net/sf/oreka/orktrack/test/ProgramTest.java b/orktrack/src/net/sf/oreka/orktrack/test/ProgramTest.java new file mode 100644 index 0000000..8195398 --- /dev/null +++ b/orktrack/src/net/sf/oreka/orktrack/test/ProgramTest.java @@ -0,0 +1,128 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orktrack.test; + +import java.util.Iterator; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.orktrack.OrkTrack; +import net.sf.oreka.orktrack.ProgramManager; +import net.sf.oreka.persistent.LoginString; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.User; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class ProgramTest extends TestCase { + + public static void main (String[] args) { + junit.textui.TestRunner.run (suite()); + } + protected void setUp() throws Exception { + OrkTrack.initialize("C:/oreka/log4j.properties", "C:/oreka/mysql.hbm.xml", "C:/oreka/orktrack.config.xml"); + } + public static Test suite() { + return new TestSuite(ProgramTest.class); + } + + public void test1() throws Exception { + + + Session hbnSession = HibernateManager.getSession(); + Transaction tx = hbnSession.beginTransaction(); + + // create a user + User user = new User(); + user.setFirstname("mawagade"); + hbnSession.save(user); + LoginString ls = new LoginString(); + ls.setLoginString("1234"); + ls.setUser(user); + hbnSession.save(ls); + + // create a program + RecProgram prog1 = new RecProgram(); + prog1.setDirection(Direction.IN); + prog1.setTargetUser(user); + hbnSession.save(prog1); + + tx.commit(); + hbnSession.close(); + + ProgramManager.instance().load(); + + RecSegment seg = new RecSegment(); + seg.setDirection(Direction.IN); + seg.setUser(user); + + hbnSession = HibernateManager.getSession(); + tx = hbnSession.beginTransaction(); + if (ProgramManager.instance().filterSegmentAgainstAllPrograms(seg, hbnSession)) { + hbnSession.save(seg); + } + tx.commit(); + hbnSession.close(); + + // verify result + hbnSession = HibernateManager.getSession(); + tx = hbnSession.beginTransaction(); + RecProgram prog = (RecProgram)hbnSession.load(RecProgram.class, prog1.getId()); + assertTrue(prog.getRecordedSoFar() == 1); + Iterator it = prog.getRecSegments().iterator(); + assertTrue(it.next().getId() == seg.getId()); + tx.commit(); + hbnSession.close(); + } + +// public void testManyToMany() throws Exception { +// +// Session hbnSession = HibernateManager.getSession(); +// Transaction tx = hbnSession.beginTransaction(); +// +// // Create two programs +// RecProgram prog1 = new RecProgram(); +// hbnSession.save(prog1); +// RecProgram prog2 = new RecProgram(); +// hbnSession.save(prog2); +// +// // create 1000 segments +// for(int i=0; i<1000; i++) { +// RecSegment seg = new RecSegment(); +// seg.getRecPrograms().add(prog1); +// seg.getRecPrograms().add(prog2); +// hbnSession.save(seg); +// } +// +// tx.commit(); +// hbnSession.close(); +// +// hbnSession = HibernateManager.getSession(); +// tx = hbnSession.beginTransaction(); +// +// // create a new segment and add it to the program +// RecProgram prog = (RecProgram)hbnSession.load(RecProgram.class, prog2.getId()); +// RecSegment seg = new RecSegment(); +// seg.getRecPrograms().add(prog); +// hbnSession.save(seg); +// +// tx.commit(); +// hbnSession.close(); +// } +} diff --git a/orkweb/.classpath b/orkweb/.classpath new file mode 100644 index 0000000..9093aef --- /dev/null +++ b/orkweb/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/orkweb/.project b/orkweb/.project new file mode 100644 index 0000000..56a2e2b --- /dev/null +++ b/orkweb/.project @@ -0,0 +1,17 @@ + + + orkweb + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/orkweb/context/WEB-INF/Home.html b/orkweb/context/WEB-INF/Home.html new file mode 100644 index 0000000..e2ff6d5 --- /dev/null +++ b/orkweb/context/WEB-INF/Home.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + +
Here goes the main menu
+
+ + + + + + + + + + + + + + + + + + +
+ Please login +
+ + Error Message + +
Username
Password
+
+
+ + \ No newline at end of file diff --git a/orkweb/context/WEB-INF/Home.page b/orkweb/context/WEB-INF/Home.page new file mode 100644 index 0000000..93a41cd --- /dev/null +++ b/orkweb/context/WEB-INF/Home.page @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/orkweb/context/WEB-INF/RecSegments.html b/orkweb/context/WEB-INF/RecSegments.html new file mode 100644 index 0000000..cf4cf42 --- /dev/null +++ b/orkweb/context/WEB-INF/RecSegments.html @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + +
Here goes the main menu
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
error in this field
Min Duration
error in this field
Max Duration
error in this field
Local Party
error in this field
Remote Party
Start Date
End Date
+ + + Outgoing Out + Incoming In + Both Both + +
+ + + + + + + + + + + + + +
+
+
+ + + + + + + + + + +
Paging goes here
+ + + + +
+ + + + + + + + + + + +
timestampdurationlocal party + + In + Out + remote party + + tape id + + + + Play + +
+
+
Paging goes here
+
+ No results +
+ + + + \ No newline at end of file diff --git a/orkweb/context/WEB-INF/RecSegments.page b/orkweb/context/WEB-INF/RecSegments.page new file mode 100644 index 0000000..5894409 --- /dev/null +++ b/orkweb/context/WEB-INF/RecSegments.page @@ -0,0 +1,44 @@ + + + + + + + + + + new java.util.ArrayList() + + + new net.sf.oreka.services.RecSegmentFilter() + + + new net.sf.oreka.tapestry.TableState() + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/orkweb/context/WEB-INF/RecSegments.properties b/orkweb/context/WEB-INF/RecSegments.properties new file mode 100644 index 0000000..a8606db --- /dev/null +++ b/orkweb/context/WEB-INF/RecSegments.properties @@ -0,0 +1,18 @@ + +Duration=Duration +LocalParty=Local Party +RemoteParty=Remote Party + +seg.timestamp=Time +seg.direction=Direction +seg.duration=Duration +seg.localParty=Local Party +seg.remoteParty=Remote Party +tape.id=Tape Id + +firstPage=<< +lastPage=>> +previousPage=< +nextPage=> + +NoResults=There was no results \ No newline at end of file diff --git a/orkweb/context/WEB-INF/TestComponent.html b/orkweb/context/WEB-INF/TestComponent.html new file mode 100644 index 0000000..e295913 --- /dev/null +++ b/orkweb/context/WEB-INF/TestComponent.html @@ -0,0 +1,10 @@ + + + + +
+ * + + goHome + +
\ No newline at end of file diff --git a/orkweb/context/WEB-INF/orkweb.application b/orkweb/context/WEB-INF/orkweb.application new file mode 100644 index 0000000..3a3b934 --- /dev/null +++ b/orkweb/context/WEB-INF/orkweb.application @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + diff --git a/orkweb/context/WEB-INF/web.xml b/orkweb/context/WEB-INF/web.xml new file mode 100644 index 0000000..7fd4fa3 --- /dev/null +++ b/orkweb/context/WEB-INF/web.xml @@ -0,0 +1,42 @@ + + + + + + + orkweb + + Log4jConfigFile + c:/oreka/orkweb/log4j.properties + + + HibernateConfigFile + c:/oreka/orkweb/mysql.hbm.xml + + + Debug + true + + + redirect + org.apache.tapestry.RedirectFilter + + + redirect + / + + + net.sf.oreka.orkweb.ContextListener + + + orkweb + org.apache.tapestry.ApplicationServlet + 1 + + + orkweb + /app + + diff --git a/orkweb/context/css/base.css b/orkweb/context/css/base.css new file mode 100644 index 0000000..499a858 --- /dev/null +++ b/orkweb/context/css/base.css @@ -0,0 +1,394 @@ + +td.navigation { + color: gray; +} + +td.navigation a { +} + +BODY { + SCROLLBAR-FACE-COLOR: #448BF5; + SCROLLBAR-HIGHLIGHT-COLOR: #448BF5; + SCROLLBAR-SHADOW-COLOR: #0066CC; + SCROLLBAR-3DLIGHT-COLOR: #33CCFF; + SCROLLBAR-ARROW-COLOR: #66CCFF; + SCROLLBAR-TRACK-COLOR: #99CCFF; + SCROLLBAR-DARKSHADOW-COLOR: #0066CC; + font-family : Verdana; + font-size: 8pt; +} + +A { + color: #0071E1; + text-decoration: none; +} + +A:hover { + color: #848484; + text-decoration: underline; +} + +TD { + font-family : Verdana; + font-size: 8pt; +} + +th, .th, th a { + font-family : Arial; + font-size: 10pt; + color: #ffffff; + background-color: #0073E7; + padding-left: 3; padding-right: 3; + font-weight: bold; +} + +th a:hover { + color: #ffffff; +} + +th.dayname { + font-size: 9pt; + font-weight: normal; +} + +td.weekend, tr.absence { + background-color: #FFE1E1; +} + +li.error { + color: red; +} + +td.topmenu { + color: #848484; + text-decoration: none; + FONT-SIZE: 9pt; + FONT-WEIGHT: bold; +} + + +td.topmenu a { + color: #0073E7; +} + +td.topmenu a:hover { + color: #848484; +} + +tr.odd td.noborder, tr.even td.noborder { + background-color: #ffffff; + padding-left: 0; padding-right: 0; +} + +tr.odd td, tr.even td, tr.header td { + padding-left: 4; padding-right: 4; +} + +tr.even { + background-color: #ffffff; +} + +tr.odd { + background-color: #eeeeee; +} + +tr.header { + background-color: #dddddd; +} + +.tdFrame { + background-color: #ffffff; + padding-left: 4; padding-right: 4; + border: 1px solid #eeeeee; +} + +.tdFrameRed { + background-color: #ffffff; + padding-left: 4; padding-right: 4; + border: 2px solid #ff0000; +} + +.tdCalendar1 { + color: #848484; + background-color: #ffffff; + text-decoration: none; + FONT-FAMILY: verdana; + FONT-SIZE: 12pt; + FONT-WEIGHT: bold; +} +.calendarEvent { + color: #000000; + font-family : Verdana; + font-size: 8pt; + text-decoration: none; +} +.calendarEvent:hover { + color: #000000; +} + + +td.label { + font-weight: bold; +} + +td.input { + +} + +td.readOnly { + border: 1px solid #dddddd; padding-left: 4; padding-right: 4; +} + +td.readOnly a { + font-weight: normal; +} + +td.filterLabel { + font-weight: bold; +} + + +H2 { + + font-family : Arial; + font-size: 14pt; + color:# 094E92; +} + +H3 { + font-family : Arial; + font-size: 12pt; + color: #094E92; +} + +H4 { + font-family : Arial; + font-size: 10pt; + color: #094E92; +} + +H5 { + font-family : Verdana, Arial; + font-size: 11px; + color: #094E92; +} + +a.menu { + color: white; + text-decoration: none; + FONT-FAMILY: verdana; + FONT-SIZE: 7pt; + FONT-WEIGHT: normal; +} + +a.menu:hover { + color: black; + text-decoration: underline; + FONT-FAMILY: verdana; + FONT-SIZE: 7pt; + FONT-WEIGHT: normal; +} + +a.g { + color: silver; + text-decoration: none; + +} + +a.g:hover { + color: black; + text-decoration: underline; + +} + +HR { + color: #0071E1; + height: 1pt; +} + +HR.gray { + color: #eeeeee; + height: 1pt; +} + +.male { + color : black; + font-family : Arial; + font-size: 8pt; +} + + +.malevs { + + color : silver; + font-family : Verdana; + font-size: 8pt; + +} + +.nadpis { + font-family : Arial; + font-size: 12pt; + color: #094E92; + font-weight : bold; +} + +.tickerstyle {font-family:"Arial"; font-size:11pt; color:#000000;} + +UL { + + font-family : Verdana; + font-size: 8pt; + +} + +.TDMezi {background: #EEEEEE;} + +LI { + + font-family : Verdana; + font-size: 8pt; + +} + +#box { +position:absolute; +visibility:hidden; +layer-background-color:silver } + +#bluebox { + background-color: #448BF5; + FONT-FAMILY: verdana; + FONT-SIZE: 7pt; + FONT-WEIGHT: normal; +} + +#mnubar { + FONT-FAMILY: verdana; + FONT-SIZE: 8pt; + FONT-WEIGHT: normal; +} + +INPUT { + font-family : Verdana; + font-size: 8pt; + color : Black; + background : #FFFFFF; +} + +INPUT.error { + background : #aaaaaa; +} + +INPUT.Button01 { + background-color:#448BF5; + border-style:1px; + font-family : Verdana; + font-size: 8pt; + color : White; +} + +SELECT.Button01 { + background-color:#448BF5; + border-style:1px; + font-family : Verdana; + font-size: 8pt; + color : White; +} + +OPTION.Button01 { + background-color:#448BF5; + border-style:1px; + font-family : Verdana; + font-size: 8pt; + color : White; +} + +.velke { + font-family : Arial; + font-size: 12pt; + color: #094E92; +} + +.barevneAtluste { + color: #094E92; + font-weight: bold; +} + +.Symboly { + + font-family : Symbol, SymbolPS; + font-size: 8pt; + +} + +li.PodMenuArrow { list-style-position: outside; list-style-image: url(../images/sipecka_smala.gif); } + +#Roztahly { + text-align: justify; +} + +TD.error { + font-weight: bold; + color: red; +} + +TD.TDHead { + border-bottom: 1px solid #0071E1; + border-top: 1px solid #0071E1; + font-weight: bold; +} + +TD.TDHeadFull { + border-bottom: 1px solid #0071E1; + border-top: 1px solid #0071E1; + border-right: 1px solid #0071E1; + border-left: 1px solid #0071E1; + font-weight: bold; +} + +TD.TDHeadFullRight { + border-bottom: 1px solid #0071E1; + border-top: 1px solid #0071E1; + border-right: 1px solid #0071E1; + font-weight: bold; +} + + +TD.TDHeadFullLeft { + border-bottom: 1px solid #0071E1; + border-top: 1px solid #0071E1; + border-left: 1px solid #0071E1; + font-weight: bold; +} + +TD.TDSeznam { + border-bottom: 1px solid #DBDBDB; +} + +TD.TDSeznamFull { + border-bottom: 1px solid #DBDBDB; + border-left: 1px solid #DBDBDB; + border-right: 1px solid #DBDBDB; +} + +TD.TDSeznamFullRight { + border-bottom: 1px solid #DBDBDB; + border-right: 1px solid #DBDBDB; +} + +TD.TDSeznamFullLeft { + border-bottom: 1px solid #DBDBDB; + border-left: 1px solid #DBDBDB; +} + + +span.Kod { + font-family: "Courier New", Courier, monospace; + font-size: 9px; + color: #094E92; +} + +TD.TDSeznamBarevny { + border-bottom: 1px solid #0071E1; +} \ No newline at end of file diff --git a/orkweb/context/css/orekastyle.css b/orkweb/context/css/orekastyle.css new file mode 100644 index 0000000..343b65c --- /dev/null +++ b/orkweb/context/css/orekastyle.css @@ -0,0 +1,115 @@ +body { + margin: 0; padding: 0; + font-family: Arial, Helvetica, sans-serif; + font-size: 11px;} +img {border: 0;} + +#masthead {padding: 2px;} + +.menuContainer { + font-weight: bold; + border-bottom: 1px solid #000000; + border-top: 1px solid #000000; + background-color: #E6E6E6; + background-image: url(../images/menuback1.gif); + background-repeat: repeat-x; + padding: 0px; + margin: 0px; +} +.menubuttons { +} +.menubuttons td { + background-color: #E9E9E9; + text-align: center; + padding: 2px 8px; + border: 1px solid #000000; +} +.menubuttons td.on { + color: #FFFFFF; + background-color: #003366; + text-align: center; +} + +.menubuttons td.on a {color: #FFF;} + +.menubuttons a {display: block;} +.menubuttons a:link {color: #003366;} +.menubuttons a:visited {color: #003366;} +.menubuttons a:hover {color:#FFCC00;} + +.inputform { + padding: 0px; width: 350px; + /*border: 1px solid #000000;*/ +} +.inputform th { + text-align: right; +} + +.inputform td { + padding: 4px; font-weight: bold; +} + +.inputform input {font-weight: normal;} +.error { + font-size: 10px; + font-style: italic; + color: #FF0000; +} +.cursor { + background-color: white; + text-align: right; + padding-right: 0; +} + +.cursor div { + border-top: solid 2px #930512; + background-color: #FD0D24; + border-bottom: solid 2px #930512; + text-align: right; + color: white; + float: left; + padding-top: 0; + height: 1em; +} + +.bar { + background-color: white; + text-align: right; + padding-right: 0; +} + +.bar div { + border-top: solid 2px #03144B; + background-color: #0930AC; + border-bottom: solid 2px #03144B; + text-align: right; + color: white; + float: left; + padding-top: 0; + height: 1em; +} + +table#container { + border: 1px solid #000000; + padding: 0px; + margin: 0px; + width: 100%; + background-image:url(../images/bg_container.jpg); background-repeat: repeat-x; +} +table#container td {vertical-align: top;} +td.criteria {border: 1px solid #000; width: 350px; background-color: #FFF;} +td.results {border: 1px solid #000; background-color: #FFF;} +td.results table {width: 100%;} + +tr.header {font-weight: bold; background-color:#333333; color: #fff;} +tr.header td {padding: 4px;} +tr.header a:link {color: #FFF; text-decoration: none;} +tr.header a:visited {color: #FFF; text-decoration: none;} +tr.header a:hover {text-decoration: underline;} + +tr.even {background-color: #EAEAEA;} +tr.odd {background-color:#E0E0E0;} + +td.results table.paging {width: auto;} +.paging tr.odd {background-color:#FFFFFF;} +.paging tr.even {background-color:#FFFFFF;} diff --git a/orkweb/context/images/bg_container.gif b/orkweb/context/images/bg_container.gif new file mode 100644 index 0000000..63aa265 Binary files /dev/null and b/orkweb/context/images/bg_container.gif differ diff --git a/orkweb/context/images/bg_container.jpg b/orkweb/context/images/bg_container.jpg new file mode 100644 index 0000000..51657f1 Binary files /dev/null and b/orkweb/context/images/bg_container.jpg differ diff --git a/orkweb/context/images/icon_calendar.gif b/orkweb/context/images/icon_calendar.gif new file mode 100644 index 0000000..a0482f0 Binary files /dev/null and b/orkweb/context/images/icon_calendar.gif differ diff --git a/orkweb/context/images/icon_in.gif b/orkweb/context/images/icon_in.gif new file mode 100644 index 0000000..9f130e5 Binary files /dev/null and b/orkweb/context/images/icon_in.gif differ diff --git a/orkweb/context/images/icon_out.gif b/orkweb/context/images/icon_out.gif new file mode 100644 index 0000000..eeba975 Binary files /dev/null and b/orkweb/context/images/icon_out.gif differ diff --git a/orkweb/context/images/icon_pagefirst.gif b/orkweb/context/images/icon_pagefirst.gif new file mode 100644 index 0000000..327f0be Binary files /dev/null and b/orkweb/context/images/icon_pagefirst.gif differ diff --git a/orkweb/context/images/icon_pagelast.gif b/orkweb/context/images/icon_pagelast.gif new file mode 100644 index 0000000..560fb0a Binary files /dev/null and b/orkweb/context/images/icon_pagelast.gif differ diff --git a/orkweb/context/images/icon_pagenext.gif b/orkweb/context/images/icon_pagenext.gif new file mode 100644 index 0000000..7e3a275 Binary files /dev/null and b/orkweb/context/images/icon_pagenext.gif differ diff --git a/orkweb/context/images/icon_pageprev.gif b/orkweb/context/images/icon_pageprev.gif new file mode 100644 index 0000000..346a814 Binary files /dev/null and b/orkweb/context/images/icon_pageprev.gif differ diff --git a/orkweb/context/images/icon_play.gif b/orkweb/context/images/icon_play.gif new file mode 100644 index 0000000..1835148 Binary files /dev/null and b/orkweb/context/images/icon_play.gif differ diff --git a/orkweb/context/images/logofpo.gif b/orkweb/context/images/logofpo.gif new file mode 100644 index 0000000..5e50fa5 Binary files /dev/null and b/orkweb/context/images/logofpo.gif differ diff --git a/orkweb/context/images/menuback1.gif b/orkweb/context/images/menuback1.gif new file mode 100644 index 0000000..27847d1 Binary files /dev/null and b/orkweb/context/images/menuback1.gif differ diff --git a/orkweb/deploy-template.xml b/orkweb/deploy-template.xml new file mode 100644 index 0000000..343e65a --- /dev/null +++ b/orkweb/deploy-template.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${remove.result} + + + + + + + + + + + + + + + + + + ${install.result} + + + + + + -- cgit v1.2.3