Permalink
Browse files

libtorc-core: Add basic user messaging functionality.

  • Loading branch information...
mark-kendall committed Oct 11, 2012
1 parent 0fb6ffc commit 48943f9ae06bba283e5671ab1e45a87040233313
Showing with 66 additions and 0 deletions.
  1. +39 −0 libs/libtorc-core/torclocalcontext.cpp
  2. +27 −0 libs/libtorc-core/torclocalcontext.h
@@ -249,6 +249,45 @@ void TorcLocalContext::NotifyEvent(int Event)
gLocalContext->Notify(event);
}
+#define MESSAGE_TIMEOUT_DEFAULT 3000
+#define MESSAGE_TIMEOUT_SHORT 1000
+#define MESSAGE_TIMEOUT_LONG 10000
+
+void TorcLocalContext::SendMessage(Torc::MessageType Type,
+ Torc::MessageDestination Destination,
+ Torc::MessageTimeout Timeout, QString Uuid,
+ const QString &Header, const QString &Body)
+{
+ if (Body.isEmpty())
+ return;
+
+ int timeout = -1;
+ switch (Timeout)
+ {
+ case Torc::DefaultTimeout:
+ timeout = MESSAGE_TIMEOUT_DEFAULT;
+ break;
+ case Torc::ShortTimeout:
+ timeout = MESSAGE_TIMEOUT_SHORT;
+ break;
+ case Torc::LongTimeout:
+ timeout = MESSAGE_TIMEOUT_LONG;
+ break;
+ default:
+ break;
+ }
+
+ QVariantMap data;
+ data.insert("type", Type);
+ data.insert("destination", Destination);
+ data.insert("timeout", timeout);
+ data.insert("uuid", Uuid);
+ data.insert("header", Header);
+ data.insert("body", Body);
+ TorcEvent event(Torc::Message, data);
+ gLocalContext->Notify(event);
+}
+
TorcLocalContext::TorcLocalContext(TorcCommandLineParser* CommandLine, int ApplicationFlags)
: QObject(),
m_priv(new TorcLocalContextPriv(ApplicationFlags))
@@ -32,6 +32,30 @@ class TORC_CORE_PUBLIC Torc
USB = (1 << 5)
};
+ typedef enum MessageTypes
+ {
+ GenericError,
+ CriticalError,
+ GenericWarning,
+ ExternalMessage,
+ InternalMessage
+ } MessageType;
+
+ typedef enum MessageDestinations
+ {
+ Internal = (0 << 0),
+ Local = (1 << 0),
+ Broadcast = (1 << 1)
+ } MessageDestination;
+
+ typedef enum MessageTimeouts
+ {
+ DefaultTimeout,
+ ShortTimeout,
+ LongTimeout,
+ Acknowledge
+ } MessageTimeout;
+
enum Actions
{
None = 0,
@@ -125,6 +149,9 @@ class TORC_CORE_PUBLIC TorcLocalContext : public QObject, public TorcObservable
static qint16 Create (TorcCommandLineParser* CommandLine, int ApplicationFlags);
static void TearDown (void);
static void NotifyEvent (int Event);
+ static void SendMessage (Torc::MessageType Type, Torc::MessageDestination Destination,
+ Torc::MessageTimeout Timeout, QString Uuid,
+ const QString &Header, const QString &Body);
Q_INVOKABLE QString GetSetting (const QString &Name, const QString &DefaultValue);
Q_INVOKABLE bool GetSetting (const QString &Name, const bool &DefaultValue);

0 comments on commit 48943f9

Please sign in to comment.