diff options
Diffstat (limited to 'src')
28 files changed, 104 insertions, 1368 deletions
diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index 623b551..787e0ff 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -65,7 +65,7 @@ Factory::Factory() { pluma.acceptProviderType<InvokerImplProvider>(); pluma.acceptProviderType<IOProcessorImplProvider>(); pluma.acceptProviderType<DataModelImplProvider>(); - pluma.acceptProviderType<ElementImplProvider>(); + pluma.acceptProviderType<ExecutableContentImplProvider>(); pluma.loadFromFolder(pluginPath); std::vector<InvokerImplProvider*> invokerProviders; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 0c466c9..0bc0f2e 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -206,7 +206,7 @@ void Interpreter::init() { normalize(_document); if (_capabilities & CAN_GENERIC_HTTP) - _httpServlet = new HTTPServletInvoker(this); + _httpServlet = new InterpreterServlet(this); _sendQueue = new DelayedEventQueue(); _sendQueue->start(); @@ -297,8 +297,11 @@ void Interpreter::interpret() { if (_dataModel) { _dataModel.assign("_x.args", _cmdLineOptions); - if (_httpServlet) - _dataModel.assign("_ioprocessors['http']", _httpServlet->getDataModelVariables()); + if (_httpServlet) { + Data data; + data.compound["location"] = Data(_httpServlet->getURL(), Data::VERBATIM); + _dataModel.assign("_ioprocessors['http']", data); + } } setupIOProcessors(); diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 90c2b3b..9929f70 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -24,6 +24,8 @@ #include "uscxml/Message.h" #include "uscxml/Factory.h" +#include "uscxml/server/InterpreterServlet.h" + #define ORIG_ENTERSTATES namespace uscxml { @@ -120,7 +122,7 @@ public: return _cmdLineOptions; } - HTTPServletInvoker* getHTTPServlet() { + InterpreterServlet* getHTTPServlet() { return _httpServlet; } @@ -247,7 +249,7 @@ protected: Event _currEvent; - HTTPServletInvoker* _httpServlet; + InterpreterServlet* _httpServlet; std::set<InterpreterMonitor*> _monitors; diff --git a/src/uscxml/plugins/Plugins.cpp b/src/uscxml/plugins/Plugins.cpp index 65740e1..1f74a28 100644 --- a/src/uscxml/plugins/Plugins.cpp +++ b/src/uscxml/plugins/Plugins.cpp @@ -6,7 +6,7 @@ namespace uscxml { PLUMA_PROVIDER_SOURCE(DataModelImpl, 1, 1); PLUMA_PROVIDER_SOURCE(IOProcessorImpl, 1, 1); PLUMA_PROVIDER_SOURCE(InvokerImpl, 1, 1); -PLUMA_PROVIDER_SOURCE(ElementImpl, 1, 1); +PLUMA_PROVIDER_SOURCE(ExecutableContentImpl, 1, 1); #endif }
\ No newline at end of file diff --git a/src/uscxml/plugins/Plugins.h b/src/uscxml/plugins/Plugins.h index 338dcaf..8b574b1 100644 --- a/src/uscxml/plugins/Plugins.h +++ b/src/uscxml/plugins/Plugins.h @@ -9,7 +9,7 @@ namespace uscxml { #ifdef BUILD_AS_PLUGINS PLUMA_PROVIDER_HEADER(IOProcessorImpl); PLUMA_PROVIDER_HEADER(InvokerImpl); -PLUMA_PROVIDER_HEADER(ElementImpl); +PLUMA_PROVIDER_HEADER(ExecutableContentImpl); PLUMA_PROVIDER_HEADER(DataModelImpl); #endif diff --git a/src/uscxml/plugins/element/fetch/FetchElement.h b/src/uscxml/plugins/element/fetch/FetchElement.h index aadbb7c..b553293 100644 --- a/src/uscxml/plugins/element/fetch/FetchElement.h +++ b/src/uscxml/plugins/element/fetch/FetchElement.h @@ -40,7 +40,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(FetchElement, Element); +PLUMA_INHERIT_PROVIDER(FetchElement, ExecutableContentImpl); #endif } diff --git a/src/uscxml/plugins/element/postpone/PostponeElement.h b/src/uscxml/plugins/element/postpone/PostponeElement.h index 268493f..7886415 100644 --- a/src/uscxml/plugins/element/postpone/PostponeElement.h +++ b/src/uscxml/plugins/element/postpone/PostponeElement.h @@ -63,7 +63,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(PostponeElement, Element); +PLUMA_INHERIT_PROVIDER(PostponeElement, ExecutableContentImpl); #endif } diff --git a/src/uscxml/plugins/element/response/ResponseElement.cpp b/src/uscxml/plugins/element/response/ResponseElement.cpp index 2da0d07..cd7ef2d 100644 --- a/src/uscxml/plugins/element/response/ResponseElement.cpp +++ b/src/uscxml/plugins/element/response/ResponseElement.cpp @@ -35,7 +35,7 @@ void ResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) std::string requestId = (HAS_ATTR(node, "request") ? ATTR(node, "request") : _interpreter->getDataModel().evalAsString(ATTR(node, "requestexpr"))); // try to get the request object - HTTPServletInvoker* servlet = _interpreter->getHTTPServlet(); + InterpreterServlet* servlet = _interpreter->getHTTPServlet(); tthread::lock_guard<tthread::recursive_mutex> lock(servlet->getMutex()); if (servlet->getRequests().find(requestId) == servlet->getRequests().end()) { diff --git a/src/uscxml/plugins/element/response/ResponseElement.h b/src/uscxml/plugins/element/response/ResponseElement.h index 9b3ce61..de3991c 100644 --- a/src/uscxml/plugins/element/response/ResponseElement.h +++ b/src/uscxml/plugins/element/response/ResponseElement.h @@ -33,7 +33,7 @@ public: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(ResponseElement, Element); +PLUMA_INHERIT_PROVIDER(ResponseElement, ExecutableContentImpl); #endif } diff --git a/src/uscxml/plugins/invoker/ffmpeg/FFMPEGInvoker.h b/src/uscxml/plugins/invoker/ffmpeg/FFMPEGInvoker.h index 9b1b0ca..734467f 100644 --- a/src/uscxml/plugins/invoker/ffmpeg/FFMPEGInvoker.h +++ b/src/uscxml/plugins/invoker/ffmpeg/FFMPEGInvoker.h @@ -31,7 +31,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(FFMPEGInvoker, Invoker); +PLUMA_INHERIT_PROVIDER(FFMPEGInvoker, InvokerImpl); #endif } diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h b/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h index 3fd9258..e2abf54 100644 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h +++ b/src/uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h @@ -91,7 +91,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(DirMonInvoker, Invoker); +PLUMA_INHERIT_PROVIDER(DirMonInvoker, InvokerImpl); #endif } diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcher.cpp b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcher.cpp deleted file mode 100644 index 9399495..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcher.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/**
- Copyright (c) 2009 James Wynn (james@jameswynn.com)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#include <FileWatcher/FileWatcher.h>
-#include <FileWatcher/FileWatcherImpl.h>
-
-#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32
-# include <FileWatcher/FileWatcherWin32.h>
-# define FILEWATCHER_IMPL FileWatcherWin32
-#elif FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE
-# include <FileWatcher/FileWatcherOSX.h>
-# define FILEWATCHER_IMPL FileWatcherOSX
-#elif FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX
-# include <FileWatcher/FileWatcherLinux.h>
-# define FILEWATCHER_IMPL FileWatcherLinux
-#endif
-
-namespace FW {
-
-//--------
-FileWatcher::FileWatcher() {
- mImpl = new FILEWATCHER_IMPL();
-}
-
-//--------
-FileWatcher::~FileWatcher() {
- delete mImpl;
- mImpl = 0;
-}
-
-//--------
-WatchID FileWatcher::addWatch(const String& directory, FileWatchListener* watcher) {
- return mImpl->addWatch(directory, watcher, false);
-}
-
-//--------
-WatchID FileWatcher::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) {
- return mImpl->addWatch(directory, watcher, recursive);
-}
-
-//--------
-void FileWatcher::removeWatch(const String& directory) {
- mImpl->removeWatch(directory);
-}
-
-//--------
-void FileWatcher::removeWatch(WatchID watchid) {
- mImpl->removeWatch(watchid);
-}
-
-//--------
-void FileWatcher::update() {
- mImpl->update();
-}
-
-};//namespace FW
diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcher.h b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcher.h deleted file mode 100644 index 0e659b6..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcher.h +++ /dev/null @@ -1,141 +0,0 @@ -/**
- Main header for the FileWatcher class. Declares all implementation
- classes to reduce compilation overhead.
-
- @author James Wynn
- @date 4/15/2009
-
- Copyright (c) 2009 James Wynn (james@jameswynn.com)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#ifndef _FW_FILEWATCHER_H_
-#define _FW_FILEWATCHER_H_
-#pragma once
-
-#include <string>
-#include <stdexcept>
-
-namespace FW {
-/// Type for a string
-typedef std::string String;
-/// Type for a watch id
-typedef unsigned long WatchID;
-
-// forward declarations
-class FileWatcherImpl;
-class FileWatchListener;
-
-/// Base exception class
-/// @class Exception
-class Exception : public std::runtime_error {
-public:
- Exception(const String& message)
- : std::runtime_error(message)
- {}
-};
-
-/// Exception thrown when a file is not found.
-/// @class FileNotFoundException
-class FileNotFoundException : public Exception {
-public:
- FileNotFoundException()
- : Exception("File not found")
- {}
-
- FileNotFoundException(const String& filename)
- : Exception("File not found (" + filename + ")")
- {}
-};
-
-/// Actions to listen for. Rename will send two events, one for
-/// the deletion of the old file, and one for the creation of the
-/// new file.
-namespace Actions {
-enum Action {
- /// Sent when a file is created or renamed
- Add = 1,
- /// Sent when a file is deleted or renamed
- Delete = 2,
- /// Sent when a file is modified
- Modified = 4,
- /// Sent when an existing file is reported
- Existing = 8
-};
-};
-typedef Actions::Action Action;
-
-/// Listens to files and directories and dispatches events
-/// to notify the parent program of the changes.
-/// @class FileWatcher
-class FileWatcher {
-public:
- ///
- ///
- FileWatcher();
-
- ///
- ///
- virtual ~FileWatcher();
-
- /// Add a directory watch. Same as the other addWatch, but doesn't have recursive option.
- /// For backwards compatibility.
- /// @exception FileNotFoundException Thrown when the requested directory does not exist
- WatchID addWatch(const String& directory, FileWatchListener* watcher);
-
- /// Add a directory watch
- /// @exception FileNotFoundException Thrown when the requested directory does not exist
- WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive);
-
- /// Remove a directory watch. This is a brute force search O(nlogn).
- void removeWatch(const String& directory);
-
- /// Remove a directory watch. This is a map lookup O(logn).
- void removeWatch(WatchID watchid);
-
- /// Updates the watcher. Must be called often.
- void update();
-
-private:
- /// The implementation
- FileWatcherImpl* mImpl;
-
-};//end FileWatcher
-
-
-/// Basic interface for listening for file events.
-/// @class FileWatchListener
-class FileWatchListener {
-public:
- FileWatchListener() {}
- virtual ~FileWatchListener() {}
-
- /// Handles the action file action
- /// @param watchid The watch id for the directory
- /// @param dir The directory
- /// @param filename The filename that was accessed (not full path)
- /// @param action Action that was performed
- virtual void handleFileAction(WatchID watchid, const String& dir, const String& filename, Action action) = 0;
-
-};//class FileWatchListener
-
-};//namespace FW
-
-#endif//_FW_FILEWATCHER_H_
diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherImpl.h b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherImpl.h deleted file mode 100644 index 08cfed1..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherImpl.h +++ /dev/null @@ -1,77 +0,0 @@ -/**
- Basic interface for the FileWatcher backend.
-
- @author James Wynn
- @date 5/11/2009
-
- Copyright (c) 2009 James Wynn (james@jameswynn.com)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-#ifndef _FW_FILEWATCHERIMPL_H_
-#define _FW_FILEWATCHERIMPL_H_
-#pragma once
-
-#include "FileWatcher.h"
-
-#define FILEWATCHER_PLATFORM_WIN32 1
-#define FILEWATCHER_PLATFORM_LINUX 2
-#define FILEWATCHER_PLATFORM_KQUEUE 3
-
-#if defined(_WIN32)
-# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_WIN32
-#elif defined(__APPLE_CC__) || defined(BSD)
-# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_KQUEUE
-#elif defined(__linux__)
-# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_LINUX
-#endif
-
-namespace FW {
-struct WatchStruct;
-
-class FileWatcherImpl {
-public:
- ///
- ///
- FileWatcherImpl() {}
-
- ///
- ///
- virtual ~FileWatcherImpl() {}
-
- /// Add a directory watch
- /// @exception FileNotFoundException Thrown when the requested directory does not exist
- virtual WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive) = 0;
-
- /// Remove a directory watch. This is a brute force lazy search O(nlogn).
- virtual void removeWatch(const String& directory) = 0;
-
- /// Remove a directory watch. This is a map lookup O(logn).
- virtual void removeWatch(WatchID watchid) = 0;
-
- /// Updates the watcher. Must be called often.
- virtual void update() = 0;
-
- /// Handles the action
- virtual void handleAction(WatchStruct* watch, const String& filename, unsigned long action) = 0;
-
-};//end FileWatcherImpl
-};//namespace FW
-
-#endif//_FW_FILEWATCHERIMPL_H_
diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherLinux.cpp b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherLinux.cpp deleted file mode 100644 index ea5d259..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherLinux.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/** - Copyright (c) 2009 James Wynn (james@jameswynn.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - - James Wynn james@jameswynn.com -*/ - -#include <FileWatcher/FileWatcherLinux.h> - -#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX - -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> -#include <sys/inotify.h> -#include <unistd.h> - -#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024) - -namespace FW { - -struct WatchStruct { - WatchID mWatchID; - String mDirName; - FileWatchListener* mListener; -}; - -//-------- -FileWatcherLinux::FileWatcherLinux() { - mFD = inotify_init(); - if (mFD < 0) - fprintf (stderr, "Error: %s\n", strerror(errno)); - - mTimeOut.tv_sec = 0; - mTimeOut.tv_usec = 0; - - FD_ZERO(&mDescriptorSet); -} - -//-------- -FileWatcherLinux::~FileWatcherLinux() { - WatchMap::iterator iter = mWatches.begin(); - WatchMap::iterator end = mWatches.end(); - for(; iter != end; ++iter) { - delete iter->second; - } - mWatches.clear(); -} - -//-------- -WatchID FileWatcherLinux::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) { - int wd = inotify_add_watch (mFD, directory.c_str(), - IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE); - if (wd < 0) { - if(errno == ENOENT) - throw FileNotFoundException(directory); - else - throw Exception(strerror(errno)); - -// fprintf (stderr, "Error: %s\n", strerror(errno)); -// return -1; - } - - WatchStruct* pWatch = new WatchStruct(); - pWatch->mListener = watcher; - pWatch->mWatchID = wd; - pWatch->mDirName = directory; - - mWatches.insert(std::make_pair(wd, pWatch)); - - return wd; -} - -//-------- -void FileWatcherLinux::removeWatch(const String& directory) { - WatchMap::iterator iter = mWatches.begin(); - WatchMap::iterator end = mWatches.end(); - for(; iter != end; ++iter) { - if(directory == iter->second->mDirName) { - removeWatch(iter->first); - return; - } - } -} - -//-------- -void FileWatcherLinux::removeWatch(WatchID watchid) { - WatchMap::iterator iter = mWatches.find(watchid); - - if(iter == mWatches.end()) - return; - - WatchStruct* watch = iter->second; - mWatches.erase(iter); - - inotify_rm_watch(mFD, watchid); - - delete watch; - watch = 0; -} - -//-------- -void FileWatcherLinux::update() { - FD_SET(mFD, &mDescriptorSet); - - int ret = select(mFD + 1, &mDescriptorSet, NULL, NULL, &mTimeOut); - if(ret < 0) { - perror("select"); - } else if(FD_ISSET(mFD, &mDescriptorSet)) { - ssize_t len, i = 0; - char action[81+FILENAME_MAX] = {0}; - char buff[BUFF_SIZE] = {0}; - - len = read (mFD, buff, BUFF_SIZE); - - while (i < len) { - struct inotify_event *pevent = (struct inotify_event *)&buff[i]; - - WatchStruct* watch = mWatches[pevent->wd]; - handleAction(watch, pevent->name, pevent->mask); - i += sizeof(struct inotify_event) + pevent->len; - } - } -} - -//-------- -void FileWatcherLinux::handleAction(WatchStruct* watch, const String& filename, unsigned long action) { - if(!watch->mListener) - return; - - if(IN_CLOSE_WRITE & action) { - watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, - Actions::Modified); - } - if(IN_MOVED_TO & action || IN_CREATE & action) { - watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, - Actions::Add); - } - if(IN_MOVED_FROM & action || IN_DELETE & action) { - watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, - Actions::Delete); - } -} - -};//namespace FW - -#endif//FILEWATCHER_PLATFORM_LINUX diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherLinux.h b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherLinux.h deleted file mode 100644 index b681e52..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherLinux.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - Implementation header file for Linux based on inotify. - - @author James Wynn - @date 4/15/2009 - - Copyright (c) 2009 James Wynn (james@jameswynn.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -#ifndef _FW_FILEWATCHERLINUX_H_ -#define _FW_FILEWATCHERLINUX_H_ -#pragma once - -#include "FileWatcherImpl.h" - -#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX - -#include <map> -#include <sys/types.h> - -namespace FW { -/// Implementation for Linux based on inotify. -/// @class FileWatcherLinux -class FileWatcherLinux : public FileWatcherImpl { -public: - /// type for a map from WatchID to WatchStruct pointer - typedef std::map<WatchID, WatchStruct*> WatchMap; - -public: - /// - /// - FileWatcherLinux(); - - /// - /// - virtual ~FileWatcherLinux(); - - /// Add a directory watch - /// @exception FileNotFoundException Thrown when the requested directory does not exist - WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); - - /// Remove a directory watch. This is a brute force lazy search O(nlogn). - void removeWatch(const String& directory); - - /// Remove a directory watch. This is a map lookup O(logn). - void removeWatch(WatchID watchid); - - /// Updates the watcher. Must be called often. - void update(); - - /// Handles the action - void handleAction(WatchStruct* watch, const String& filename, unsigned long action); - -private: - /// Map of WatchID to WatchStruct pointers - WatchMap mWatches; - /// The last watchid - WatchID mLastWatchID; - /// inotify file descriptor - int mFD; - /// time out data - struct timeval mTimeOut; - /// File descriptor set - fd_set mDescriptorSet; - -};//end FileWatcherLinux - -};//namespace FW - -#endif//FILEWATCHER_PLATFORM_LINUX - -#endif//_FW_FILEWATCHERLINUX_H_ diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherOSX.cpp b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherOSX.cpp deleted file mode 100644 index a47d635..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherOSX.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/** - Copyright (c) 2009 James Wynn (james@jameswynn.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - - James Wynn james@jameswynn.com -*/ - -#include <FileWatcher/FileWatcherOSX.h> - -#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE - -#include <sys/event.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <dirent.h> -#include <string.h> -#include <iostream> - -// this is more suited: -// https://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/FSEvents_ProgGuide/UsingtheFSEventsFramework/UsingtheFSEventsFramework.html - -namespace FW { - -#define MAX_CHANGE_EVENT_SIZE 2000 - -typedef struct kevent KEvent; - -struct EntryStruct { - EntryStruct(const char* filename, time_t mtime = 0) - : mFilename(filename), mModifiedTime(mtime) { - } - ~EntryStruct() { - delete[] mFilename; - } - const char* mFilename; - time_t mModifiedTime; -}; - -int comparator(const void* ke1, const void* ke2) { - /*KEvent* kevent1 = (KEvent*) ke1; - KEvent* kevent2 = (KEvent*) ke2; - - EntryStruct* event1 = (EntryStruct*)kevent1->udata; - EntryStruct* event2 = (EntryStruct*)kevent2->udata; - return strcmp(event1->mFilename, event2->mFilename); - */ - return strcmp(((EntryStruct*)(((KEvent*)(ke1))->udata))->mFilename, ((EntryStruct*)(((KEvent*)(ke2))->udata))->mFilename); -} - -struct WatchStruct { - WatchID mWatchID; - String mDirName; - FileWatchListener* mListener; - FileWatcherOSX* mWatcher; - bool mRecursive; - - // index 0 is always the directory - KEvent mChangeList[MAX_CHANGE_EVENT_SIZE]; - size_t mChangeListCount; - - WatchStruct(WatchID watchid, const String& dirname, FileWatchListener* listener, FileWatcherOSX* watcher, bool recursive = false) - : mWatchID(watchid), mDirName(dirname), mListener(listener), mWatcher(watcher), mRecursive(recursive) { - mChangeListCount = 0; - addAll(); - } - - void addFile(const String& name, bool emitEvents = true) { - //fprintf(stderr, "ADDED: %s\n", name.c_str()); - - // create entry - struct stat attrib; - stat(name.c_str(), &attrib); - - int fd = open(name.c_str(), O_RDONLY); - - if(fd == -1) - throw FileNotFoundException(name); - - ++mChangeListCount; - - char* namecopy = new char[name.length() + 1]; - strncpy(namecopy, name.c_str(), name.length()); - namecopy[name.length()] = 0; - EntryStruct* entry = new EntryStruct(namecopy, attrib.st_mtime); - - // set the event data at the end of the list - EV_SET(&mChangeList[mChangeListCount], fd, EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_ONESHOT, - NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB | NOTE_RENAME, - 0, (void*)entry); - - // qsort - qsort(mChangeList + 1, mChangeListCount, sizeof(KEvent), comparator); - - // handle action - if(emitEvents) - handleAction(name, Actions::Add); - } - - void removeFile(const String& name, bool emitEvents = true) { - // bsearch - KEvent target; - EntryStruct tempEntry(name.c_str(), 0); - target.udata = &tempEntry; - KEvent* ke = (KEvent*)bsearch(&target, &mChangeList, mChangeListCount + 1, sizeof(KEvent), comparator); - if(!ke) - throw FileNotFoundException(name); - - tempEntry.mFilename = 0; - - // delete - close(ke->ident); - delete((EntryStruct*)ke->udata); - memset(ke, 0, sizeof(KEvent)); - - // move end to current - memcpy(ke, &mChangeList[mChangeListCount], sizeof(KEvent)); - memset(&mChangeList[mChangeListCount], 0, sizeof(KEvent)); - --mChangeListCount; - - // qsort - qsort(mChangeList + 1, mChangeListCount, sizeof(KEvent), comparator); - - // handle action - if(emitEvents) - handleAction(name, Actions::Delete); - } - - // called when the directory is actually changed - // means a file has been added or removed - // rescans the watched directory adding/removing files and sending notices - void rescan() { - // if new file, call addFile - // if missing file, call removeFile - // if timestamp modified, call handleAction(filename, ACTION_MODIFIED); - DIR* dir = opendir(mDirName.c_str()); - if(!dir) - return; - - struct dirent* dentry; - KEvent* ke = &mChangeList[1]; - EntryStruct* entry = 0; - struct stat attrib; - - while((dentry = readdir(dir)) != NULL) { - String fname = mDirName + "/" + dentry->d_name; - stat(fname.c_str(), &attrib); - if(!S_ISREG(attrib.st_mode)) - continue; - - if(ke <= &mChangeList[mChangeListCount]) { - entry = (EntryStruct*)ke->udata; - int result = strcmp(entry->mFilename, fname.c_str()); - //fprintf(stderr, "[%s cmp %s]\n", entry->mFilename, fname.c_str()); - if(result == 0) { - stat(entry->mFilename, &attrib); - time_t timestamp = attrib.st_mtime; - - if(entry->mModifiedTime != timestamp) { - entry->mModifiedTime = timestamp; - handleAction(entry->mFilename, Actions::Modified); - } - ke++; - } else if(result < 0) { - // f1 was deleted - removeFile(entry->mFilename); - ke++; - } else { - // f2 was created - addFile(fname); - ke++; - } - } else { - // just add - addFile(fname); - ke++; - } - }//end while - - closedir(dir); - }; - - void handleAction(const String& filename, FW::Action action) { - mListener->handleFileAction(mWatchID, mDirName, filename, action); - } - - void addAll() { - // add base dir - int fd = open(mDirName.c_str(), O_RDONLY); - EV_SET(&mChangeList[0], fd, EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_ONESHOT, - NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB | NOTE_RENAME, - 0, 0); - - //fprintf(stderr, "ADDED: %s\n", mDirName.c_str()); - - // scan directory and call addFile(name, false) on each file - DIR* dir = opendir(mDirName.c_str()); - if(!dir) - throw FileNotFoundException(mDirName); - - struct dirent* entry; - struct stat attrib; - while((entry = readdir(dir)) != NULL) { - String fname = (mDirName + "/" + String(entry->d_name)); - stat(fname.c_str(), &attrib); - if(S_ISREG(attrib.st_mode)) { - addFile(fname, false); - } else if(S_IFDIR && mRecursive && entry->d_name[0] != '.') { - mWatcher->addWatch(fname, mListener, mRecursive); - } else { - fprintf(stderr, "NOT ADDED: %s (%d)\n", fname.c_str(), attrib.st_mode); - } - }//end while - - closedir(dir); - } - - void removeAll() { - KEvent* ke = NULL; - - // go through list removing each file and sending an event - for(int i = 0; i < mChangeListCount; ++i) { - ke = &mChangeList[i]; - //handleAction(name, Action::Delete); - EntryStruct* entry = (EntryStruct*)ke->udata; - - handleAction(entry->mFilename, Actions::Delete); - - // delete - close(ke->ident); - delete((EntryStruct*)ke->udata); - } - } -}; - -void FileWatcherOSX::update() { - int nev = 0; - struct kevent event; - - WatchMap::iterator iter = mWatches.begin(); - WatchMap::iterator end = mWatches.end(); - for(; iter != end; ++iter) { - WatchStruct* watch = iter->second; - - while((nev = kevent(mDescriptor, (KEvent*)&(watch->mChangeList), watch->mChangeListCount + 1, &event, 1, &mTimeOut)) != 0) { - if(nev == -1) - perror("kevent"); - else { - if (event.fflags & NOTE_DELETE) { - fprintf(stderr, "NOTE_DELETE "); - } - if (event.fflags & NOTE_EXTEND) { - fprintf(stderr, "NOTE_EXTEND "); - } - if (event.fflags & NOTE_WRITE) { - fprintf(stderr, "NOTE_WRITE "); - } - if (event.fflags & NOTE_ATTRIB) { - fprintf(stderr, "NOTE_ATTRIB "); - } - if (event.fflags & NOTE_RENAME) { - fprintf(stderr, "NOTE_RENAME "); - } - - EntryStruct* entry = 0; - if((entry = (EntryStruct*)event.udata) != 0) { - fprintf(stderr, " to %s -- \n", (char*)entry->mFilename); - - if(event.fflags & NOTE_DELETE) { - //watch->handleAction(entry->mFilename, Action::Delete); - watch->removeFile(entry->mFilename); - } - if(event.fflags & NOTE_EXTEND || - event.fflags & NOTE_WRITE || - event.fflags & NOTE_ATTRIB) { - //watch->rescan(); - struct stat attrib; - stat(entry->mFilename, &attrib); - entry->mModifiedTime = attrib.st_mtime; - watch->handleAction(entry->mFilename, FW::Actions::Modified); - } - } else { - fprintf(stderr, " in %s -- rescanning\n", watch->mDirName.c_str()); - watch->rescan(); - } - } - } - } -} - -//-------- -FileWatcherOSX::FileWatcherOSX() { - mDescriptor = kqueue(); - mTimeOut.tv_sec = 0; - mTimeOut.tv_nsec = 20000000; -} - -//-------- -FileWatcherOSX::~FileWatcherOSX() { - WatchMap::iterator iter = mWatches.begin(); - WatchMap::iterator end = mWatches.end(); - for(; iter != end; ++iter) { - delete iter->second; - } - mWatches.clear(); - - close(mDescriptor); -} - -//-------- -WatchID FileWatcherOSX::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) { - /* int fd = open(directory.c_str(), O_RDONLY); - if(fd == -1) - perror("open"); - - EV_SET(&change, fd, EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_ONESHOT, - NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB, - 0, (void*)"testing"); - */ - - std::cout << "Adding watch for " << directory << std::endl; - - WatchID currWatch = ++mLastWatchID; - WatchStruct* watch = new WatchStruct(currWatch, directory, watcher, this, recursive); - mWatches.insert(std::make_pair(currWatch, watch)); - return currWatch; -} - -//-------- -void FileWatcherOSX::removeWatch(const String& directory) { - WatchMap::iterator iter = mWatches.begin(); - WatchMap::iterator end = mWatches.end(); - for(; iter != end; ++iter) { - if(directory == iter->second->mDirName) { - removeWatch(iter->first); - return; - } - } -} - -//-------- -void FileWatcherOSX::removeWatch(WatchID watchid) { - WatchMap::iterator iter = mWatches.find(watchid); - - if(iter == mWatches.end()) - return; - - WatchStruct* watch = iter->second; - mWatches.erase(iter); - - //inotify_rm_watch(mFD, watchid); - - delete watch; - watch = 0; -} - -//-------- -void FileWatcherOSX::handleAction(WatchStruct* watch, const String& filename, unsigned long action) { -} - -};//namespace FW - -#endif//FILEWATCHER_PLATFORM_KQUEUE diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherOSX.h b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherOSX.h deleted file mode 100644 index 92e3957..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherOSX.h +++ /dev/null @@ -1,88 +0,0 @@ -/** - Implementation header file for OSX based on KEvent. - - @author James Wynn - @date 4/15/2009 - - Copyright (c) 2009 James Wynn (james@jameswynn.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -#ifndef _FW_FILEWATCHEROSX_H_ -#define _FW_FILEWATCHEROSX_H_ -#pragma once - -#include "FileWatcherImpl.h" - -#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE - -#include <map> -#include <sys/types.h> - -namespace FW { -/// Implementation for OSX based on kqueue. -/// @class FileWatcherOSX -class FileWatcherOSX : public FileWatcherImpl { -public: - /// type for a map from WatchID to WatchStruct pointer - typedef std::map<WatchID, WatchStruct*> WatchMap; - -public: - /// - /// - FileWatcherOSX(); - - /// - /// - virtual ~FileWatcherOSX(); - - /// Add a directory watch - /// @exception FileNotFoundException Thrown when the requested directory does not exist - WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive = false); - - /// Remove a directory watch. This is a brute force lazy search O(nlogn). - void removeWatch(const String& directory); - - /// Remove a directory watch. This is a map lookup O(logn). - void removeWatch(WatchID watchid); - - /// Updates the watcher. Must be called often. - void update(); - - /// Handles the action - void handleAction(WatchStruct* watch, const String& filename, unsigned long action); - -private: - /// Map of WatchID to WatchStruct pointers - WatchMap mWatches; - /// The descriptor for the kqueue - int mDescriptor; - /// time out data - struct timespec mTimeOut; - /// WatchID allocator - int mLastWatchID; - - friend class WatchStruct; -};//end FileWatcherOSX - -};//namespace FW - -#endif//__APPLE_CC__ - -#endif//_FW_FILEWATCHEROSX_H_ diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherWin32.cpp b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherWin32.cpp deleted file mode 100644 index ee5de7e..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherWin32.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/**
- Copyright (c) 2009 James Wynn (james@jameswynn.com)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#include <FileWatcher/FileWatcherWin32.h>
-
-#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32
-
-#define _WIN32_WINNT 0x0550
-#include <windows.h>
-
-#if defined(_MSC_VER)
-#pragma comment(lib, "comctl32.lib")
-#pragma comment(lib, "user32.lib")
-#pragma comment(lib, "ole32.lib")
-
-// disable secure warnings
-#pragma warning (disable: 4996)
-#endif
-
-namespace FW {
-/// Internal watch data
-struct WatchStruct {
- OVERLAPPED mOverlapped;
- HANDLE mDirHandle;
- BYTE mBuffer[32 * 1024];
- LPARAM lParam;
- DWORD mNotifyFilter;
- bool mStopNow;
- FileWatcherImpl* mFileWatcher;
- FileWatchListener* mFileWatchListener;
- char* mDirName;
- WatchID mWatchid;
- bool mIsRecursive;
-};
-
-#pragma region Internal Functions
-
-// forward decl
-bool RefreshWatch(WatchStruct* pWatch, bool _clear = false);
-
-/// Unpacks events and passes them to a user defined callback.
-void CALLBACK WatchCallback(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) {
- TCHAR szFile[MAX_PATH];
- PFILE_NOTIFY_INFORMATION pNotify;
- WatchStruct* pWatch = (WatchStruct*) lpOverlapped;
- size_t offset = 0;
-
- if(dwNumberOfBytesTransfered == 0)
- return;
-
- if (dwErrorCode == ERROR_SUCCESS) {
- do {
- pNotify = (PFILE_NOTIFY_INFORMATION) &pWatch->mBuffer[offset];
- offset += pNotify->NextEntryOffset;
-
-# if defined(UNICODE)
- {
- lstrcpynW(szFile, pNotify->FileName,
- min(MAX_PATH, pNotify->FileNameLength / sizeof(WCHAR) + 1));
- }
-# else
- {
- int count = WideCharToMultiByte(CP_ACP, 0, pNotify->FileName,
- pNotify->FileNameLength / sizeof(WCHAR),
- szFile, MAX_PATH - 1, NULL, NULL);
- szFile[count] = TEXT('\0');
- }
-# endif
-
- pWatch->mFileWatcher->handleAction(pWatch, szFile, pNotify->Action);
-
- } while (pNotify->NextEntryOffset != 0);
- }
-
- if (!pWatch->mStopNow) {
- RefreshWatch(pWatch);
- }
-}
-
-/// Refreshes the directory monitoring.
-bool RefreshWatch(WatchStruct* pWatch, bool _clear) {
- return ReadDirectoryChangesW(
- pWatch->mDirHandle, pWatch->mBuffer, sizeof(pWatch->mBuffer), pWatch->mIsRecursive,
- pWatch->mNotifyFilter, NULL, &pWatch->mOverlapped, _clear ? 0 : WatchCallback) != 0;
-}
-
-/// Stops monitoring a directory.
-void DestroyWatch(WatchStruct* pWatch) {
- if (pWatch) {
- pWatch->mStopNow = TRUE;
-
- CancelIo(pWatch->mDirHandle);
-
- RefreshWatch(pWatch, true);
-
- if (!HasOverlappedIoCompleted(&pWatch->mOverlapped)) {
- SleepEx(5, TRUE);
- }
-
- CloseHandle(pWatch->mOverlapped.hEvent);
- CloseHandle(pWatch->mDirHandle);
- delete pWatch->mDirName;
- HeapFree(GetProcessHeap(), 0, pWatch);
- }
-}
-
-/// Starts monitoring a directory.
-WatchStruct* CreateWatch(LPCTSTR szDirectory, bool recursive, DWORD mNotifyFilter) {
- WatchStruct* pWatch;
- size_t ptrsize = sizeof(*pWatch);
- pWatch = static_cast<WatchStruct*>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptrsize));
-
- pWatch->mDirHandle = CreateFile(szDirectory, FILE_LIST_DIRECTORY,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
- OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL);
-
- if (pWatch->mDirHandle != INVALID_HANDLE_VALUE) {
- pWatch->mOverlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- pWatch->mNotifyFilter = mNotifyFilter;
- pWatch->mIsRecursive = recursive;
-
- if (RefreshWatch(pWatch)) {
- return pWatch;
- } else {
- CloseHandle(pWatch->mOverlapped.hEvent);
- CloseHandle(pWatch->mDirHandle);
- }
- }
-
- HeapFree(GetProcessHeap(), 0, pWatch);
- return NULL;
-}
-
-#pragma endregion
-
-//--------
-FileWatcherWin32::FileWatcherWin32()
- : mLastWatchID(0) {
-}
-
-//--------
-FileWatcherWin32::~FileWatcherWin32() {
- WatchMap::iterator iter = mWatches.begin();
- WatchMap::iterator end = mWatches.end();
- for(; iter != end; ++iter) {
- DestroyWatch(iter->second);
- }
- mWatches.clear();
-}
-
-//--------
-WatchID FileWatcherWin32::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) {
- WatchID watchid = ++mLastWatchID;
-
- WatchStruct* watch = CreateWatch(directory.c_str(), recursive,
- FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME);
-
- if(!watch)
- throw FileNotFoundException(directory);
-
- watch->mWatchid = watchid;
- watch->mFileWatcher = this;
- watch->mFileWatchListener = watcher;
- watch->mDirName = new char[directory.length()+1];
- strcpy(watch->mDirName, directory.c_str());
-
- mWatches.insert(std::make_pair(watchid, watch));
-
- return watchid;
-}
-
-//--------
-void FileWatcherWin32::removeWatch(const String& directory) {
- WatchMap::iterator iter = mWatches.begin();
- WatchMap::iterator end = mWatches.end();
- for(; iter != end; ++iter) {
- if(directory == iter->second->mDirName) {
- removeWatch(iter->first);
- return;
- }
- }
-}
-
-//--------
-void FileWatcherWin32::removeWatch(WatchID watchid) {
- WatchMap::iterator iter = mWatches.find(watchid);
-
- if(iter == mWatches.end())
- return;
-
- WatchStruct* watch = iter->second;
- mWatches.erase(iter);
-
- DestroyWatch(watch);
-}
-
-//--------
-void FileWatcherWin32::update() {
- MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, MWMO_ALERTABLE);
-}
-
-//--------
-void FileWatcherWin32::handleAction(WatchStruct* watch, const String& filename, unsigned long action) {
- Action fwAction;
-
- switch(action) {
- case FILE_ACTION_RENAMED_NEW_NAME:
- case FILE_ACTION_ADDED:
- fwAction = Actions::Add;
- break;
- case FILE_ACTION_RENAMED_OLD_NAME:
- case FILE_ACTION_REMOVED:
- fwAction = Actions::Delete;
- break;
- case FILE_ACTION_MODIFIED:
- fwAction = Actions::Modified;
- break;
- };
-
- watch->mFileWatchListener->handleFileAction(watch->mWatchid, watch->mDirName, filename, fwAction);
-}
-
-};//namespace FW
-
-#endif//_WIN32
diff --git a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherWin32.h b/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherWin32.h deleted file mode 100644 index d1626b0..0000000 --- a/src/uscxml/plugins/invoker/filesystem/dirmon/FileWatcher/FileWatcherWin32.h +++ /dev/null @@ -1,83 +0,0 @@ -/**
- Implementation for Windows. Uses ReadDirectoryChangesW to watch for
- file system changes.
-
- @author James Wynn
- @date 4/15/2009
-
- Copyright (c) 2009 James Wynn (james@jameswynn.com)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-#ifndef _FW_FILEWATCHERWIN32_H_
-#define _FW_FILEWATCHERWIN32_H_
-#pragma once
-
-#include "FileWatcherImpl.h"
-
-#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32
-
-#include <map>
-
-namespace FW {
-/// Implementation for Win32 based on ReadDirectoryChangesW.
-/// @class FileWatcherWin32
-class FileWatcherWin32 : public FileWatcherImpl {
-public:
- /// type for a map from WatchID to WatchStruct pointer
- typedef std::map<WatchID, WatchStruct*> WatchMap;
-
-public:
- ///
- ///
- FileWatcherWin32();
-
- ///
- ///
- virtual ~FileWatcherWin32();
-
- /// Add a directory watch
- /// @exception FileNotFoundException Thrown when the requested directory does not exist
- WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive);
-
- /// Remove a directory watch. This is a brute force lazy search O(nlogn).
- void removeWatch(const String& directory);
-
- /// Remove a directory watch. This is a map lookup O(logn).
- void removeWatch(WatchID watchid);
-
- /// Updates the watcher. Must be called often.
- void update();
-
- /// Handles the action
- void handleAction(WatchStruct* watch, const String& filename, unsigned long action);
-
-private:
- /// Map of WatchID to WatchStruct pointers
- WatchMap mWatches;
- /// The last watchid
- WatchID mLastWatchID;
-
-};//end FileWatcherWin32
-
-};//namespace FW
-
-#endif//FILEWATCHER_PLATFORM_WIN32
-
-#endif//_FW_FILEWATCHERWIN32_H_
diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGConverter.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.cpp index 93a238c..93a238c 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGConverter.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.cpp diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGConverter.h b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h index f493e73..28c908d 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGConverter.h +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h @@ -73,7 +73,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(OSGConverter, Invoker); +PLUMA_INHERIT_PROVIDER(OSGConverter, InvokerImpl); #endif } diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h index cb3e9ee..fa66038 100644 --- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h +++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h @@ -91,7 +91,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(MilesSessionInvoker, Invoker); +PLUMA_INHERIT_PROVIDER(MilesSessionInvoker, InvokerImpl); #endif } diff --git a/src/uscxml/plugins/invoker/sample/SampleInvoker.h b/src/uscxml/plugins/invoker/sample/SampleInvoker.h index 018dfc5..d689bda 100644 --- a/src/uscxml/plugins/invoker/sample/SampleInvoker.h +++ b/src/uscxml/plugins/invoker/sample/SampleInvoker.h @@ -31,7 +31,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(SampleInvoker, Invoker); +PLUMA_INHERIT_PROVIDER(SampleInvoker, InvokerImpl); #endif } diff --git a/src/uscxml/plugins/invoker/sqlite3/Sqlite3Invoker.h b/src/uscxml/plugins/invoker/sqlite3/Sqlite3Invoker.h index f2ae915..505d263 100644 --- a/src/uscxml/plugins/invoker/sqlite3/Sqlite3Invoker.h +++ b/src/uscxml/plugins/invoker/sqlite3/Sqlite3Invoker.h @@ -31,7 +31,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(Sqlite3Invoker, Invoker); +PLUMA_INHERIT_PROVIDER(Sqlite3Invoker, InvokerImpl); #endif } diff --git a/src/uscxml/plugins/invoker/system/SystemInvoker.h b/src/uscxml/plugins/invoker/system/SystemInvoker.h index 1440e79..67bd1a9 100644 --- a/src/uscxml/plugins/invoker/system/SystemInvoker.h +++ b/src/uscxml/plugins/invoker/system/SystemInvoker.h @@ -31,7 +31,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(SystemInvoker, Invoker); +PLUMA_INHERIT_PROVIDER(SystemInvoker, InvokerImpl); #endif } diff --git a/src/uscxml/server/InterpreterServlet.cpp b/src/uscxml/server/InterpreterServlet.cpp new file mode 100644 index 0000000..fb8a6ef --- /dev/null +++ b/src/uscxml/server/InterpreterServlet.cpp @@ -0,0 +1,34 @@ +#include "InterpreterServlet.h" +#include "uscxml/Interpreter.h" + +namespace uscxml { + +InterpreterServlet::InterpreterServlet(Interpreter* interpreter) { + _interpreter = interpreter; + + std::stringstream path; + path << _interpreter->getName(); + int i = 2; + while(!HTTPServer::registerServlet(path.str(), this)) { + path.clear(); + path.str(); + path << _interpreter->getName() << i++; + } + _path = path.str(); +} + +void InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { + tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); + + // evhttp_request_own(req.curlReq); + + _requests[toStr((uintptr_t)req.curlReq)] = req; + + Event event = req; + + event.name = "http." + event.data.compound["type"].atom; + event.origin = toStr((uintptr_t)req.curlReq); + _interpreter->receive(event); +} + +}
\ No newline at end of file diff --git a/src/uscxml/server/InterpreterServlet.h b/src/uscxml/server/InterpreterServlet.h new file mode 100644 index 0000000..7235466 --- /dev/null +++ b/src/uscxml/server/InterpreterServlet.h @@ -0,0 +1,46 @@ +#ifndef INTERPRETERSERVLET_H_XQLWNMH4 +#define INTERPRETERSERVLET_H_XQLWNMH4 + +#include "HTTPServer.h" + +namespace uscxml { + +class Interpreter; + +class InterpreterServlet : public HTTPServlet { +public: + InterpreterServlet(Interpreter* interpreter); + virtual void httpRecvRequest(const HTTPServer::Request& req); + + std::string getPath() { + return _path; + } + std::string getURL() { + return _url; + } + void setURL(const std::string& url) { + _url = url; + } + bool canAdaptPath() { return false; } + + std::map<std::string, HTTPServer::Request>& getRequests() { + return _requests; + } + tthread::recursive_mutex& getMutex() { + return _mutex; + } + +protected: + Interpreter* _interpreter; + + tthread::recursive_mutex _mutex; + std::map<std::string, HTTPServer::Request> _requests; + std::string _path; + std::string _url; + +}; + +} + + +#endif /* end of include guard: INTERPRETERSERVLET_H_XQLWNMH4 */ |