2015-08-09 22:58:13 +03:00
|
|
|
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
|
|
|
|
|
2015-03-04 03:07:11 +03:00
|
|
|
#include "Translator.h"
|
2015-03-21 18:54:52 +03:00
|
|
|
#include "TranslationRequest.h"
|
2015-08-04 03:59:28 +03:00
|
|
|
#include "Server.h"
|
2015-03-04 03:07:11 +03:00
|
|
|
|
|
|
|
namespace MosesServer
|
|
|
|
{
|
|
|
|
|
2015-05-02 13:45:24 +03:00
|
|
|
using namespace std;
|
|
|
|
using namespace Moses;
|
2015-03-04 03:07:11 +03:00
|
|
|
|
2015-05-02 13:45:24 +03:00
|
|
|
Translator::
|
2015-08-04 03:59:28 +03:00
|
|
|
Translator(Server& server)
|
2015-11-29 20:57:04 +03:00
|
|
|
: m_server(server),
|
|
|
|
m_threadPool(server.options().numThreads)
|
2015-05-02 13:45:24 +03:00
|
|
|
{
|
|
|
|
// signature and help strings are documentation -- the client
|
|
|
|
// can query this information with a system.methodSignature and
|
|
|
|
// system.methodHelp RPC.
|
|
|
|
this->_signature = "S:S";
|
|
|
|
this->_help = "Does translation";
|
|
|
|
}
|
2015-04-30 08:05:11 +03:00
|
|
|
|
2015-05-02 13:45:24 +03:00
|
|
|
void
|
|
|
|
Translator::
|
|
|
|
execute(xmlrpc_c::paramList const& paramList,
|
|
|
|
xmlrpc_c::value * const retvalP)
|
|
|
|
{
|
|
|
|
boost::condition_variable cond;
|
|
|
|
boost::mutex mut;
|
2015-08-02 23:28:47 +03:00
|
|
|
boost::shared_ptr<TranslationRequest> task;
|
2015-08-03 02:29:34 +03:00
|
|
|
task = TranslationRequest::create(this, paramList,cond,mut);
|
2015-05-02 13:45:24 +03:00
|
|
|
m_threadPool.Submit(task);
|
|
|
|
boost::unique_lock<boost::mutex> lock(mut);
|
|
|
|
while (!task->IsDone())
|
|
|
|
cond.wait(lock);
|
|
|
|
*retvalP = xmlrpc_c::value_struct(task->GetRetData());
|
|
|
|
}
|
2015-04-30 08:05:11 +03:00
|
|
|
|
2015-08-02 23:28:47 +03:00
|
|
|
Session const&
|
|
|
|
Translator::
|
|
|
|
get_session(uint64_t const id)
|
|
|
|
{
|
2015-08-04 03:59:28 +03:00
|
|
|
return m_server.get_session(id);
|
2015-08-02 23:28:47 +03:00
|
|
|
}
|
|
|
|
|
2015-03-04 03:07:11 +03:00
|
|
|
}
|