├── .astylerc ├── .clang-format ├── .editorconfig ├── .gdbinit ├── .githooks ├── commit-msg │ └── multiple-commits ├── post-commit │ └── generate-ctags └── pre-commit │ └── whitespace ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── CODE_OF_CONDUCT.markdown ├── CONTRIBUTING.markdown ├── INSTALL.markdown ├── LICENSE.txt ├── README.markdown ├── TESTING.markdown ├── Vagrantfile ├── ansible ├── roles │ └── packages │ │ └── tasks │ │ ├── compilers.yml │ │ ├── libconfig.yml │ │ ├── libzmq.yml │ │ ├── main.yml │ │ ├── ppa.yml │ │ ├── uv.yml │ │ └── zmqpp.yml ├── site.yml └── vars │ └── site.yml ├── cmake ├── CMakeLists.txt ├── Modules │ ├── FindWintermute.cmake │ ├── FindZeroMQCXX.cmake │ ├── Internal │ │ ├── CMakeProvideUninstallTarget.cmake │ │ └── WintermuteSourceBuild.cmake │ ├── WintermuteCI.cmake │ ├── WintermuteDependencies.cmake │ ├── WintermuteDocumentation.cmake │ ├── WintermuteFlagDependencies.cmake │ ├── WintermuteFunctionDependencies.cmake │ ├── WintermuteMacros.cmake │ ├── WintermutePlugin.cmake │ ├── WintermuteTest.cmake │ ├── WintermuteTestMacros.cmake │ ├── WintermuteVariables.cmake │ └── WintermuteVersion.cmake └── Templates │ ├── Doxyfile.in │ ├── Internal │ ├── UseWintermute.cmake.in │ └── cmake_uninstall.cmake.in │ ├── doc │ └── layout │ │ ├── footer.html │ │ ├── header.html │ │ ├── layout.xml │ │ └── page.css │ ├── plugin_driver.hh.in │ └── test_runner.cpp.in ├── doc ├── WntrHardware.markdown └── wintermute-core │ ├── Configuration.markdown │ ├── Events.markdown │ ├── LibraryAsCore.markdown │ ├── Main.markdown │ └── ProcedureCalling.markdown ├── script └── _masthead.bash ├── src ├── CMakeLists.txt ├── wintermute-core │ ├── CMakeLists.txt │ ├── call.cc │ ├── call.cpp │ ├── call.hh │ ├── call.hpp │ ├── event_emitter.cpp │ ├── event_emitter.hh │ ├── event_listener.cpp │ ├── event_listener.hh │ ├── event_loop.cpp │ ├── event_loop.hh │ ├── event_object.cpp │ ├── event_object.hh │ ├── event_poller.cpp │ ├── event_poller.hh │ ├── event_signal_handler.cc │ ├── event_signal_handler.cpp │ ├── event_signal_handler.hh │ ├── event_timer.cpp │ ├── event_timer.hh │ ├── events.hpp │ ├── globals.hpp.in │ ├── library.cc │ ├── library.cpp │ ├── library.hh │ ├── library.hpp │ ├── logging.cpp │ ├── logging.hpp │ ├── message.cc │ ├── message.cpp │ ├── message.hh │ ├── message.hpp │ ├── method.cc │ ├── method.cpp │ ├── method.hh │ ├── method.hpp │ ├── module.cc │ ├── module.cpp │ ├── module.hh │ ├── module.hpp │ ├── module_call.cc │ ├── module_call.cpp │ ├── module_call.hh │ ├── module_designation.cc │ ├── module_designation.cpp │ ├── module_designation.hh │ ├── module_pool.cc │ ├── module_pool.cpp │ ├── module_pool.hh │ ├── plugin.cc │ ├── plugin.cpp │ ├── plugin.hh │ ├── plugin.hpp │ ├── tunnel.cc │ ├── tunnel.cpp │ ├── tunnel.hh │ ├── tunnel.hpp │ ├── tunnel_dispatcher.cc │ ├── tunnel_dispatcher.cpp │ ├── tunnel_dispatcher.hh │ ├── tunnel_receiver.cc │ ├── tunnel_receiver.cpp │ ├── tunnel_receiver.hh │ ├── util.hh │ ├── util │ │ ├── configuration.cc │ │ ├── configuration.cpp │ │ ├── configuration.hh │ │ ├── configuration.hpp │ │ ├── invokable.hpp │ │ ├── serializable.cpp │ │ └── serializable.hpp │ ├── version.cpp │ ├── version.hpp │ └── wintermute.hpp ├── wintermute-daemon │ ├── CMakeLists.txt │ ├── README.markdown │ ├── globals.hpp.in │ ├── module.cc │ ├── module.cpp │ ├── module.hh │ ├── module.hpp │ ├── plugin.cc │ ├── plugin.cpp │ ├── plugin.hh │ ├── plugin.hpp │ └── test │ │ └── CMakeLists.txt ├── wintermute-heartbeat │ ├── CMakeLists.txt │ ├── README.markdown │ ├── globals.hpp.in │ ├── messages.hpp │ ├── module.cc │ ├── module.cpp │ ├── module.hh │ ├── module.hpp │ ├── ping_message.cpp │ ├── ping_module.cpp │ ├── ping_module.hpp │ ├── plugin.cc │ ├── plugin.cpp │ ├── plugin.hh │ ├── plugin.hpp │ ├── pong_message.cpp │ ├── pong_module.cpp │ ├── pong_module.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── message-structure.hh │ │ └── message-transport.hh └── wintermute-transport-zeromq │ ├── CMakeLists.txt │ ├── README.markdown │ ├── dispatcher.cpp │ ├── dispatcher.hpp │ ├── globals.hpp.in │ ├── plugin.cpp │ ├── plugin.hpp │ ├── receiver.cpp │ ├── receiver.hpp │ └── test │ ├── CMakeLists.txt │ └── tunnel.hh └── test ├── CMakeLists.txt ├── CTestConfig.cmake.in ├── bootstrap ├── features └── CMakeLists.txt ├── fixtures ├── CMakeLists.txt ├── wintermute_sample.cc └── wintermute_sample.hh ├── include ├── fixtures.hpp └── test_suite.hpp.in └── unit ├── CMakeLists.txt ├── call.hh ├── event_emitter.hh ├── event_listener.hh ├── event_loop.hh ├── event_poller.hh ├── event_timer.hh ├── library.hh ├── message.hh ├── method.hh ├── module.hh ├── module_call.hh ├── module_designation.hh ├── module_pool.hh ├── plugin.hh ├── sample.cfg.in ├── singleton.hh ├── tunnel.hh ├── tunnel_dispatcher.hh ├── tunnel_receiver.hh ├── util.hh ├── util_configuration.hh ├── util_serializable.hh └── version.hh /.astylerc: -------------------------------------------------------------------------------- 1 | # Wintermute's Style Configuration 2 | 3 | --style=google 4 | --indent-switches 5 | --indent=spaces=2 6 | --indent=tab=2 7 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Mozilla 4 | AccessModifierOffset: -2 5 | ConstructorInitializerIndentWidth: 4 6 | AlignEscapedNewlinesLeft: false 7 | AlignTrailingComments: true 8 | AllowAllParametersOfDeclarationOnNextLine: false 9 | AllowShortBlocksOnASingleLine: false 10 | AllowShortIfStatementsOnASingleLine: false 11 | AllowShortLoopsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: All 13 | AlwaysBreakTemplateDeclarations: false 14 | AlwaysBreakBeforeMultilineStrings: false 15 | BreakBeforeBinaryOperators: false 16 | BreakBeforeTernaryOperators: true 17 | BreakConstructorInitializersBeforeComma: false 18 | BinPackParameters: true 19 | ColumnLimit: 80 20 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 21 | DerivePointerAlignment: true 22 | ExperimentalAutoDetectBinPacking: false 23 | IndentCaseLabels: true 24 | IndentWrappedFunctionNames: false 25 | IndentFunctionDeclarationAfterType: false 26 | MaxEmptyLinesToKeep: 1 27 | KeepEmptyLinesAtTheStartOfBlocks: true 28 | NamespaceIndentation: None 29 | ObjCSpaceAfterProperty: true 30 | ObjCSpaceBeforeProtocolList: false 31 | PenaltyBreakBeforeFirstCallParameter: 19 32 | PenaltyBreakComment: 300 33 | PenaltyBreakString: 1000 34 | PenaltyBreakFirstLessLess: 120 35 | PenaltyExcessCharacter: 1000000 36 | PenaltyReturnTypeOnItsOwnLine: 200 37 | PointerAlignment: Left 38 | SpacesBeforeTrailingComments: 1 39 | Cpp11BracedListStyle: false 40 | Standard: Cpp11 41 | IndentWidth: 2 42 | TabWidth: 8 43 | UseTab: Never 44 | BreakBeforeBraces: Attach 45 | SpacesInParentheses: false 46 | SpacesInAngles: false 47 | SpaceInEmptyParentheses: false 48 | SpacesInCStyleCastParentheses: false 49 | SpacesInContainerLiterals: true 50 | SpaceBeforeAssignmentOperators: true 51 | ContinuationIndentWidth: 4 52 | CommentPragmas: '^ IWYU pragma:' 53 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 54 | SpaceBeforeParens: ControlStatements 55 | DisableFormat: false 56 | ... 57 | 58 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = LF 5 | charset = utf-8 6 | 7 | [*.{cpp,hpp,hh,hpp,cmake}] 8 | indent_style = space 9 | indent_size = 2 10 | insert_final_newline = false 11 | trim_trailing_whitespace = true 12 | max_line_length = 80 13 | 14 | [.travis.yml] 15 | indent_style = space 16 | indent_size = 2 17 | 18 | [**/*/CMakeLists.txt] 19 | indent_style = space 20 | indent_size = 2 21 | insert_final_newline = false 22 | trim_trailing_whitespace = true 23 | max_line_length = 80 24 | -------------------------------------------------------------------------------- /.gdbinit: -------------------------------------------------------------------------------- 1 | cd build 2 | -------------------------------------------------------------------------------- /.githooks/commit-msg/multiple-commits: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2010-2012, Benjamin C. Meyer 4 | # Copyright (c) 2015 Jacky Alciné 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions are met: 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 2. Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | # 3. Neither the name of the project nor the 15 | # names of its contributors may be used to endorse or promote products 16 | # derived from this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY 19 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 22 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | 30 | run_test() 31 | { 32 | warnings=$(cat "${1}" | egrep -i "(also|while here|^And)") 33 | if [ ! -z "${warnings}" ] ; then 34 | echo >&2 "This commit message hints that this commit might contain multiple different fixes that should be split into their own commit." 35 | echo -en >&2 "\t"${warnings}""; 36 | fi 37 | } 38 | 39 | case "${1}" in 40 | --about ) 41 | echo -n "Check the commit message for hints that the commit contains multiple fixes: " 42 | ;; 43 | * ) 44 | run_test "$@" 45 | ;; 46 | esac 47 | -------------------------------------------------------------------------------- /.githooks/post-commit/generate-ctags: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (c) 20132013, Jacky Alcine 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 3. Neither the name of the project nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY 18 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | # 28 | 29 | case "${1}" in 30 | --about ) 31 | echo "Generates ctags for the files in this repository." 32 | ;; 33 | * ) 34 | echo "[ctags] Generating tags for repository..." 35 | ctags -f .git/tags `git ls-files` 36 | echo "[ctags] Tags generated for `(git ls-files | wc -l)` files to .git/tags." 37 | ;; 38 | esac 39 | -------------------------------------------------------------------------------- /.githooks/pre-commit/whitespace: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2010, Benjamin C. Meyer 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 3. Neither the name of the project nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY 18 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | # 28 | 29 | set -e 30 | 31 | function run_test { 32 | if git rev-parse --verify HEAD >/dev/null 2>&1 ; then 33 | head="HEAD" 34 | else 35 | # First commit, use an empty tree 36 | head="4b825dc642cb6eb9a060e54bf8d69288fbee4904" 37 | fi 38 | git diff-index --check --cached "${head}" -- 39 | } 40 | 41 | case "${1}" in 42 | --about ) 43 | echo "Check for introduced trailing whitespace or an indent that uses a space before a tab." 44 | ;; 45 | * ) 46 | run_test 47 | ;; 48 | esac 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # vim: set ft=gitignore : 2 | build/* 3 | .ycm_extra_conf.pyc 4 | CTestConfig.cmake 5 | *.orig 6 | CTestConfig.cmake 7 | **/**/globals.hpp 8 | **/**/test_suite.hpp 9 | .vagrant/* 10 | **/wintermute.log 11 | src/wintermute-core/export.hh 12 | cmake/Modules/UseWintermute.cmake 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | branches: 6 | - only: 7 | - master 8 | - develop 9 | - /^feature-.*$/ 10 | before_install: 11 | - test/bootstrap --before 12 | before_script: 13 | - test/bootstrap --generate 14 | script: 15 | - test/bootstrap --run 16 | after_success: 17 | - test/bootstrap --post 18 | notifications: 19 | webhooks: 20 | urls: 21 | - https://webhooks.gitter.im/e/a01dbbba8dcad4b82db8 22 | on_success: change 23 | on_failure: always 24 | on_start: always 25 | slack: 26 | secure: cjpZPOmM9uJNyOTd09fTcT7cMoghjOc4Qiu3hThU8XhkAJ5rkUZWaXKGpiSoCM1+7t9MM3DtnFa91KNOSPPjb+OoJNrr54+RNbLUT16OIYxzynbPSQxYWJ4osqrpoLImerSjW3JQsgKsj+eWTp442OkizJsxFkAsBmPIOAh1NsA= 27 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | 22 | # == Enable testing. The way CTest works, this has to be invoked from the 23 | # topmost CMakeLists.txt file. 24 | ENABLE_TESTING() 25 | INCLUDE(CTest) 26 | 27 | # == Include the subcomponents of the project. 28 | ADD_SUBDIRECTORY(cmake) 29 | ADD_SUBDIRECTORY(src) 30 | ADD_SUBDIRECTORY(test) 31 | 32 | # == Print out some build information. 33 | INCLUDE(WintermuteVersion) 34 | message(STATUS "Building Wintermute ${WINTERMUTE_VERSION}...") 35 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.markdown: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.markdown: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | This project uses the [git flow][] model for development. 4 | There's [a handy git module for git flow][github]. 5 | If you'd like to be added as a contributor, the price of admission is 6 | 1 pull request. Please follow the general code style guides 7 | (read the code) and in your pull request explain the reason for the 8 | proposed change and how it is valuable. 9 | 10 | ## Pull Requests 11 | 12 | Please make your pull requests against the `develop` branch; we stage changes 13 | for testing there to avoid unexpected breakages for our users. :) 14 | 15 | ## Bug report 16 | 17 | Report a bug on [GitHub Issues](https://github.com/jalcine/wintermute/issues). 18 | 19 | [git flow]: http://nvie.com/posts/a-successful-git-branching-model/ 20 | [github]: https://github.com/nvie/gitflow 21 | -------------------------------------------------------------------------------- /INSTALL.markdown: -------------------------------------------------------------------------------- 1 | # Installing Wintermute 2 | 3 | In order to build Wintermute, you'll need the following libraries and programs 4 | already existing on your machine: 5 | 6 | * [json-cpp][] 0.6.0 7 | * [log4cxx][] 0.10.0 8 | * [libuv][] 0.10.20 9 | * [libuuid][] 2.25.1 10 | 11 | For testing, you'll need a few more dependencies. Check the [testing 12 | prerequisites](./TESTING.markdown#install) about that. 13 | 14 | ## Platforms 15 | 16 | Wintermute's been built on the following platforms: 17 | 18 | Compiler (Version) | Target 19 | :-----------------:|:----------: 20 | GCC 4.9 | amd64-linux 21 | Clang 3.6 | amd64-linux 22 | 23 | If you get the tests passing on your platform, please add your platform to the 24 | list above. 25 | 26 | ## Using Vagrant 27 | 28 | If you don't want to install anything on your machine, you can use [Vagrant][] 29 | to run a virtual machine of Ubuntu 14.04 64-bit (the target operating system 30 | for Wintermute) and develop on that from there. Running the following should 31 | get you going: 32 | 33 | ```bash 34 | $ vagrant up 35 | ... vagrant install chef/ubuntu-14.04 ... 36 | ... vagrant provision 37 | $ vagrant ssh 38 | # Go into the project's directory. 39 | cd /vagrant 40 | # Run the variant of the test bootstrap for Vagrant. 41 | /vagrant/test/bootstrap --generate-vagrant 42 | ``` 43 | 44 | [json-cpp]: https://github.com/open-source-parsers/jsoncpp 45 | [log4cxx]: http://logging.apache.org/log4cxx/index.html 46 | [vagrant]: https://vagrantup.com 47 | [libuv]: https://github.com/libuv/libuv 48 | [libuuid]: http://linux.die.net/man/3/libuuid 49 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 - 2015 Jacky Alciné 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /TESTING.markdown: -------------------------------------------------------------------------------- 1 | # Testing Wintermute {#testing} 2 | 3 | Testing's an important part of Wintermute. It provides a level of insurance of 4 | contract upholding between classes and higher-level interactions and allows for 5 | rapid application development without too much concern for the breaking of 6 | existing software. The test harness used by Wintermute is [CxxTest][] and 7 | [CTest][] is used to drive the whole test suite (via `make test`). Coverage 8 | support is handled by `gcov` and memory checking is handled by `valgrind`. 9 | 10 | ## Recommended Testing Targets 11 | 12 | Thanks to `ctest`, testing can include coverage as well as memory leak 13 | detection. After obtaining your sources and configuring the project for the 14 | first time, you can set everything up for the first time by invoking 15 | 16 | ``` 17 | $ make Experimental 18 | ``` 19 | 20 | Of course, if you want to build a specific target, you can do so, but for 21 | full project testing, this serves as a meta target to handle testing and the 22 | other class of tests for the project. 23 | 24 | ## Wintermute's Fixture Library {#testing-fixture-lib} 25 | 26 | Wintermute has a fixture library `wintermute-fixtures` that 27 | allows test developers to write more introspective actions into Wintermute and 28 | even take advantage of mock classes into Wintermute's operations that are 29 | typically, by design, closed off. In essence, the fixture library is a 30 | recompilation of the core Wintermute library with these additives, thus 31 | preventing the parallel installation of said libraries. 32 | 33 | ### Available Fixtures {#testing-fixture-lib-fixtures} 34 | 35 | ### Available Macros {#testing-fixture-lib-macros} 36 | 37 | ### Available Functions {#testing-fixture-lib-functions} 38 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # vi: set ft=ruby : 2 | 3 | VAGRANTFILE_API_VERSION = "2" 4 | 5 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 6 | config.vm.box_check_update = true 7 | config.ssh.forward_agent = true 8 | 9 | if Vagrant.has_plugin? 'vagrant-cachier' 10 | config.cache.scope = :box 11 | config.cache.enable :apt 12 | config.cache.enable :apt_lists 13 | end 14 | 15 | config.vm.provider :virtualbox do |vb| 16 | vb.gui = false 17 | vb.memory = 1500 # 1.5 GiB 18 | end 19 | 20 | config.vm.provision :ansible do |a| 21 | a.verbose = 'v' 22 | a.playbook = 'ansible/site.yml' 23 | a.extra_vars = { 24 | ansible_ssh_user: :vagrant, 25 | compiler_family: ENV['CC'] || 'gcc', 26 | hosts: 'localhost' 27 | } 28 | end 29 | 30 | config.vm.define :target do |t| 31 | t.vm.box = 'chef/ubuntu-13.04' 32 | end 33 | 34 | config.vm.define :travis do |t| 35 | t.vm.box = 'chef/ubuntu-12.04' 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/compilers.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: compilers | Install clang 3 | apt: > 4 | name={{ item }} 5 | state=present 6 | when: compiler_family == "clang" 7 | register: compiler_install_clang 8 | with_items: 9 | - clang-3.5 10 | 11 | - name: compilers | Install gcc 12 | apt: > 13 | name={{ item }} 14 | state=present 15 | register: compiler_install_gcc 16 | with_items: 17 | - g++-4.9 18 | - gcc-4.9 19 | - libgcc-4.9-dev 20 | 21 | - name: compilers | Set g++-4.9 as the compiler for g++. 22 | shell: | 23 | update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 10; 24 | update-alternatives --set g++ /usr/bin/g++-4.9; 25 | update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 10; 26 | update-alternatives --set gcc /usr/bin/gcc-4.9; 27 | 28 | - name: compilers | Set proper coverage tool for GNU tools. 29 | shell: | 30 | update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90; 31 | update-alternatives --set gcov /usr/bin/gcov-4.9; 32 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/libconfig.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Add build dependencies. 3 | command: apt-get build-dep libconfig -y --force-yes 4 | 5 | - name: Check if we've already installed libconfig. 6 | stat: > 7 | path=/usr/local/lib/libconfig++.so.9 8 | register: libconfig_lib 9 | 10 | - name: Check if we've downloaded the tarball for libconfig already. 11 | stat: > 12 | path=/tmp/libconfig.tar.gz 13 | register: libconfig_tarball 14 | when: libconfig_lib.stat.exists == false 15 | 16 | - name: Download tarball for libconfig. 17 | get_url: > 18 | url="https://github.com/hyperrealm/libconfig/archive/f034214e1b7a7d20321fc9d5f007f6e5b21c6a76.tar.gz" 19 | dest=/tmp/libconfig.tar.gz 20 | when: libconfig_lib.stat.exists == false and libconfig_tarball.stat.exists == false 21 | 22 | - name: Check if the tarball's been extracted already. 23 | stat: > 24 | path=/tmp/libconfig 25 | register: libconfig_extracted 26 | when: libconfig_lib.stat.exists == false 27 | 28 | - name: Extract the tarball. 29 | command: tar -xzf libconfig.tar.gz 30 | args: 31 | chdir: /tmp 32 | when: libconfig_lib.stat.exists == false and libconfig_extracted.stat.exists == false 33 | 34 | - name: Preconfigure libconfig for the local environment. 35 | shell: | 36 | autoreconf -v -W none -f; 37 | args: 38 | chdir: /tmp/libconfig-f034214e1b7a7d20321fc9d5f007f6e5b21c6a76 39 | when: libconfig_lib.stat.exists == false 40 | 41 | - name: Configure libconfig for the local environment. 42 | command: ./configure --prefix=/usr/local 43 | args: 44 | chdir: /tmp/libconfig-f034214e1b7a7d20321fc9d5f007f6e5b21c6a76 45 | when: libconfig_lib.stat.exists == false 46 | 47 | - name: Compile libconfig. 48 | command: make -j4 49 | args: 50 | chdir: /tmp/libconfig-f034214e1b7a7d20321fc9d5f007f6e5b21c6a76 51 | when: libconfig_lib.stat.exists == false 52 | 53 | - name: Install libconfig. 54 | command: make install 55 | args: 56 | chdir: /tmp/libconfig-f034214e1b7a7d20321fc9d5f007f6e5b21c6a76 57 | when: libconfig_lib.stat.exists == false 58 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/libzmq.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check if we've already installed ZeroMQ. 3 | stat: > 4 | path=/usr/local/lib/libzmq.so 5 | register: libzmq_lib 6 | 7 | - name: Check if we've downloaded the tarball for ZeroMQ already. 8 | stat: > 9 | path="/tmp/zeromq-{{zmq_version}}.tar.gz" 10 | register: libzmq_tarball 11 | when: libzmq_lib.stat.exists == false 12 | 13 | - name: Download tarball for ZeroMQ. 14 | get_url: > 15 | url="http://download.zeromq.org/zeromq-{{zmq_version}}-rc1.tar.gz" 16 | dest="/tmp/zeromq-{{zmq_version}}.tar.gz" 17 | when: libzmq_lib.stat.exists == false and libzmq_tarball.stat.exists == false 18 | 19 | - name: Check if the tarball's been extracted already. 20 | stat: > 21 | path="/tmp/zeromq-{{zmq_version}}" 22 | register: libzmq_extracted 23 | when: libzmq_lib.stat.exists == false 24 | 25 | - name: Extract the tarball. 26 | command: tar -xzf /tmp/zeromq-{{zmq_version}}.tar.gz 27 | args: 28 | chdir: /tmp 29 | creates: /tmp/zeromq-{{zmq_version}} 30 | when: libzmq_lib.stat.exists == false and libzmq_extracted.stat.exists == false 31 | 32 | - name: Configure ZeroMQ. 33 | shell: | 34 | ./autogen.sh; 35 | ./configure --prefix=/usr/local; 36 | args: 37 | chdir: "/tmp/zeromq-{{zmq_version}}" 38 | when: libzmq_lib.stat.exists == false 39 | 40 | - name: Build ZeroMQ. 41 | command: make -j4 all 42 | args: 43 | chdir: "/tmp/zeromq-{{zmq_version}}" 44 | when: libzmq_lib.stat.exists == false 45 | 46 | - name: Install ZeroMQ. 47 | command: make install 48 | args: 49 | chdir: "/tmp/zeromq-{{zmq_version}}" 50 | when: libzmq_lib.stat.exists == false 51 | 52 | - include: zmqpp.yml tags=packages,zmq,zmqpp 53 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - include: ppa.yml tags=ppa,packages 3 | 4 | - name: Update system package cache. 5 | apt: > 6 | update_cache=yes 7 | cache_valid_time=14400 8 | 9 | - name: Install base tooling and Git. 10 | apt: > 11 | state=present 12 | name={{ item }} 13 | with_items: 14 | - libtool 15 | - automake 16 | - autoconf 17 | - bison 18 | - pkg-config 19 | - git 20 | - python-pip 21 | - binutils 22 | - libboost-program-options-dev 23 | 24 | - include: compilers.yml tags=packages,compilers,gcc,clang 25 | 26 | - name: Install 'coveralls' client package. 27 | pip: > 28 | name={{ item }} 29 | state=present 30 | with_items: 31 | - cpp-coveralls 32 | 33 | - name: Install dependencies for Wintermute. 34 | apt: > 35 | state=present 36 | name={{ item }} 37 | with_items: 38 | - libjsoncpp-dev 39 | - liblog4cxx10-dev 40 | 41 | - name: Install test and documenation dependencies for Wintermute 42 | sudo: True 43 | apt: > 44 | state=present 45 | name={{ item }} 46 | with_items: 47 | - doxygen 48 | - cxxtest 49 | - valgrind 50 | - lcov 51 | - cmake=2.8.12.2-0ubuntu1~ubuntu12.04.1~ppa2 52 | 53 | - include: uv.yml tags=packages,uv 54 | - include: libconfig.yml tags=packages,libconfig 55 | - include: libzmq.yml tags=packages,zmq 56 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/ppa.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Add David Hart's PPA for cxxtest. 3 | apt_repository: > 4 | repo='ppa:dhart/ppa' 5 | 6 | - name: Add Kubuntu's Backports PPA for cmake. 7 | apt_repository: > 8 | repo='ppa:kubuntu-ppa/backports' 9 | 10 | - name: Add Ubuntu restricted toolchain. 11 | apt_repository: > 12 | repo='ppa:ubuntu-toolchain-r/test' 13 | 14 | - name: Add LLVM PPA key when we're using Clang. 15 | apt_key: > 16 | url=http://llvm.org/apt/llvm-snapshot.gpg.key 17 | state=present 18 | when: compiler_family == "clang" 19 | 20 | - name: Add LLVM PPA when we're using Clang. 21 | apt_repository: > 22 | repo="{{ item }}" 23 | with_items: 24 | - 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.5 main' 25 | - 'deb-src http://llvm.org/apt/precise/ llvm-toolchain-precise-3.5 main' 26 | when: compiler_family == "clang" 27 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/uv.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check if we've already installed libuv. 3 | stat: > 4 | path=/usr/local/lib/libuv.so.1 5 | register: libuv_lib 6 | 7 | - name: Check if we've downloaded the tarball for libuv already. 8 | stat: > 9 | path=/tmp/libuv-{{uv_version}}.tar.gz 10 | register: libuv_tarball 11 | when: libuv_lib.stat.exists == false 12 | 13 | - name: Download tarball for libuv. 14 | get_url: > 15 | url="https://github.com/libuv/libuv/archive/v{{uv_version}}.tar.gz" 16 | dest=/tmp/libuv-{{uv_version}}.tar.gz 17 | when: libuv_lib.stat.exists == false and libuv_tarball.stat.exists == false 18 | 19 | - name: Check if the tarball's been extracted already. 20 | stat: > 21 | path=/tmp/libuv-{{uv_version}} 22 | register: libuv_extracted 23 | when: libuv_lib.stat.exists == false 24 | 25 | - name: Extract the tarball. 26 | command: tar -xzf /tmp/libuv-{{uv_version}}.tar.gz 27 | args: 28 | chdir: /tmp 29 | when: libuv_lib.stat.exists == false and libuv_extracted.stat.exists == false 30 | 31 | - name: Preconfigure libuv for the local environment. 32 | command: ./autogen.sh 33 | args: 34 | chdir: /tmp/libuv-{{uv_version}} 35 | when: libuv_lib.stat.exists == false 36 | 37 | - name: Configure libuv for the local environment. 38 | command: ./configure --prefix=/usr/local 39 | args: 40 | chdir: /tmp/libuv-{{uv_version}} 41 | when: libuv_lib.stat.exists == false 42 | 43 | - name: Compile libuv. 44 | command: make -j4 45 | args: 46 | chdir: /tmp/libuv-{{uv_version}} 47 | when: libuv_lib.stat.exists == false 48 | 49 | - name: Install libuv. 50 | command: make install 51 | args: 52 | chdir: /tmp/libuv-{{uv_version}} 53 | when: libuv_lib.stat.exists == false 54 | -------------------------------------------------------------------------------- /ansible/roles/packages/tasks/zmqpp.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check if we've already installed ZeroMQ for C++. 3 | stat: > 4 | path=/usr/local/lib/libzmqpp.so 5 | register: zmqpp_lib 6 | 7 | - name: Check if we've downloaded the tarball for ZeroMQ for C++ already. 8 | stat: > 9 | path="/tmp/zmqpp.tar.gz" 10 | register: zmqpp_tarball 11 | when: zmqpp_lib.stat.exists == false 12 | 13 | - name: Download tarball for ZeroMQ for C++. 14 | get_url: > 15 | url="https://github.com/zeromq/zmqpp/archive/develop.tar.gz" 16 | dest="/tmp/zmqpp.tar.gz" 17 | when: zmqpp_lib.stat.exists == false and zmqpp_tarball.stat.exists == false 18 | 19 | - name: Check if the tarball's been extracted already. 20 | stat: > 21 | path="/tmp/zmqpp-develop" 22 | register: zmqpp_extracted 23 | when: zmqpp_lib.stat.exists == false 24 | 25 | - name: Extract the tarball. 26 | command: tar -xzf /tmp/zmqpp.tar.gz 27 | args: 28 | chdir: /tmp 29 | when: zmqpp_lib.stat.exists == false and zmqpp_extracted.stat.exists == false 30 | 31 | - name: Configure ZeroMQ for C++. 32 | shell: cmake . 33 | args: 34 | chdir: "/tmp/zmqpp-develop" 35 | when: zmqpp_lib.stat.exists == false 36 | 37 | - name: Build ZeroMQ for C++. 38 | command: make -j4 all install 39 | args: 40 | chdir: "/tmp/zmqpp-develop" 41 | when: zmqpp_lib.stat.exists == false 42 | -------------------------------------------------------------------------------- /ansible/site.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | gather_facts: True 4 | sudo: True 5 | vars_files: 6 | - vars/site.yml 7 | 8 | roles: 9 | - packages 10 | -------------------------------------------------------------------------------- /ansible/vars/site.yml: -------------------------------------------------------------------------------- 1 | --- 2 | cmake_version: 2.8.12 3 | uv_version: 1.5.0 4 | zmq_version: 4.1.0 5 | compiler_family: gcc 6 | -------------------------------------------------------------------------------- /cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | # == Import prerequistie modules. 22 | INCLUDE(GNUInstallDirs) 23 | 24 | # == Set variables to make Wintermute building a bit more sane. 25 | SET(BUILD_SHARED_LIBRARIES ON PARENT_SCOPE) 26 | SET(CMAKE_COLOR_MAKEFILE ON PARENT_SCOPE) 27 | SET(CMAKE_EXPORT_COMPILE_COMMANDS ON PARENT_SCOPE) 28 | SET(CMAKE_VERBOSE_MAKEFILE OFF PARENT_SCOPE) 29 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin PARENT_SCOPE) 30 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib PARENT_SCOPE) 31 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib PARENT_SCOPE) 32 | 33 | # == Allow this project to use the modules we've provided. 34 | set(CMAKE_MODULE_PATH 35 | ${CMAKE_MODULE_PATH} 36 | ${CMAKE_SOURCE_DIR}/cmake/Modules/ 37 | ${CMAKE_SOURCE_DIR}/cmake/Modules/Internal/ 38 | ${CMAKE_SOURCE_DIR}/cmake/Templates/ 39 | ${CMAKE_SOURCE_DIR}/cmake/Templates/Internal/ 40 | CACHE INTERNAL "Include paths." 41 | ) 42 | 43 | # == Generate 'UseWintermute.cmake'. 44 | CONFIGURE_FILE( 45 | ${CMAKE_CURRENT_SOURCE_DIR}/Templates/Internal/UseWintermute.cmake.in 46 | ${CMAKE_CURRENT_SOURCE_DIR}/Modules/UseWintermute.cmake 47 | @ONLY) 48 | 49 | INCLUDE(CMakeProvideUninstallTarget) 50 | INCLUDE(UseWintermute) 51 | 52 | # == Install modules and templates. 53 | file(GLOB _modules Modules/*.cmake) 54 | file(GLOB _templates Templates/*.in) 55 | 56 | message(STATUS ${WINTERMUTE_INSTALL_CMAKE_MODULE_DIR}) 57 | 58 | INSTALL(FILES ${_modules} 59 | DESTINATION ${WINTERMUTE_INSTALL_CMAKE_MODULE_DIR} 60 | ) 61 | INSTALL(FILES ${_templates} 62 | DESTINATION ${WINTERMUTE_INSTALL_CMAKE_TEMPLATE_DIR} 63 | ) 64 | -------------------------------------------------------------------------------- /cmake/Modules/FindWintermute.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | include(${CMAKE_CURRENT_LIST_DIR}/UseWintermute.cmake OPTIONAL) 22 | 23 | if(NOT WINTERMUTE_FOUND) 24 | message(FATAL_ERROR "Wintermute was not found at '${CMAKE_CURRENT_LIST_DIR}'.") 25 | else() 26 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Internal) 27 | include(WintermuteVariables) 28 | include(WintermuteDependencies) 29 | include(WintermuteVersion) 30 | include(WintermuteMacros) 31 | message(STATUS "Wintermute development enabled.") 32 | endif() 33 | -------------------------------------------------------------------------------- /cmake/Modules/FindZeroMQCXX.cmake: -------------------------------------------------------------------------------- 1 | # Find zmq.hpp 2 | 3 | INCLUDE(FindPkgConfig) 4 | 5 | PKG_SEARCH_MODULE(ZMQ REQUIRED 6 | libzmq>=3.0 libzmq<=4.1) 7 | 8 | set(ZEROMQCXX_LIBRARIES ${ZMQ_LIBRARIES} zmqpp) 9 | set(ZEROMQCXX_INCLUDE_DIR ${ZMQ_INCLUDE_DIRS}) 10 | set(ZEROMQCXX_CFLAGS ${ZMQ_CFLAGS} ${ZMQ_CFLAGS_OTHER}) 11 | set(ZEROMQCXX_LDFLAGS ${ZMQ_LDFLAGS} ${ZMQ_LDFLAGS_OTHER}) 12 | set(ZEROMQCXX_FOUND ZMQ_FOUND) 13 | -------------------------------------------------------------------------------- /cmake/Modules/Internal/CMakeProvideUninstallTarget.cmake: -------------------------------------------------------------------------------- 1 | # TODO: Add default CMake banner here. 2 | ############################################################################### 3 | ### Copyright (C) 2013 Jacky Alciné 4 | ### 5 | ### This file is part of Wintermute, the extensible AI platform. 6 | ### 7 | ### Wintermute is free software; you can redistribute it and/or modify 8 | ### it under the terms of the GNU General Public License as published by 9 | ### the Free Software Foundation; either version 3 of the License, or 10 | ### (at your option) any later version. 11 | ### 12 | ### Wintermute is distributed in the hope that it will be useful, 13 | ### but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ### GNU General Public License for more details. 16 | ### 17 | ### You should have received a copy of the GNU General Public License 18 | ### along with Wintermute. If not, see . 19 | ############################################################################### 20 | 21 | # Only execute the following block if the 'uninstall' target doesn't exist. 22 | if (NOT TARGET uninstall) 23 | # Check if the template exists. 24 | find_file(CMAKE_UNINSTALL_TEMPLATE_FILE cmake_uninstall.cmake.in 25 | PATHS 26 | ${CMAKE_MODULE_PATH} 27 | DOC "Path to the CMake uninstallation template.") 28 | 29 | # Proceed only if the file exists. 30 | if (EXISTS "${CMAKE_UNINSTALL_TEMPLATE_FILE}") 31 | # Configure the file accordingly. 32 | configure_file(${CMAKE_UNINSTALL_TEMPLATE_FILE} 33 | "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" @ONLY) 34 | 35 | # Define the 'uninstall' target. 36 | add_custom_target(uninstall 37 | "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake") 38 | else() 39 | message(WARNING "Couldn't find template 'cmake_uninstall.cmake' for uninstalls.") 40 | endif(EXISTS "${CMAKE_UNINSTALL_TEMPLATE_FILE}") 41 | 42 | endif(NOT TARGET uninstall) 43 | -------------------------------------------------------------------------------- /cmake/Modules/Internal/WintermuteSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=marker 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | 22 | #== Preserve some older paths. 23 | if (NOT WINTERMUTE_INSTALL_CMAKE_MODULE_DIR AND DEFINED WINTERMUTE_CMAKE_DIR) 24 | set(WINTERMUTE_INSTALL_CMAKE_MODULE_DIR 25 | ${WINTERMUTE_CMAKE_DIR}/Modules CACHE INTERNAL "" FORCE) 26 | set(WINTERMUTE_INSTALL_CMAKE_TEMPLATE_DIR 27 | ${WINTERMUTE_CMAKE_DIR}/Templates CACHE INTERNAL "" FORCE) 28 | endif() 29 | 30 | #== Override other paths. 31 | SET(WINTERMUTE_CMAKE_DIR ${CMAKE_SOURCE_DIR}/cmake 32 | CACHE INTERNAL "Localized CMake modules directory." FORCE) 33 | SET(WINTERMUTE_SOURCE_INCLUDE_DIRS 34 | ${CMAKE_SOURCE_DIR}/src 35 | PARENT_SCOPE) 36 | SET(WINTERMUTE_TEST_INCLUDE_DIRS 37 | ${CMAKE_SOURCE_DIR}/test/include 38 | ${CMAKE_SOURCE_DIR}/test 39 | ${CMAKE_SOURCE_DIR}/src 40 | ${CMAKE_BINARY_DIR}/src 41 | PARENT_SCOPE) 42 | 43 | set(WINTERMUTE_CMAKE_MODULE_DIR 44 | ${WINTERMUTE_CMAKE_DIR}/Modules CACHE INTERNAL "" FORCE) 45 | set(WINTERMUTE_CMAKE_TEMPLATE_DIR 46 | ${WINTERMUTE_CMAKE_DIR}/Templates CACHE INTERNAL "" FORCE) 47 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteCI.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=marker 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | INCLUDE(ProcessorCount) 22 | 23 | SET(CMAKE_VERBOSE_MAKEFILE ON PARENT_SCOPE) 24 | SET(CMAKE_BUILD_TYPE Debug PARENT_SCOPE) 25 | SET(CI_BUILD_DEFINED ON PARENT_SCOPE) 26 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteDependencies.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=marker 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | # = Look up package-level dependencies. 22 | INCLUDE(FindPkgConfig) 23 | INCLUDE(WintermuteVariables) 24 | 25 | PKG_SEARCH_MODULE(JsonCpp jsoncpp>=0.6.0 jsoncpp<=0.7.0 REQUIRED) 26 | PKG_SEARCH_MODULE(Log4Cxx liblog4cxx REQUIRED) 27 | PKG_SEARCH_MODULE(LibUv libuv>=1.4 libuv<=1.5 REQUIRED) 28 | PKG_SEARCH_MODULE(LibConfig libconfig++>=1.4.0 libconfig++<=1.5.0 REQUIRED) 29 | 30 | # == Exported variables 31 | set(WINTERMUTE_INCLUDE_DIRS 32 | ${JsonCpp_INCLUDE_DIRS} 33 | ${Log4Cxx_INCLUDE_DIRS} 34 | ${LibUv_INCLUDE_DIRS} 35 | ${LibConfig_INCLUDE_DIRS} 36 | ) 37 | 38 | set(WINTERMUTE_LIBRARIES 39 | ${JsonCpp_LIBRARIES} 40 | ${Log4Cxx_LIBRARIES} 41 | ${LibUv_LIBRARIES} 42 | ${LibConfig_LIBRARIES} 43 | ) 44 | 45 | list(APPEND WINTERMUTE_COMPILE_FLAGS 46 | ${JsonCpp_CFLAGS} 47 | ${Log4Cxx_CFLAGS} 48 | ${LibUv_CFLAGS} 49 | ${LibConfig_CLAGS} 50 | ) 51 | 52 | list(APPEND WINTERMUTE_LINK_FLAGS 53 | ${JsonCpp_LDFLAGS} 54 | ${Log4Cxx_LDFLAGS} 55 | ${LibUv_LDFLAGS} 56 | ${LibConfig_LDFLAGS} 57 | ) 58 | 59 | # == Add to the required varibles to improve searching. 60 | set(CMAKE_REQUIRED_INCLUDES ${WINTERMUTE_INCLUDE_DIRS}) 61 | set(CMAKE_REQUIRED_FLAGS ${WINTERMUTE_LINK_FLAGS} ${WINTERMUTE_COMPILE_FLAGS}) 62 | 63 | # == Extra inclusion. 64 | include(WintermuteFunctionDependencies) 65 | include(WintermuteFlagDependencies) 66 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteFlagDependencies.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=marker 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | INCLUDE(CheckCXXCompilerFlag) 21 | 22 | IF (CMAKE_BUILD_TYPE STREQUAL Debug) 23 | CHECK_CXX_COMPILER_FLAG(-ftemplate-backtrace-limit=0 CHKFLG_TEMPLATE_BT_LIMIT) 24 | CHECK_CXX_COMPILER_FLAG(-Wpedantic CHKFLG_WARNING_PEDANTIC) 25 | ENDIF() 26 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteFunctionDependencies.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | 22 | if (NOT DEFINED _wntr_func_deps) 23 | set(_wntr_func_deps ON) 24 | else() 25 | return() 26 | endif() 27 | 28 | include(CheckFunctionExists) 29 | 30 | CHECK_FUNCTION_EXISTS(basename CFE_basename) 31 | CHECK_FUNCTION_EXISTS(getenv CFE_getenv) 32 | CHECK_FUNCTION_EXISTS(setenv CFE_setenv) 33 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteTest.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | 22 | INCLUDE(CTest) 23 | INCLUDE(WintermuteTestMacros) 24 | INCLUDE(UseWintermute) 25 | 26 | #== Handle work if we're in CI mode. 27 | OPTION(CI_BUILD "CI build. Extra compilation flags will be set." OFF) 28 | 29 | if (BUILD_TESTING) 30 | INCLUDE(Dart) 31 | INCLUDE(FindCxxTest) 32 | IF (NOT CXXTEST_FOUND) 33 | MESSAGE(ERROR "We need CxxTest for the test suite.") 34 | RETURN() 35 | ENDIF() 36 | ENDIF() 37 | 38 | #== Define the template file to use. 39 | SET(_wntr_test_tpl ${WINTERMUTE_CMAKE_TEMPLATE_DIR}/test_runner.cpp.in) 40 | 41 | #== Define options for CxxTest. 42 | SET(CXXTEST_TESTGEN_ARGS 43 | --have-eh --have-std 44 | --template ${_wntr_test_tpl} 45 | ) 46 | 47 | LIST(APPEND WINTERMUTE_TEST_INCLUDE_DIRS 48 | ${CXXTEST_INCLUDE_DIR}) 49 | 50 | #== Use Valgrind for memory checking. 51 | SET(CMAKE_MEMORYCHECK_COMMAND valgrind) 52 | SET(CMAKE_MEMORYCHECK_COMMAND_OPTIONS 53 | "--error-exitcode=1 --leak-check=full --show-reachable=yes --track-origins=yes -q") 54 | SET(MEMORYCHECK_COMMAND 55 | "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}") 56 | SEPARATE_ARGUMENTS(MEMORYCHECK_COMMAND) 57 | 58 | #== Conditionally build necessary test files. 59 | CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/test/include/test_suite.hpp.in 60 | ${CMAKE_CURRENT_SOURCE_DIR}/test_suite.hpp 61 | @ONLY) 62 | if (WINTERMUTE_SOURCE_BUILD) 63 | CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/test/CTestConfig.cmake.in 64 | ${CMAKE_SOURCE_DIR}/CTestConfig.cmake 65 | @ONLY) 66 | endif() 67 | 68 | IF(CI_BUILD) 69 | INCLUDE(WintermuteCI) 70 | ENDIF() 71 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteTestMacros.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | MACRO(wintermute_add_test _prefix _name _hdr) 22 | SET(_target ${_prefix}-${_name}) 23 | CXXTEST_ADD_TEST(${_target} ${_target}_test.cc ${_hdr}) 24 | WINTERMUTE_LINK_LIBRARIES(${_target}) 25 | WINTERMUTE_ADD_TARGET_PROPERTIES(${_target}) 26 | TARGET_LINK_LIBRARIES(${_target} wintermute-core) 27 | TARGET_INCLUDE_DIRECTORIES(${_target} PUBLIC ${WINTERMUTE_TEST_INCLUDE_DIRS}) 28 | ENDMACRO(wintermute_add_test) 29 | -------------------------------------------------------------------------------- /cmake/Modules/WintermuteVersion.cmake: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | set(WINTERMUTE_VERSION_MAJOR 0) 21 | set(WINTERMUTE_VERSION_MINOR 0) 22 | set(WINTERMUTE_VERSION_PATCH 1) 23 | set(WINTERMUTE_VERSION_RC dev) 24 | set(WINTERMUTE_VERSION 25 | ${WINTERMUTE_VERSION_MAJOR}.${WINTERMUTE_VERSION_MINOR}.${WINTERMUTE_VERSION_PATCH}-${WINTERMUTE_VERSION_RC} 26 | ) 27 | set(WINTERMUTE_VERSION_STRING 28 | ${WINTERMUTE_VERSION_MAJOR}.${WINTERMUTE_VERSION_MINOR}.${WINTERMUTE_VERSION_PATCH} 29 | ) 30 | -------------------------------------------------------------------------------- /cmake/Templates/Internal/UseWintermute.cmake.in: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | set(WINTERMUTE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") 22 | set(WINTERMUTE_LIBRARY_DIR 23 | ${WINTERMUTE_INSTALL_PREFIX}/@CMAKE_INSTALL_LIBDIR@) 24 | set(WINTERMUTE_BINARY_DIR 25 | ${WINTERMUTE_INSTALL_PREFIX}/@CMAKE_INSTALL_BINDIR@) 26 | set(WINTERMUTE_INCLUDE_DIR 27 | ${WINTERMUTE_INSTALL_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@/wintermute) 28 | set(WINTERMUTE_DOCS_DIR 29 | ${WINTERMUTE_INSTALL_PREFIX}/@CMAKE_INSTALL_DATAROOTDIR@/doc) 30 | set(WINTERMUTE_DATA_DIR 31 | ${WINTERMUTE_INSTALL_PREFIX}/@CMAKE_INSTALL_DATAROOTDIR@/wintermute) 32 | set(WINTERMUTE_CMAKE_DIR 33 | "${WINTERMUTE_INSTALL_PREFIX}/@CMAKE_INSTALL_DATAROOTDIR@/cmake-@CMAKE_MAJOR_VERSION@.@CMAKE_MINOR_VERSION@") 34 | set(WINTERMUTE_CMAKE_MODULE_DIR 35 | ${WINTERMUTE_CMAKE_DIR}/Modules) 36 | set(WINTERMUTE_CMAKE_TEMPLATE_DIR 37 | ${WINTERMUTE_CMAKE_DIR}/Templates) 38 | set(WINTERMUTE_FOUND ON) 39 | 40 | INCLUDE(WintermuteSourceBuild OPTIONAL) 41 | -------------------------------------------------------------------------------- /cmake/Templates/Internal/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Jacky Alciné 3 | 4 | IF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 5 | MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"") 6 | ENDIF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 7 | 8 | FILE(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 9 | STRING(REGEX REPLACE "\n" ";" files "${files}") 10 | FOREACH(file ${files}) 11 | MESSAGE(STATUS "Uninstalling \"${file}\"") 12 | IF(NOT EXISTS "${file}" AND NOT IS_SYMLINK "${file}") 13 | MESSAGE(WARNING "File \"${file}\" does not exists.") 14 | ELSE() 15 | EXEC_PROGRAM("@CMAKE_COMMAND@" ARGS "-E remove -f \"${file}\"" 16 | OUTPUT_VARIABLE rm_out 17 | RETURN_VARIABLE rm_retval) 18 | IF("${rm_retval}" GREATER 0) 19 | MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"") 20 | ENDIF("${rm_retval}" GREATER 0) 21 | ENDIF(NOT EXISTS "${file}" AND NOT IS_SYMLINK "${file}") 22 | ENDFOREACH(file) 23 | -------------------------------------------------------------------------------- /cmake/Templates/doc/layout/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /cmake/Templates/doc/layout/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
32 |
$projectname 33 |  $projectnumber 34 |
35 |
$projectbrief
36 |
41 |
$projectbrief
42 |
$searchbox
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /cmake/Templates/plugin_driver.hh.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | #include "test_suite.hpp" 21 | 22 | using Wintermute::Plugin; 23 | 24 | class PluginVerifyTestSuite : public CxxTest::TestSuite 25 | { 26 | public: 27 | void testWorkWithPlugin() 28 | { 29 | Plugin::Ptr pluginPtr = Plugin::find(PLUGIN_PATH); 30 | TSM_ASSERT ( "Plugin was loaded from disk.", pluginPtr ); 31 | TSM_ASSERT ( "Plugin was released from memory.", Plugin::release(pluginPtr->name()) ); 32 | } 33 | }; 34 | 35 | 36 | -------------------------------------------------------------------------------- /cmake/Templates/test_runner.cpp.in: -------------------------------------------------------------------------------- 1 | //#define CXXTEST_HAVE_EH 2 | //#define CXXTEST_ABORT_TEST_ON_FAIL 3 | #include 4 | #include 5 | using std::cout; 6 | using std::endl; 7 | 8 | int main() 9 | { 10 | cout << "[wntr] Test suite starting..." << endl; 11 | int status = CxxTest::ErrorPrinter().run(); 12 | cout << "[wntr] Test suite complete with status " << status << endl; 13 | return status; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/WntrHardware.markdown: -------------------------------------------------------------------------------- 1 | Using the RPi as a interfacing hub into the home network. It'd make sense to 2 | have one Pi per room as we can name them and have them handle core processing. 3 | 4 | It would also make sense to get a private build server for Wintermute using 5 | sources lists for Debian so that we can push updates using APT instead of using 6 | a hand-rolled solution. 7 | 8 | `zordon.jalcine.me` serves as a public, unrelated server. But if it's possible 9 | to have be connected to a VPN, it can probably serve as a middleman to my VPNs. 10 | Else, we'd have `vpn.jalcine.me` and that'd be a proxying box to whichever VPN 11 | I have set up for that day. 12 | 13 | # Hubs 14 | 15 | A **hub** serves as a computer that's meant to run an instance of Wintermute 16 | and specialized plugins for the sake of providing extra metadata and relevancy 17 | to Wintermute. Using the bookbag could allow for pedometers, location awareness 18 | and even unlocking when on premises. 19 | 20 | Each RPi could be named after a bird picked randomly off a list of the ones 21 | picked out of that book you bought. One for your bedroom, one for the living 22 | room and another to place in the bookbag. 23 | 24 | | Nickname | Internal Hostname | 25 | | bedroom | bedroom.hub.rpi-jalcine | 26 | | bookbag | bookbag.hub.rpi-jalcine | 27 | 28 | The bookbag RPI can be sewed on with a denim casing, inside a hard shell to 29 | protect itself. The only concern from there would be battery power, that of 30 | which we can do with a external battery pack from the RPi but connected via USB 31 | into the inside pocket, so it's near seamless. It'd be nice to have an onboard 32 | battery but we'll make do for now. 33 | 34 | # Software 35 | 36 | We'll have to get the C++ library down and then ported to the RPi architecture, 37 | as well as Android 4.4's Linux. Bindings to Node and Ruby are required to make 38 | scripting Wintermute tremendously easier; using pry as the base REPL for 39 | Wintermute is a +1 as well. 40 | -------------------------------------------------------------------------------- /doc/wintermute-core/Configuration.markdown: -------------------------------------------------------------------------------- 1 | # Configuration {#configuration} 2 | 3 | Wintermute's configuration is stored using [libconfig][]; providing a level of 4 | flexibility in how the information can be stored. The following are paths at 5 | which Wintermute expects to find said configuration. 6 | 7 | * `/etc/wintermute` - System-wide globals; sanity reference point. 8 | * `$HOME/.config/wintermute` - User-specific overrides. 9 | 10 | For points of reference, all of the locations in which configuration is meant 11 | to be stored is done in accordance to the [XDG Base Directory Specification][xbds]. 12 | 13 | Wintermute defines an abstraction for configuration loading and parsing via the 14 | `Wintermute::Util::Configuration` class. Check the class documentation header 15 | for more information. 16 | 17 | [libconfig]: http://www.hyperrealm.com/libconfig 18 | [xbds]: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html 19 | -------------------------------------------------------------------------------- /doc/wintermute-core/Events.markdown: -------------------------------------------------------------------------------- 1 | # Events {#events} 2 | ================== 3 | 4 | * `Wintermute::EventEmittable` serves as basis for subscribing to and handling 5 | events in Wintermute. It adds auxiliary methods for events like: 6 | 7 | - `listenFor` 8 | - `stopListeningFor` 9 | - `emit` 10 | -------------------------------------------------------------------------------- /doc/wintermute-core/LibraryAsCore.markdown: -------------------------------------------------------------------------------- 1 | A Library As the Core {#libascore} 2 | ==================== 3 | 4 | 5 | Wintermute's internals are defined in `libwintermute-core`, a C++ library meant 6 | to be built against in possibly different languages but also allowing for 7 | immediate reloads when breaking changes come to play. A shell application 8 | called `wintermute-driver` serves the purpose of loading and starting a plug-in 9 | as a standalone process. This allows for wrapping shell scripts to run and load 10 | specific plugins. 11 | -------------------------------------------------------------------------------- /doc/wintermute-core/Main.markdown: -------------------------------------------------------------------------------- 1 | Wintermute {#mainpage} 2 | ============ 3 | 4 | Wintermute's a project that's meant to be the foundation of a suite of 5 | transparently connected processes. Regardless of the communication protocol, 6 | language of implementation or the system it's executing on; the intended task 7 | that's sent gets invoked. 8 | -------------------------------------------------------------------------------- /script/_masthead.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | cat < 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | # == Enforce source building. 21 | INCLUDE(WintermuteSourceBuild) 22 | 23 | # == Root library. 24 | ADD_SUBDIRECTORY(wintermute-core) 25 | 26 | # == Standalone Plugins 27 | ADD_SUBDIRECTORY(wintermute-daemon) 28 | ADD_SUBDIRECTORY(wintermute-heartbeat) 29 | 30 | # == Transports 31 | #ADD_SUBDIRECTORY(wintermute-transport-dbus) 32 | ADD_SUBDIRECTORY(wintermute-transport-zeromq) 33 | #ADD_SUBDIRECTORY(wintermute-transport-http) 34 | #ADD_SUBDIRECTORY(wintermute-transport-gcm) 35 | -------------------------------------------------------------------------------- /src/wintermute-core/call.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "call.hh" 19 | -------------------------------------------------------------------------------- /src/wintermute-core/call.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include "call.hh" 17 | #include "call.hpp" 18 | #include "logging.hpp" 19 | 20 | using Wintermute::Call; 21 | using Wintermute::CallPrivate; 22 | using Wintermute::Util::Serializable; 23 | 24 | Call::Call(const string& callName) : 25 | Invokable(), Serializable(), 26 | d_ptr(new CallPrivate) 27 | { 28 | Call::d_ptr->name = callName; 29 | } 30 | 31 | Call::~Call() 32 | { 33 | } 34 | 35 | string Call::name() const 36 | { 37 | W_PRV(const Call); 38 | return d->name; 39 | } 40 | 41 | void Call::deserialize(const Serializable::Map& map) 42 | { 43 | W_PRV(Call); 44 | d->name = map.find("name")->second; 45 | } 46 | 47 | Serializable::Map Call::serialize() const 48 | { 49 | Serializable::Map map; 50 | map.insert(std::make_pair("name", name())); 51 | return map; 52 | } 53 | -------------------------------------------------------------------------------- /src/wintermute-core/call.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include "call.hpp" 20 | 21 | using std::string; 22 | 23 | namespace Wintermute 24 | { 25 | class CallPrivate 26 | { 27 | public: 28 | string name; 29 | Call::Function function; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /src/wintermute-core/call.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_CORE_CALL_HPP 19 | # define WINTERMUTE_CORE_CALL_HPP 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using std::list; 29 | using std::unordered_map; 30 | 31 | namespace Wintermute 32 | { 33 | class CallPrivate; 34 | /** 35 | * Represents a invokable action in Wintermute. 36 | * @ingroup Procedure Calling 37 | */ 38 | class WINTERMUTE_EXPORT_PUBLIC Call : 39 | #ifndef DOXYGEN_SKIP 40 | W_DEF_SHAREABLE(Call), 41 | #endif 42 | public Wintermute::Util::Invokable, 43 | public Wintermute::Util::Serializable 44 | { 45 | W_DEF_PRIVATE(Call); 46 | 47 | protected: 48 | /** 49 | * Default constructor. 50 | * @param name The name that the call would be identified by. 51 | */ 52 | explicit Call(const string & name); 53 | 54 | public: 55 | W_DECL_PTR_TYPE(Call) 56 | 57 | // Represents a list of Call objects. 58 | typedef list List; 59 | 60 | typedef unordered_map Map; 61 | 62 | virtual ~Call(); 63 | 64 | /** 65 | * Obtains the name of this Call. 66 | * @return string 67 | */ 68 | string name() const; 69 | 70 | /** 71 | * Serializes this call into Wintermute's hash. 72 | * @return Serializable::Map 73 | */ 74 | virtual Serializable::Map serialize() const; 75 | 76 | /** 77 | * 78 | */ 79 | virtual void deserialize(const Serializable::Map& data); 80 | }; 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/wintermute-core/event_emitter.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include 17 | #include "events.hpp" 18 | 19 | using std::unordered_multimap; 20 | 21 | namespace Wintermute 22 | { 23 | namespace Events 24 | { 25 | class EmitterPrivate 26 | { 27 | public: 28 | Loop::Ptr loop; 29 | unordered_multimap listeners; 30 | }; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/wintermute-core/event_listener.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "event_listener.hh" 19 | #include "events.hpp" 20 | #include "logging.hpp" 21 | 22 | using namespace Wintermute::Events; 23 | 24 | Listener::Listener(Callback callback) throw (std::invalid_argument) : 25 | d_ptr(make_shared()) 26 | { 27 | d_ptr = make_shared(); 28 | W_PRV(Listener); 29 | 30 | if (!callback) 31 | { 32 | throw std::invalid_argument("Invalid callback functions provided."); 33 | } 34 | 35 | d->callback = callback; 36 | } 37 | 38 | Listener::~Listener() 39 | { 40 | } 41 | 42 | void Listener::invoke(const Event::Ptr& event) throw (std::invalid_argument) 43 | { 44 | if (!event) 45 | { 46 | throw std::invalid_argument("An invalid Event pointer was provided."); 47 | } 48 | 49 | W_PRV(Listener); 50 | 51 | if (d->callback) 52 | { 53 | wdebug("Invoking a callback for " + event->name() + "..."); 54 | d->callback(event); 55 | } 56 | else 57 | { 58 | wdebug("No callback set up for this listener. A potential bug?"); 59 | } 60 | 61 | if (d->callback) 62 | { 63 | wdebug("Invoking callback for " + event->name() + "..."); 64 | d->callback(event); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/wintermute-core/event_listener.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "events.hpp" 19 | 20 | namespace Wintermute 21 | { 22 | namespace Events 23 | { 24 | class ListenerPrivate 25 | { 26 | public: 27 | Listener::Callback callback; 28 | explicit ListenerPrivate() : 29 | callback(nullptr) 30 | { 31 | } 32 | 33 | ~ListenerPrivate() 34 | { 35 | callback = Listener::Callback(nullptr); 36 | } 37 | }; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/wintermute-core/event_loop.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include "logging.hpp" 17 | #include "events.hpp" 18 | #include "event_loop.hh" 19 | 20 | using namespace Wintermute::Events; 21 | 22 | Loop::Loop(const bool useDefault) : d_ptr(make_shared()) 23 | { 24 | W_PRV(Loop); 25 | useDefault ? d->useDefaultLoop() : d->createNewLoop(); 26 | assert(d->loop); 27 | d->loop->data = this; 28 | wdebug("Crafted loop."); 29 | } 30 | 31 | Loop::~Loop() 32 | { 33 | wdebug("Loop destroyed."); 34 | } 35 | 36 | bool Loop::isRunning() const 37 | { 38 | W_PRV(Loop); 39 | assert(d->loop); 40 | const bool isActive = (uv_loop_alive(d->loop) > 0); 41 | return isActive; 42 | } 43 | 44 | bool Loop::isPrimary() const 45 | { 46 | W_PRV(const Loop); 47 | assert(d->loop); 48 | const bool isDefault = (uv_default_loop() == d->loop); 49 | return isDefault; 50 | } 51 | 52 | bool Loop::run() 53 | { 54 | W_PRV(Loop); 55 | assert(d->loop); 56 | wdebug("Running loop..."); 57 | const int resultRun = uv_run(d->loop, UV_RUN_DEFAULT); 58 | wdebug("Ran loop."); 59 | return resultRun == 0; 60 | } 61 | 62 | bool Loop::stop() 63 | { 64 | W_PRV(Loop); 65 | bool wasStopped = false; 66 | wdebug("Stopping loop..."); 67 | uv_stop(d->loop); 68 | 69 | wdebug("Loop stopped; closing loop..."); 70 | //const int resultRun = uv_loop_close(d->loop); 71 | //W_CHECK_UV(resultRun, "uv_loop_close"); 72 | wasStopped = true; 73 | 74 | wdebug("Loop closed."); 75 | return wasStopped; 76 | } 77 | 78 | Loop::Ptr Loop::primary() 79 | { 80 | Loop::Ptr primaryLoop = make_shared(true); 81 | assert(primaryLoop->isPrimary()); 82 | wdebug("Handle to primary loop obtained."); 83 | return primaryLoop; 84 | } 85 | -------------------------------------------------------------------------------- /src/wintermute-core/event_loop.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include "events.hpp" 17 | #include 18 | 19 | using namespace Wintermute::Events; 20 | 21 | namespace Wintermute 22 | { 23 | namespace Events 24 | { 25 | class LoopPrivate 26 | { 27 | public: 28 | uv_loop_t* loop; 29 | LoopPrivate() : loop(NULL) 30 | { 31 | } 32 | 33 | void useDefaultLoop() 34 | { 35 | loop = uv_default_loop(); 36 | assert(loop); 37 | } 38 | 39 | void createNewLoop() 40 | { 41 | // NOTE: Should we clear out 'loop' if it's already there? 42 | loop = new uv_loop_t; 43 | uv_loop_init(loop); 44 | assert(loop); 45 | } 46 | 47 | ~LoopPrivate() 48 | { 49 | // TODO: Close the loop if it's active. 50 | } 51 | }; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/wintermute-core/event_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include "event_object.hh" 17 | #include "events.hpp" 18 | 19 | using namespace Wintermute::Events; 20 | 21 | Event::Event(const string& eventName) : d_ptr(new EventPrivate) 22 | { 23 | W_PRV(Event); 24 | d->name = eventName; 25 | } 26 | 27 | Event::~Event() 28 | { 29 | } 30 | 31 | string Event::name() const 32 | { 33 | W_PRV(const Event); 34 | return d->name; 35 | } 36 | -------------------------------------------------------------------------------- /src/wintermute-core/event_object.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include 17 | 18 | namespace Wintermute 19 | { 20 | namespace Events 21 | { 22 | class EventPrivate 23 | { 24 | public: 25 | string name; 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/wintermute-core/event_poller.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include 17 | #include 18 | #include "logging.hpp" 19 | #include "events.hpp" 20 | 21 | using std::function; 22 | using std::to_string; 23 | using namespace std::placeholders; 24 | 25 | namespace Wintermute 26 | { 27 | namespace Events 28 | { 29 | class PollerPrivate 30 | { 31 | public: 32 | W_DEF_PUBLIC(Poller); 33 | int fd; 34 | Poller::PollDirection direction; 35 | Loop::Ptr loop; 36 | Emitter::Ptr emitter; 37 | function callback; 38 | SharedPtr handle; 39 | 40 | explicit PollerPrivate(Poller::Ptr qPtr = nullptr) : 41 | q_ptr(qPtr), fd(0), direction(Poller::PollReadable), loop(nullptr), 42 | emitter(nullptr), callback(nullptr), handle(nullptr) 43 | { 44 | } 45 | 46 | void applyCallback(uv_loop_t* loopHdl) 47 | { 48 | assert(this); 49 | assert(q_ptr && q_ptr.get() != NULL); 50 | assert(loopHdl); 51 | assert(fd > 0); 52 | 53 | int r = 0; 54 | r = uv_poll_init_socket(loopHdl, handle.get(), fd); 55 | W_CHECK_UV(r, "uv_poll_init_socket"); 56 | handle->data = this; 57 | assert(handle->data); 58 | 59 | callback = [](Poller::Ptr& pollerPtr) -> void 60 | { 61 | assert(pollerPtr.get() != NULL); 62 | wdebug("Obtained a poll event from the provided file descriptor: " 63 | + to_string(pollerPtr->fd())); 64 | 65 | PollEvent::Ptr event = make_shared(pollerPtr); 66 | assert(event && event.get() != NULL); 67 | 68 | pollerPtr->emitEvent(event); 69 | }; 70 | assert(callback); 71 | } 72 | }; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/wintermute-core/event_signal_handler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include "logging.hpp" 17 | #include "event_loop.hh" 18 | #include "event_signal_handler.hh" 19 | 20 | using Wintermute::Events::Emitter; 21 | using Wintermute::Events::SignalHandler; 22 | using Wintermute::Events::SignalHandlerPrivate; 23 | 24 | SignalHandlerPrivate::SignalHandlerPrivate( const int& signalNumber) : 25 | q_ptr(nullptr), signum(signalNumber), emitter(new Emitter) 26 | { 27 | handle = make_shared(); 28 | handle->data = (void*) this; // sigh. 29 | } 30 | 31 | SignalHandlerPrivate::~SignalHandlerPrivate() 32 | { 33 | const int signalStopped = uv_signal_stop(handle.get()); 34 | if (signalStopped != 0) 35 | { 36 | // TODO: Handle error. 37 | } 38 | } 39 | 40 | void SignalHandlerPrivate::attachSignal() 41 | { 42 | Loop::Ptr loop = Loop::primary(); 43 | const int signalCreated = uv_signal_init(loop->d_func()->loop, handle.get()); 44 | if (signalCreated != 0) 45 | { 46 | wwarn("Failed to create signal handler."); 47 | // TODO: Handle error. 48 | return; 49 | } 50 | 51 | const int signalStarted = uv_signal_start(handle.get(), &w_event_signal_cb, signum); 52 | if (signalStarted != 0) 53 | { 54 | // TODO: Handle error. 55 | wwarn("Failed to start signal handler."); 56 | handle = nullptr; 57 | return; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/wintermute-core/event_signal_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include "events.hpp" 17 | #include "event_signal_handler.hh" 18 | #include "logging.hpp" 19 | 20 | using Wintermute::Events::Event; 21 | using Wintermute::Events::Emitter; 22 | using Wintermute::Events::SignalEvent; 23 | using Wintermute::Events::SignalHandler; 24 | using Wintermute::Events::SignalHandlerPrivate; 25 | 26 | void w_event_signal_cb(uv_signal_t* handle, int signum) 27 | { 28 | wdebug("Obtained signal event for signal " + to_string(signum) + "..."); 29 | SignalHandlerPrivate* dptr = (SignalHandlerPrivate*)(handle->data); 30 | assert(dptr); 31 | Event::Ptr event = make_shared(dptr->q_ptr); 32 | dptr->emitter->emit(event); 33 | } 34 | 35 | SignalHandler::SignalHandler(const int& signalNumber) : 36 | d_ptr(new SignalHandlerPrivate(signalNumber)) 37 | { 38 | W_PRV(SignalHandler); 39 | d->q_ptr = make_shared(*this); 40 | d->attachSignal(); 41 | } 42 | 43 | SignalHandler::~SignalHandler() 44 | { 45 | } 46 | 47 | Emitter::Ptr SignalHandler::emitter() const 48 | { 49 | W_PRV(const SignalHandler); 50 | return d->emitter; 51 | } 52 | 53 | int SignalHandler::signal() const 54 | { 55 | W_PRV(const SignalHandler); 56 | return d->signum; 57 | } 58 | -------------------------------------------------------------------------------- /src/wintermute-core/event_signal_handler.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #ifndef WINTERMUTE_EVENT_SIGNAL_HANDLER_HH_ 17 | #define WINTERMUTE_EVENT_SIGNAL_HANDLER_HH_ 18 | 19 | #include 20 | #include "events.hpp" 21 | 22 | namespace Wintermute 23 | { 24 | namespace Events 25 | { 26 | class SignalHandlerPrivate 27 | { 28 | public: 29 | W_DEF_PUBLIC(SignalHandler); 30 | typedef uv_signal_t SignalType; 31 | typedef SharedPtr SignalPtr; 32 | 33 | explicit SignalHandlerPrivate(const int& signum); 34 | virtual ~SignalHandlerPrivate(); 35 | void attachSignal(); 36 | 37 | SignalPtr handle; 38 | int signum; 39 | Emitter::Ptr emitter; 40 | SignalHandler* qptr; 41 | }; 42 | } 43 | } 44 | 45 | void w_event_signal_cb(uv_signal_t* handle, int signum); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/wintermute-core/event_timer.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * Library General Public License for more details. 9 | * 10 | * You should have received a copy of the GNU Library General Public 11 | * License along with Wintermute; if not, write to the 12 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 13 | * Boston, MA 02111-1307, USA. 14 | */ 15 | 16 | #include 17 | #include 18 | #include "logging.hpp" 19 | #include "events.hpp" 20 | 21 | using std::function; 22 | using std::to_string; 23 | 24 | namespace Wintermute 25 | { 26 | namespace Events 27 | { 28 | class TimerPrivate 29 | { 30 | public: 31 | W_DEF_PUBLIC(Timer); 32 | Loop::Ptr loop; 33 | Emitter::Ptr emitter; 34 | function)> callback; 35 | uv_timer_t handle; 36 | bool active; 37 | 38 | TimerPrivate() : loop(nullptr), emitter(nullptr), callback(nullptr), 39 | handle(), active(false) { } 40 | 41 | void applyCallback(uv_loop_t* loopHdl) 42 | { 43 | W_PUB(Timer); 44 | int r = 0; 45 | r = uv_timer_init(loopHdl, &handle); 46 | assert ( r == 0 ); 47 | handle.data = this; 48 | 49 | callback = [&q](SharedPtr dPtr) -> void 50 | { 51 | Timer::Ptr qPtr = dPtr->q_ptr; 52 | qPtr->emitEvent(make_shared(qPtr)); 53 | }; 54 | 55 | assert(callback); 56 | } 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/wintermute-core/library.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "logging.hpp" 19 | #include "library.hpp" 20 | #include "library.hh" 21 | 22 | using Wintermute::Library; 23 | using Wintermute::LibraryPrivate; 24 | typedef std::unordered_map LibraryHandleMap; 25 | 26 | LibraryHandleMap LibraryPrivate::libraryHandles = LibraryHandleMap(); 27 | 28 | LibraryPrivate::LibraryPrivate() : 29 | handle(nullptr), filename(""), loadState(Library::LoadUndefined) 30 | { 31 | } 32 | 33 | bool LibraryPrivate::claimHandle(const string& filenameToLoad) 34 | { 35 | auto itr = LibraryPrivate::libraryHandles.find(filenameToLoad); 36 | if (itr != LibraryPrivate::libraryHandles.end()) 37 | { 38 | wdebug("Fetching existing library handle."); 39 | handle = itr->second; 40 | return true; 41 | } 42 | 43 | LibraryPrivate::HandlePtr handlePtr = make_shared(); 44 | const int handleOpened = uv_dlopen(filenameToLoad.c_str(), handlePtr.get()); 45 | 46 | if (handleOpened == 0) 47 | { 48 | auto pair = std::make_pair(filenameToLoad, handlePtr); 49 | LibraryPrivate::libraryHandles.insert(pair); 50 | handle = handlePtr; 51 | return true; 52 | } 53 | else 54 | { 55 | wdebug("Failed to load library: " + string(uv_dlerror(handlePtr.get()))); 56 | } 57 | 58 | handle = nullptr; 59 | return false; 60 | } 61 | 62 | bool LibraryPrivate::freeHandle() 63 | { 64 | if (handle) 65 | { 66 | uv_dlclose(handle.get()); 67 | LibraryPrivate::libraryHandles.erase(filename); 68 | } 69 | 70 | return true; 71 | } 72 | 73 | LibraryPrivate::~LibraryPrivate() 74 | { 75 | } 76 | -------------------------------------------------------------------------------- /src/wintermute-core/library.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | using std::string; 24 | 25 | namespace Wintermute { 26 | class LibraryPrivate { 27 | public: 28 | typedef uv_lib_t HandleType; 29 | typedef SharedPtr HandlePtr; 30 | 31 | explicit LibraryPrivate(); 32 | virtual ~LibraryPrivate(); 33 | bool claimHandle(const string& filename); 34 | bool freeHandle(); 35 | 36 | HandlePtr handle; 37 | string filename; 38 | Library::LoadState loadState; 39 | 40 | private: 41 | static std::unordered_map libraryHandles; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /src/wintermute-core/message.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include "message.hh" 20 | #include "message.hpp" 21 | #include "logging.hpp" 22 | 23 | using Wintermute::Message; 24 | using Wintermute::Module; 25 | using Wintermute::MessagePrivate; 26 | using Wintermute::Util::Serializable; 27 | using std::chrono::system_clock; 28 | 29 | MessagePrivate::MessagePrivate() : 30 | data(Message::HashType()), 31 | sender(), 32 | receiver(), 33 | timestamp(system_clock::now()) 34 | { 35 | } 36 | 37 | void MessagePrivate::clone(const SharedPtr& d) 38 | { 39 | this->data = d->data; 40 | this->sender = d->sender; 41 | this->receiver = d->receiver; 42 | this->timestamp = d->timestamp; 43 | } 44 | 45 | bool MessagePrivate::isEmpty() const 46 | { 47 | /// TODO This needs a better check. If anything, check only if the sender AND 48 | //payload are empty/null. 49 | return !sender.isNull() && !receiver.isNull() && 50 | !data.empty() && timestamp != system_clock::time_point(); 51 | } 52 | -------------------------------------------------------------------------------- /src/wintermute-core/message.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "message.hpp" 23 | #include "module.hpp" 24 | 25 | namespace Wintermute 26 | { 27 | class Designation; 28 | class MessagePrivate 29 | { 30 | public: 31 | Message::HashType data; 32 | Module::Designation sender; 33 | Module::Designation receiver; 34 | std::chrono::system_clock::time_point timestamp; 35 | 36 | void clone(const SharedPtr& d); 37 | bool isEmpty() const; 38 | 39 | MessagePrivate(); 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /src/wintermute-core/message.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_MESSAGE_HPP 19 | #define WINTERMUTE_MESSAGE_HPP 20 | 21 | #include 22 | #include 23 | #include "globals.hpp" 24 | #include "module.hpp" 25 | #include "util/serializable.hpp" 26 | 27 | using std::string; 28 | using std::map; 29 | 30 | namespace Wintermute 31 | { 32 | class MessagePrivate; 33 | 34 | /** 35 | * Serves as the basis for message passing between modules. 36 | * Message is the data class that allows for passing of data 37 | * structures over ambigious means of data trasveral. 38 | * 39 | * @sa Wintermute::Tunnel::Dispatcher 40 | * @sa Wintermute::Tunnel::Receiver 41 | */ 42 | class WINTERMUTE_EXPORT_PUBLIC Message : 43 | public Util::Serializable 44 | { 45 | private: 46 | W_DEF_PRIVATE(Message) 47 | W_SERIALIZABLE(Message) 48 | 49 | public: 50 | typedef string HashKey; 51 | typedef string HashValue; 52 | typedef Serializable::Map HashType; 53 | 54 | explicit Message(const Message::HashType& data, 55 | const Module::Designation& receiver = Module::Designation(), 56 | const Module::Designation& sender = Module::Designation()); 57 | 58 | Message(const Message& other); 59 | 60 | Message(); 61 | 62 | virtual ~Message(); 63 | 64 | bool isEmpty() const; 65 | 66 | Message clone() const; 67 | 68 | HashType payload() const; 69 | 70 | Module::Designation sender() const; 71 | 72 | Module::Designation receiver() const; 73 | 74 | string timestamp() const; 75 | 76 | void setSender(const Module::Designation& newSender); 77 | 78 | void setReceiver(const Module::Designation& newReceiver); 79 | 80 | void setPayload(const Message::HashType& newData); 81 | 82 | bool operator==(const Message& other) const; 83 | 84 | bool operator!() const; 85 | 86 | using Serializable::operator=; 87 | }; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/wintermute-core/method.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jalcine/wintermute/702d33bc60f03855f5539c60908226e3d0fd0d55/src/wintermute-core/method.cc -------------------------------------------------------------------------------- /src/wintermute-core/method.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_CORE_METHOD_HH 19 | # define WINTERMUTE_CORE_METHOD_HH 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | using std::string; 26 | using Wintermute::Util::Serializable; 27 | 28 | namespace Wintermute 29 | { 30 | class MethodPrivate 31 | { 32 | public: 33 | string callName; 34 | Module::Designation originatingModule; 35 | Module::Designation destinationModule; 36 | Serializable::Map arguments; 37 | }; 38 | } 39 | 40 | #endif 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/wintermute-core/module.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module.hh" 19 | #include "logging.hpp" 20 | 21 | using Wintermute::ModulePrivate; 22 | using Wintermute::Events::Emitter; 23 | 24 | ModulePrivate::ModulePrivate(const Module::Designation& des) : 25 | designation(des), 26 | emitter(nullptr) 27 | { 28 | emitter = make_shared(); 29 | calls.clear(); 30 | } 31 | 32 | ModulePrivate::~ModulePrivate() 33 | { 34 | wdebug("Flushing out calls for " + static_cast(designation) + "..."); 35 | calls.clear(); 36 | wdebug("Cleared calls for " + static_cast(designation) + "."); 37 | } 38 | -------------------------------------------------------------------------------- /src/wintermute-core/module.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module.hpp" 19 | #include "call.hpp" 20 | 21 | namespace Wintermute 22 | { 23 | class ModulePrivate 24 | { 25 | public: 26 | W_DEF_PUBLIC(Module); 27 | Module::Designation designation; 28 | Module::Call::Map calls; 29 | Events::Emitter::Ptr emitter; 30 | 31 | explicit ModulePrivate(const Module::Designation& des); 32 | ~ModulePrivate(); 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/wintermute-core/module_call.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module_call.hh" 19 | 20 | -------------------------------------------------------------------------------- /src/wintermute-core/module_call.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "logging.hpp" 19 | #include "module.hpp" 20 | #include "module_call.hh" 21 | #include "call.hh" 22 | #include "util/serializable.hpp" 23 | 24 | using Wintermute::Call; 25 | using Wintermute::Module; 26 | using Wintermute::ModuleCallPrivate; 27 | using Wintermute::Util::Serializable; 28 | 29 | Module::Call::Call(const Module::Ptr modulePtr, const string& callName) : 30 | Wintermute::Call(callName), 31 | d_ptr(new ModuleCallPrivate) 32 | { 33 | W_PRV(ModuleCall); 34 | d->module = modulePtr; 35 | } 36 | 37 | Module::Ptr Module::Call::module() const 38 | { 39 | W_PRV(const ModuleCall); 40 | return d->module; 41 | } 42 | 43 | Module::Call::~Call() 44 | { 45 | } 46 | 47 | Serializable::Map Module::Call::serialize() const 48 | { 49 | Serializable::Map callMap; 50 | callMap.insert(std::make_pair("designation", "")); 51 | callMap.insert(std::make_pair("name", name())); 52 | 53 | return callMap; 54 | } 55 | void Module::Call::deserialize(const Serializable::Map& data) 56 | { 57 | throw new std::invalid_argument("Cannot deserialize a Module::Call of size " + std::to_string(data.size()) + "."); 58 | } 59 | -------------------------------------------------------------------------------- /src/wintermute-core/module_call.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module.hpp" 19 | 20 | namespace Wintermute 21 | { 22 | class ModuleCallPrivate 23 | { 24 | public: 25 | Module::Ptr module; 26 | }; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/wintermute-core/module_designation.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module_designation.hh" 19 | 20 | using std::hash; 21 | using std::string; 22 | using Wintermute::Module; 23 | using Wintermute::DesignationPrivate; 24 | 25 | DesignationPrivate::DesignationPrivate() 26 | : pid(0), name(), domain() 27 | { 28 | } 29 | 30 | DesignationPrivate::~DesignationPrivate() 31 | { 32 | } 33 | 34 | void DesignationPrivate::clone(const SharedPtr& other) 35 | { 36 | assert(other); 37 | this->pid = other->pid; 38 | this->name = other->name; 39 | this->domain = other->domain; 40 | } 41 | 42 | size_t DesignationPrivate::Hash::operator()(const Module::Designation& des) const 43 | { 44 | hash hashStr_fn; 45 | return hashStr_fn((string) des); 46 | } 47 | -------------------------------------------------------------------------------- /src/wintermute-core/module_designation.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include "globals.hpp" 20 | #include "module.hpp" 21 | 22 | using std::string; 23 | 24 | namespace Wintermute 25 | { 26 | class DesignationPrivate 27 | { 28 | public: 29 | PID pid; 30 | string name; 31 | string domain; 32 | explicit DesignationPrivate(); 33 | ~DesignationPrivate(); 34 | 35 | void clone(const SharedPtr& other); 36 | 37 | struct Hash 38 | { 39 | size_t operator()(const Wintermute::Module::Designation &des) const; 40 | }; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/wintermute-core/module_pool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module_pool.hh" 19 | 20 | using Wintermute::ModulePoolPrivate; 21 | 22 | ModulePoolPrivate::ModulePoolPrivate() 23 | : modules() 24 | { 25 | } 26 | 27 | ModulePoolPrivate::~ModulePoolPrivate() 28 | { 29 | modules.clear(); 30 | } 31 | -------------------------------------------------------------------------------- /src/wintermute-core/module_pool.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "module.hpp" 19 | #include "module_designation.hh" 20 | #include 21 | 22 | using std::unordered_map; 23 | 24 | namespace Wintermute 25 | { 26 | class ModulePoolPrivate 27 | { 28 | public: 29 | typedef unordered_map Map; 30 | Map modules; 31 | 32 | explicit ModulePoolPrivate(); 33 | ~ModulePoolPrivate(); 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /src/wintermute-core/plugin.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "plugin.hpp" 19 | #include "logging.hpp" 20 | #include "plugin.hh" 21 | 22 | using std::end; 23 | using std::to_string; 24 | using Wintermute::Plugin; 25 | using Wintermute::PluginPrivate; 26 | 27 | PluginPrivate::PluginMap PluginPrivate::plugins; 28 | 29 | PluginPrivate::PluginPrivate(const string& pluginName) : 30 | library(), name(pluginName) 31 | { 32 | wdebug("Defined the internals for the plugin " + pluginName + "."); 33 | } 34 | 35 | PluginPrivate::~PluginPrivate() 36 | { 37 | } 38 | 39 | bool PluginPrivate::registerPlugin(Plugin::Ptr& plugin) 40 | { 41 | wdebug("Inserted " + plugin->name() + " into the pool."); 42 | auto insertionStatus = PluginPrivate::plugins.emplace(plugin->name(), plugin); 43 | wdebug("Was the plugin " + plugin->name() + " inserted? " 44 | + to_string(insertionStatus.second)); 45 | return insertionStatus.second; 46 | } 47 | 48 | bool PluginPrivate::unregisterPlugin(const string& pluginName) 49 | { 50 | wdebug("Removed " + pluginName + " from the pool."); 51 | const auto erasedCount = PluginPrivate::plugins.erase(pluginName); 52 | wdebug("Was the plugin " + pluginName + " removed? " 53 | + to_string(erasedCount)); 54 | return erasedCount == 1; 55 | } 56 | 57 | Plugin::Ptr PluginPrivate::lookupPlugin(const string& pluginQuery) 58 | { 59 | auto itr = PluginPrivate::plugins.find(pluginQuery); 60 | assert(itr != end(PluginPrivate::plugins)); 61 | Plugin::Ptr pluginPtr = itr->second; 62 | assert(pluginPtr); 63 | 64 | return pluginPtr; 65 | } 66 | -------------------------------------------------------------------------------- /src/wintermute-core/plugin.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_PRIVATE_PLUGIN_HPP 19 | #define WINTERMUTE_PRIVATE_PLUGIN_HPP 20 | 21 | #include 22 | #include 23 | #include "library.hpp" 24 | #include "plugin.hpp" 25 | 26 | using std::unordered_map; 27 | using std::string; 28 | 29 | namespace Wintermute 30 | { 31 | class PluginPrivate 32 | { 33 | public: 34 | typedef Plugin*(*CtorFunctionPtr)(void); 35 | typedef const char*(*VersionFunctionPtr)(void); 36 | typedef bool(*DtorFunctionPtr)(Plugin::Ptr&); 37 | typedef unordered_map PluginMap; 38 | 39 | static PluginMap plugins; 40 | Library::Ptr library; 41 | string name; 42 | 43 | explicit PluginPrivate(const string& pluginName); 44 | virtual ~PluginPrivate(); 45 | static bool registerPlugin(Plugin::Ptr& plugin); 46 | static bool unregisterPlugin(const string& pluginName); 47 | static Plugin::Ptr lookupPlugin(const string& pluginQuery); 48 | }; 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /src/wintermute-core/tunnel.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "logging.hpp" 19 | #include "tunnel.hh" 20 | 21 | using Wintermute::TunnelPrivate; 22 | using Wintermute::Events::Emitter; 23 | using Wintermute::Events::Loop; 24 | 25 | TunnelPrivate::TunnelPrivate() : 26 | dispatchers(), 27 | receivers(), 28 | emitter(nullptr) 29 | { 30 | emitter = make_shared(); 31 | wdebug("Built up Tunnel's private data."); 32 | } 33 | 34 | TunnelPrivate::~TunnelPrivate() 35 | { 36 | // TODO: Free up all of the dispatchers, if not automatically. 37 | // TODO: Free up all of the receivers, if not automatically. 38 | } 39 | -------------------------------------------------------------------------------- /src/wintermute-core/tunnel.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "tunnel.hpp" 22 | 23 | using std::unordered_map; 24 | using std::stack; 25 | using std::string; 26 | 27 | namespace Wintermute 28 | { 29 | class TunnelPrivate 30 | { 31 | public: 32 | typedef unordered_map DispatcherMap; 33 | typedef unordered_map ReceiverMap; 34 | explicit TunnelPrivate(); 35 | ~TunnelPrivate(); 36 | 37 | DispatcherMap dispatchers; 38 | ReceiverMap receivers; 39 | Events::Emitter::Ptr emitter; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /src/wintermute-core/tunnel_dispatcher.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jalcine/wintermute/702d33bc60f03855f5539c60908226e3d0fd0d55/src/wintermute-core/tunnel_dispatcher.cc -------------------------------------------------------------------------------- /src/wintermute-core/tunnel_dispatcher.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * ree Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | namespace Wintermute 22 | { 23 | class DispatcherPrivate 24 | { 25 | public: 26 | string name; 27 | Events::Emitter::Ptr emitter; 28 | }; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/wintermute-core/tunnel_receiver.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jalcine/wintermute/702d33bc60f03855f5539c60908226e3d0fd0d55/src/wintermute-core/tunnel_receiver.cc -------------------------------------------------------------------------------- /src/wintermute-core/tunnel_receiver.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * ree Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | namespace Wintermute 22 | { 23 | class ReceiverPrivate 24 | { 25 | public: 26 | string name; 27 | Events::Emitter::Ptr emitter; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /src/wintermute-core/util.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_CORE_UTIL_HH_ 22 | # define WINTERMUTE_CORE_UTIL_HH_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | using std::list; 32 | using std::regex; 33 | using std::string; 34 | using std::copy; 35 | using std::sregex_token_iterator; 36 | using std::back_inserter; 37 | using std::begin; 38 | using std::end; 39 | 40 | namespace Wintermute 41 | { 42 | namespace Util 43 | { 44 | // TODO: Document. 45 | inline list split_string(const string& str, const regex& delim) 46 | { 47 | list tokens; 48 | copy ( sregex_token_iterator(str.begin(), str.end(), delim, -1), 49 | sregex_token_iterator(), 50 | back_inserter(tokens) ); 51 | 52 | return tokens; 53 | } 54 | 55 | // TODO: Document. 56 | inline string join_string(const list& tokens, const string& delim) 57 | { 58 | string resultingString; 59 | 60 | if (!tokens.empty()) 61 | { 62 | resultingString = tokens.front(); 63 | 64 | for_each(++begin(tokens), end(tokens), [&](const string& token) 65 | { 66 | resultingString += delim + token; 67 | }); 68 | } 69 | 70 | return resultingString; 71 | } 72 | 73 | /** 74 | * @fn Wintermute::Util::generate_uuid 75 | * @return A UUID as a string. 76 | * Generates a UUID. 77 | * @TODO: Make this generate pure UUIDs, as opposed to a random number. 78 | */ 79 | inline string generate_uuid() 80 | { 81 | const int randomNumber = rand(); 82 | const string uuidStr = std::to_string(randomNumber); 83 | return uuidStr; 84 | } 85 | } 86 | } 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/wintermute-core/util/configuration.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include "globals.hpp" 22 | #include "util/configuration.hpp" 23 | #include 24 | 25 | using libconfig::Setting; 26 | 27 | namespace Wintermute 28 | { 29 | namespace Util 30 | { 31 | class ConfigurationPrivate 32 | { 33 | public: 34 | static list directories; 35 | void buildConfigurationObject(); 36 | bool loadConfiguration(const string& name); 37 | Setting* addSetting(const string& key, const Setting::Type& valueType); 38 | SharedPtr config; 39 | }; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/wintermute-core/wintermute.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | -------------------------------------------------------------------------------- /src/wintermute-daemon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | PROJECT(WintermuteDaemon CXX) 22 | 23 | INCLUDE(WintermutePlugin) 24 | INCLUDE(FindPkgConfig) 25 | 26 | SET(WINTERMUTE_DAEMON_VERSION 0.0.1-dev) 27 | 28 | SET(_srcs 29 | plugin.cpp 30 | plugin.cc 31 | module.cpp 32 | module.cc 33 | ) 34 | 35 | CONFIGURE_FILE(globals.hpp.in 36 | ${CMAKE_CURRENT_SOURCE_DIR}/globals.hpp 37 | @ONLY 38 | ) 39 | 40 | ADD_LIBRARY(wintermute-daemon 41 | SHARED ${_srcs} 42 | ) 43 | 44 | WINTERMUTE_PLUGIN_DECLARE( 45 | NAME daemon 46 | TARGET wintermute-daemon 47 | VERSION ${WINTERMUTE_DAEMON_VERSION} 48 | ) 49 | 50 | WINTERMUTE_PLUGIN_VALIDATE(TARGET wintermute-daemon) 51 | 52 | ADD_SUBDIRECTORY(test) 53 | -------------------------------------------------------------------------------- /src/wintermute-daemon/README.markdown: -------------------------------------------------------------------------------- 1 | # Daemon Plugin for Wintermute {#daemon} 2 | 3 | The daemon plugin in Wintermute serves as a way to maintain plugins that 4 | Wintermute needs in order to stabilize its remote procedure calling system like 5 | module existence on a local machine and sending machines from a local machine 6 | out over a network. It does this by reading the daemon's configuration options 7 | and loading the designation plugins to be used for _relaying messages_ over a 8 | stream (UNIX socket, TCP, etc) and starts that up. 9 | 10 | The next step would be loading the **heartbeat** plugin. The heartbeat plugin 11 | collects heartbeat signals from other processes on the local system and allows 12 | one to build a model of what the system looks in an elastic fashion. This model 13 | isn't required for _any_ procedure calling but it's provided as a model for 14 | services that'd like to ensure the existence of another module or call. 15 | 16 | After that, the **RPC relay** plugin, designated by the daemon's configuration, 17 | is loaded and prepped to listen for incoming messages from the external network 18 | and send outgoing messages to the outgoing network. 19 | 20 | ## Heartbeat Plugin {#heartbeat} 21 | 22 | The heartbeat plugin is an utility plugin loaded into the daemon instance that 23 | collects information from other instances of Wintermute running on the local 24 | machine. It fetches this by sending out pings designated to be answered by 25 | instances of Wintermute and collects pongs and records the time of said 26 | collection to see which process is still currently active or is need of a kick. 27 | Very simple in ideology, if you ask me. 28 | 29 | ## Loading the RPC Relay Plugin {#rpc-relay} 30 | 31 | The RPC relay is meant to transport messages designated to go _off_ the current 32 | network or come from _outside_ the current network and pass them back onto the 33 | local network. This is handy for having instances of Wintermute running 34 | on the same network but on different machines, perhaps for home automation or 35 | distributed computing. By default, [ZeroMQ][] is used to handle local _and_ 36 | remote communications between Wintermute. The addresses it listens to is 37 | defined with compile-time defaults, `WINTERMUTE_ZMQ_ADDRESS_LOCAL` and 38 | `WINTERMUTE_ZMQ_ADDRESS_REMOTE` but it also allows for added addresses in the 39 | event that the internal defaults don't work on said machine. 40 | 41 | [ZeroMQ]: http://zeromq.org/ 42 | -------------------------------------------------------------------------------- /src/wintermute-daemon/globals.hpp.in: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_DAEMON_GLOBALS_HPP_ 22 | # define WINTERMUTE_DAEMON_GLOBALS_HPP_ 23 | 24 | #include 25 | 26 | #define WINTERMUTE_DAEMON_PLUGIN_NAME "DAEMON" 27 | #define WINTERMUTE_DAEMON_DOMAIN WINTERMUTE_DOMAIN 28 | #define WINTERMUTE_DAEMON_MODULE "daemon" 29 | 30 | // TODO: Provide a proper path for the daemon's configuration. 31 | #define WINTERMUTE_DAEMON_CFG_PATH "@CMAKE_BINARY_DIR@/test/unit/sample" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/wintermute-daemon/module.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include "module.hh" 22 | 23 | using Wintermute::Events::SignalHandler; 24 | using Wintermute::Daemon::ModulePrivate; 25 | 26 | ModulePrivate::ModulePrivate() : 27 | signalHandler(make_shared(SIGINT)) 28 | { 29 | } 30 | 31 | ModulePrivate::~ModulePrivate() 32 | { 33 | } 34 | -------------------------------------------------------------------------------- /src/wintermute-daemon/module.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "module.hpp" 25 | #include "module.hh" 26 | 27 | using Wintermute::Method; 28 | using Wintermute::Module; 29 | using DaemonModule = Wintermute::Daemon::Module; 30 | using Wintermute::Events::SignalEvent; 31 | 32 | DaemonModule::Module() : 33 | Wintermute::Module(Module::Designation("in.wintermute", "daemon")), 34 | d_ptr(new DaemonModule::_Prv) 35 | { 36 | W_PRV(Daemon::Module); 37 | 38 | d->signalHandler->listenForEvent(W_EVENT_SIGNAL, 39 | [&](const SignalEvent::Ptr& sigEvent){ 40 | wdebug("Signal given..."); 41 | assert(sigEvent); 42 | }); 43 | } 44 | 45 | DaemonModule::~Module() 46 | { 47 | } 48 | 49 | void DaemonModule::startRelay() 50 | { 51 | // TODO: Update 'Module' to have a generator method for this. 52 | Method::Ptr startMethodCall = std::make_shared( 53 | "startRelay", 54 | Module::Designation(WINTERMUTE_DOMAIN, "heartbeat"), 55 | designation() 56 | ); 57 | 58 | startMethodCall->invoke(); 59 | } 60 | 61 | void DaemonModule::stopRelay() 62 | { 63 | // TODO: Update 'Module' to have a generator method for this. 64 | Method::Ptr stopMethodCall = std::make_shared( 65 | "stopRelay", 66 | Module::Designation(WINTERMUTE_DOMAIN, "heartbeat"), 67 | designation() 68 | ); 69 | 70 | stopMethodCall->invoke(); 71 | } 72 | -------------------------------------------------------------------------------- /src/wintermute-daemon/module.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_DAEMON_MODULE_HH_ 22 | #define WINTERMUTE_DAEMON_MODULE_HH_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace Wintermute 30 | { 31 | namespace Daemon 32 | { 33 | class ModulePrivate 34 | { 35 | public: 36 | Events::SignalHandler::Ptr signalHandler; 37 | 38 | explicit ModulePrivate(); 39 | virtual ~ModulePrivate(); 40 | }; 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/wintermute-daemon/module.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_DAEMON_MODULE_HPP_ 22 | #define WINTERMUTE_DAEMON_MODULE_HPP_ 23 | 24 | #include 25 | 26 | namespace Wintermute 27 | { 28 | namespace Daemon 29 | { 30 | class ModulePrivate; 31 | class Module : public Wintermute::Module 32 | { 33 | W_DEF_PRIVATE(Module); 34 | 35 | public: 36 | explicit Module(); 37 | virtual ~Module(); 38 | void startRelay(); 39 | void stopRelay(); 40 | }; 41 | } 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /src/wintermute-daemon/plugin.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_DAEMON_PLUGIN_HH_ 22 | #define WINTERMUTE_DAEMON_PLUGIN_HH_ 23 | 24 | #include 25 | #include "globals.hpp" 26 | #include "module.hpp" 27 | 28 | namespace Wintermute 29 | { 30 | namespace Daemon { 31 | class PluginPrivate 32 | { 33 | public: 34 | explicit PluginPrivate(); 35 | ~PluginPrivate(); 36 | void loadHeartbeat(); 37 | void unloadHeartbeat(); 38 | Util::Configuration::Ptr config() const; 39 | Daemon::Module::Ptr module; 40 | 41 | private: 42 | /* data */ 43 | }; 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/wintermute-daemon/plugin.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_DAEMON_PLUGIN_HPP_ 22 | # define WINTERMUTE_DAEMON_PLUGIN_HPP_ 23 | 24 | #include 25 | #include "globals.hpp" 26 | 27 | namespace Wintermute 28 | { 29 | namespace Daemon 30 | { 31 | class PluginPrivate; 32 | class Plugin : public Wintermute::Plugin 33 | { 34 | W_DEF_PRIVATE(Wintermute::Daemon::Plugin) 35 | 36 | public: 37 | explicit Plugin(); 38 | virtual ~Plugin(); 39 | virtual bool startup(); 40 | virtual bool shutdown(); 41 | virtual Plugin::PluginType type() const; 42 | 43 | private: 44 | void startHeartbeatInstance(); 45 | void stopHeartbeatInstance(); 46 | void startModule(); 47 | void stopModule(); 48 | void startDesignatedPlugins(); 49 | void stopDesignatedPlugins(); 50 | }; 51 | } 52 | } 53 | 54 | W_DECL_PLUGIN(Wintermute::Daemon::Plugin, WINTERMUTE_DAEMON_VERSION) 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/wintermute-daemon/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | PROJECT(WintermuteHeartbeat CXX) 22 | 23 | INCLUDE(WintermutePlugin) 24 | 25 | SET(WINTERMUTE_HEARTBEAT_VERSION 0.0.1-dev) 26 | 27 | SET(_srcs 28 | plugin.cpp 29 | plugin.cc 30 | module.cpp 31 | module.cc 32 | pong_message.cpp 33 | ping_message.cpp 34 | pong_module.cpp 35 | ping_module.cpp 36 | ) 37 | 38 | CONFIGURE_FILE(globals.hpp.in 39 | ${CMAKE_CURRENT_SOURCE_DIR}/globals.hpp 40 | @ONLY 41 | ) 42 | 43 | ADD_LIBRARY(wintermute-heartbeat 44 | SHARED ${_srcs} 45 | ) 46 | 47 | WINTERMUTE_PLUGIN_DECLARE( 48 | NAME heartbeat 49 | TARGET wintermute-heartbeat 50 | VERSION ${WINTERMUTE_HEARTBEAT_VERSION} 51 | ) 52 | 53 | WINTERMUTE_PLUGIN_VALIDATE(TARGET wintermute-heartbeat) 54 | 55 | ADD_SUBDIRECTORY(test) 56 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/globals.hpp.in: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_GLOBALS_HPP_ 22 | # define WINTERMUTE_HEARTBEAT_GLOBALS_HPP_ 23 | 24 | #include 25 | 26 | /** 27 | * Defines the name of the heartbeat plugin. 28 | * @todo Document. 29 | * @def WINTERMUTE_HEARTBEAT_PLUGIN_NAME 30 | */ 31 | #define WINTERMUTE_HEARTBEAT_PLUGIN_NAME "wintermute-heartbeat" 32 | 33 | /** 34 | * Defines the base domain to be used for module calls. 35 | * @todo Document 36 | * @def WINTERMUTE_HEARTBEAT_DOMAIN 37 | */ 38 | #define WINTERMUTE_HEARTBEAT_DOMAIN WINTERMUTE_DOMAIN 39 | #define WINTERMUTE_HEARTBEAT_MODULE "heartbeat" 40 | #define WINTERMUTE_HEARTBEAT_MODULE_PONGER WINTERMUTE_HEARTBEAT_MODULE".ponger" 41 | #define WINTERMUTE_HEARTBEAT_MODULE_PINGER WINTERMUTE_HEARTBEAT_MODULE".pinger" 42 | 43 | /** 44 | * Defines the rate of message sending in milliseconds. 45 | * @todo Document. 46 | * @def WINTERMUTE_HEARTBEAT_INTERVAL 47 | */ 48 | #define WINTERMUTE_HEARTBEAT_INTERVAL 750 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/messages.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_MESSAGES_HPP_ 22 | # define WINTERMUTE_HEARTBEAT_MESSAGES_HPP_ 23 | 24 | #include 25 | #include 26 | #include "module.hpp" 27 | #include "globals.hpp" 28 | 29 | namespace Wintermute 30 | { 31 | namespace Heartbeat 32 | { 33 | /** 34 | * A ping message to be sent by a child process of Wintermute. 35 | * @sa Wintermute::Message 36 | */ 37 | class PingMessage : public Wintermute::Message 38 | { 39 | friend class Wintermute::Heartbeat::Module; 40 | 41 | protected: 42 | explicit PingMessage(); 43 | virtual ~PingMessage(); 44 | 45 | public: 46 | static Message craft(); 47 | }; 48 | 49 | /** 50 | * A pong message to be sent by the heartbeat center of Wintermute. 51 | */ 52 | class PongMessage : public Wintermute::Message 53 | { 54 | friend class Wintermute::Heartbeat::Module; 55 | 56 | protected: 57 | explicit PongMessage(); 58 | virtual ~PongMessage(); 59 | 60 | public: 61 | static Message craft(); 62 | }; 63 | } 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/module.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include "module.hpp" 22 | #include "module.hh" 23 | #include 24 | #include 25 | 26 | using Wintermute::Module; 27 | using HeartbeatModule = Wintermute::Heartbeat::Module; 28 | 29 | HeartbeatModule::Module() : 30 | Wintermute::Module(Wintermute::Module::Designation( 31 | WINTERMUTE_HEARTBEAT_MODULE, 32 | WINTERMUTE_HEARTBEAT_DOMAIN 33 | )), 34 | d_ptr(make_shared()) 35 | { 36 | W_PRV(Heartbeat::Module); 37 | 38 | auto disableModuleFunc = [this](const Events::Event::Ptr& event) 39 | { 40 | wdebug("Heartbeat sub module disabling..."); 41 | this->d_ptr->tearDownSubModule(); 42 | wdebug("Heartbeat sub module disabled."); 43 | }; 44 | 45 | d->setUpSubModule(); 46 | listenForEvent(WINTERMUTE_EVENT_MODULE_DISABLE, disableModuleFunc); 47 | } 48 | 49 | HeartbeatModule::~Module() 50 | { 51 | } 52 | 53 | bool HeartbeatModule::sendMessage(const Message& message) 54 | { 55 | return false; 56 | } 57 | 58 | bool HeartbeatModule::receiveMessage(const Message& message) const 59 | { 60 | return false; 61 | } 62 | 63 | HeartbeatModule::Mode HeartbeatModule::mode() const 64 | { 65 | W_PRV(const Heartbeat::Module); 66 | return d->mode; 67 | } 68 | 69 | void HeartbeatModule::setMode(const HeartbeatModule::Mode modeToUse) 70 | { 71 | W_PRV(Heartbeat::Module); 72 | d->mode = modeToUse; 73 | } 74 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/module.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "module.hpp" 25 | 26 | using std::string; 27 | 28 | namespace Wintermute 29 | { 30 | namespace Heartbeat 31 | { 32 | class ModulePrivate 33 | { 34 | public: 35 | explicit ModulePrivate(); 36 | virtual ~ModulePrivate(); 37 | void setUpSubModule(); 38 | void tearDownSubModule(); 39 | Wintermute::Module::Ptr modeModule; 40 | Heartbeat::Module::Mode mode; 41 | 42 | private: 43 | void generateUuid(); 44 | void determineMode(); 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/module.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_MODULE_HPP_ 22 | # define WINTERMUTE_HEARTBEAT_MODULE_HPP_ 23 | 24 | #include 25 | #include "globals.hpp" 26 | 27 | namespace Wintermute 28 | { 29 | namespace Heartbeat 30 | { 31 | class ModulePrivate; 32 | class Module : public Wintermute::Module 33 | { 34 | W_DEF_PRIVATE(Wintermute::Heartbeat::Module) 35 | public: 36 | W_DECL_PTR_TYPE(Wintermute::Heartbeat::Module) 37 | 38 | public: 39 | explicit Module(); 40 | virtual ~Module(); 41 | 42 | enum Mode { 43 | ModeUndefined = 0x0, 44 | ModePing = 0x1, 45 | ModePong = 0x2 46 | }; 47 | 48 | void setMode(const Mode modeToUse); 49 | Mode mode() const; 50 | 51 | protected: 52 | virtual bool sendMessage(const Message& message); 53 | virtual bool receiveMessage(const Message& message) const; 54 | }; 55 | } 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/ping_message.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include "messages.hpp" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using Wintermute::Message; 29 | using Wintermute::Plugin; 30 | using Wintermute::Heartbeat::PingMessage; 31 | using Wintermute::Util::join_string; 32 | using std::for_each; 33 | 34 | PingMessage::PingMessage() : Message() 35 | { 36 | } 37 | 38 | PingMessage::~PingMessage() 39 | { 40 | } 41 | 42 | Message PingMessage::craft() 43 | { 44 | Message msg; 45 | Message::HashType msgData; 46 | list pluginNames, moduleNames; 47 | const auto pluginList = Plugin::all(); 48 | const auto moduleList = Module::Pool::instance()->modules(); 49 | 50 | if (!pluginList.empty()) 51 | { 52 | for ( auto pluginName : pluginList ) 53 | { 54 | pluginNames.push_back(pluginName); 55 | } 56 | } 57 | 58 | if (!moduleList.empty()) 59 | { 60 | for_each ( begin(moduleList), end(moduleList), 61 | [&moduleNames](const Wintermute::Module::Ptr& modulePtr) 62 | { 63 | auto des = modulePtr->designation(); 64 | string name = des.domain() + "." + des.name(); 65 | moduleNames.push_back(name); 66 | }); 67 | } 68 | 69 | const auto pluginNamesStr = join_string(pluginNames, ","); 70 | const auto moduleNamesStr = join_string(moduleNames, ","); 71 | 72 | msgData.emplace("modules", moduleNamesStr); 73 | msgData.emplace("plugins", pluginNamesStr); 74 | msg.setPayload(msgData); 75 | msg.setReceiver(Module::Designation( 76 | WINTERMUTE_HEARTBEAT_MODULE_PONGER, 77 | WINTERMUTE_HEARTBEAT_DOMAIN 78 | )); 79 | return msg; 80 | } 81 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/ping_module.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include 22 | #include "ping_module.hpp" 23 | #include "globals.hpp" 24 | #include "messages.hpp" 25 | 26 | using Wintermute::Heartbeat::PingModule; 27 | using Wintermute::Heartbeat::PongMessage; 28 | using Wintermute::Module; 29 | using Wintermute::Events::Timer; 30 | using Wintermute::Events::Event; 31 | using std::placeholders::_1; 32 | 33 | PingModule::PingModule() : 34 | Module(Wintermute::Module::Designation( 35 | WINTERMUTE_HEARTBEAT_MODULE_PINGER, 36 | WINTERMUTE_HEARTBEAT_DOMAIN 37 | )), 38 | timer(make_shared()) 39 | { 40 | auto bindFunc = bind(&PingModule::onTimerElasped, *this, _1); 41 | timer->setInterval(WINTERMUTE_HEARTBEAT_INTERVAL); 42 | timer->listenForEvent(W_EVENT_TIMEOUT, bindFunc); 43 | 44 | listenForEvent(WINTERMUTE_EVENT_MODULE_ENABLE, 45 | [this](const Event::Ptr& event) 46 | { 47 | this->timer->start(); 48 | }); 49 | } 50 | 51 | PingModule::~PingModule() 52 | { 53 | } 54 | 55 | void PingModule::onTimerElasped(const Event::Ptr& event) 56 | { 57 | assert(event); 58 | wdebug("Timer elasped; sending ping message."); 59 | const auto msg = PingMessage::craft(); 60 | sendMessage(msg); 61 | wdebug("Sent ping message."); 62 | } 63 | 64 | bool PingModule::sendMessage(const Message& message) 65 | { 66 | return Module::sendMessage(message); 67 | } 68 | 69 | bool PingModule::receiveMessage(const Message& message) const 70 | { 71 | return Module::receiveMessage(message); 72 | } 73 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/ping_module.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_PING_MODULE_HPP_ 22 | # define WINTERMUTE_HEARTBEAT_PING_MODULE_HPP_ 23 | 24 | #include "globals.hpp" 25 | #include 26 | #include 27 | 28 | namespace Wintermute 29 | { 30 | namespace Heartbeat 31 | { 32 | class PingModule : public Wintermute::Module 33 | { 34 | public: 35 | W_DECL_PTR_TYPE(PingModule) 36 | 37 | Events::Timer::Ptr timer; 38 | void onTimerElasped(const Events::Event::Ptr& ); 39 | 40 | public: 41 | explicit PingModule(); 42 | virtual ~PingModule(); 43 | 44 | protected: 45 | virtual bool sendMessage(const Message& message) override; 46 | virtual bool receiveMessage(const Message& message) const override; 47 | }; 48 | } /* end namespace Heartbeat */ 49 | } /* end namespace Wintermute */ 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/plugin.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "plugin.hh" 25 | 26 | using Wintermute::Plugin; 27 | using HeartbeatPluginPrivate = Wintermute::Heartbeat::PluginPrivate; 28 | using std::to_string; 29 | 30 | HeartbeatPluginPrivate::PluginPrivate() : 31 | module() 32 | { 33 | } 34 | 35 | HeartbeatPluginPrivate::~PluginPrivate() 36 | { 37 | } 38 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/plugin.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_PLUGIN_HH_ 22 | # define WINTERMUTE_HEARTBEAT_PLUGIN_HH_ 23 | 24 | #include "globals.hpp" 25 | #include "module.hpp" 26 | #include "plugin.hpp" 27 | 28 | namespace Wintermute 29 | { 30 | namespace Heartbeat { 31 | class PluginPrivate 32 | { 33 | public: 34 | explicit PluginPrivate(); 35 | ~PluginPrivate(); 36 | Heartbeat::Module::Ptr module; 37 | Events::Listener::Ptr startUpModuleListener; 38 | Events::Listener::Ptr shutDownModuleListener; 39 | }; 40 | } /* end namespace Heartbeat */ 41 | } /* end namespace Wintermute */ 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/plugin.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_PLUGIN_HPP_ 22 | # define WINTERMUTE_HEARTBEAT_PLUGIN_HPP_ 23 | 24 | #include 25 | #include "globals.hpp" 26 | 27 | namespace Wintermute 28 | { 29 | namespace Heartbeat 30 | { 31 | class PluginPrivate; 32 | class Plugin final : public Wintermute::Plugin 33 | { 34 | W_DEF_PRIVATE(Wintermute::Heartbeat::Plugin) 35 | 36 | public: 37 | explicit Plugin(); 38 | ~Plugin(); 39 | bool startup() override; 40 | bool shutdown() override; 41 | Plugin::PluginType type() const override; 42 | }; 43 | } 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/pong_message.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include "messages.hpp" 22 | #include "pong_module.hpp" 23 | #include 24 | 25 | using std::dynamic_pointer_cast; 26 | using Wintermute::Message; 27 | using Wintermute::Heartbeat::Module; 28 | using Wintermute::Heartbeat::PongMessage; 29 | 30 | // TODO: Have this require a module to pull the UUID from. 31 | PongMessage::PongMessage() : 32 | Message() 33 | { 34 | } 35 | 36 | PongMessage::~PongMessage() 37 | { 38 | } 39 | 40 | /* 41 | * TODO: Craft the required UUID message for this instance. 42 | */ 43 | Message PongMessage::craft() 44 | { 45 | Message msg; 46 | auto hbDes = Module::Designation( 47 | WINTERMUTE_HEARTBEAT_MODULE_PONGER, 48 | WINTERMUTE_HEARTBEAT_DOMAIN 49 | ); 50 | 51 | auto modulePtr = Module::Pool::instance()->find(hbDes); 52 | assert(modulePtr); 53 | 54 | auto pongModulePtr = dynamic_pointer_cast(modulePtr); 55 | assert(pongModulePtr); 56 | 57 | if (!modulePtr || !pongModulePtr) 58 | { 59 | return msg; 60 | } 61 | 62 | const string uuid = pongModulePtr->uuid; 63 | 64 | Message::HashType msgData; 65 | msgData.emplace("uuid", uuid); 66 | msg.setPayload(msgData); 67 | msg.setReceiver(Module::Designation( 68 | WINTERMUTE_HEARTBEAT_MODULE_PINGER, 69 | WINTERMUTE_HEARTBEAT_DOMAIN 70 | )); 71 | 72 | return msg; 73 | } 74 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/pong_module.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wintermute - A foundation for intelligent computing. 3 | Copyright (c) 2010 - 2015 by Jacky Alcine 4 | 5 | Wintermute is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public 7 | License as published by the Free Software Foundation; either 8 | version 3 of the License, or (at your option) any later version. 9 | 10 | Wintermute is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with Wintermute; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef WINTERMUTE_HEARTBEAT_PONG_MODULE_HPP_ 22 | # define WINTERMUTE_HEARTBEAT_PONG_MODULE_HPP_ 23 | 24 | #include "globals.hpp" 25 | #include 26 | 27 | namespace Wintermute 28 | { 29 | namespace Heartbeat 30 | { 31 | class PongModule : public Wintermute::Module 32 | { 33 | Events::Timer::Ptr timer; 34 | void onTimerElasped(const Events::Event::Ptr& ); 35 | 36 | public: 37 | W_DECL_PTR_TYPE(PongModule) 38 | explicit PongModule(); 39 | ~PongModule() override; 40 | string uuid; 41 | void regenerateUuid(); 42 | 43 | protected: 44 | virtual bool sendMessage(const Message& message); 45 | virtual bool receiveMessage(const Message& message) const; 46 | }; 47 | } 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/wintermute-heartbeat/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | 22 | macro(_add_heartbeat_test name file) 23 | WINTERMUTE_PLUGIN_ADD_TEST( 24 | PREFIX unit-heartbeat 25 | TARGET wintermute-heartbeat 26 | NAME ${name} 27 | HEADER ${CMAKE_CURRENT_SOURCE_DIR}/${file} 28 | ) 29 | endmacro() 30 | 31 | _add_heartbeat_test(message-transport message-transport.hh) 32 | _add_heartbeat_test(message-structure message-structure.hh) 33 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | PROJECT(WintermtueTransportZeroMQ CXX) 22 | 23 | INCLUDE(WintermutePlugin) 24 | FIND_PACKAGE(ZeroMQCXX REQUIRED) 25 | 26 | if (NOT ZEROMQCXX_FOUND) 27 | message(STATUS "ZeroMQ not found; not building extension.") 28 | return() 29 | endif() 30 | 31 | SET(WINTERMUTE_ZMQ_VERSION 0.0.1-dev) 32 | SET(WINTERMUTE_ZMQ_IPC_ADDRESS /tmp/wintermute.sock) 33 | 34 | SET(_srcs 35 | plugin.cpp 36 | dispatcher.cpp 37 | receiver.cpp 38 | ) 39 | 40 | CONFIGURE_FILE(globals.hpp.in 41 | ${CMAKE_CURRENT_SOURCE_DIR}/globals.hpp 42 | @ONLY 43 | ) 44 | 45 | ADD_LIBRARY(wintermute-transport-zmq 46 | SHARED ${_srcs} 47 | ) 48 | 49 | TARGET_LINK_LIBRARIES(wintermute-transport-zmq ${ZEROMQCXX_LIBRARIES}) 50 | 51 | TARGET_INCLUDE_DIRECTORIES(wintermute-transport-zmq 52 | PUBLIC ${ZEROMQCXX_INCLUDE_DIRS} 53 | ) 54 | 55 | WINTERMUTE_PLUGIN_DECLARE( 56 | NAME wintermute-transport-zmq 57 | TARGET wintermute-transport-zmq 58 | VERSION ${WINTERMUTE_ZMQ_VERSION} 59 | ) 60 | 61 | WINTERMUTE_PLUGIN_VALIDATE(TARGET wintermute-transport-zmq) 62 | 63 | ADD_SUBDIRECTORY(test) 64 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/README.markdown: -------------------------------------------------------------------------------- 1 | # [ZeroMQ][] Support for Wintermute 2 | This library aims to extend Wintermute's ability to communicate with other 3 | processes by making use of [ZeroMQ][], specifically in a publish-subscribe 4 | fashion. There's a core socket that Wintermute communicates over in a 5 | write-only fashion dubbed `wintermute.sock`. Each sub process has their own 6 | dedicated input socket, dubbed `wintermute-${PID}.sock`. There's also a general 7 | purpose TCP port used by Wintermute to allow for external communication with 8 | all sub processes. 9 | 10 | [zeromq]: https://github.com/zeromq/zmqpp 11 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/dispatcher.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_ZMQ_DISPATCHER_HPP_ 19 | # define WINTERMUTE_ZMQ_DISPATCHER_HPP_ 20 | 21 | #include 22 | #include 23 | #include "globals.hpp" 24 | 25 | namespace Wintermute 26 | { 27 | class ZMQDispatcher : public Tunnel::Dispatcher 28 | { 29 | private: 30 | SharedPtr context; 31 | SharedPtr socketPtr; 32 | void bindTo(const string& bindStr); 33 | list clients() const; 34 | 35 | public: 36 | W_DECL_PTR_TYPE(ZMQDispatcher) 37 | explicit ZMQDispatcher(const SharedPtr& context); 38 | virtual ~ZMQDispatcher(); 39 | virtual bool send(const Message& message) final; 40 | virtual void start(); 41 | virtual void stop(); 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/globals.hpp.in: -------------------------------------------------------------------------------- 1 | /* 2 | * vim: set ft=cpp : 3 | * Wintermute is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Library General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 3 of the License, or (at your option) any later version. 7 | * 8 | * Wintermute is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Library General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Library General Public 14 | * License along with Wintermute; if not, write to the 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | * Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef WINTERMUTE_ZMQ_GLOBALS_HPP 20 | #define WINTERMUTE_ZMQ_GLOBALS_HPP 21 | 22 | #include 23 | 24 | #define WINTERMUTE_ZMQ_PLUGIN_NAME "ZMQ" 25 | #define WINTERMUTE_ZMQ_TUNNEL_NAME "zmq" 26 | #define WINTERMUTE_ZMQ_VERSION "@WINTERMUTE_ZMQ_VERSION@" 27 | #define WINTERMUTE_ZMQ_PORT 9931 28 | #define WINTERMUTE_ZMQ_IPC_ADDRESS "@WINTERMUTE_ZMQ_IPC_ADDRESS@" 29 | #define WINTERMUTE_ZMQ_FILTER "{" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/plugin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include "globals.hpp" 20 | #include "plugin.hpp" 21 | #include "dispatcher.hpp" 22 | #include "receiver.hpp" 23 | 24 | using Wintermute::Plugin; 25 | using Wintermute::ZMQPlugin; 26 | using Wintermute::ZMQDispatcher; 27 | using Wintermute::ZMQReceiver; 28 | 29 | ZMQPlugin::ZMQPlugin() : 30 | Plugin(WINTERMUTE_ZMQ_PLUGIN_NAME), 31 | context(nullptr), 32 | receiver(nullptr), 33 | dispatcher(nullptr) 34 | { 35 | assert(!receiver); 36 | assert(!dispatcher); 37 | 38 | context = make_shared(); 39 | assert(context); 40 | } 41 | 42 | ZMQPlugin::~ZMQPlugin() 43 | { 44 | wdebug("Killed the ZeroMQ plugin."); 45 | } 46 | 47 | bool ZMQPlugin::startup() 48 | { 49 | wdebug("ZeroMQ plugin starting..."); 50 | if (!receiver) 51 | { 52 | ZMQReceiver* r = new ZMQReceiver(context); 53 | receiver.reset(r); 54 | assert(receiver.unique()); 55 | } 56 | 57 | if (!dispatcher) 58 | { 59 | dispatcher = make_shared(context); 60 | assert(dispatcher); 61 | } 62 | 63 | assert(Tunnel::registerReceiver(receiver)); 64 | assert(Tunnel::registerDispatcher(dispatcher)); 65 | wdebug("ZeroMQ plugin started."); 66 | return true; 67 | } 68 | 69 | bool ZMQPlugin::shutdown() 70 | { 71 | wdebug("ZeroMQ plugin shutting down..."); 72 | assert(Tunnel::unregisterDispatcher(dispatcher)); 73 | assert(Tunnel::unregisterReceiver(receiver)); 74 | receiver.reset(); 75 | dispatcher.reset(); 76 | wdebug("ZeroMQ plugin shut down."); 77 | return true; 78 | } 79 | 80 | Plugin::PluginType ZMQPlugin::type() const 81 | { 82 | return Plugin::PluginTypeSupport; 83 | } 84 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/plugin.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | #include 20 | #include "dispatcher.hpp" 21 | #include "receiver.hpp" 22 | 23 | namespace Wintermute 24 | { 25 | class ZMQPlugin : public Plugin 26 | { 27 | public: 28 | explicit ZMQPlugin(); 29 | virtual ~ZMQPlugin(); 30 | virtual bool startup(); 31 | virtual bool shutdown(); 32 | virtual Plugin::PluginType type() const; 33 | 34 | SharedPtr context; 35 | ZMQReceiver::Ptr receiver; 36 | ZMQDispatcher::Ptr dispatcher; 37 | }; 38 | } 39 | 40 | W_DECL_PLUGIN(Wintermute::ZMQPlugin, WINTERMUTE_VERSION) 41 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/receiver.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_ZMQ_RECEIVER_HPP_ 19 | # define WINTERMUTE_ZMQ_RECEIVER_HPP_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace Wintermute 26 | { 27 | class ZMQReceiver : public Tunnel::Receiver 28 | { 29 | private: 30 | SharedPtr context; 31 | SharedPtr socketPtr; 32 | Events::Poller::Ptr pollerPtr; 33 | Events::Listener::Ptr listenerReceived; 34 | 35 | list clients(); 36 | void connectToClients(); 37 | void disconnectFromClients(); 38 | void attachPoller(); 39 | void attachPollerToSocket(); 40 | void detachPoller(); 41 | void subscribeTo(const string& subscriptionStr); 42 | void unsubscribeFrom(const string& subscriptionStr); 43 | void connectTo(const string& connectionStr); 44 | void disconnectFrom(const string& connectionStr); 45 | 46 | public: 47 | W_DECL_PTR_TYPE(ZMQReceiver) 48 | explicit ZMQReceiver(const SharedPtr& context); 49 | virtual ~ZMQReceiver(); 50 | virtual void start(); 51 | virtual void stop(); 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/wintermute-transport-zeromq/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 21 | 22 | WINTERMUTE_PLUGIN_ADD_TEST( 23 | PREFIX unit-zmq 24 | TARGET wintermute-transport-zmq 25 | NAME tunnel 26 | HEADER ${CMAKE_CURRENT_SOURCE_DIR}/tunnel.hh 27 | ) 28 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | PROJECT(WintermuteTest) 21 | 22 | INCLUDE(WintermuteTest) 23 | INCLUDE(WintermuteDependencies) 24 | 25 | ADD_SUBDIRECTORY(fixtures) 26 | ADD_SUBDIRECTORY(unit) 27 | ADD_SUBDIRECTORY(features) 28 | -------------------------------------------------------------------------------- /test/CTestConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(CTEST_PROJECT_NAME "@PROJECT_NAME@") 2 | set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") 3 | set(CTEST_DROP_METHOD "http") 4 | set(CTEST_DROP_SITE "my.cdash.org") 5 | set(CTEST_DROP_LOCATION "/submit.php?project=Wintermute") 6 | set(CTEST_DROP_SITE_CDASH TRUE) 7 | set(DART_VERBOSE_BUILD ON) 8 | -------------------------------------------------------------------------------- /test/features/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | # TODO Set up behavioral level testing here 22 | # TODO Include the use of cppspec. 23 | # TODO (test) Ensure that a message can be sent from one module to another 24 | # locally. 25 | #FIND_PACKAGE(CppSpec REQUIRED) 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | PROJECT(WintermuteTestFixtures) 21 | INCLUDE(WintermutePlugin) 22 | 23 | # TODO: Create dynamic fixture library to drop into tests. 24 | 25 | set(_srcs 26 | ./wintermute_sample.cc 27 | ) 28 | 29 | ADD_LIBRARY(wintermute-sample-plugin SHARED ${_srcs}) 30 | 31 | WINTERMUTE_PLUGIN_DECLARE( 32 | AUTO_INSTALL OFF 33 | TARGET 34 | wintermute-sample-plugin 35 | INCLUDE_DIRECTORIES 36 | ${WINTERMUTE_TEST_INCLUDE_DIRS} 37 | ) 38 | -------------------------------------------------------------------------------- /test/fixtures/wintermute_sample.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #define WINTERMUTE_TEST_SAMPLE 1 19 | #include 20 | #include "test_suite.hpp" 21 | #include "wintermute_sample.hh" 22 | 23 | int w_sample_test() 24 | { 25 | winfo("Invoking a function from beyond."); 26 | return 2014; 27 | } 28 | 29 | using Wintermute::Plugin; 30 | using Wintermute::SamplePlugin; 31 | 32 | SamplePlugin::SamplePlugin() : Plugin(SAMPLE_PLUGIN_NAME) 33 | { 34 | wdebug("Created the sample plugin!"); 35 | } 36 | 37 | SamplePlugin::~SamplePlugin() 38 | { 39 | wdebug("Killed the sample plugin!"); 40 | } 41 | 42 | bool SamplePlugin::startup() 43 | { 44 | wdebug("Sample plugin started."); 45 | return true; 46 | } 47 | 48 | bool SamplePlugin::shutdown() 49 | { 50 | wdebug("Sample plugin killed."); 51 | return true; 52 | } 53 | 54 | Plugin::PluginType SamplePlugin::type() const 55 | { 56 | return Plugin::PluginTypeSupport; 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/wintermute_sample.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include 19 | 20 | namespace Wintermute 21 | { 22 | class SamplePlugin : public Plugin 23 | { 24 | public: 25 | explicit SamplePlugin(); 26 | virtual ~SamplePlugin(); 27 | virtual bool startup(); 28 | virtual bool shutdown(); 29 | virtual Plugin::PluginType type() const; 30 | }; 31 | } 32 | 33 | W_DECL_PLUGIN(Wintermute::SamplePlugin, WINTERMUTE_VERSION) 34 | 35 | extern "C" int w_sample_test(); 36 | -------------------------------------------------------------------------------- /test/include/test_suite.hpp.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #ifndef WINTERMUTE_TEST_SUITE_HPP 19 | #define WINTERMUTE_TEST_SUITE_HPP 20 | 21 | #define TEST_BASE_DIR "@CMAKE_BINARY_DIR@/test" 22 | #define TEST_LIB_DIR "@CMAKE_BINARY_DIR@/lib" 23 | #define TEST_BIN_DIR "@CMAKE_BINARY_DIR@/bin" 24 | #define SAMPLE_PLUGIN_NAME "sample" 25 | #define SAMPLE_PLUGIN_SIMPLE_NAME "sample-plugin" 26 | 27 | #define SAMPLE_PLUGIN_FILE_NAME \ 28 | "libwintermute-" SAMPLE_PLUGIN_SIMPLE_NAME ".so" 29 | 30 | #define SAMPLE_PLUGIN_PATH \ 31 | "@CMAKE_BINARY_DIR@/lib/" SAMPLE_PLUGIN_FILE_NAME 32 | 33 | #define SAMPLE_TEST_FILE "@CMAKE_SOURCE_DIR@/CMakeLists.txt" 34 | 35 | #ifndef WINTERMUTE_TEST_SAMPLE 36 | #include "fixtures.hpp" 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /test/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sts=2 sw=2 fdm=indent 2 | ############################################################################### 3 | # Author: Jacky Alciné 4 | # 5 | # Wintermute is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Library General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3 of the License, or (at your option) any later version. 9 | # 10 | # Wintermute is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Library General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Library General Public 16 | # License along with Wintermute; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | ############################################################################### 20 | 21 | macro(add_a_unit_test _name) 22 | wintermute_add_test(unit ${_name} 23 | ${CMAKE_SOURCE_DIR}/test/unit/${_name}.hh) 24 | endmacro(add_a_unit_test) 25 | 26 | configure_file(sample.cfg.in sample.cfg @ONLY) 27 | 28 | # == Define the root tests. 29 | add_a_unit_test(util) 30 | add_a_unit_test(util_serializable) 31 | add_a_unit_test(util_configuration) 32 | add_a_unit_test(singleton) 33 | add_a_unit_test(message) 34 | add_a_unit_test(module) 35 | add_a_unit_test(module_pool) 36 | add_a_unit_test(module_designation) 37 | add_a_unit_test(call) 38 | #add_a_unit_test(signal) 39 | #add_a_unit_test(signalable) 40 | #add_a_unit_test(reply_call) 41 | #add_a_unit_test(signal_call) 42 | add_a_unit_test(tunnel) 43 | add_a_unit_test(tunnel_dispatcher) 44 | add_a_unit_test(tunnel_receiver) 45 | add_a_unit_test(method) 46 | add_a_unit_test(plugin) 47 | add_a_unit_test(library) 48 | add_a_unit_test(version) 49 | add_a_unit_test(event_loop) 50 | add_a_unit_test(event_emitter) 51 | add_a_unit_test(event_listener) 52 | add_a_unit_test(event_poller) 53 | add_a_unit_test(event_timer) 54 | -------------------------------------------------------------------------------- /test/unit/call.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include "wintermute-core/call.hpp" 20 | 21 | using Wintermute::Logging; 22 | using Wintermute::Call; 23 | 24 | class CallTestSuite : public CxxTest::TestSuite 25 | { 26 | public: 27 | void testBuildVoidCalls() 28 | { 29 | const string args; 30 | Call::Ptr voidCall(new SampleVoidCall); 31 | const string result = voidCall->invokeFunction(args); 32 | TS_ASSERT ( result.empty() ); 33 | } 34 | 35 | void testBuildCallsWithReturnValue() 36 | { 37 | const string value("cookie"), args; 38 | Call::Ptr resultCall(new SampleCallWithValue(value)); 39 | const string result = resultCall->invokeFunction(args); 40 | TS_ASSERT_EQUALS ( result, value ); 41 | } 42 | 43 | void testCallPermitNoParameters() 44 | { 45 | const string args = "foo"; 46 | Call::Ptr resultCall(new SampleCallWithValue(args)); 47 | TS_ASSERT_EQUALS ( resultCall->invokeFunction(args), args ); 48 | } 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /test/unit/event_listener.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include "wintermute-core/events.hpp" 20 | 21 | using Wintermute::Events::Loop; 22 | using Wintermute::Events::Event; 23 | using Wintermute::Events::Listener; 24 | 25 | class EventListenerTestSuite : public CxxTest::TestSuite 26 | { 27 | public: 28 | void testPreventEmptyCallbacks() 29 | { 30 | Listener::Ptr listener; 31 | Listener::Callback sampleCallback; 32 | TS_ASSERT_THROWS( 33 | listener = make_shared(sampleCallback), 34 | std::invalid_argument 35 | ); 36 | } 37 | 38 | void testInvokesProvidedCallback() 39 | { 40 | Listener::Ptr listener; 41 | Event::Ptr sampleEvent = make_shared("sampleCallback"); 42 | Listener::Callback func = [&](const Event::Ptr& event) { 43 | TS_ASSERT_EQUALS(event->name(), sampleEvent->name()); 44 | }; 45 | 46 | TS_ASSERT_THROWS_NOTHING( listener = make_shared(func) ); 47 | listener->invoke(sampleEvent); 48 | } 49 | 50 | void testPreventNullEventsFromBeingInvoked() 51 | { 52 | Listener::Ptr listener; 53 | Listener::Callback func = [&](const Event::Ptr& event) { assert(event); }; 54 | 55 | TS_ASSERT_THROWS_NOTHING( listener = make_shared(func) ); 56 | TS_ASSERT_THROWS( 57 | listener->invoke(nullptr), 58 | std::invalid_argument 59 | ); 60 | } 61 | }; 62 | 63 | 64 | -------------------------------------------------------------------------------- /test/unit/event_loop.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | 20 | using ::uv_loop_t; 21 | using Wintermute::Events::Loop; 22 | 23 | class EventLoopTestSuite : public CxxTest::TestSuite 24 | { 25 | public: 26 | void testCanStartNoopLoops() 27 | { 28 | Loop::Ptr loop = make_shared(); 29 | TS_ASSERT ( loop ); 30 | TS_ASSERT ( !loop->isRunning() ); 31 | TS_ASSERT ( loop->run() ); 32 | TS_ASSERT ( !loop->isRunning() ); 33 | } 34 | 35 | void testCanUseDefaultLoop() 36 | { 37 | Loop::Ptr loop = make_shared(true); 38 | Loop::Ptr anotherLoop = make_shared(false); 39 | Loop::Ptr defaultLoop = Loop::primary(); 40 | TS_ASSERT ( loop ); 41 | TS_ASSERT ( anotherLoop ); 42 | 43 | TSM_ASSERT_EQUALS ( "Both equate to 'uv_default_loop'.", 44 | std::static_pointer_cast(loop)->uvLoop(), 45 | uv_default_loop() ); 46 | TS_ASSERT ( !anotherLoop->isPrimary() ); 47 | TS_ASSERT ( loop->isPrimary() ); 48 | TS_ASSERT ( defaultLoop->isPrimary() ); 49 | } 50 | }; 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/unit/event_timer.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include "wintermute-core/events.hpp" 20 | 21 | using Wintermute::Events::Event; 22 | using Wintermute::Events::Loop; 23 | using Wintermute::Events::Timer; 24 | 25 | class EventTimerTestSuite : public CxxTest::TestSuite 26 | { 27 | public: 28 | void testRequiresAValidEventLoop() 29 | { 30 | Timer::Ptr timer, timer2; 31 | Loop::Ptr loop = Loop::primary(); 32 | 33 | TS_ASSERT ( loop ); 34 | 35 | TS_ASSERT_THROWS_NOTHING ( 36 | timer = make_shared(loop); 37 | ); 38 | 39 | TS_ASSERT_THROWS ( 40 | timer2 = make_shared(nullptr), 41 | std::invalid_argument 42 | ); 43 | 44 | TS_ASSERT ( loop->run() ); 45 | } 46 | 47 | void testWorkWithIntervals() 48 | { 49 | Timer::Ptr timer; 50 | Loop::Ptr loop = Loop::primary(); 51 | 52 | TS_ASSERT ( loop ); 53 | TS_ASSERT_THROWS_NOTHING ( timer = make_shared(loop) ); 54 | 55 | timer->listenForEvent("core.events.timeout", 56 | [&](const Event::Ptr& event) -> void 57 | { 58 | assert(event); 59 | TS_TRACE("We get here."); 60 | assert(event); 61 | timer->stop(); 62 | }, Listener::FrequencyEvery); 63 | timer->setInterval(0); 64 | timer->start(1); 65 | 66 | TS_ASSERT ( loop->run() ); 67 | } 68 | }; 69 | -------------------------------------------------------------------------------- /test/unit/module.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include 20 | #include 21 | 22 | using Wintermute::Module; 23 | using Wintermute::Call; 24 | 25 | class ModuleTestSuite : public CxxTest::TestSuite 26 | { 27 | public: 28 | 29 | void testHasDesignation(void) 30 | { 31 | Module::Ptr modulePtr(new SampleModule); 32 | TS_ASSERT ( !modulePtr->designation().isNull() ); 33 | } 34 | 35 | // FIXME Finish this test. 36 | void testCanEnableModule(void) { } 37 | 38 | // FIXME Finish this test. 39 | void testCanDisableModule(void) { } 40 | 41 | void testAddCallToModule() 42 | { 43 | const string expectedValue("CookieMonster"); 44 | Module::Ptr modulePtr(new SampleModule); 45 | Module::Call::Ptr resultCall(new SampleModuleCallWithValue(modulePtr, expectedValue)); 46 | 47 | TS_ASSERT ( modulePtr->addCall(resultCall) ); 48 | Module::Call::Ptr obtainedCall = modulePtr->call(resultCall->name()); 49 | TS_ASSERT ( obtainedCall ); 50 | TS_ASSERT_EQUALS ( obtainedCall, resultCall ); 51 | 52 | string arguments; 53 | const string result = obtainedCall->invokeFunction(arguments); 54 | TS_ASSERT_EQUALS ( result, expectedValue ); 55 | } 56 | 57 | void testRemoveCallFromModule() 58 | { 59 | Module::Ptr modulePtr(new SampleModule); 60 | Module::Call::Ptr resultCall(new SampleModuleCallWithValue(modulePtr)); 61 | 62 | TS_ASSERT ( modulePtr->addCall(resultCall) ); 63 | TS_ASSERT ( modulePtr->removeCall(resultCall->name()) ); 64 | TS_ASSERT ( resultCall ); 65 | } 66 | }; 67 | 68 | -------------------------------------------------------------------------------- /test/unit/module_call.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include "wintermute-core/module.hpp" 20 | 21 | using Wintermute::Logging; 22 | using Wintermute::Module; 23 | 24 | class ModuleCallTestSuite : public CxxTest::TestSuite 25 | { 26 | public: 27 | 28 | void testBuildVoidCalls() 29 | { 30 | Module::Ptr module(new SampleModule); 31 | Call::Ptr voidCall(new SampleVoidModuleCall(module)); 32 | const string result = voidCall->invoke(); 33 | TS_ASSERT ( result.empty() ); 34 | } 35 | 36 | void testBuildCallsWithReturnValue() 37 | { 38 | Module::Ptr module(new SampleModule); 39 | Call::Ptr resultCall(new SampleModuleCallWithValue(module)); 40 | const string result = resultCall->invoke(); 41 | TS_ASSERT_EQUALS ( result, SampleCallWithValue::DefaultValue ); 42 | } 43 | 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /test/unit/sample.cfg.in: -------------------------------------------------------------------------------- 1 | #---------------------------- 2 | # Example Configuration File 3 | #--------------------------- 4 | # 5 | 6 | test: 7 | { 8 | value = "test"; 9 | }; 10 | 11 | 12 | ### eof 13 | -------------------------------------------------------------------------------- /test/unit/singleton.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include 20 | 21 | class SingletonClass 22 | { 23 | W_DEF_SINGLETON(SingletonClass) 24 | }; 25 | 26 | W_DECLARE_SINGLETON(SingletonClass) 27 | 28 | class SingletonTestSuite : public CxxTest::TestSuite 29 | { 30 | public: 31 | void testIsASingleton(void) 32 | { 33 | auto ptr = SingletonClass::instance(); 34 | TS_ASSERT ( ptr.get() != nullptr ); 35 | 36 | auto otherPtr = SingletonClass::instance(); 37 | TS_ASSERT ( ptr == otherPtr ); 38 | } 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /test/unit/tunnel_dispatcher.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * ree Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "test_suite.hpp" 19 | #include 20 | 21 | using Wintermute::Tunnel; 22 | using Wintermute::Message; 23 | 24 | class TunnelDispatcherTestSuite : public CxxTest::TestSuite 25 | { 26 | public: 27 | void testBuild() 28 | { 29 | Tunnel::Dispatcher::Ptr dispatcher(new SampleDispatcher); 30 | TS_ASSERT ( dispatcher ); 31 | } 32 | 33 | void testSendOutMessage(void) 34 | { 35 | Tunnel::Dispatcher::Ptr dispatcherPtr(new SampleDispatcher); 36 | TS_ASSERT ( Tunnel::registerDispatcher(dispatcherPtr) ); 37 | 38 | Message message = craftRandomMessage(); 39 | TS_ASSERT_THROWS_NOTHING ( Tunnel::sendMessage(message) ); 40 | 41 | dispatcherPtr->listenForEvent(W_EVENT_TUNNEL_MESSAGE, 42 | [&message](const Event::Ptr& eventPtr) 43 | { 44 | const Tunnel::MessageEvent::Ptr msgPtr = 45 | std::dynamic_pointer_cast(eventPtr); 46 | 47 | const Message obtainedMessage = msgPtr->message; 48 | TS_ASSERT ( !obtainedMessage.isEmpty() ); 49 | TS_ASSERT_EQUALS ( message, obtainedMessage ); 50 | Tunnel::instance()->emitter()->loop()->stop(); 51 | }); 52 | 53 | Tunnel::instance()->emitter()->loop()->run(); 54 | } 55 | 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /test/unit/util_serializable.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Wintermute is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Library General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 3 of the License, or (at your option) any later version. 6 | * 7 | * Wintermute is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Library General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Library General Public 13 | * License along with Wintermute; if not, write to the 14 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 | * Boston, MA 02111-1307, USA. 16 | */ 17 | 18 | #include "wintermute-core/util/serializable.hpp" 19 | #include 20 | 21 | using std::string; 22 | 23 | using Wintermute::Util::Serializable; 24 | 25 | class SerializableTestSuite : public CxxTest::TestSuite 26 | { 27 | public: 28 | void testConvertMapIntoString(void) 29 | { 30 | Serializable::Map aMap; 31 | aMap.insert(std::make_pair("bar", std::to_string(0x2))); 32 | aMap.insert(std::make_pair("baz", std::to_string(0x4))); 33 | aMap.insert(std::make_pair("foo", std::to_string(0x1))); 34 | 35 | const std::string theString = "{\"bar\":\"2\",\"baz\":\"4\",\"foo\":\"1\"}\n"; 36 | 37 | const std::string craftedString = Serializable::toString(aMap); 38 | TS_ASSERT_EQUALS(theString, craftedString); 39 | } 40 | 41 | void testConvertStringToMap(void) 42 | { 43 | Serializable::Map aMap; 44 | aMap.insert(std::make_pair("foo", std::to_string(0x2))); 45 | aMap.insert(std::make_pair("bar", std::to_string(0x3))); 46 | aMap.insert(std::make_pair("baz", std::to_string(0x5))); 47 | 48 | const std::string theString = "{\"foo\":2, \"bar\":3, \"baz\":5}"; 49 | 50 | const Serializable::Map craftedMap = Serializable::fromString(theString); 51 | TS_ASSERT_EQUALS(craftedMap, aMap); 52 | } 53 | }; 54 | 55 | 56 | --------------------------------------------------------------------------------