2929#include " log.h"
3030#include " routesfile.h"
3131#include " timer.h"
32+ #include < QCoreApplication>
3233#include < QDir>
3334#include < QFile>
3435#include < QHash>
@@ -723,6 +724,8 @@ class DomainMap::Thread {
723724 }
724725
725726 thread.join ();
727+
728+ log_debug (" domainmap thread stopped" );
726729 }
727730
728731 void start () {
@@ -742,6 +745,8 @@ class DomainMap::Thread {
742745 }
743746
744747 void run () {
748+ log_debug (" domainmap thread started" );
749+
745750 // Will unlock during exec
746751 m.lock ();
747752
@@ -770,9 +775,13 @@ class DomainMap::Private {
770775 DomainMap *q;
771776 Thread *thread;
772777 Connection changedConnection;
773- DeferCall deferCall;
778+ std::unique_ptr< DeferCall> deferCall;
774779
775- Private (DomainMap *_q) : q(_q), thread(0 ) {}
780+ Private (DomainMap *_q) : q(_q), thread(0 ) {
781+ // Only emit signals in the current thread if there is an event loop
782+ if (EventLoop::instance () || QCoreApplication::instance ())
783+ deferCall = std::make_unique<DeferCall>();
784+ }
776785
777786 ~Private () {
778787 changedConnection.disconnect ();
@@ -792,10 +801,12 @@ class DomainMap::Private {
792801private:
793802 // NOTE: called from worker thread
794803 void workerChanged () {
795- deferCall.defer ([=] {
796- // NOTE: called from outer thread
797- doChanged ();
798- });
804+ if (deferCall) {
805+ deferCall->defer ([=] {
806+ // NOTE: called from outer thread
807+ doChanged ();
808+ });
809+ }
799810 }
800811
801812 void doChanged () { q->changed (); }
@@ -896,3 +907,42 @@ bool DomainMap::addRouteLine(const QString &line) {
896907 QMutexLocker locker (&d->thread ->worker ->m );
897908 return d->thread ->worker ->addRouteLine (line);
898909}
910+
911+ // FFI functions for Rust integration
912+ extern " C" {
913+
914+ // Route parameters struct for FFI
915+ struct DomainMapRouteParams {
916+ int log_level;
917+ };
918+
919+ DomainMap *domainmap_create (const char *filename) {
920+ if (!filename) {
921+ return nullptr ;
922+ }
923+
924+ QString qfilename = QString::fromUtf8 (filename);
925+ return new DomainMap (qfilename);
926+ }
927+
928+ void domainmap_destroy (DomainMap *handle) { delete handle; }
929+
930+ int domainmap_entry_params (DomainMap *handle, const char *route_id, DomainMapRouteParams *params) {
931+ if (!handle || !route_id || !params) {
932+ return -1 ;
933+ }
934+
935+ QString qroute_id = QString::fromUtf8 (route_id);
936+ DomainMap::Entry entry = handle->entry (qroute_id);
937+
938+ if (entry.isNull ()) {
939+ return -1 ;
940+ }
941+
942+ // Extract route parameters
943+ params->log_level = entry.logLevel ;
944+
945+ return 0 ;
946+ }
947+
948+ } // extern "C"
0 commit comments