summaryrefslogtreecommitdiff
path: root/src/utils/process.cpp
diff options
context:
space:
mode:
authorVasily <danilka.pro@gmail.com>2015-12-03 03:25:30 +0300
committerAndrei Karas <akaras@inbox.ru>2015-12-03 16:18:08 +0300
commitd090aa77c4d0b31aded37128cae011b882f3dd9b (patch)
treef7957b084285916d4dbff43b9025a2c1eb439a51 /src/utils/process.cpp
parent1b47ede798838c9f50ad3175c9d05e1dfbad2474 (diff)
downloadmanaverse-d090aa77c4d0b31aded37128cae011b882f3dd9b.tar.gz
manaverse-d090aa77c4d0b31aded37128cae011b882f3dd9b.tar.bz2
manaverse-d090aa77c4d0b31aded37128cae011b882f3dd9b.tar.xz
manaverse-d090aa77c4d0b31aded37128cae011b882f3dd9b.zip
Added NaCl messaging and clipboard functions
Diffstat (limited to 'src/utils/process.cpp')
-rw-r--r--src/utils/process.cpp74
1 files changed, 69 insertions, 5 deletions
diff --git a/src/utils/process.cpp b/src/utils/process.cpp
index 74ac20b53..d3d154270 100644
--- a/src/utils/process.cpp
+++ b/src/utils/process.cpp
@@ -269,13 +269,9 @@ bool openBrowser(std::string url)
return execFile("/usr/bin/xdg-open", "/usr/bin/xdg-open", url, "");
}
#elif defined __native_client__
-#include <ppapi_simple/ps.h>
-#include <ppapi/cpp/instance.h>
-#include <ppapi/cpp/var.h>
bool openBrowser(std::string url)
{
- pp::Var msgVar = pp::Var(std::string("open-browser: ").append(url));
- pp::Instance(PSGetInstanceId()).PostMessage(msgVar);
+ naclPostMessage("open-browser", url);
return true;
}
#else
@@ -300,3 +296,71 @@ void setPriority(const bool big A_UNUSED)
{
}
#endif
+
+#ifdef __native_client__
+#include <ppapi_simple/ps.h>
+#include <ppapi_simple/ps_event.h>
+#include <ppapi/cpp/instance.h>
+#include <ppapi/cpp/var.h>
+
+#include <mutex>
+#include <condition_variable>
+
+struct _NaclMessageHandle {
+ bool handled;
+ std::string type;
+ std::string message;
+ std::condition_variable condv;
+};
+
+void naclPostMessage(const std::string &type, const std::string &message)
+{
+ pp::Var msgVar = pp::Var(std::string(type).append(":").append(message));
+ pp::Instance(PSGetInstanceId()).PostMessage(msgVar);
+}
+
+void naclMessageHandlerFunc(struct PP_Var key,
+ struct PP_Var value,
+ void* user_data)
+{
+ NaclMessageHandle *handle = (NaclMessageHandle *)user_data;
+
+ if (key.type != PP_VARTYPE_STRING || value.type != PP_VARTYPE_STRING)
+ return;
+ if (pp::Var(key).AsString() != handle->type)
+ return;
+
+ handle->handled = true;
+ handle->message = pp::Var(value).AsString();
+
+ handle->condv.notify_one();
+}
+
+NaclMessageHandle *naclRegisterMessageHandler(const std::string &type)
+{
+ NaclMessageHandle *handle = new NaclMessageHandle;
+ handle->handled = false;
+ handle->type = type;
+
+ PSEventRegisterMessageHandler(type.c_str(), naclMessageHandlerFunc, (void *)handle);
+ return handle;
+}
+
+void naclUnregisterMessageHandler(NaclMessageHandle *handle)
+{
+ PSEventRegisterMessageHandler(handle->type.c_str(), NULL, NULL);
+ delete handle;
+}
+
+std::string naclWaitForMessage(NaclMessageHandle *handle)
+{
+ std::mutex mtx;
+ std::unique_lock <std::mutex> lck(mtx);
+
+ while (!handle->handled)
+ handle->condv.wait(lck);
+
+ handle->handled = false;
+ return handle->message;
+}
+#endif