/* ****************************************************************************
*
* mongoGetContextElementResponses_fail -
*/
TEST(mongoOntimeintervalOperations, mongoGetContextElementResponses_fail)
{
    HttpStatusCode ms;

    /* Forge the parameters */
    EntityIdVector enV;
    EntityId en("E5", "T", "false");
    enV.push_back(&en);
    AttributeList attrL;
    attrL.push_back("A1");
    attrL.push_back("A2");
    attrL.push_back("A3");
    attrL.push_back("A4");
    ContextElementResponseVector cerV;
    std::string err;

    /* Prepare database */
    prepareDatabase();

    /* Do operation */
    ms = mongoGetContextElementResponses(enV, attrL, &cerV, &err);

    /* Check results */
    EXPECT_EQ(SccOk, ms);
    ASSERT_EQ(0, cerV.size());
}
Example #2
0
AttributeList
SunPyInstance::build_preedit_attribs (const IPreeditString* ppd)
{
    AttributeList attrs;
    const int sz = ppd->charTypeSize();
    for (int i = 0; i < sz; ) {
        const int ct = ppd->charTypeAt(i);
        if (ct & IPreeditString::ILLEGAL) {
            const int start = i;
            for (++i; (i<sz) && (ppd->charTypeAt(i) & IPreeditString::ILLEGAL); ++i) ;
            attrs.push_back( Attribute(start, i-start,
                                       SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_REVERSE));
        } else if (ct & IPreeditString::NORMAL_CHAR) {
            if (ct & IPreeditString::USER_CHOICE) {
                const int start = i;
                for (++i; (i<sz) && (ppd->charTypeAt(i) & IPreeditString::USER_CHOICE); ++i) ;
                attrs.push_back( Attribute(start, i-start,
                                           SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_UNDERLINE));
            } else {
                ++i;
            }
        } else {
            ++i;
        }
    }
    return attrs;
}
Example #3
0
AttributeList Program::getActiveAttributes() const {
   AttributeList al;

   // Get the number of active attributes
   GLint num_attributes;
   getProgram(Program::ActiveAttributes, &num_attributes);

   // The the maximum size of the attribe names
   GLsizei max_name_length;
   getProgram(Program::ActiveAttributeMaxLength, &max_name_length);

   GLsizei length;
   std::vector<GLchar> name(max_name_length);

   for(int index = 0; index < num_attributes; index++) {
      AttributeInfo ai;

      // Retrive atribute data and store it in the info struct
      ai.index = index;
      glGetActiveAttrib(getProgramId(),
         index,
         name.size(),
         &length,
         &ai.size,
         &ai.type,
         &name[0]);
      ai.name = std::string(&name[0], length);

      al.push_back(ai);
   }
   return al;
}
Example #4
0
AttributeList
OGR_Feature::getAttributes() const
{
    AttributeTable attrs;

    if ( !store_attrs_loaded )
    {
        const_cast<OGR_Feature*>(this)->loadAttributes();
    }

    // accumulate the attrs from the store:
    for( AttributeTable::const_iterator i = store_attrs.begin(); i != store_attrs.end(); i++ )
    {
        attrs[ (*i).first ] = (*i).second;
    }

    // finally add in the user attrs (overwriting the store attrs if necessary)
    for( AttributeTable::const_iterator i = getUserAttrs().begin(); i != getUserAttrs().end() ; i++ )
        attrs[ (*i).first ] = (*i).second;

    // shove it all into a list
    AttributeList result;
    for( AttributeTable::const_iterator i = attrs.begin(); i != attrs.end(); i++ )
        result.push_back( (*i).second );

    return result;
}
void
HangulInstance::hangul_update_preedit_string ()
{
    WideString wstr = get_preedit_string ();

    if (wstr.length ()) {
        AttributeList attrs;
        attrs.push_back(Attribute(0, m_preedit.length(), SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_UNDERLINE));
        attrs.push_back(Attribute(m_preedit.length(), wstr.length() - m_preedit.length(), SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_REVERSE));
        show_preedit_string ();
        update_preedit_string (wstr, attrs);
        update_preedit_caret (wstr.length());
    } else {
        hide_preedit_string ();
    }
}
bool Connection::table_exists( const string &table_name ) {
  AttributeList parameters;
  parameters.push_back( table_name );
  RowSet rows = select_all( "SELECT name FROM sqlite_master WHERE type='table' AND name = ?;",
                            parameters );
  return ( rows.size() ? true : false );
}
/* ****************************************************************************
*
* mongoGetContextElementResponses_dbfail -
*
* FIXME: not sure if this test should exist... it should be include in unit testing
* for entitiesQuery()
*/
TEST(mongoOntimeintervalOperations, mongoGetContextElementResponses_dbfail)
{
    HttpStatusCode ms;

    /* Prepare mock */
    const DBException e = DBException("boom!!", 33);
    DBClientConnectionMock* connectionMock = new DBClientConnectionMock();
    ON_CALL(*connectionMock,_query("utest.entities",_,_,_,_,_,_))
            .WillByDefault(Throw(e));

    /* Forge the parameters */
    EntityIdVector enV;
    EntityId en1("E1", "T", "false");
    EntityId en2("E2", "T", "false");
    enV.push_back(&en1);
    enV.push_back(&en2);
    AttributeList attrL;
    attrL.push_back("A1");
    attrL.push_back("A2");
    attrL.push_back("A3");
    attrL.push_back("A4");
    ContextElementResponseVector cerV;
    std::string err;

    /* Set MongoDB connection (prepare database first with the "actual" connection object) */
    prepareDatabase();
    DBClientBase* connectionDb = getMongoConnection();
    setMongoConnectionForUnitTest(connectionMock);

    /* Do operation */
    ms = mongoGetContextElementResponses(enV, attrL, &cerV, &err);    

    /* Check results */
    EXPECT_EQ(SccOk, ms);
    EXPECT_EQ("Database Error (collection: utest.entities - "
              "query(): { query: { $or: [ { _id.id: \"E1\", _id.type: \"T\" }, { _id.id: \"E2\", _id.type: \"T\" } ], _id.servicePath: { $in: [ /^/.*/, null ] }, "
              "attrNames: { $in: [ \"A1\", \"A2\", \"A3\", \"A4\" ] } }, orderby: { creDate: 1 } } - "
              "exception: boom!!)", err);

    /* Restore real DB connection */
    setMongoConnectionForUnitTest(connectionDb);

    /* Release mocks */
    delete connectionMock;
}
AttributeList Connection::select_values( const string &query,
					 const AttributeList &parameters ) {
  sqlite3_stmt *ppStmt = prepare( query, parameters );
  AttributeList results;
  while( sqlite3_step( ppStmt ) == SQLITE_ROW ) {
    results.push_back( Attribute::from_field( ppStmt, 0 ) );
  }
  sqlite3_finalize( ppStmt );
  return results;
}
AttributeList
NativeLookupTable::get_attributes (int index) const
{
    AttributeList attrs;

#if 0
    if (index >= 0 && index < (int) m_strings.size ())
        attrs.push_back (Attribute (0, m_strings [index].length (), SCIM_ATTR_FOREGROUND, SCIM_RGB_COLOR(32, 32, 255)));
#endif

    return attrs;
}
/* ****************************************************************************
*
* ok - 
*/
TEST(AttributeList, ok)
{
  AttributeList  al;
  std::string    out;
  const char*    outfile1 = "ngsi.attributeList.ok.middle.json";
  
  utInit();

  out = al.render("");
  EXPECT_STREQ("", out.c_str());

  al.push_back("a1");
  al.push_back("a2");
  
  out = al.render("");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  al.push_back("");
  out = al.check(RegisterContext, "", "", 0);
  EXPECT_STREQ("empty attribute name", out.c_str());

  utExit();
}
Example #11
0
void
StandardIMInstance::imm_update_candidates_list (const IME_InputContext   *ic,
                                                const IME_CandidatesList *candidates)
{
    if (ic && ic->id >= 0 && candidates) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            inst->m_lookup_table.clear ();
            if (candidates->nr_candidates > 0 && candidates->candidates) {

                std::vector <WideString> labels;
                AttributeList attrs;
                WideString wstr;

                if ((candidates->page_state & IME_FIRST_PAGE) == 0)
                    inst->m_lookup_table.append_candidate ((ucs4_t) 0x20);

                for (int i = 0; i < candidates->nr_candidates; ++i) {
                    labels.push_back (inst->m_factory->convert_string (String (candidates->candidates [i].label)));

                    attrs.clear ();

                    for (int j = 0; j < candidates->candidates [i].content.nr_attributes; ++j)
                        attrs.push_back (convert_attribute (candidates->candidates [i].content.attributes [j]));

                    wstr = inst->m_factory->convert_string (String (candidates->candidates [i].content.string));
                    inst->m_lookup_table.append_candidate (wstr, attrs);
                }

                if ((candidates->page_state & IME_LAST_PAGE) == 0)
                    inst->m_lookup_table.append_candidate ((ucs4_t) 0x20);

                if ((candidates->page_state & IME_FIRST_PAGE) == 0) {
                    inst->m_lookup_table.set_page_size (1);
                    inst->m_lookup_table.page_down ();
                }

                inst->m_lookup_table.set_page_size (candidates->nr_candidates);
                inst->m_lookup_table.set_candidate_labels (labels);

                if (candidates->focused_candidate >= 0 && candidates->focused_candidate < candidates->nr_candidates)
                    inst->m_lookup_table.set_cursor_pos_in_current_page (candidates->focused_candidate);
            }

            inst->update_lookup_table (inst->m_lookup_table);
        }
    }
}
Example #12
0
AttributeList
SKKCandList::get_attributes (int index) const
{
    AttributeList al = CommonLookupTable::get_attributes(index);
    if (annot_view && annot_pos &&
        (annot_target || get_cursor_pos() == index)) {
        WideString annot = get_annot(index);
        WideString cand = get_cand(index);
        if (annot_highlight && !annot.empty()) {
            al.push_back(Attribute(cand.length(), annot.length(),
                                   SCIM_ATTR_BACKGROUND,
                                   annot_bgcolor));
        }
    }
    return al;
}
Example #13
0
void
StandardIMInstance::imm_update_aux_string      (const IME_InputContext   *ic,
                                                const IME_String         *string)
{
    if (ic && ic->id >= 0 && string) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            WideString str = inst->m_factory->convert_string (String (string->string));
            AttributeList attrs;
            if (string->nr_attributes > 0 && string->attributes) {
                for (int i = 0; i < string->nr_attributes; ++i)
                    attrs.push_back (convert_attribute (string->attributes [i]));
            }
            inst->update_aux_string (str, attrs);
        }
    }
}
Example #14
0
void
SunPyInstance::redraw_preedit_string (const IPreeditString* ppd)
{
    SCIM_DEBUG_IMENGINE (3) << get_id() <<  ": redraw_preedit_string()\n";
    if (ppd->size() != 0) {
        AttributeList attrs;
        const int caret = ppd->caret();
        if (caret > 0 && caret <= ppd->size()) {
            attrs.push_back( Attribute(ppd->candi_start(),
                                       ppd->charTypeSize(),
                                       SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_REVERSE));
        }
        update_preedit_string( wstr_to_widestr(ppd->string(), ppd->size()) );
        show_preedit_string ();
        update_preedit_caret (caret);
    } else {
        hide_preedit_string ();
    }
}
unsigned int
CannaJRKanji::convert_string (WideString &dest,
                              AttributeList &attr_list,
                              const char *str,
                              unsigned int len,
                              unsigned int cur_pos,
                              unsigned int cur_len)
{
    // cut the string
    char left_str[cur_pos + 1];
    char cur_str[cur_len + 1];
    char right_str[len - cur_pos - cur_len + 1];
    strncpy (left_str, str, cur_pos);
    left_str[cur_pos] = '\0';
    strncpy (cur_str, (const char *) (str + cur_pos), cur_len);
    cur_str[cur_len] = '\0';
    strncpy (right_str, (const char *) (str + cur_pos + cur_len),
             len - cur_pos - cur_len);
    right_str[len - cur_pos - cur_len] = '\0';

    // convert
    WideString left, cur, right;
    m_iconv.convert (left,  left_str);
    m_iconv.convert (cur,   cur_str);
    m_iconv.convert (right, right_str);

    // join all string
    dest = left + cur + right;

    // set attributes
    Attribute attr (left.length (), cur.length (), SCIM_ATTR_DECORATE);
    attr.set_value (SCIM_ATTR_DECORATE_REVERSE);
    attr_list.push_back (attr);

    return left.length ();
}
/* ****************************************************************************
*
* mongoGetContextElementResponses_pattern -
*/
TEST(mongoOntimeintervalOperations, mongoGetContextElementResponses_pattern)
{
    HttpStatusCode ms;

    /* Forge the parameters */
    EntityIdVector enV;
    EntityId en("E[1-2]", "T", "true");
    enV.push_back(&en);
    AttributeList attrL;
    attrL.push_back("A1");
    attrL.push_back("A2");
    attrL.push_back("A3");
    attrL.push_back("A4");
    ContextElementResponseVector cerV;
    std::string err;

    /* Prepare database */
    prepareDatabase();

    /* Do operation */
    ms = mongoGetContextElementResponses(enV, attrL, &cerV, &err);

    /* Check results */
    EXPECT_EQ(SccOk, ms);
    ASSERT_EQ(2, cerV.size());
    ContextElementResponse cer0 = *cerV[0];
    ContextElementResponse cer1 = *cerV[1];
    ContextAttribute ca0, ca1, ca2, ca3;

    /* Context Element Response #1 */
    EXPECT_EQ(SccOk, cer0.statusCode.code);
    EXPECT_EQ("OK", cer0.statusCode.reasonPhrase);
    EXPECT_EQ(0, cer0.statusCode.details.length());
    EXPECT_EQ("E1", cer0.contextElement.entityId.id);
    EXPECT_EQ("T", cer0.contextElement.entityId.type);
    EXPECT_EQ("false", cer0.contextElement.entityId.isPattern);
    ASSERT_EQ(3, cer0.contextElement.contextAttributeVector.size());
    ca0 = *cer0.contextElement.contextAttributeVector[0];
    ca1 = *cer0.contextElement.contextAttributeVector[1];
    ca2 = *cer0.contextElement.contextAttributeVector[2];
    EXPECT_EQ("A1", ca0.name);
    EXPECT_EQ("TA1", ca0.type);
    EXPECT_EQ("X", ca0.stringValue);
    EXPECT_EQ("A2", ca1.name);
    EXPECT_EQ("TA2", ca1.type);
    EXPECT_EQ("Z", ca1.stringValue);
    EXPECT_EQ("A3", ca2.name);
    EXPECT_EQ("TA3", ca2.type);
    EXPECT_EQ("W", ca2.stringValue);

    /* Context Element Response #2 */
    EXPECT_EQ(SccOk, cer1.statusCode.code);
    EXPECT_EQ("OK", cer1.statusCode.reasonPhrase);
    EXPECT_EQ(0, cer1.statusCode.details.length());
    EXPECT_EQ("E2", cer1.contextElement.entityId.id);
    EXPECT_EQ("T", cer1.contextElement.entityId.type);
    EXPECT_EQ("false", cer1.contextElement.entityId.isPattern);
    ASSERT_EQ(2, cer1.contextElement.contextAttributeVector.size());
    ca0 = *cer1.contextElement.contextAttributeVector[0];
    ca1 = *cer1.contextElement.contextAttributeVector[1];
    EXPECT_EQ("A1", ca0.name);
    EXPECT_EQ("TA1", ca0.type);
    EXPECT_EQ("S", ca0.stringValue);
    EXPECT_EQ("A4", ca1.name);
    EXPECT_EQ("TA4", ca1.type);
    EXPECT_EQ("T", ca1.stringValue);

    EXPECT_EQ(0, err.length());
}
void PixelBufferX11::init()
{
    if (_initialized) return;

    if (!_traits)
    {
        _valid = false;
        return;
    }

    if (_traits->target != 0)
    {
        // we don't support Pbuffer render to texture under GLX.
        _valid = false;
        return;
    }


    _display = XOpenDisplay(_traits->displayName().c_str());

    unsigned int screen = _traits->screenNum;

    if (!_display)
    {
        OSG_NOTICE<<"Error: Unable to open display \"" << XDisplayName(_traits->displayName().c_str()) << "\"."<<std::endl;
        _valid = false;
        return;
    }

    // Query for GLX extension
    int errorBase, eventBase;
    if( glXQueryExtension( _display, &errorBase, &eventBase)  == False )
    {
        OSG_NOTICE<<"Error: " << XDisplayName(_traits->displayName().c_str()) <<" has no GLX extension." << std::endl;

        XCloseDisplay( _display );
        _display = 0;
        _valid = false;
        return;
    }

    // OSG_NOTICE<<"GLX extension, errorBase="<<errorBase<<" eventBase="<<eventBase<<std::endl;

    int major, minor;
    if (glXQueryVersion(_display, &major, &minor) == False)
    {
        OSG_NOTICE << "Error: " << XDisplayName(_traits->displayName().c_str())
                                 << " can not query GLX version." << std::endl;
        XCloseDisplay( _display );
        _display = 0;
        _valid = false;
        return;
    }

    // Just be paranoid, if we are older than 1.1, we cannot even call glxQueryExtensionString
    if (major < 1 || (1 == major && minor < 1))
    {
        OSG_NOTICE << "Error: " << XDisplayName(_traits->displayName().c_str())
                                 << " GLX version " << major << "." << minor << " is too old." << std::endl;
        XCloseDisplay( _display );
        _display = 0;
        _valid = false;
        return;
    }

    bool haveGLX1_3 = false;
    bool haveSGIX_pbuffer = false;

    // We need to have at least GLX 1.3 to use getFBConfigFromVisual and glXCreatePbuffer
    if (1 < major || (1 == major && 3 <= minor))
    {
        haveGLX1_3 = true;
    }

#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_pbuffer)
    // We need at least GLX 1.1 for glXQueryExtensionsString
    if (!haveGLX1_3 && 1 <= minor)
    {
        const char *extensions = glXQueryExtensionsString(_display, screen);
        haveSGIX_pbuffer = osg::isExtensionInExtensionString("GLX_SGIX_pbuffer", extensions)
           && osg::isExtensionInExtensionString("GLX_SGIX_fbconfig", extensions);

        if (haveSGIX_pbuffer)
        {
            osg::setGLExtensionFuncPtr(_glXCreateGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX");
            osg::setGLExtensionFuncPtr(_glXDestroyGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX");
            osg::setGLExtensionFuncPtr(_glXQueryGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX");
            osg::setGLExtensionFuncPtr(_glXGetFBConfigFromVisualSGIX, "glXGetFBConfigFromVisualSGIX");
            if (_glXCreateGLXPbufferSGIX == NULL ||
                _glXDestroyGLXPbufferSGIX == NULL ||
                _glXQueryGLXPbufferSGIX == NULL ||
                _glXGetFBConfigFromVisualSGIX == NULL) {
                haveSGIX_pbuffer = false;
            }
        }
    }
#endif

    if (!haveGLX1_3 && !haveSGIX_pbuffer)
    {
        OSG_NOTICE << "Error: " << XDisplayName(_traits->displayName().c_str())
                                 << " no Pbuffer support in GLX available." << std::endl;
        XCloseDisplay( _display );
        _display = 0;
        _valid = false;
        return;
    }


    if (!createVisualInfo())
    {
        _traits->red /= 2;
        _traits->green /= 2;
        _traits->blue /= 2;
        _traits->alpha /= 2;
        _traits->depth /= 2;

        OSG_INFO<<"Relaxing traits"<<std::endl;

        if (!createVisualInfo())
        {
            OSG_NOTICE<<"Error: Not able to create requested visual." << std::endl;
            XCloseDisplay( _display );
            _display = 0;
            _valid = false;
            return;
        }
    }

    // get any shared GLX contexts
    GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext.get());
    Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;

    _context = glXCreateContext( _display, _visualInfo, sharedContext, True );

    if (!_context)
    {
        OSG_NOTICE<<"Error: Unable to create OpenGL graphics context."<<std::endl;
        XCloseDisplay( _display );
        _display = 0;
        _valid = false;
        return;
    }

#ifdef GLX_VERSION_1_3
    // First try the regular glx extension if we have a new enough version available.
    if (haveGLX1_3)
    {
        int nelements;
        GLXFBConfig *fbconfigs = glXGetFBConfigs( _display, screen, &nelements );
        for ( int i = 0; i < nelements; ++i )
        {
            int visual_id;
            if ( glXGetFBConfigAttrib( _display, fbconfigs[i], GLX_VISUAL_ID, &visual_id ) == 0 )
            {
                if ( !_pbuffer && (unsigned int)visual_id == _visualInfo->visualid )
                {
                    typedef std::vector <int> AttributeList;

                    AttributeList attributes;
                    attributes.push_back( GLX_PBUFFER_WIDTH );
                    attributes.push_back( _traits->width );
                    attributes.push_back( GLX_PBUFFER_HEIGHT );
                    attributes.push_back( _traits->height );
                    attributes.push_back( GLX_LARGEST_PBUFFER );
                    attributes.push_back( GL_TRUE );
                    attributes.push_back( 0L );

                    _pbuffer = glXCreatePbuffer(_display, fbconfigs[i], &attributes.front() );
                    _useGLX1_3 = true;
                }
            }
        }
        if (_pbuffer)
        {
            int iWidth = 0;
            int iHeight = 0;
            glXQueryDrawable(_display, _pbuffer, GLX_WIDTH  , (unsigned int *)&iWidth);
            glXQueryDrawable(_display, _pbuffer, GLX_HEIGHT , (unsigned int *)&iHeight);

            if (_traits->width != iWidth || _traits->height != iHeight)
            {
                OSG_NOTICE << "PixelBufferX11::init(), pbuffer created with different size then requsted" << std::endl;
                OSG_NOTICE << "\tRequested size (" << _traits->width << "," << _traits->height << ")" << std::endl;
                OSG_NOTICE << "\tPbuffer size (" << iWidth << "," << iHeight << ")" << std::endl;
                _traits->width  = iWidth;
                _traits->height = iHeight;
            }
        }
        XFree( fbconfigs );
    }
#endif

#ifdef GLX_SGIX_pbuffer
    // If we still have no pbuffer but a capable display with the SGIX extension, try to use that
    if (!_pbuffer && haveSGIX_pbuffer)
    {
        GLXFBConfigSGIX fbconfig = _glXGetFBConfigFromVisualSGIX( _display, _visualInfo );
        typedef std::vector <int> AttributeList;

        AttributeList attributes;
        attributes.push_back( GLX_LARGEST_PBUFFER_SGIX );
        attributes.push_back( GL_TRUE );
        attributes.push_back( 0L );

        _pbuffer = _glXCreateGLXPbufferSGIX(_display, fbconfig, _traits->width, _traits->height,  &attributes.front() );
        if (_pbuffer)
        {
            _useSGIX = true;
            int iWidth = 0;
            int iHeight = 0;
            _glXQueryGLXPbufferSGIX(_display, _pbuffer, GLX_WIDTH_SGIX , (unsigned int *)&iWidth);
            _glXQueryGLXPbufferSGIX(_display, _pbuffer, GLX_HEIGHT_SGIX, (unsigned int *)&iHeight);
                                                                                        
            if (_traits->width != iWidth || _traits->height != iHeight)
            {
                OSG_NOTICE << "PixelBufferX11::init(), SGIX_pbuffer created with different size then requsted" << std::endl;
                OSG_NOTICE << "\tRequested size (" << _traits->width << "," << _traits->height << ")" << std::endl;
                OSG_NOTICE << "\tPbuffer size (" << iWidth << "," << iHeight << ")" << std::endl;
                _traits->width =  iWidth;
                _traits->height = iHeight;
            }
        }
        XFree( fbconfig );
    }
#endif

    if (!_pbuffer)
    {
        OSG_NOTICE<<"Error: Unable to create pbuffer."<<std::endl;
        XCloseDisplay( _display );
        _display = 0;
        _context = 0;
        _valid = false;
        return;
    }


    XFlush( _display );
    XSync( _display, 0 );

    _valid = true;
    _initialized = true;
}
/* ****************************************************************************
*
* associationsDiscoverContextAvailability -
*/
static HttpStatusCode associationsDiscoverContextAvailability
(
  DiscoverContextAvailabilityRequest*   requestP,
  DiscoverContextAvailabilityResponse*  responseP,
  const std::string&                    scope,
  const std::string&                    tenant,
  int                                   offset,
  int                                   limit,
  bool                                  details,
  const std::vector<std::string>&       servicePathV
)
{
    if (scope == SCOPE_VALUE_ASSOC_ALL)
    {
        LM_W(("Bad Input (%s scope not supported)", SCOPE_VALUE_ASSOC_ALL));
        responseP->errorCode.fill(SccNotImplemented, std::string("Not supported scope: '") + SCOPE_VALUE_ASSOC_ALL + "'");
        return SccOk;
    }

    MetadataVector mdV;
    std::string err;
    if (!associationsQuery(&requestP->entityIdVector, &requestP->attributeList, scope, &mdV, &err, tenant, offset, limit, details, servicePathV))
    {
        mdV.release();
        responseP->errorCode.fill(SccReceiverInternalError, std::string("Database error: ") + err);
        return SccOk;
    }

    LM_T(LmtPagination, ("Offset: %d, Limit: %d, Details: %s", offset, limit, (details == true)? "true" : "false"));

    /* Query for associated entities */
    for (unsigned int ix = 0; ix < mdV.size(); ++ix) {
        /* Each association involves a registrationsQuery() operation, accumulating the answer in
         * responseP->responseVector */
        Metadata* md = mdV.get(ix);
        EntityIdVector enV;
        AttributeList attrL;

        EntityId en;
        if (scope == SCOPE_VALUE_ASSOC_SOURCE) {
            en = EntityId(md->association.entityAssociation.source.id, md->association.entityAssociation.source.type);
        }
        else {  // SCOPE_VALUE_ASSOC_TARGET
            en = EntityId(md->association.entityAssociation.target.id, md->association.entityAssociation.target.type);
        }
        enV.push_back(&en);

        for (unsigned int jx = 0; jx < md->association.attributeAssociationList.size(); ++jx) {
            if (scope == SCOPE_VALUE_ASSOC_SOURCE) {
                attrL.push_back(md->association.attributeAssociationList.get(jx)->source);
            }
            else {
                attrL.push_back(md->association.attributeAssociationList.get(jx)->target);
            }
        }

        ContextRegistrationResponseVector crrV;
        if (!registrationsQuery(enV, attrL, &crrV, &err, tenant, servicePathV))
        {
            responseP->errorCode.fill(SccReceiverInternalError, err);
            mdV.release();
            return SccOk;
        }

        /* Accumulate in responseP */
        for (unsigned int jx = 0; jx < crrV.size(); ++jx) {
            responseP->responseVector.push_back(crrV.get(jx));
        }
    }

    if (responseP->responseVector.size() == 0)
    {
      mdV.release();
      responseP->errorCode.fill(SccContextElementNotFound, "Could not query association with combination of entity/attribute");
      LM_RE(SccOk, (responseP->errorCode.details.c_str()));
    }

    /* Set association metadata as final ContextRegistrationResponse */
    ContextRegistrationResponse* crrMd = new ContextRegistrationResponse();
    crrMd->contextRegistration.providingApplication.set("http://www.fi-ware.eu/NGSI/association");
    crrMd->contextRegistration.registrationMetadataVector = mdV;
    responseP->responseVector.push_back(crrMd);

    return SccOk;
}