AspenEvent()

 

Related Items

 

 

Purpose

Obtains an Aspen event notice to process.

 

 

Syntax

#include <aspen.h>

...

int AspenEvent (

   int  *event_code,

   void **notice );

 

 

Parameters

*event_code

*event_code is a pointer to a integer that receives an Aspen Event Notice value.

 

**notice

**notice is a pointer to a void pointer that receives the address of a dynamically allocated Aspen API event structure appropriate for *event_code.

 

 

Remarks

AspenEvent() is used to obtain notice of an event via the Aspen Event Notification System.

 

The Aspen Event Notification System must be enabled prior to calling AspenEvent(). The event system is enabled automatically when AspenInit() is called with an eventSemaphore. If the eventSemaphore is not used in AspenInit(), AspenEnableEvents() may be called to enable (and subsequently disable/enable) the Aspen Event Notification System.

 

On multi-tasking systems, this function may be used in conjunction with the eventSemaphore parameter that is passed to the AspenInit() function. On these platforms, the eventSemaphore parameter is signaled using a platform specific function to indicate that an asynchronous notice has been queued. For more information on using the eventSemaphore parameter see Aspen Event Notification System.

 

 

Return Value

ASPEN_OK

Success.

ASPEN_FN_NO_EVENTS

No event notices available to process.

ASPEN_FN_ALLOC_ERROR

Unable to allocate memory for the event structure.

ASPEN_FN_CONTEXT_ERROR

Aspen is not properly initialized, or the session has not been validated.

 

 

See Also

Aspen Event Notification System

AspenInit()

ASPEN_AlertNotice

ASPEN_ClosureNotice

ASPEN_DefineServerNotice

ASPEN_InstrumentUpdateNotice

ASPEN_SessionFailureNotice

ASPEN_SymbolChangeNotice

ASPEN_TimeSetNotice

ASPEN_TransportAvailableNotice

ASPEN_TransportUnavailableNotice

ASPEN_UndefineServerNotice

ASPEN_PRICE

 

 

Example

void CSuperQuoteDlg::DoASPEN_EventHandling()

