Пример #1
0
void CGroupPrice::GetGroupPrice(const _QuoteUpdateParams& Params)
{
	_SetDbKey(Params);

	long nResult = _GetOptions(Params);
	if(DBA_ERR_NO_ERROR == nResult)
	{
		if(m_bIsGotOptions && !m_bIsGotError)
		{
			DBA_RECORD_3 rec;
			ZeroMemory(&rec, sizeof(rec));
			PublicLastQuote(Params, rec);
		}
		else if(!m_bIsGotOptions && !m_bIsGotError) 
		{
			CErrorResponse* pError = new CErrorResponse();
			pError->m_enRequestType = enRequestLastQuote;
			const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
			pError->m_bstrDescription = L"Couldn't get options prices for underlying. Unknown symbol.";
			pError->m_Error = enNoDataAvailableForSymbol;
			CResponseBasePtr pErrorPtr = CResponseBasePtr((CResponseBase*)pError);
			PublicResponse(pErrorPtr);
		}
	}
	else
	{
		CErrorResponse* pError = new CErrorResponse();
		pError->m_enRequestType = enRequestLastQuote;
		const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
		if(nResult == DBA_ERR_KEY_NOT_FOUND)
		{
			pError->m_bstrDescription = L"Couldn't get options prices for underlying. Unknown symbol.";
			pError->m_Error = enNoDataAvailableForSymbol;
		}
		else if(nResult == DBA_TERMINATED)
		{
			pError->m_bstrDescription = L"Operation canceled by user.";
			pError->m_Error = enInternalError;
		}
		else
		{
			_bstr_t bs =  "Couldn't get options prices for underlying. Error: ";
			bs += EtGetMessage(DBA_ERROR,nResult);
			TCHAR buffer[0x100] = {0};				
			_ltot(nResult,buffer,10);
			bs += " (";
			bs += buffer;
			bs += ")";
			pError->m_bstrDescription = bs;
			pError->m_Error = enProviderInternalError;
		}
		CResponseBasePtr pErrorPtr = CResponseBasePtr((CResponseBase*)pError);
		PublicResponse(pErrorPtr);
	}
	m_vtRequest.Clear();
}
Пример #2
0
void CGroupPrice::GetGroupPrice(const _QuoteUpdateParams& Params)
{
	try
	{
		_SetDbKey(Params);

		long nResult = _GetOptions(Params);
		if(DBA_ERR_NO_ERROR == nResult)
		{
			if(m_bIsGotOptions && !m_bIsGotError)
			{
				CDBARecordPtr pRec = CDBARecordPtr(new DBA_RECORD_3);
				if(pRec != NULL)
				{
					ZeroMemory(pRec.get(), sizeof(DBA_RECORD_3));
					PublicLastQuote(&Params, pRec);
				}
			}
			else if(!m_bIsGotOptions && !m_bIsGotError) 
			{
				CErrorResponsePtr pError(new CErrorResponse());
				pError->m_enRequestType = enRequestLastQuote;
				const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
				pError->m_bstrDescription = L"Couldn't get options prices for underlying. Unknown symbol.";
				pError->m_Error = enNoDataAvailableForSymbol;
				CResponseBasePtr pErrorPtr = boost::shared_dynamic_cast<CResponseBase>(pError);
				PublicResponse(pErrorPtr);
			}
		}
		else
		{
			if(DBA_TERMINATED != nResult)
			{
				CErrorResponsePtr pError(new CErrorResponse());

				pError->m_enRequestType = enRequestLastQuote;
				const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
				if(nResult == DBA_ERR_KEY_NOT_FOUND)
				{
					pError->m_bstrDescription = L"Couldn't get options prices for underlying. Unknown symbol.";
					pError->m_Error = enNoDataAvailableForSymbol;
				}
				else if(nResult == DBA_TERMINATED)
				{
					pError->m_bstrDescription = L"Operation canceled by user.";
					pError->m_Error = enInternalError;
				}
				else
				{
					_bstr_t bs =  L"Couldn't get options prices for underlying. Error: ";
					bs += EtGetMessage(DBA_ERROR,nResult);
					bs += L" (";
					bs += _bstr_t(nResult);
					bs += L")";
					pError->m_bstrDescription = bs;
					pError->m_Error = enProviderInternalError;
				}
				CResponseBasePtr pErrorPtr = boost::shared_dynamic_cast<CResponseBase>(pError);
				PublicResponse(pErrorPtr);
			}
		}
	}
	catch (...) 
	{
	}
	m_vtRequest.Clear();
}
Пример #3
0
void CGroupPrice::SubscribeGroup(const _QuoteUpdateParams& Params, GroupRequestType enRequest)
{
	_SetDbKey(Params);
	m_NeedToUnsubscribe.clear();
	long nResult = _GetOptions(Params, enRequest);
	if(DBA_ERR_NO_ERROR == nResult || DBA_TERMINATED == nResult)
	{
		if(m_bIsGotOptions && !m_bIsGotError)
		{
			if(enGroupRequestSubscribe != enRequest && enGroupRequestAllNotify != enRequest)
			{
				CDBARecordPtr pRec = CDBARecordPtr(new DBA_RECORD_3);
				ZeroMemory(pRec.get(), sizeof(DBA_RECORD_3));
				PublicLastQuote(&Params, pRec);
			}
			else if(enGroupRequestAllNotify == enRequest)
			{
				CResponseBasePtr pResponse = 
					boost::shared_static_cast<CResponseBase>(CSubscribedResponsePtr(new CSubscribedResponse(Params)));
				PublicResponse(pResponse);
			}
		}
		else if(!m_bIsGotOptions && !m_bIsGotError) 
		{
			CErrorResponsePtr pError = CErrorResponsePtr(new CErrorResponse());
			if(pError)
			{
				pError->m_enRequestType = enSubscribeQuote;
				const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
				pError->m_bstrDescription = L"Couldn't subscribe underlings options. Unknown symbol.";
				pError->m_Error = enNoDataAvailableForSymbol;

				PublicResponse(boost::shared_static_cast<CResponseBase>(pError));
			}
		}
		if(!m_NeedToUnsubscribe.empty())
		{
			boost::shared_ptr<CVectorKeys> pKeys = boost::shared_ptr<CVectorKeys>(new CVectorKeys());
			pKeys->insert(pKeys->end(), m_NeedToUnsubscribe.begin(), m_NeedToUnsubscribe.end());
			m_UnsubscribeStrategy.PushData(pKeys);
			m_NeedToUnsubscribe.clear();
		}

	}
	else
	{
		CErrorResponsePtr pError = CErrorResponsePtr(new CErrorResponse());
		if(pError)
		{
			pError->m_enRequestType = enSubscribeQuote;
			const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
			if(nResult == DBA_ERR_KEY_NOT_FOUND)
			{
				pError->m_bstrDescription = L"Unable to subscribe underlings options.";
				pError->m_Error = enNoDataAvailableForSymbol;
			}
			else if(nResult == DBA_ERR_INTEREST)
			{
				pError->m_bstrDescription = L"HyperFeed server subscription list is full";
				pError->m_Error = enProviderInternalError;
			}
			else if(nResult == DBA_TERMINATED)
			{
				pError->m_bstrDescription = L"Operation canceled by user.";
				pError->m_Error = enInternalError;
			}
			else
			{
				_bstr_t bs =  "Unable to subscribe underlings options. Error: ";
				bs += EtGetMessage(DBA_ERROR,nResult);
				TCHAR buffer[0x100] = {0};				
				_ltot(nResult,buffer,10);
				bs += " (";
				bs += buffer;
				bs += ")";
				pError->m_bstrDescription = bs;
				pError->m_Error = enProviderInternalError;
			}
			PublicResponse(boost::shared_static_cast<CResponseBase>(pError));
			EgLib::CEgLibTraceManager::Trace(LogError, __FUNCTION__ , _T("[%s]\t %s"), m_strUserName.c_str(), (LPCSTR)pError->m_bstrDescription);

		}
	}
	m_vtRequest.Clear();
}
Пример #4
0
int main(int argc, char** argv)
{
    const unsigned short PORT = 8888;
    Selector selector;
#if defined(HAVE_POSIX)
    Listener unixListener;
#endif
    Listener inetListener;
    char sockfileBuf[MAX_PATH_SIZE];
#if defined(ENABLE_PIDFILE)
    int pidfile;
    char pidfileBuf[MAX_PATH_SIZE];
#endif /* defined(ENABLE_PIDFILE) */

    arg0 = argv[0];
    ErrSetArg0(arg0);

    /* Set the default options */
    memset(&g_options, 0, sizeof(Options));
    g_options.sockfile = MakePath(ID_SOCKFILE, sockfileBuf);
    g_options.port = PORT;

    /* Set the default options */
#if defined(ENABLE_ROLES)
    /* Load roles.conf */
    {
        char buf[MAX_PATH_SIZE];
        char err[128];

        if (RolesLoad(MakePath(ID_ROLES_CONF, buf), err, sizeof(err)) != 0)
            Err("%s", err);
    }
#endif /* defined(ENABLE_ROLES) */

    /* Set the default options */
    /* Process the configuration file before the command-line options */
    _GetConfFileOptions();

    /* Get command line options */
    _GetOptions(&g_options, &argc, argv);

    /* Dump the paths? */
    if (g_options.paths)
    {
        DumpPaths();
        exit(0);
    }

    /* Dump the roles */
    if (g_options.roles)
    {
        RoleDump();
        exit(0);
    }

#if defined(ENABLE_PAM_AUTH)
    /* Check that the PAM plugin is installed */
    if (access("/etc/pam.d/phit", R_OK) != 0)
    {
        fprintf(stderr, "%s: /etc/pam.d/phit not found\n\n", arg0);
        exit(1);
    }
#endif

    /* Stop the server? */
    if (g_options.stop)
    {
#if defined(ENABLE_PIDFILE)
        _StopServer();
#else
        Err("use kill (-s option is diabled)");
#endif /* defined(ENABLE_PIDFILE) */
    }

    /* Check arguments */
    if (argc != 1)
    {
        fprintf(stderr, "Use -h for help\n");
        exit(1);
    }

#if defined(ENABLE_PIDFILE)
    /* Bail out if server is already running */
    if (PIDFileIsRunning() == 0)
    {
        Err("already running: %s", MakePath(ID_PIDFILE, pidfileBuf));
    }
#endif /* defined(ENABLE_PIDFILE) */

    /* Load the plugins file */
    {
        char error[128];

        if (PluginLoad(error, PHIT_ARRAY_SIZE(error)) != 0)
            Err("%s", error);
    }

    /* Initialize the selector */
    SelectorInit(&selector);

    /* Handle SIGTERM */
    signal(SIGTERM, _HandleSIGTERM);

    /* Ignore SIGPIPE */
#if defined(HAVE_POSIX)
    signal(SIGPIPE, SIG_IGN);
#endif

    /* Initialize the sockets layer */
    {
        int r = SockStart();
        (void)r;
        DEBUG_ASSERT(r == 0);
    }

#if defined(HAVE_POSIX)
    /* Create listener for Unix-domain sockets */
    if (ListenerInit(&unixListener, &selector, g_options.sockfile, 0) != 0)
    {
        char buf[MAX_PATH_SIZE];
        Err("listen failed (uds): %s", MakePath(ID_SOCKFILE, buf));
    }
#endif /* defined(HAVE_POSIX) */

    /* Create listener for internet sockets */
    if (ListenerInit(&inetListener, &selector, NULL, g_options.port) != 0)
    {
        Err("listen failed (inet): port %u", g_options.port);
    }

    /* Daemonize */
#if defined(HAVE_POSIX)
    if (!g_options.nodaemonize)
        ProcessDaemonize();
#endif

#if defined(ENABLE_PIDFILE)
    /* Create PID file (after daemonize) */
    if ((pidfile = PIDFileCreate()) == -1)
    {
        Err("failed to create %s", MakePath(ID_PIDFILE, pidfileBuf));
    }
#endif /* defined(ENABLE_PIDFILE) */

    /* Run the selector */
    while (!_terminated)
    {
        SelectorRun(&selector, 1, 0);
    }

    /* Unload the plugins */
    PluginUnload();

    /* Close and delete the PID file */
#if defined(ENABLE_PIDFILE)
    {
        close(pidfile);

        if (PIDFileDelete() != 0)
        {
            Err("delete failed: %s\n", MakePath(ID_PIDFILE, pidfileBuf));
        }
    }
#endif /* defined(ENABLE_PIDFILE) */

    /* Release the selector (and any surviving handlers) */
    SelectorDestroy(&selector);

    /* Remove the socket file */
#if defined(ENABLE_EXEC_PROVIDERS)
    unlink(MakePath(ID_SOCKFILE, sockfileBuf));
#endif

    /* Shutdown the sockets layer */
    SockStop();

    LOGI(("Terminated"));

    /* Call all cleanup handlers */
    Cleanup();

#if defined(ENABLE_ALLOCATOR)
    /* Print allocation statistics */
    AllocPrintStatsAssert();
#endif

#if defined(ENABLE_SOCKTRACE)
    printf("Bytes sent: %llu\n", SockGetBytesSent());
    printf("Bytes recv: %llu\n", SockGetBytesRecv());
#endif /* ENABLE_SOCKTRACE */

    return 0;
}
Пример #5
0
void CGroupPrice::SubscribeGroup(const _QuoteUpdateParams& Params, GroupRequestType enRequest)
{
	_SetDbKey(Params);
	
	long nResult = _GetOptions(Params, enRequest);
	if(DBA_ERR_NO_ERROR == nResult)
	{
		if(m_bIsGotOptions && !m_bIsGotError)
		{
			if(enGroupRequestSubscribe != enRequest && enGroupRequestAllNotify != enRequest)
			{
				DBA_RECORD_3 rec;
				ZeroMemory(&rec, sizeof(rec));
				PublicLastQuote(Params, rec);
			}
			else if(enGroupRequestAllNotify == enRequest)
			{
				CResponseBasePtr pResponse = 
					boost::shared_dynamic_cast<CResponseBase>(CSubscribedResponsePtr(new CSubscribedResponse(Params)));
				PublicResponse(pResponse);
			}
		}
		else if(!m_bIsGotOptions && !m_bIsGotError) 
		{
			CErrorResponsePtr pError = CErrorResponsePtr(new CErrorResponse());
			if(pError)
			{
				pError->m_enRequestType = enSubscribeQuote;
				const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
				pError->m_bstrDescription = L"Couldn't subscribe underlyings options. Unknown symbol.";
				pError->m_Error = enNoDataAvailableForSymbol;

				PublicResponse(boost::shared_dynamic_cast<CResponseBase>(pError));
			}
		}
	}
	else
	{
		CErrorResponsePtr pError = CErrorResponsePtr(new CErrorResponse());
		if(pError)
		{
			pError->m_enRequestType = enSubscribeQuote;
			const_cast<_QuoteUpdateParams&>(Params).CopyTo(pError->m_vtRequest);			
			if(nResult == DBA_ERR_KEY_NOT_FOUND)
			{
				pError->m_bstrDescription = L"Couldn't subscribe underlyings options.";
				pError->m_Error = enNoDataAvailableForSymbol;
			}
			else if(nResult == DBA_ERR_INTEREST)
			{
				pError->m_bstrDescription = L"HyperFeed server subscription list is full";
				pError->m_Error = enProviderInternalError;
			}
			else if(nResult == DBA_TERMINATED)
			{
				pError->m_bstrDescription = L"Operation canceled by user.";
				pError->m_Error = enInternalError;
			}
			else
			{
				_bstr_t bs =  "Couldn't underlyings options. Error: ";
				bs += EtGetMessage(DBA_ERROR,nResult);
				TCHAR buffer[0x100] = {0};				
				_ltot(nResult,buffer,10);
				bs += " (";
				bs += buffer;
				bs += ")";
				pError->m_bstrDescription = bs;
				pError->m_Error = enProviderInternalError;
			}
			PublicResponse(boost::shared_dynamic_cast<CResponseBase>(pError));
		}
	}
	m_vtRequest.Clear();
}