Exemplo n.º 1
0
void BlackBerryMessenger::Init(const char* UUID)
{
    MyAssert( m_State == BBMState_None || m_State == BBMState_Failed );
    if( m_State != BBMState_None && m_State != BBMState_Failed )
        return;

    m_State = BBMState_Initializing;

    // Start the BPS library and initialize the event queue
    //bps_initialize(); // done in main.cpp

    // Request that events flow into event queue
    bbmsp_result_t rc = bbmsp_request_events( 0 ); // 0 = request all events
    if( rc != BBMSP_SUCCESS )
    {
        m_State = BBMState_Failed;
        return;
    }

    // we'll get a "BBMSP_SP_EVENT_ACCESS_CHANGED" event when we're ready to try to register
}
Exemplo n.º 2
0
int BBMBPS::WaitForEvents()
{
    MUTEX_LOCK();
    int status = bbmsp_request_events(0);

    bps_event_t *event = NULL;
    bbmsp_event_t *bbmEvent;
    bbmsp_profile_t *bbmProfile;

    for (;;) {
        MUTEX_UNLOCK();
        bps_get_event(&event, -1);
        MUTEX_LOCK();
        if (event) {
            int event_domain = bps_event_get_domain(event);

            if (event_domain == bbmsp_get_domain()) {
                int eventCategory = 0;
                int eventType = 0;

                bbmsp_event_get(event, &bbmEvent);

                if (bbmsp_event_get_category(event, &eventCategory) == BBMSP_SUCCESS) {
                    switch (eventCategory) {
                        case BBMSP_REGISTRATION:
                        {
                            if (bbmsp_event_get_type(event, &eventType) == BBMSP_SUCCESS) {
                                switch (eventType) {
                                    case BBMSP_SP_EVENT_ACCESS_CHANGED:
                                        processAccessCode(bbmsp_event_access_changed_get_access_error_code(bbmEvent));
                                        break;
                                }
                            }
                            break;
                        }
                        case BBMSP_USER_PROFILE:
                        {
                            if (bbmsp_event_get_type(event, &eventType) == BBMSP_SUCCESS) {
                                switch (eventType) {
                                    case BBMSP_SP_EVENT_PROFILE_CHANGED:
                                    {
                                        bbmsp_presence_update_types_t profileUpdateType;
                                        bbmsp_event_profile_changed_get_profile(bbmEvent, &bbmProfile);
                                        if (bbmsp_event_profile_changed_get_presence_update_type(bbmEvent, &profileUpdateType) == BBMSP_SUCCESS) {
                                            if (profileUpdateType == BBMSP_DISPLAY_PICTURE) {
                                                bbmsp_image_t *avatar;
                                                char *imgData = NULL;
                                                char *output = NULL;

                                                bbmsp_image_create_empty(&avatar);
                                                if (bbmsp_profile_get_display_picture(bbmProfile, avatar) == BBMSP_SUCCESS) {
                                                    imgData = bbmsp_image_get_data(avatar);

                                                    int size = bbmsp_image_get_data_size(avatar);
                                                    output = new char[size*4];

                                                    int bufferSize = b64_ntop(reinterpret_cast<unsigned char *>(imgData), bbmsp_image_get_data_size(avatar), output, size*4);
                                                    output[bufferSize] = 0;
                                                    m_pParent->NotifyEvent(std::string("self.getDisplayPicture ").append(output));
                                                    delete output;
                                                }
                                                bbmsp_image_destroy(&avatar);
                                            } else {
                                                processProfileUpdate(bbmEvent);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                        case BBMSP_CONTACT_LIST:
                        {
                            if (bbmsp_event_get_type(event, &eventType) == BBMSP_SUCCESS) {
                                switch (eventType) {
                                    case BBMSP_SP_EVENT_CONTACT_CHANGED:
                                    {
                                        processContactUpdate(bbmEvent);
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (event_domain == m_BBMInternalDomain) {
                int code = bps_event_get_code(event);
                if (code == INTERNAL_EVENT_REGISTER) {
                    bps_event_payload_t *payload = bps_event_get_payload(event);
                    char *uuid = reinterpret_cast<char *>(payload->data1);
                    bbmsp_register(uuid);
                    delete uuid;
                } else if (code == INTERNAL_EVENT_CONTACT_EVENTS) {
                    bbmsp_event_contact_list_register_event();
                    contactEventsEnabled = true;
                } else if (code == INTERNAL_EVENT_STOP) {
                    break;
                }
            }
        }
    }
    return (status == BPS_SUCCESS) ? 0 : 1;
}