Exemplo n.º 1
0
PANTHEIOS_CALL(int) pantheios_be_init(
    PAN_CHAR_T const*   processIdentity
,   void*               reserved
,   void**              ptoken
)
{
    pan_lr_tokens_t tokens  =   { NULL, NULL };
    int             res;

    /* Initialise the local first */
    res = pantheios_be_local_init(processIdentity, reserved, &tokens.localToken);

    if(0 != res)
    {
        pantheios_onBailOut3(PANTHEIOS_SEV_ALERT, "local back-end did not initialise", NULL);

        return res;
    }
    else
    {
        res = pantheios_be_remote_init(processIdentity, reserved, &tokens.remoteToken);

        if(0 != res)
        {
            pantheios_onBailOut3(PANTHEIOS_SEV_ALERT, "remote back-end did not initialise", NULL);

            pantheios_be_local_uninit(tokens.localToken);

            return res;
        }
        else
        {
            pan_lr_tokens_t* ptokens = (pan_lr_tokens_t*)malloc(sizeof(pan_lr_tokens_t));

            if(NULL == ptokens)
            {
                pantheios_be_remote_uninit(tokens.remoteToken);
                pantheios_be_local_uninit(tokens.localToken);

                return PANTHEIOS_INIT_RC_OUT_OF_MEMORY;
            }
            else
            {
                *ptokens    =   tokens;
                *ptoken     =   ptokens;

                return 0;
            }
        }
    }
}
Exemplo n.º 2
0
static int pantheios_be_WindowsSyslog_logEntry_a_(
    void*       feToken
,   void*       beToken
,   int         severity
,   char const* entry
,   size_t      cchEntry
)
{
    STLSOFT_SUPPRESS_UNUSED(feToken);

    PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(NULL != beToken, "back-end token must be non-null");

    static const char   tm_fmt[]                                =   "%b %d %I:%M:%S";
# ifdef PANTHEIOS_USING_SAFE_STR_FUNCTIONS
    static errno_t      (*fns[2])(struct tm*, const time_t*)    =   { ::localtime_s, ::gmtime_s };
# else /* ? PANTHEIOS_USING_SAFE_STR_FUNCTIONS */
    static struct tm*   (*fns[2])(const time_t*)                =   { ::localtime, ::gmtime };
# endif /* PANTHEIOS_USING_SAFE_STR_FUNCTIONS */

    WindowsSysLog_Context* ctxt       =   static_cast<WindowsSysLog_Context*>(beToken);
    char                szPri_[6];
    char*               szPri;
    char                szTime[31];
    const int           priority    =   (ctxt->facility * 8) + (severity % 8);  /* This stock back-end ignores any custom severity information. */
    time_t              t           =   time(NULL);
# ifdef PANTHEIOS_USING_SAFE_STR_FUNCTIONS
    struct tm           tm_;
    struct tm*          tm          =   &tm_;
    errno_t             err         =   fns[0 != (ctxt->flags & PANTHEIOS_BE_WINDOWSSYSLOG_F_USE_SYSTEM_TIME)](tm, &t);

    if(0 != err)
    {
        char    msg[1001];

        if(0 != ::strerror_s(&msg[0], STLSOFT_NUM_ELEMENTS(msg), err))
        {
            msg[0] = '\0';
        }

        pantheios_onBailOut3(pantheios::critical, "failed to elicit time", msg);

        return 0;
    }
# else /* ? PANTHEIOS_USING_SAFE_STR_FUNCTIONS */
    struct tm*          tm          =   fns[0 != (ctxt->flags & PANTHEIOS_BE_WINDOWSSYSLOG_F_USE_SYSTEM_TIME)](&t);
# endif /* PANTHEIOS_USING_SAFE_STR_FUNCTIONS */
    size_t              cchPriority;
    size_t              cchTime;
    size_t              cchTotal;

    PANTHEIOS_CONTRACT_ENFORCE_ASSUMPTION(priority < 1000);

    szPri       =   pri_print_(&szPri_[0], STLSOFT_NUM_ELEMENTS(szPri_), priority, cchPriority);
    cchTime     =   ::strftime(&szTime[0], STLSOFT_NUM_ELEMENTS(szTime), tm_fmt, tm);

    cchTotal = cchPriority + cchTime + 1 + ctxt->cchHostIdentity + 1 + ctxt->cchProcessIdentity + 1 + cchEntry;

    buffer_a_t buffer(1 + cchTotal);

#ifndef STLSOFT_CF_THROW_BAD_ALLOC
    if(0 == buffer.size())
    {
        return PANTHEIOS_INIT_RC_OUT_OF_MEMORY;
    }
    else
#endif /* !STLSOFT_CF_THROW_BAD_ALLOC */
    {
        // === "%s%s %s %s %s", szPri, szTime, ctxt->hostIdentity, ctxt->processIdentity, entry

        size_t  cchWritten  =   0;
        char*   p           =   &buffer[0];

        ::memcpy(p, szPri, cchPriority * sizeof(char));
        cchWritten += cchPriority;
        p += cchPriority;

        ::memcpy(p, szTime, cchTime * sizeof(char));
        cchWritten += cchTime;
        p += cchTime;

        *p++ = ' ';
        ++cchWritten;

        ::memcpy(p, ctxt->hostIdentity, ctxt->cchHostIdentity * sizeof(char));
        cchWritten += ctxt->cchHostIdentity;
        p += ctxt->cchHostIdentity;

        *p++ = ' ';
        ++cchWritten;

        ::memcpy(p, ctxt->processIdentity, ctxt->cchProcessIdentity * sizeof(char));
        cchWritten += ctxt->cchProcessIdentity;
        p += ctxt->cchProcessIdentity;

        *p++ = ' ';
        ++cchWritten;

        ::memcpy(p, entry, cchEntry * sizeof(char));
        cchWritten += cchEntry;
        p += cchEntry;

        PANTHEIOS_CONTRACT_ENFORCE_ASSUMPTION(cchWritten == size_t(p - buffer.data()));
        PANTHEIOS_CONTRACT_ENFORCE_ASSUMPTION(cchWritten == cchTotal);

        STLSOFT_SUPPRESS_UNUSED(p);

        return ::send(ctxt->sk, buffer.data(), (int)cchWritten, 0);
    }
}
Exemplo n.º 3
0
int pantheios_be_speech_init__cpp(
    pan_char_t const*           processIdentity
,   int                         backEndId
,   pan_be_speech_init_t const* init
,   void*                       reserved
,   void**                      ptoken
)
#endif /* _PANTHEIOS_COMPILER_REQUIRES_EXTERNCPP_DEFINITIONS */
{
    STLSOFT_SUPPRESS_UNUSED(reserved);

    PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(NULL != ptoken, "token pointer may not be null");

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
    try
    {
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */

        /* (i) apply Null Object (Variable) pattern */

        pan_be_speech_init_t init_;

        if(NULL == init)
        {
            pantheios_be_speech_getDefaultAppInit(&init_);

            init = &init_;

#ifdef PANTHEIOS_BE_USE_CALLBACK
            pantheios_be_speech_getAppInit(backEndId, &init_);
#endif /* PANTHEIOS_BE_USE_CALLBACK */
        }

        /* (ii) verify the version */

        if(init->version < 0x010001b8)
        {
            return PANTHEIOS_BE_INIT_RC_OLD_VERSION_NOT_SUPPORTED;
        }
        else if(init->version > PANTHEIOS_VER)
        {
            return PANTHEIOS_BE_INIT_RC_FUTURE_VERSION_REQUESTED;
        }

        /* (iii) create the context */

        *ptoken = NULL;

        comstl::com_initializer         coinit;
        be_speech_context::voice_type   voice;
        HRESULT                         hr = comstl::co_create_instance(CLSID_SpVoice, voice);

        if(E_OUTOFMEMORY == hr)
        {
            return PANTHEIOS_INIT_RC_OUT_OF_MEMORY;
        }
        else if(FAILED(hr))
        {
            std::string msg("Failed to create the speech server component: ");

            msg += winstl::error_desc_a(hr).c_str();

            pantheios_onBailOut3(PANTHEIOS_SEV_CRITICAL, msg.c_str(), NULL);

            return PANTHEIOS_INIT_RC_UNSPECIFIED_EXCEPTION;
        }
        else
        {
            be_speech_context* ctxt = new be_speech_context(processIdentity, backEndId, init->flags, voice);

            if(NULL == ctxt)
            {
                return PANTHEIOS_INIT_RC_UNSPECIFIED_EXCEPTION;
            }

            *ptoken = ctxt;

            return 0;
        }

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
    }
    catch(std::bad_alloc&)
    {
        return PANTHEIOS_INIT_RC_OUT_OF_MEMORY;
    }
    catch(std::exception&)
    {
        return PANTHEIOS_INIT_RC_UNSPECIFIED_EXCEPTION;
    }
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}