std::string BBMBPS::GetContact(bbmsp_contact_t *contact, BBMField field) { MUTEX_LOCK(); std::string value; char buffer[4096]; switch (field) { case BBM_DISPLAY_NAME: { if (bbmsp_contact_get_display_name(contact, buffer, sizeof(buffer)) == BBMSP_SUCCESS) { value = buffer; } break; } case BBM_STATUS: { bbmsp_presence_status_t status; if (bbmsp_contact_get_status(contact, &status) == BBMSP_SUCCESS) { if (status == BBMSP_PRESENCE_STATUS_AVAILABLE) { value = "available"; } else if (status == BBMSP_PRESENCE_STATUS_BUSY) { value = "busy"; } break; } } case BBM_STATUS_MESSAGE: { if (bbmsp_contact_get_status_message(contact, buffer, sizeof(buffer)) == BBMSP_SUCCESS) { value = buffer; } break; } case BBM_PERSONAL_MESSAGE: { if (bbmsp_contact_get_personal_message(contact, buffer, sizeof(buffer)) == BBMSP_SUCCESS) { value = buffer; } break; } case BBM_PPID: { if (bbmsp_contact_get_ppid(contact, buffer, sizeof(buffer)) == BBMSP_SUCCESS) { value = buffer; } break; } case BBM_HANDLE: { if (bbmsp_contact_get_handle(contact, buffer, sizeof(buffer)) == BBMSP_SUCCESS) { value = buffer; } break; } case BBM_APP_VERSION: { if (bbmsp_contact_get_app_version(contact, buffer, sizeof(buffer)) == BBMSP_SUCCESS) { value = buffer; } break; } case BBM_SDK_VERSION: { int val; if (bbmsp_contact_get_platform_version(contact, &val) == BBMSP_SUCCESS) { std::stringstream ss; ss << val; value = ss.str(); } break; } } MUTEX_UNLOCK(); return value; }
/** * Creates a ActionScript net.rim.bbm.BBMContact instance from the supplied native contact. */ FREObject createActionScriptContact( const bbmsp_contact_t* contact ) { FREObject contact_AS = NULL; const int cNumAttributes = 7; FREObject resultAttributes[cNumAttributes]; bbmsp_result_t result; char ppid[BBMSP_CONTACT_PPID_MAX]; result = bbmsp_contact_get_ppid( contact, ppid, BBMSP_CONTACT_PPID_MAX ); if( result == BBMSP_SUCCESS ) { FRENewObjectFromUTF8((uint32_t)(strlen(ppid) + 1), (uint8_t*)ppid, &resultAttributes[0]); } else { trace( "createActionScriptContact ppid %i", result ); } char displayName[BBMSP_CONTACT_DISPLAY_NAME_MAX]; result = bbmsp_contact_get_display_name( contact, displayName, BBMSP_CONTACT_DISPLAY_NAME_MAX ); if( result == BBMSP_SUCCESS ) { FRENewObjectFromUTF8((uint32_t)(strlen(displayName) + 1), (uint8_t*)displayName, &resultAttributes[1]); } else { trace( "createActionScriptContact displayName %i", result ); } char personalMessage[BBMSP_CONTACT_PERSONAL_MSG_MAX]; result = bbmsp_contact_get_personal_message( contact, personalMessage, BBMSP_CONTACT_PERSONAL_MSG_MAX ); if( result == BBMSP_SUCCESS ) { FRENewObjectFromUTF8((uint32_t)(strlen(personalMessage) + 1), (uint8_t*)personalMessage, &resultAttributes[2]); } else { trace( "createActionScriptContact personalMessage %i", result ); } char statusMessage[BBMSP_CONTACT_STATUS_MSG_MAX]; result = bbmsp_contact_get_status_message( contact, statusMessage, BBMSP_CONTACT_STATUS_MSG_MAX ); if( result == BBMSP_SUCCESS ) { FRENewObjectFromUTF8((uint32_t)(strlen(statusMessage) + 1), (uint8_t*)statusMessage, &resultAttributes[3]); } else { trace( "createActionScriptContact statusMessage %i", result ); } char appVersion[BBMSP_CONTACT_APP_VERSION_MAX]; result = bbmsp_contact_get_app_version( contact, appVersion, BBMSP_CONTACT_APP_VERSION_MAX ); if( result == BBMSP_SUCCESS ) { FRENewObjectFromUTF8((uint32_t)(strlen(appVersion) + 1), (uint8_t*)appVersion, &resultAttributes[4]); } else { trace( "createActionScriptContact appVersion %i", result ); } bbmsp_presence_status_t status; result = bbmsp_contact_get_status( contact, &status ); if( result == BBMSP_SUCCESS ) { FRENewObjectFromInt32( (int32_t)status, &resultAttributes[5]); } else { trace( "createActionScriptContact status %i", result ); } bbmsp_image_t* m_contact_avatar; bbmsp_image_create_empty(&m_contact_avatar); result = bbmsp_contact_get_display_picture( contact, m_contact_avatar ); trace( "%i picture", result ); if( result == BBMSP_SUCCESS ) { char path[PATH_MAX]; getAvatarPath( m_contact_avatar, ppid, path ); FRENewObjectFromUTF8((uint32_t)(strlen(path) + 1), (uint8_t*)path, &resultAttributes[6]); } else { resultAttributes[5] = NULL; } bbmsp_image_destroy( &m_contact_avatar ); FRENewObject((const uint8_t*) "Array", cNumAttributes, resultAttributes, &contact_AS, NULL); return( contact_AS ); }