|
@@ -0,0 +1,98 @@
|
|
|
+#include "pluginapp.h"
|
|
|
+
|
|
|
+#include <memory>
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+#include <QThread>
|
|
|
+
|
|
|
+pluginapp::pluginapp(WId parentwinid, QString cid,QString strappname,const char * strdir)
|
|
|
+{
|
|
|
+ QString strapppath;
|
|
|
+ if(strdir == NULL)strapppath = strappname;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ strapppath = strdir;
|
|
|
+ strapppath = strapppath + "/" + strappname;
|
|
|
+ }
|
|
|
+
|
|
|
+ QString strmsgname = "plugin_" + strappname+"_"+cid;
|
|
|
+ mpa = iv::modulecomm::RegisterSend(strmsgname.toLatin1().data(),1000,1);
|
|
|
+
|
|
|
+ mproc = new QProcess();
|
|
|
+ connect(mproc,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOut()));
|
|
|
+ connect(mproc,SIGNAL(started()),this,SLOT(onProcStarted()));
|
|
|
+ QStringList xarg;
|
|
|
+ xarg.push_back(QString::number(parentwinid));
|
|
|
+ xarg.push_back(cid);
|
|
|
+ mproc->start(strapppath,xarg);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+pluginapp::~pluginapp()
|
|
|
+{
|
|
|
+ iv::modulecomm::Unregister(mpa);
|
|
|
+ mproc->terminate();
|
|
|
+ mproc->waitForFinished(100);
|
|
|
+}
|
|
|
+
|
|
|
+void pluginapp::SetGeometry(int x, int y, int w, int h)
|
|
|
+{
|
|
|
+ char strvalue[256];
|
|
|
+ snprintf(strvalue,256,"%d %d %d %d",x,y,w,h);
|
|
|
+ SetAttr("geometry",strvalue,strnlen(strvalue,256));
|
|
|
+}
|
|
|
+
|
|
|
+void pluginapp::SetAttr(const char *strattr, const char *strvalue, const int nvaluelen)
|
|
|
+{
|
|
|
+ iv::plugin::plugmsg xmsg;
|
|
|
+ xmsg.set_strattr(strattr);
|
|
|
+ xmsg.set_strvalue(strvalue,nvaluelen);
|
|
|
+
|
|
|
+ if(mbStarted == false)
|
|
|
+ {
|
|
|
+ std::cout<<"push to vector"<<std::endl;
|
|
|
+ mvectormsg.push_back(xmsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int ndatasize = xmsg.ByteSize();
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[ndatasize]);
|
|
|
+ if(xmsg.SerializeToArray(pstr_ptr.get(),ndatasize))
|
|
|
+ {
|
|
|
+ iv::modulecomm::ModuleSendMsg(mpa,pstr_ptr.get(),ndatasize);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<" pluginapp::SetAttr seriazlize error."<<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void pluginapp::onReadStandardOut()
|
|
|
+{
|
|
|
+ QProcess * proc = (QProcess *)sender();
|
|
|
+ QByteArray ba = proc->readAllStandardOutput();
|
|
|
+ std::cout<<ba.data()<<std::endl;
|
|
|
+}
|
|
|
+
|
|
|
+void pluginapp::onProcStarted()
|
|
|
+{
|
|
|
+ mpTimer = new QTimer(this);
|
|
|
+ connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
|
+ mpTimer->start(1000);
|
|
|
+
|
|
|
+ std::cout<<"started."<<std::endl;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void pluginapp::onTimer()
|
|
|
+{
|
|
|
+ mbStarted = true;
|
|
|
+ if(mvectormsg.size()>0)
|
|
|
+ {
|
|
|
+ std::cout<<"write msg"<<std::endl;
|
|
|
+ SetAttr(mvectormsg[mvectormsg.size()-1].strattr().data(),mvectormsg[mvectormsg.size()-1].strvalue().data(),mvectormsg[mvectormsg.size()-1].strvalue().size());
|
|
|
+ mvectormsg.clear();
|
|
|
+ }
|
|
|
+}
|