#ifndef LIBLOUIS_NACL_LIBLOUIS_INSTANCE_H_
#define LIBLOUIS_NACL_LIBLOUIS_INSTANCE_H_
#include <string>
#include "base/basictypes.h"
#include "json/json.h"
#include "liblouis_wrapper.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/message_loop.h"
#include "ppapi/cpp/var.h"
#include "ppapi/utility/completion_callback_factory.h"
#include "ppapi/utility/threading/simple_thread.h"
#include "translation_params.h"
namespace liblouis_nacl {
class LibLouisInstance : public pp::Instance {
public:
explicit LibLouisInstance(PP_Instance instance);
virtual ~LibLouisInstance();
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
virtual void HandleMessage(const pp::Var& var_message);
private:
int32_t PostWorkToBackground(const pp::CompletionCallback& callback) {
return liblouis_thread_.message_loop().PostWork(callback);
}
void PostReply(Json::Value reply, const std::string& in_reply_to);
void PostError(const std::string& error);
void PostError(const std::string& error, const std::string& in_reply_to);
void HandleCheckTable(const Json::Value& message,
const std::string& message_id);
void CheckTableInBackground(int32_t result, const std::string& table_name,
const std::string& message_id);
void HandleTranslate(const Json::Value& message,
const std::string& message_id);
void TranslateInBackground(int32_t result, const TranslationParams& params,
const std::string& message_id);
void HandleBackTranslate(const Json::Value& message,
const std::string& message_id);
void BackTranslateInBackground(int32_t result,
const std::string& table_name, const std::vector<unsigned char>& cells,
const std::string& message_id);
LibLouisWrapper liblouis_;
pp::SimpleThread liblouis_thread_;
pp::CompletionCallbackFactory<LibLouisInstance> cc_factory_;
DISALLOW_COPY_AND_ASSIGN(LibLouisInstance);
};
}
#endif