ctkEALogEventAdapter_p.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKEALOGEVENTADAPTER_P_H
  16. #define CTKEALOGEVENTADAPTER_P_H
  17. #include <QObject>
  18. #include <QMutex>
  19. #include "ctkEAAbstractAdapter_p.h"
  20. #include <ctkServiceRegistration.h>
  21. #include <service/log/ctkLogListener.h>
  22. class ctkEALogEventAdapter;
  23. class _LogListener : public QObject, public ctkLogListener
  24. {
  25. Q_OBJECT
  26. Q_INTERFACES(ctkLogListener)
  27. public:
  28. _LogListener(ctkEALogEventAdapter* adapter);
  29. void logged(ctkLogEntryPtr entry);
  30. private:
  31. ctkEALogEventAdapter* const adapter;
  32. };
  33. /**
  34. * This class registers a <tt>ctkLogListener</tt>
  35. * with the framework. Any received log event is then
  36. * posted via the ctkEventAdmin as specified in 113.6.6 OSGi R4 compendium.
  37. */
  38. class ctkEALogEventAdapter : public QObject, public ctkEAAbstractAdapter
  39. {
  40. Q_OBJECT
  41. private:
  42. QMutex mutex;
  43. ctkPluginContext* context;
  44. _LogListener* logListener;
  45. ctkServiceRegistration reg;
  46. friend class _LogListener;
  47. public:
  48. /**
  49. * The constructor of the adapter. This will register the listener with the
  50. * given context. Any received log event is then posted via the given
  51. * ctkEventAdmin.
  52. *
  53. * @param context The plugin context with which to register as a listener.
  54. * @param admin The <tt>ctkEventAdmin</tt> to use for posting events.
  55. */
  56. ctkEALogEventAdapter(ctkPluginContext* context, ctkEventAdmin* admin);
  57. ~ctkEALogEventAdapter();
  58. void destroy(ctkPluginContext* context);
  59. };
  60. #endif // CTKEALOGEVENTADAPTER_P_H