/** polling loop til buffer ready */ ssize_t Swipl_IO::_read_(char *buf, size_t bufsize) { qDebug() << "_read_" << CVP(target); int thid = PL_thread_self(); // handle setup interthread and termination for ( ; ; ) { { QMutexLocker lk(&sync); if (target) { if (!target->thids.contains(thid)) { target->add_thread(thid); int rc = PL_thread_at_exit(eng_at_exit, this, FALSE); qDebug() << "installed" << rc; } break; } } if ( PL_handle_signals() < 0 ) return -1; SwiPrologEngine::msleep(10); } if ( buffer.isEmpty() ) { PL_write_prompt(TRUE); emit user_prompt(thid, SwiPrologEngine::is_tty(this)); } for ( ; ; ) { { QMutexLocker lk(&sync); if (!query.isEmpty()) { try { int rc = PlCall(query.toStdWString().data()); qDebug() << "PlCall" << query << rc; } catch(PlException e) { qDebug() << t2w(e); } query.clear(); } uint n = buffer.length(); Q_ASSERT(bufsize >= n); if (n > 0) { uint l = bufsize < n ? bufsize : n; memcpy(buf, buffer, l); buffer.remove(0, l); return l; } if (target->status == ConsoleEdit::eof) { target->status = ConsoleEdit::running; return 0; } } if ( PL_handle_signals() < 0 ) return -1; SwiPrologEngine::msleep(10); } }
// Call the arbitrary command int SWIPLContainer::call(const QString &command) { return PlCall("call", PlTermv(PlCompound(toPlString(command)))); }
void open_store(std::string filename) { PlFrame fr; PlCall("set_prolog_flag(verbose, silent)."); PlCall("use_module(library(semweb/rdf_db))."); PlCall("rdf_register_prefix(c,'http://www.semanticweb.org/yzhao30/ontologies/2015/7/c#')."); }
// Load database into the engine bool SWIPLContainer::consult(const QString &filename) { return PlCall("consult", PlTerm(toPlString(filename))); }