-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
leandro.costa
committed
Jun 10, 2010
1 parent
da03bb1
commit a6dd88d
Showing
7 changed files
with
235 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* casocklib - An asynchronous communication library for C++ | ||
* --------------------------------------------------------- | ||
* Copyright (C) 2010 Leandro Costa | ||
* | ||
* This file is part of casocklib. | ||
* | ||
* casocklib is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* casocklib is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with casocklib. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/*! | ||
* \file casock/rpc/protobuf/client/RPCCallTimeoutHandler.h | ||
* \brief [brief description] | ||
* \author Leandro Costa | ||
* \date 2010 | ||
* | ||
* $LastChangedDate$ | ||
* $LastChangedBy$ | ||
* $Revision$ | ||
*/ | ||
|
||
#ifndef __CASOCKLIB__CASOCK_RPC_PROTOBUF_CLIENT__RPC_CALL_TIMEOUT_HANDLER_H_ | ||
#define __CASOCKLIB__CASOCK_RPC_PROTOBUF_CLIENT__RPC_CALL_TIMEOUT_HANDLER_H_ | ||
|
||
#include "casock/util/Thread.h" | ||
#include "casock/util/Lockable.h" | ||
|
||
namespace casock { | ||
namespace rpc { | ||
namespace protobuf { | ||
namespace client { | ||
class RPCCallHash; | ||
class RPCCallQueue; | ||
|
||
class RPCCallTimeoutHandler : public casock::util::Thread, private casock::util::Lockable | ||
{ | ||
public: | ||
RPCCallTimeoutHandler (RPCCallHash& rCallHash, RPCCallQueue& rCallQueue) | ||
//: id (0), timeout (), mrCallHash (rCallHash), mrCallQueue (rCallQueue) | ||
: mrCallHash (rCallHash), mrCallQueue (rCallQueue) | ||
{ } | ||
|
||
public: | ||
void run () | ||
{ | ||
/* | ||
lock (); | ||
while (true) | ||
{ | ||
if (id == 0) | ||
cond_wait (); | ||
else | ||
cond_wait (timeout.tv_sec); | ||
if (! mrCallHash.find (id)) // or timeout already expired) | ||
{ | ||
if (mrCallHash.find (id)) | ||
{ | ||
RPCCall* pCall = mrCallHash.pop (id); | ||
} | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
public: | ||
void registerTimeout (const uint32& id, const struct timeval& timeout) | ||
{ | ||
/* | ||
lock (); | ||
this->id = id; | ||
this->timeout = timeout; | ||
cond_signal (); | ||
unlock (); | ||
*/ | ||
}; | ||
|
||
private: | ||
//uint32 id; | ||
//struct timeval timeout; | ||
RPCCallHash& mrCallHash; | ||
RPCCallQueue& mrCallQueue; | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif // __CASOCKLIB__CASOCK_RPC_PROTOBUF_CLIENT__RPC_CALL_TIMEOUT_HANDLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/tests/casock/rpc/protobuf/client/test_RPCCallTimeoutHandler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* casocklib - An asynchronous communication library for C++ | ||
* --------------------------------------------------------- | ||
* Copyright (C) 2010 Leandro Costa | ||
* | ||
* This file is part of casocklib. | ||
* | ||
* casocklib is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* casocklib is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with casocklib. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/*! | ||
* \file tests/casock/rpc/protobuf/client/test_RPCCallTimeoutHandler.cc | ||
* \brief [brief description] | ||
* \author Leandro Costa | ||
* \date 2010 | ||
* | ||
* $LastChangedDate$ | ||
* $LastChangedBy$ | ||
* $Revision$ | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "casock/rpc/protobuf/api/rpc.pb.h" | ||
#include "casock/rpc/protobuf/client/RPCCall.h" | ||
#include "casock/rpc/protobuf/client/RPCCallHash.h" | ||
#include "casock/rpc/protobuf/client/RPCCallQueue.h" | ||
#include "casock/rpc/protobuf/client/RPCCallController.h" | ||
#include "casock/rpc/protobuf/client/RPCCallTimeoutHandler.h" | ||
|
||
#include "tests/casock/rpc/protobuf/client/RPCCallHandlerFactoryStub.h" | ||
#include "tests/casock/rpc/protobuf/client/RPCClientProxyTest.h" | ||
|
||
TEST(casock_rpc_protobuf_client_RPCCallTimeoutHandler, Basic) { | ||
casock::rpc::protobuf::client::RPCCallHash hash; | ||
casock::rpc::protobuf::client::RPCCallQueue queue; | ||
casock::rpc::protobuf::client::RPCCallTimeoutHandler handler (hash, queue); | ||
|
||
handler.run (); | ||
|
||
uint32 id = 0; | ||
struct timeval timeout; | ||
timeout.tv_sec = 0; | ||
timeout.tv_usec = 0; | ||
|
||
tests::casock::rpc::protobuf::client::RPCCallHandlerFactoryStub factory; | ||
tests::casock::rpc::protobuf::client::RPCClientProxyTest proxy (factory); | ||
casock::rpc::protobuf::client::RPCCallController* pController = proxy.buildRPCCallController (); | ||
casock::rpc::protobuf::client::RPCCall *pCall = new casock::rpc::protobuf::client::RPCCall (NULL, pController, NULL); | ||
hash.push (id, pCall); | ||
|
||
handler.registerTimeout (id, pController->timeout ()); | ||
usleep (1000000 * pController->timeoutInUSeconds ()); | ||
|
||
//EXPECT_TRUE (pController->Failed ()); | ||
} | ||
|
||
int main (int argc, char **argv) { | ||
::testing::InitGoogleTest (&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters