25 #include <xqsettingsmanager.h> |
25 #include <xqsettingsmanager.h> |
26 #include <xqsettingskey.h> |
26 #include <xqsettingskey.h> |
27 #include <e32std.h> |
27 #include <e32std.h> |
28 |
28 |
29 #include "xqservicelog.h" |
29 #include "xqservicelog.h" |
|
30 #include "xqserviceutil.h" |
30 #include "xqaiwutils.h" |
31 #include "xqaiwutils.h" |
31 #include "xqaiwuridriver.h" |
32 #include "xqaiwuridriver.h" |
32 #include "xqaiwdecl.h" |
33 #include "xqaiwdecl.h" |
33 #include "xqappmgr_p.h" |
34 #include "xqappmgr_p.h" |
34 |
35 |
|
36 #include <xqsettingsmanager.h> |
|
37 |
35 /*! |
38 /*! |
36 \class XQApplicationManagerPrivate |
39 \class XQApplicationManagerPrivate |
37 \brief Private implementation of the XQApplicationManager |
40 \brief Private implementation of the XQApplicationManager |
38 */ |
41 */ |
39 |
42 |
40 XQApplicationManagerPrivate::XQApplicationManagerPrivate(): |
43 XQApplicationManagerPrivate::XQApplicationManagerPrivate(): |
|
44 QObject(), |
|
45 v_ptr(0), |
41 serviceMgr(0), |
46 serviceMgr(0), |
42 aiwUtilities(0) |
47 aiwUtilities(0), |
|
48 settingsManagerInstance(0) |
43 |
49 |
44 { |
50 { |
45 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate"); |
51 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate"); |
46 serviceMgr = new XQServiceManager(); |
52 serviceMgr = new XQServiceManager(); |
47 } |
53 } |
49 XQApplicationManagerPrivate::~XQApplicationManagerPrivate() |
55 XQApplicationManagerPrivate::~XQApplicationManagerPrivate() |
50 { |
56 { |
51 XQSERVICE_DEBUG_PRINT("~XQApplicationManagerPrivate"); |
57 XQSERVICE_DEBUG_PRINT("~XQApplicationManagerPrivate"); |
52 delete serviceMgr; |
58 delete serviceMgr; |
53 delete aiwUtilities; |
59 delete aiwUtilities; |
|
60 delete settingsManagerInstance; |
54 } |
61 } |
55 |
62 |
56 XQAiwRequest* XQApplicationManagerPrivate::create( const QString &interface, const QString &operation, bool embedded) |
63 XQAiwRequest* XQApplicationManagerPrivate::create( const QString &interface, const QString &operation, bool embedded) |
57 { |
64 { |
58 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate::create(interface)"); |
65 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate::create(interface)"); |
356 { |
363 { |
357 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate bad custom property value"); |
364 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate bad custom property value"); |
358 return XQApplicationManager::Unknown; |
365 return XQApplicationManager::Unknown; |
359 } |
366 } |
360 |
367 |
361 XQSettingsManager settingsManager; |
|
362 int implId = implementation.property(XQAiwInterfaceDescriptor::ImplementationId).toInt(); |
368 int implId = implementation.property(XQAiwInterfaceDescriptor::ImplementationId).toInt(); |
363 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate %x,%x", keyId, implId); |
369 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate %x,%x", keyId, implId); |
364 |
370 |
365 XQSettingsKey statusKey (XQSettingsKey::TargetCentralRepository, implId, keyId); |
371 XQSettingsKey statusKey (XQSettingsKey::TargetCentralRepository, implId, keyId); |
366 QVariant value = settingsManager.readItemValue(statusKey); |
372 QVariant value = settingsManager()->readItemValue(statusKey); |
367 if (value.isNull()) |
373 if (value.isNull()) |
368 { |
374 { |
369 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate Cenrep %x does not contain key %x", |
375 XQSERVICE_DEBUG_PRINT("XQApplicationManagerPrivate Cenrep %x does not contain key %x", |
370 implId, keyId); |
376 implId, keyId); |
371 return XQApplicationManager::Unknown; |
377 return XQApplicationManager::Unknown; |
531 result.append(fs); |
537 result.append(fs); |
532 } |
538 } |
533 } |
539 } |
534 } |
540 } |
535 |
541 |
536 if (result.isEmpty()) |
542 if (result.isEmpty()) { |
537 { |
|
538 // No service support present, try using the MIME handlers via old way |
543 // No service support present, try using the MIME handlers via old way |
539 return mimeHandlers; |
544 return mimeHandlers; |
540 } |
545 } |
541 return result; |
546 return result; |
542 } |
547 } |
|
548 |
|
549 bool XQApplicationManagerPrivate::startNotifications(XQAiwInterfaceDescriptor& serviceImplDescriptor) |
|
550 { |
|
551 QString crcName = QString("%1.%2").arg(serviceImplDescriptor.serviceName()).arg(serviceImplDescriptor.interfaceName()).toLower(); |
|
552 |
|
553 quint32 crc = XQServiceUtil::serviceIdFromName(crcName.toLatin1().data()); |
|
554 descriptorsMap.insert(crc, serviceImplDescriptor); |
|
555 XQSettingsManager *settings = settingsManager(); |
|
556 |
|
557 bool ok = false; |
|
558 |
|
559 XQSERVICE_CONNECT(settings, SIGNAL(valueChanged(XQSettingsKey,QVariant)), this, SLOT(valueChanged(XQSettingsKey,QVariant))); |
|
560 XQSERVICE_CONNECT(settings, SIGNAL(itemDeleted(XQSettingsKey)), this, SLOT(itemDeleted(XQSettingsKey))); |
|
561 |
|
562 quint32 uid = serviceImplDescriptor.property(XQAiwInterfaceDescriptor::ImplementationId).toInt(&ok); |
|
563 |
|
564 if (ok) { |
|
565 XQSettingsKey key(XQSettingsKey::TargetPublishAndSubscribe, uid, crc); |
|
566 ok = settings->startMonitoring(key); |
|
567 // key may be discarded now, as we got full information about recreating it while stopping notifications. |
|
568 } |
|
569 |
|
570 return ok; |
|
571 } |
|
572 |
|
573 bool XQApplicationManagerPrivate::stopNotifications(XQAiwInterfaceDescriptor& serviceImplDescriptor) |
|
574 { |
|
575 quint32 crc = XQServiceUtil::serviceIdFromName(serviceImplDescriptor.serviceName().toLatin1().data()); |
|
576 descriptorsMap.remove(crc); |
|
577 XQSettingsManager *settings = settingsManager(); |
|
578 |
|
579 bool ok = false; |
|
580 quint32 uid = serviceImplDescriptor.property(XQAiwInterfaceDescriptor::ImplementationId).toInt(&ok); |
|
581 if (ok) { |
|
582 XQSettingsKey key(XQSettingsKey::TargetPublishAndSubscribe, uid, crc); |
|
583 ok = settings->stopMonitoring(key); |
|
584 } |
|
585 return ok; |
|
586 } |
|
587 |
|
588 void XQApplicationManagerPrivate::valueChanged(const XQSettingsKey& key, const QVariant& value) |
|
589 { |
|
590 XQSERVICE_DEBUG_PRINT("XQApplicationManager::valueChanged"); |
|
591 bool ok = false; |
|
592 XQApplicationManager::ServiceState state = (XQApplicationManager::ServiceState)(value.toInt(&ok)); |
|
593 |
|
594 if (ok) { |
|
595 switch (state) { |
|
596 case XQApplicationManager::ServiceStarted: |
|
597 { |
|
598 XQSERVICE_DEBUG_PRINT("XQApplicationManager::valueChanged : service started"); |
|
599 XQAiwInterfaceDescriptor descriptor = descriptorsMap.value(key.key()); |
|
600 //TODO add dummy descriptor check (no entry in map) |
|
601 emit v_ptr->serviceStarted(descriptor); |
|
602 } |
|
603 break; |
|
604 case XQApplicationManager::ServiceStopped: |
|
605 { |
|
606 XQSERVICE_DEBUG_PRINT("XQApplicationManager::valueChanged : service stopped"); |
|
607 XQAiwInterfaceDescriptor descriptor = descriptorsMap.value(key.key()); |
|
608 //TODO add dummy descriptor check (no entry in map) |
|
609 emit v_ptr->serviceStopped(descriptor); |
|
610 } |
|
611 break; |
|
612 default: |
|
613 ok = false; |
|
614 break; |
|
615 } |
|
616 } |
|
617 |
|
618 if (!ok) { |
|
619 //assertion |
|
620 XQSERVICE_WARNING_PRINT("XQApplicationManager::valueChanged : Service status undecipherable. Potential bug, please report."); |
|
621 } |
|
622 } |
|
623 |
|
624 void XQApplicationManagerPrivate::itemDeleted(const XQSettingsKey& key) |
|
625 { |
|
626 XQSERVICE_DEBUG_PRINT("XQApplicationManager::itemDeleted"); |
|
627 Q_UNUSED(key); |
|
628 } |
|
629 |
|
630 XQSettingsManager *XQApplicationManagerPrivate::settingsManager() |
|
631 { |
|
632 if (settingsManagerInstance == 0) { |
|
633 settingsManagerInstance = new XQSettingsManager(); |
|
634 } |
|
635 return settingsManagerInstance; |
|
636 } |
|
637 |