last ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,295 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCNotifier
|
||||
// Description: provides all Base Notification requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Notification Model ...
|
||||
typedef void (*OnMessage)(
|
||||
string, // action ...
|
||||
string // payload ...
|
||||
);
|
||||
|
||||
//
|
||||
struct XNotifierEventListener
|
||||
{
|
||||
string action;
|
||||
OnMessage listeners[];
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCNotifier
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
bool AddEventListener(
|
||||
string action, // Specific Action ...
|
||||
OnMessage listener // Specific Listener ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int aIndex = FindActionIndex(action);
|
||||
if (aIndex < 0)
|
||||
{
|
||||
//
|
||||
// Create a New Structure ...
|
||||
XNotifierEventListener model;
|
||||
|
||||
//
|
||||
model.action = action;
|
||||
|
||||
//
|
||||
Add(
|
||||
listener,
|
||||
model.listeners);
|
||||
|
||||
//
|
||||
Add(
|
||||
model,
|
||||
mEventListeners);
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Just Add Listener to Exists model ...
|
||||
Add(
|
||||
listener,
|
||||
mEventListeners[aIndex].listeners);
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool NotifyEvent(
|
||||
string action, // action ...
|
||||
string payload // payload ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int actionIndex = FindActionIndex(action);
|
||||
result = actionIndex >= 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int aListenersCount = ArraySize(mEventListeners[actionIndex].listeners);
|
||||
result = aListenersCount > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < aListenersCount; i++)
|
||||
{
|
||||
//
|
||||
OnMessage iListener = mEventListeners[actionIndex].listeners[i];
|
||||
|
||||
//
|
||||
// Call Listener ...
|
||||
iListener(
|
||||
action,
|
||||
payload);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
XNotifierEventListener mEventListeners[];
|
||||
|
||||
//
|
||||
// Find Specific Actions Index in Registered Event Listeners ...
|
||||
int FindActionIndex(string action)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int listenersCount = ArraySize(mEventListeners);
|
||||
if (listenersCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < listenersCount; i++)
|
||||
{
|
||||
//
|
||||
XNotifierEventListener iModel = mEventListeners[i];
|
||||
|
||||
//
|
||||
if (iModel.action == action)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
void Clean(
|
||||
OnMessage &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
0);
|
||||
}
|
||||
void Clean(
|
||||
XNotifierEventListener &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
0);
|
||||
}
|
||||
|
||||
//
|
||||
void Add(
|
||||
OnMessage item, // Item ...
|
||||
OnMessage &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
void Add(
|
||||
XNotifierEventListener &item, // Item ...
|
||||
XNotifierEventListener &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user