Пример #1
0
int Channel::UnSubscribe(const ISubscriber* subscriber) {
    if (NULL == subscriber) {
        return -1;
    }

    int ret = 0;
    std::map<int64_t, ISubscriber*>::iterator it = m_subscribers.find(subscriber->Id());
    if (it != m_subscribers.end()) {
        m_subscribers.erase(it);
    } else {
        ret = -2;
        PLOG_ERROR("subscriber unexisted(%ld).", subscriber->Id());
    }

    int64_t session_id = const_cast<ISubscriber*>(subscriber)->SessionId();
    if (-1 == session_id) {
        return ret;
    }

    std::map<int64_t, ISubscriber*>::iterator sit = m_sessioned_subscribers.find(session_id);
    if (sit == m_sessioned_subscribers.end()) {
        PLOG_DEBUG("sessioned(%ld) subscriber unexisted.", session_id);
        return -3;
    }

    m_sessioned_subscribers.erase(sit);

    return ret;
}
Пример #2
0
int Channel::Publish(const char* msg, size_t len, int encode_type, bool forward) {
    if (NULL == msg) {
        PLOG_ERROR("msg is NULL.");
        return -1;
    }

    if (0 == len) {
        PLOG_DEBUG("msg len = 0.");
        return 0;
    }

    if (m_messages.size() >= m_queue_size) {
        PLOG_ERROR("msg queue is full.");
        return -2;
    }

    m_messages.push_back(BroadcastMessage(msg, len, encode_type, forward)); // NOLINT

    return 0;
}
void PMaterialParameter::upload(PMaterialResource *materialResource, PRenderState *renderState, puint32 &numTextures)
{
    if (m_uniformType == P_GLSHADERUNIFORM_SAMPLER2D ||
        m_uniformType == P_GLSHADERUNIFORM_SAMPLERCUBE)
    {
#if defined P_DEBUG
        if (m_value.t == P_NULL)
        {
            PLOG_DEBUG("NULL texture parameter in material %s", materialResource->id());
        }
#endif
        PASSERT(m_value.t != P_NULL);
        renderState->useTexture(m_value.t, numTextures);
        ++numTextures;
    }

    // The location information of material parameter in instance is the index
    // to the uniform in material resource.  It is because material resource
    // may be discarded and resumed, the uniform location of each parameter may
    // change.
    pint32 location = materialResource->materialParameter(m_uniformLocation)->uniformLocation();
    (this->*m_upload)(location, materialResource->shader());
}
Пример #4
0
int GlobalChannel::UnSubscribe(const ISubscriber* subscriber) {
    if (NULL == subscriber) {
        return -1;
    }
    ISubscriber* sub = const_cast<ISubscriber*>(subscriber);
    if (0 == sub->IsDirectConnect()) {
        // 优先清理m_sessioned_subscribers表
        int64_t session_id = sub->SessionId();
        if (session_id != -1) {
            std::map<int64_t, ISubscriber*>::iterator sit =
                m_sessioned_subscribers.find(session_id);
            if (sit == m_sessioned_subscribers.end()) {
                PLOG_DEBUG("sessioned(%ld) subscriber unexisted.", session_id);
            } else {
                m_sessioned_subscribers.erase(sit);
            }
        }

        // 清理zk上注册的节点
        ChannelConfAdapter* conf = ChannelConfAdapter::Instance();
        if (!conf) { return -2; }

        std::ostringstream name;
        name << "pipe:" << sub->PeerAddress();

        int ret = conf->RmvSubInstance(m_name, name.str());
        if (ret != 0) {
            PLOG_ERROR("rmv %s from %s failed(%d).", name.str().c_str(), m_name.c_str(), ret);
            return -3;
        }

        return 0;
    }

    return Channel::UnSubscribe(sub);
}
Пример #5
0
int pwin32main(int argc, char* argv[])
{
    // Enable memory leak checks and heap validation. 
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetBreakAlloc(-1);

    int exitCode = EXIT_SUCCESS;

    // Create the memory debugger.
    PMemoryDebugger::create();

    PActivity* activity = PNEW(PActivity(argc, argv));
    if (!activity->initialize())
    {
        PDELETE(activity);
        return EXIT_FAILURE;
    }
    
    pMain(argc, argv);

    // Set console title.
    SetConsoleTitle(L"Console");
    
    // Disable the close button of the console window.
    HWND hConsoleWindow = GetConsoleWindow();
    if (hConsoleWindow != NULL)
    {
        HMENU hMenu = GetSystemMenu(hConsoleWindow, 0);
        if (hMenu != NULL)
        {
            DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
            DrawMenuBar(hConsoleWindow);
        }
    }

    PContext* context = activity->findContext(puint32(0));
    PASSERT(context != P_NULL);
    if (context == P_NULL)
    {
        exitCode = EXIT_FAILURE;
        PDELETE(activity);
        return exitCode;
    }

    PWin32Window window(context);

    if (!window.create())
    {
        exitCode = EXIT_FAILURE;
        PDELETE(activity);
        return exitCode;
    }
    
    // Initialize the context. 
    context->setState(P_CONTEXT_STATE_UNINITIALIZED);
    if (!context->initialize(context->properties()->m_windowWidth, context->properties()->m_windowHeight))
    {
        exitCode = EXIT_FAILURE;
    }
    else
    {
        if (!context->onInitialized())
        {
            context->setState(P_CONTEXT_STATE_ERROR);
        }
        else
        {
            PLOG_DEBUG("Starting program main loop");
            context->setState(P_CONTEXT_STATE_RUNNING);
        }

        if (context->state() == P_CONTEXT_STATE_ERROR)
        {
            exitCode = EXIT_FAILURE;
        }

        // The mainloop of window.
        window.run();

        // Right before destroy the context, user might have
        // something to do.
        context->onDestroy();
    }

    context->destroy();
    
    // Destroy native window.
    window.destroy();

    // Destroy the activity
    activity->uninitialize();
    PDELETE(activity);

    // Destroy the memory debugger.
    PMemoryDebugger::destroy();

    // If debugger is present, a pause is required to keep the console output
    // visible. Otherwise the pause is automatic. 
    if (IsDebuggerPresent())
    {
        system("pause");
    }

    return exitCode;
}
Пример #6
0
PImage::PImage(const pchar *path, PInputStream &inputStream)
{
    m_data = P_NULL;
    m_width = 0;
    m_height = 0;
    m_pixelFormat = P_IMAGE_PIXELFORMAT_UNKNOWN;

    // Find the type of image by checking the prefix of the path.
    const pchar* suffix = pstrrchr(path, '.');
    if (suffix == P_NULL)
    {
        PLOG_ERROR("Fail to recognize image format");
    } 
    else
    {
        suffix += 1;

#if P_ENABLE_IMAGE_PNG == 1
        if (pstrcmp(suffix, "png") == 0)
        {
            if (!pImagePNGRead(inputStream, m_width, m_height, m_pixelFormat, m_data))
            {
                PLOG_ERROR("Failed to read PNG image %s", path);

                m_width = 0;
                m_height = 0;
                m_pixelFormat = P_IMAGE_PIXELFORMAT_UNKNOWN;
                m_data = P_NULL;
            }
        }
#endif // P_ENABLE_IMAGE_PNG == 1

#if P_ENABLE_IMAGE_TGA == 1
        if (pstrcmp(suffix, "tga") == 0)
        {
            if (!pImageTGARead(inputStream, m_width, m_height, m_pixelFormat, m_data))
            {
                PLOG_ERROR("Failed to read TGA image %s", path);

                m_width = 0;
                m_height = 0;
                m_pixelFormat = P_IMAGE_PIXELFORMAT_UNKNOWN;
                m_data = P_NULL;
            }
        }
#endif // P_ENABLE_IMAGE_TGA == 1

        // TODO: other image formats

        if (m_data != P_NULL)
        {
            PLOG_DEBUG("Load image %s succeeded", path);
        }
        else
        {
            PLOG_DEBUG("Unsupported image format");
            PLOG_DEBUG("Only supports");
#if P_ENABLE_IMAGE_PNG == 1
            PLOG_DEBUG("png");
#endif
#if P_ENABLE_IMAGE_TGA == 1
            PLOG_DEBUG("tga");
#endif
        }
    }
}