X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fcore%2Fthread%2Fmain.cpp;h=596e9d549eaa6f500c6c08130d84aec417e50d73;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=abf2c0cb145f446634de9fb4e69692ed82db47e5;hpb=39033fd99e58e994a5e98c1060dcc79e0d81f9c9;p=anna.git diff --git a/example/core/thread/main.cpp b/example/core/thread/main.cpp index abf2c0c..596e9d5 100644 --- a/example/core/thread/main.cpp +++ b/example/core/thread/main.cpp @@ -1,37 +1,9 @@ -// ANNA - Anna is Not Nothingness Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// http://redmine.teslayout.com/projects/anna-suite -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: eduardo.ramos.testillano@gmail.com -// cisco.tierra@gmail.com +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // #include @@ -58,31 +30,31 @@ private: const int a_id; const int a_value; - void run () throw (RuntimeException); + void run () noexcept(false); anna_complete_runnable (Client); }; class SOAP { public: - static int theMethod (const int id, const int value) throw (RuntimeException); + static int theMethod (const int id, const int value) noexcept(false); }; class Receiver; class Waiter { public: - int getId () const throw () { return a_id; } - int getValue () const throw () { return a_value; } + int getId () const { return a_id; } + int getValue () const { return a_value; } - void setId (const int id) throw () { a_id = id; } - void setValue (const int value) throw () { a_value = value; } + void setId (const int id) { a_id = id; } + void setValue (const int value) { a_value = value; } - void sendRequest () throw (RuntimeException); - int waitResponse () throw (RuntimeException); - void notifyResponse (const int result) throw (RuntimeException); + void sendRequest () noexcept(false); + int waitResponse () noexcept(false); + void notifyResponse (const int result) noexcept(false); - void initialize () throw (RuntimeException); + void initialize () noexcept(false); private: static const int ReadChannel = 0; @@ -99,13 +71,13 @@ private: class Context : public SafeRecycler { public: - Waiter* createWaiter (const int id, const int value) throw (RuntimeException); - void destroyWaiter (Waiter* waiter) throw (RuntimeException); - Waiter* findWaiter (const int id) throw () { return a_waiters.find (id); } + Waiter* createWaiter (const int id, const int value) noexcept(false); + void destroyWaiter (Waiter* waiter) noexcept(false); + Waiter* findWaiter (const int id) { return a_waiters.find (id); } private: struct SortByID { - static int value (const Waiter* waiter) throw () { return waiter->getId (); } + static int value (const Waiter* waiter) { return waiter->getId (); } }; typedef SortedVector waiter_container; @@ -121,7 +93,7 @@ private: int a_id; int a_value; - void run () throw (RuntimeException); + void run () noexcept(false); anna_complete_runnable (Waiter); }; @@ -191,7 +163,7 @@ int main (const int argc, const char** argv) // Esto simula el proceso cliente que envía la petición al proceso gSOAP /* Se ejecuta desde el thread Tx */ void Client::run () - throw (RuntimeException) + noexcept(false) { int result = SOAP::theMethod (a_id, a_value); @@ -207,7 +179,7 @@ void Client::run () // que será el que le dé la respuesta "real" en algún momento. /* Tx */ int SOAP::theMethod (const int id, const int value) - throw (RuntimeException) + noexcept(false) { int result = -1; @@ -233,7 +205,7 @@ int SOAP::theMethod (const int id, const int value) /* Tx */ void Waiter::initialize () - throw (RuntimeException) + noexcept(false) { if (pipe (a_pipe) == -1) { string msg (functions::asText ("Waiter::initialize | Id: ", a_id)); @@ -243,7 +215,7 @@ void Waiter::initialize () /* Tx */ void Waiter::sendRequest () - throw (RuntimeException) + noexcept(false) { try { /* Ojo que esto generará memory-leaks, pero no es el objeto de éste ejemplo la buena gestión de la memoria */ @@ -259,7 +231,7 @@ void Waiter::sendRequest () /* Tx */ int Waiter::waitResponse () - throw (RuntimeException) + noexcept(false) { bool receive = io::functions::waitInput (a_pipe [ReadChannel], (Millisecond)500); @@ -276,20 +248,20 @@ int Waiter::waitResponse () /* Ty */ void Waiter::notifyResponse (const int result) - throw (RuntimeException) + noexcept(false) { int byte = 0; a_result = result; - write (a_pipe [WriteChannel], &byte, sizeof (byte)); + ssize_t r = write (a_pipe [WriteChannel], &byte, sizeof (byte)); } // Modela al thread que recibe la respuesta correspondiente a la petición por la // que debería haber un Waiter esperando. /* Ty */ void Receiver::run () - throw (RuntimeException) + noexcept(false) { anna::functions::sleep ((Millisecond)(rand () % 1000)); @@ -310,7 +282,7 @@ void Receiver::run () } Waiter* Context::createWaiter (const int id, const int value) - throw (RuntimeException) + noexcept(false) { Guard guard (*this, "Context::createWaiter"); @@ -330,7 +302,7 @@ Waiter* Context::createWaiter (const int id, const int value) } void Context::destroyWaiter (Waiter* waiter) - throw (RuntimeException) + noexcept(false) { Guard guard (this, "Context::destroyWaiter");