{

   ASPEN_INSTRUMENT_UPDATE_NOTICE *instrumentUpdate;

   ASPEN_CLOSURE_NOTICE *closureNotice;

   ASPEN_SESSION_FAILURE_NOTICE *failureNotice;

   ASPEN_DEFINE_SERVER_NOTICE *defineServer;

   ASPEN_ALERT_NOTICE *alertNotice;

   ASPEN_SYMBOL_CHANGE_NOTICE *symbolChange;

   ASPEN_HISTORICAL_UPDATE_NOTICE *historicalUpdate;

   ASPEN_TIME_SET_NOTICE *timeSet;

   ASPEN_TRANSPORT_AVAILABLE_NOTICE *transAvailable;

   ASPEN_TRANSPORT_UNAVAILABLE_NOTICE *transUnavailable;

   ASPEN_UNDEFINE_SERVER_NOTICE *undefServer;

   CString strText;

   int retval,event;

   void *notice;

   CSuperQuoteDlg dlg;

 

   do{

      WaitForSingleObject(GLOBAL_eventThreadHandle,100);

      retval = AspenEvent(&event, &notice);

      if (retval == ASPEN_OK)

      {

         CWnd *Super = FindWindow(NULL,"SuperQuoter'");

         switch(event)

         {

            case ASPEN_AlertNotice:

               alertNotice = (ASPEN_ALERT_NOTICE *)notice;

               strText.Format("**ALERT** : %s",alertNotice->text);

               m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_ClosureNotice:

               closureNotice = (ASPEN_CLOSURE_NOTICE *)notice;

               strText.Format("**ClosureNotice** %s",closureNotice->text);

               m_HistoryEdit.AppendString(strText);

               TerminateThread(GLOBAL_eventThreadHandle, GLOBAL_eventThreadID);

               if (GLOBAL_eventSemaphore) CloseHandle(GLOBAL_eventSemaphore);

               break;

            case ASPEN_InstrumentUpdateNotice:

               instrumentUpdate = (ASPEN_INSTRUMENT_UPDATE_NOTICE *)notice;

               a_inst = instrumentUpdate->instrument;

               if (!Super)

               {

                  strText.Format("Symbol: %s  Last Price: %ld",

instrumentUpdate->instrument.symbol,

instrumentUpdate->instrument.last);

                  m_HistoryEdit.AppendString(strText);

               }

               else DoASPEN_SuperQuote();

               break;

            case ASPEN_HistoricalUpdateNotice:

               historicalUpdate = (ASPEN_HISTORICAL_UPDATE_NOTICE *)notice;

               strText.Format("**HistoricalUpdate** INUM: %d,DB_ID: %hd, StartTime: %ld, EndTime: %ld", historicalUpdate->inum, historicalUpdate->db_id, historicalUpdate->start_time, historicalUpdate->end_time);

               m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_SymbolChangeNotice:

               symbolChange = (ASPEN_SYMBOL_CHANGE_NOTICE *)notice;

               strText.Format("Symbol: %s\tOld INUM: %ld\tNew INUM: %ld", symbolChange->symbol, symbolChange->old_inum, symbolChange->new_inum);

               m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_TimeSetNotice:

               timeSet = (ASPEN_TIME_SET_NOTICE *)notice;

               strText.Format("**TimeSetNotice** Minutes: %ld, Seconds: %hd", timeSet->minutes, timeSet->seconds);

               m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_TransportAvailableNotice:

               transAvailable = (ASPEN_TRANSPORT_AVAILABLE_NOTICE *)notice;

               strText.Format("**TransportAvailable** Family: %d, Protocol: %s, Provider: %s", transAvailable->family, transAvailable->protocol, transAvailable->provider);

               m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_TransportUnavailableNotice:

               transUnavailable = (ASPEN_TRANSPORT_UNAVAILABLE_NOTICE *)notice;

               strText.Format("**TransportUnavailable** Family: %d, Protocol: %s, Provider: %s\nError: %s", transUnavailable->family,

transUnavailable->protocol, transUnavailable->provider, transUnavailable->errorText);

               m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_DefineServerNotice:

               char buffer[12];

               defineServer = (ASPEN_DEFINE_SERVER_NOTICE *)notice;

               sprintf(buffer,"%c%c%c%c%c%c%c%c%c%c%c", defineServer->server_name[8],defineServer->server_name[9], defineServer->server_name[10],defineServer->server_name[11],

defineServer->server_name[12],defineServer->server_name[13], defineServer->server_name[14],defineServer->server_name[15],

defineServer->server_name[16],defineServer->server_name[17], defineServer->server_name[18],defineServer->server_name[19]);

               strText.Format("%s  (%d.%d.%d.%d)  AVAILABLE",buffer,

defineServer->address.address[0], defineServer->address.address[1], defineServer->address.address[2], defineServer->address.address[3]);

m_HistoryEdit.AppendString(strText);

               break;

            case ASPEN_SessionFailureNotice:

               failureNotice = (ASPEN_SESSION_FAILURE_NOTICE *)notice;

               strText.Format("**SessionFailureNotice** %s",

failureNotice->errorText);

               m_HistoryEdit.AppendString(strText);

               TerminateThread(GLOBAL_eventThreadHandle, GLOBAL_eventThreadID);

               if (GLOBAL_eventSemaphore) CloseHandle(GLOBAL_eventSemaphore);

               break;

            case ASPEN_UndefineServerNotice:

               undefServer = (ASPEN_UNDEFINE_SERVER_NOTICE *)notice;

               strText.Format("**UndefineServerNotice** Addr: %ld, ServerName: %s", undefServer->address, undefServer->server_name);

               m_HistoryEdit.AppendString(strText);

               break;

         }

         AspenFreeMemory(notice);

      }

   }while(retval == ASPEN_OK);

}

 

©2006 Aspen Research Group, Ltd. All rights reserved. Terms of Use.