text:
#include "associations.hpp"

#include <boost/algorithm/string/predicate.hpp>
#include <iostream>

void removeAssociation(const std::string& sourcePath, const std::string& owner,
                       sdbusplus::asio::object_server& server,
                       AssociationMaps& assocMaps)
{
    // Use associationOwners to find the association paths and endpoints
    // that the passed in object path and service own.  Remove all of
    // these endpoints from the actual association D-Bus objects, and if
    // the endpoints property is then empty, the whole association object
    // can be removed.  Note there can be multiple services that own an
    // association, and also that sourcePath is the path of the object
    // that contains the org.openbmc.Associations interface and not the
    // association path itself.

    // Find the services that have associations for this object path
    auto owners = assocMaps.owners.find(sourcePath);
    if (owners == assocMaps.owners.end())
    {
        return;
    }

    // Find the association paths and endpoints owned by this object
    // path for this service.
    auto assocs = owners->second.find(owner);
    if (assocs == owners->second.end())
    {
        return;
    }

    for (const auto& [assocPath, endpointsToRemove] : assocs->second)
    {
        removeAssociationEndpoints(server, assocPath, endpointsToRemove,
                                   assocMaps);
    }

    // Remove the associationOwners entries for this owning path/service.
    owners->second.erase(assocs);
    if (owners->second.empty())
    {
        assocMaps.owners.erase(owners);
    }

    // If we were still waiting on the other side of this association to
    // show up, cancel that wait.
    removeFromPendingAssociations(sourcePath, assocMaps);
}

void removeAssociationEndpoints(
    sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
    const boost::container::flat_set<std::string>& endpointsToRemove,
    AssociationMaps& assocMaps)
{
    auto assoc = assocMaps.ifaces.find(assocPath);
    if (assoc == assocMaps.ifaces.end())
    {
        return;
    }

    auto& endpointsInDBus = std::get<endpointsPos>(assoc->second);

    for (const auto& endpointToRemove : endpointsToRemove)
    {
        auto e = std::find(endpointsInDBus.begin(), endpointsInDBus.end(),
                           endpointToRemove);

        if (e != endpointsInDBus.end())
        {
            endpointsInDBus.erase(e);
        }
    }

    if (endpointsInDBus.empty())
    {
        objectServer.remove_interface(std::get<ifacePos>(assoc->second));
        std::get<ifacePos>(assoc->second) = nullptr;
        std::get<endpointsPos>(assoc->second).clear();
    }
    else
    {
        std::get<ifacePos>(assoc->second)
            ->set_property("endpoints", endpointsInDBus);
    }
}

void checkAssociationEndpointRemoves(
    const std::string& sourcePath, const std::string& owner,
    const AssociationPaths& newAssociations,
    sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps)
{
    // Find the services that have associations on this path.
    auto originalOwners = assocMaps.owners.find(sourcePath);
    if (originalOwners == assocMaps.owners.end())
    {
        return;
    }

    // Find the associations for this service
    auto originalAssociations = originalOwners->second.find(owner);
    if (originalAssociations == originalOwners->second.end())
    {
        return;
    }

    // Compare the new endpoints versus the original endpoints, and
    // remove any of the original ones that aren't in the new list.
    for (const auto& [originalAssocPath, originalEndpoints] :
         originalAssociations->second)
    {
        // Check if this source even still has each association that
        // was there previously, and if not, remove all of its endpoints
        // from the D-Bus endpoints property which will cause the whole
        // association path to be removed if no endpoints remain.
        auto newEndpoints = newAssociations.find(originalAssocPath);
        if (newEndpoints == newAssociations.end())
        {
            removeAssociationEndpoints(objectServer, originalAssocPath,
                                       originalEndpoints, assocMaps);
        }
        else
        {
            // The association is still there.  Check if the endpoints
            // changed.
            boost::container::flat_set<std::string> toRemove;

            for (auto& originalEndpoint : originalEndpoints)
            {
                if (std::find(newEndpoints->second.begin(),
                              newEndpoints->second.end(),
                              originalEndpoint) == newEndpoints->second.end())
                {
                    toRemove.emplace(originalEndpoint);
                }
            }
            if (!toRemove.empty())
            {
                removeAssociationEndpoints(objectServer, originalAssocPath,
                                           toRemove, assocMaps);
            }
        }
    }
}

void addEndpointsToAssocIfaces(
    sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
    const boost::container::flat_set<std::string>& endpointPaths,
    AssociationMaps& assocMaps)
{
    auto& iface = assocMaps.ifaces[assocPath];
    auto& i = std::get<ifacePos>(iface);
    auto& endpoints = std::get<endpointsPos>(iface);

    // Only add new endpoints
    for (auto& e : endpointPaths)
    {
        if (std::find(endpoints.begin(), endpoints.end(), e) == endpoints.end())
        {
            endpoints.push_back(e);
        }
    }

    // If the interface already exists, only need to update
    // the property value, otherwise create it
    if (i)
    {
        i->set_property("endpoints", endpoints);
    }
    else
    {
        i = objectServer.add_interface(assocPath, XYZ_ASSOCIATION_INTERFACE);
        i->register_property("endpoints", endpoints);
        i->initialize();
    }
}

void associationChanged(sdbusplus::asio::object_server& objectServer,
                        const std::vector<Association>& associations,
                        const std::string& path, const std::string& owner,
                        const interface_map_type& interfaceMap,
                        AssociationMaps& assocMaps)
{
    AssociationPaths objects;

    for (const Association& association : associations)
    {
        std::string forward;
        std::string reverse;
        std::string endpoint;
        std::tie(forward, reverse, endpoint) = association;

        if (endpoint.empty())
        {
            std::cerr << "Found invalid association on path " << path << "\n";
            continue;
        }

        // Can't create this association if the endpoint isn't on D-Bus.
        if (interfaceMap.find(endpoint) == interfaceMap.end())
        {
            addPendingAssociation(endpoint, reverse, path, forward, owner,
                                  assocMaps);
            continue;
        }

        if (forward.size())
        {
            objects[path + "/" + forward].emplace(endpoint);
        }
        if (reverse.size())
        {
            objects[endpoint + "/" + reverse].emplace(path);
        }
    }
    for (const auto& object : objects)
    {
        addEndpointsToAssocIfaces(objectServer, object.first, object.second,
                                  assocMaps);
    }

    // Check for endpoints being removed instead of added
    checkAssociationEndpointRemoves(path, owner, objects, objectServer,
                                    assocMaps);

    if (!objects.empty())
    {
        // Update associationOwners with the latest info
        auto a = assocMaps.owners.find(path);
        if (a != assocMaps.owners.end())
        {
            auto o = a->second.find(owner);
            if (o != a->second.end())
            {
                o->second = std::move(objects);
            }
            else
            {
                a->second.emplace(owner, std::move(objects));
            }
        }
        else
        {
            boost::container::flat_map<std::string, AssociationPaths> owners;
            owners.emplace(owner, std::move(objects));
            assocMaps.owners.emplace(path, owners);
        }
    }
}

void addPendingAssociation(const std::string& objectPath,
                           const std::string& type,
                           const std::string& endpointPath,
                           const std::string& endpointType,
                           const std::string& owner, AssociationMaps& assocMaps)
{
    Association assoc{type, endpointType, endpointPath};

    auto p = assocMaps.pending.find(objectPath);
    if (p == assocMaps.pending.end())
    {
        ExistingEndpoints ee;
        ee.emplace_back(owner, std::move(assoc));
        assocMaps.pending.emplace(objectPath, std::move(ee));
    }
    else
    {
        // Already waiting on this path for another association,
        // so just add this endpoint and owner.
        auto& endpoints = p->second;
        auto e =
            std::find_if(endpoints.begin(), endpoints.end(),
                         [&assoc, &owner](const auto& endpoint) {
                             return (std::get<ownerPos>(endpoint) == owner) &&
                                    (std::get<assocPos>(endpoint) == assoc);
                         });
        if (e == endpoints.end())
        {
            endpoints.emplace_back(owner, std::move(assoc));
        }
    }
}

void removeFromPendingAssociations(const std::string& endpointPath,
                                   AssociationMaps& assocMaps)
{
    auto assoc = assocMaps.pending.begin();
    while (assoc != assocMaps.pending.end())
    {
        auto endpoint = assoc->second.begin();
        while (endpoint != assoc->second.end())
        {
            auto& e = std::get<assocPos>(*endpoint);
            if (std::get<reversePathPos>(e) == endpointPath)
            {
                endpoint = assoc->second.erase(endpoint);
                continue;
            }

            endpoint++;
        }

        if (assoc->second.empty())
        {
            assoc = assocMaps.pending.erase(assoc);
            continue;
        }

        assoc++;
    }
}

void addSingleAssociation(sdbusplus::asio::object_server& server,
                          const std::string& assocPath,
                          const std::string& endpoint, const std::string& owner,
                          const std::string& ownerPath,
                          AssociationMaps& assocMaps)
{
    boost::container::flat_set<std::string> endpoints{endpoint};

    addEndpointsToAssocIfaces(server, assocPath, endpoints, assocMaps);

    AssociationPaths objects;
    boost::container::flat_set e{endpoint};
    objects.emplace(assocPath, e);

    auto a = assocMaps.owners.find(ownerPath);
    if (a != assocMaps.owners.end())
    {
        auto o = a->second.find(owner);
        if (o != a->second.end())
        {
            auto p = o->second.find(assocPath);
            if (p != o->second.end())
            {
                p->second.emplace(endpoint);
            }
            else
            {
                o->second.emplace(assocPath, e);
            }
        }
        else
        {
            a->second.emplace(owner, std::move(objects));
        }
    }
    else
    {
        boost::container::flat_map<std::string, AssociationPaths> owners;
        owners.emplace(owner, std::move(objects));
        assocMaps.owners.emplace(endpoint, owners);
    }
}

void checkIfPendingAssociation(const std::string& objectPath,
                               const interface_map_type& interfaceMap,
                               AssociationMaps& assocMaps,
                               sdbusplus::asio::object_server& server)
{
    auto pending = assocMaps.pending.find(objectPath);
    if (pending == assocMaps.pending.end())
    {
        return;
    }

    if (interfaceMap.find(objectPath) == interfaceMap.end())
    {
        return;
    }

    auto endpoint = pending->second.begin();

    while (endpoint != pending->second.end())
    {
        const auto& e = std::get<assocPos>(*endpoint);

        // Ensure the other side of the association still exists
        if (interfaceMap.find(std::get<reversePathPos>(e)) ==
            interfaceMap.end())
        {
            endpoint++;
            continue;
        }

        // Add both sides of the association:
        //  objectPath/forwardType and reversePath/reverseType
        //
        // The ownerPath is the reversePath - i.e. the endpoint that
        // is on D-Bus and owns the org.openbmc.Associations iface.
        //
        const auto& ownerPath = std::get<reversePathPos>(e);
        const auto& owner = std::get<ownerPos>(*endpoint);

        auto assocPath = objectPath + '/' + std::get<forwardTypePos>(e);
        auto endpointPath = ownerPath;

        addSingleAssociation(server, assocPath, endpointPath, owner, ownerPath,
                             assocMaps);

        // Now the reverse direction (still the same owner and ownerPath)
        assocPath = endpointPath + '/' + std::get<reverseTypePos>(e);
        endpointPath = objectPath;
        addSingleAssociation(server, assocPath, endpointPath, owner, ownerPath,
                             assocMaps);

        // Not pending anymore
        endpoint = pending->second.erase(endpoint);
    }

    if (pending->second.empty())
    {
        assocMaps.pending.erase(objectPath);
    }
}

void findAssociations(const std::string& endpointPath,
                      AssociationMaps& assocMaps,
                      FindAssocResults& associationData)
{
    for (const auto& [sourcePath, owners] : assocMaps.owners)
    {
        for (const auto& [owner, assocs] : owners)
        {
            for (const auto& [assocPath, endpoints] : assocs)
            {
                if (std::find(endpoints.begin(), endpoints.end(),
                              endpointPath) != endpoints.end())
                {
                    // assocPath is <path>/<type> which tells us what is on the
                    // other side of the association.
                    auto pos = assocPath.rfind('/');
                    auto otherPath = assocPath.substr(0, pos);
                    auto otherType = assocPath.substr(pos + 1);

                    // Now we need to find the endpointPath/<type> ->
                    // [otherPath] entry so that we can get the type for
                    // endpointPath's side of the assoc.  Do this by finding
                    // otherPath as an endpoint, and also checking for
                    // 'endpointPath/*' as the key.
                    auto a = std::find_if(
                        assocs.begin(), assocs.end(),
                        [&endpointPath, &otherPath](const auto& ap) {
                            const auto& endpoints = ap.second;
                            auto endpoint = std::find(
                                endpoints.begin(), endpoints.end(), otherPath);
                            if (endpoint != endpoints.end())
                            {
                                return boost::starts_with(ap.first,
                                                          endpointPath + '/');
                            }
                            return false;
                        });

                    if (a != assocs.end())
                    {
                        // Pull out the type from endpointPath/<type>
                        pos = a->first.rfind('/');
                        auto thisType = a->first.substr(pos + 1);

                        // Now we know the full association:
                        // endpointPath/thisType -> otherPath/otherType
                        Association association{thisType, otherType, otherPath};
                        associationData.emplace_back(owner, association);
                    }
                }
            }
        }
    }
}

/** @brief Remove an endpoint for a particular association from D-Bus.
 *
 * If the last endpoint is gone, remove the whole association interface,
 * otherwise just update the D-Bus endpoints property.
 *
 * @param[in] assocPath     - the association path
 * @param[in] endpointPath  - the endpoint path to find and remove
 * @param[in,out] assocMaps - the association maps
 * @param[in,out] server    - sdbus system object
 */
void removeAssociationIfacesEntry(const std::string& assocPath,
                                  const std::string& endpointPath,
                                  AssociationMaps& assocMaps,
                                  sdbusplus::asio::object_server& server)
{
    auto assoc = assocMaps.ifaces.find(assocPath);
    if (assoc != assocMaps.ifaces.end())
    {
        auto& endpoints = std::get<endpointsPos>(assoc->second);
        auto e = std::find(endpoints.begin(), endpoints.end(), endpointPath);
        if (e != endpoints.end())
        {
            endpoints.erase(e);

            if (endpoints.empty())
            {
                server.remove_interface(std::get<ifacePos>(assoc->second));
                std::get<ifacePos>(assoc->second) = nullptr;
            }
            else
            {
                std::get<ifacePos>(assoc->second)
                    ->set_property("endpoints", endpoints);
            }
        }
    }
}

/** @brief Remove an endpoint from the association owners map.
 *
 * For a specific association path and owner, remove the endpoint.
 * Remove all remaining artifacts of that endpoint in the owners map
 * based on what frees up after the erase.
 *
 * @param[in] assocPath     - the association object path
 * @param[in] endpointPath  - the endpoint object path
 * @param[in] owner         - the owner of the association
 * @param[in,out] assocMaps - the association maps
 * @param[in,out] server    - sdbus system object
 */
void removeAssociationOwnersEntry(const std::string& assocPath,
                                  const std::string& endpointPath,
                                  const std::string& owner,
                                  AssociationMaps& assocMaps,
                                  sdbusplus::asio::object_server& server)
{
    auto sources = assocMaps.owners.begin();
    while (sources != assocMaps.owners.end())
    {
        auto owners = sources->second.find(owner);
        if (owners != sources->second.end())
        {
            auto entry = owners->second.find(assocPath);
            if (entry != owners->second.end())
            {
                auto e = std::find(entry->second.begin(), entry->second.end(),
                                   endpointPath);
                if (e != entry->second.end())
                {
                    entry->second.erase(e);
                    if (entry->second.empty())
                    {
                        owners->second.erase(entry);
                    }
                }
            }

            if (owners->second.empty())
            {
                sources->second.erase(owners);
            }
        }

        if (sources->second.empty())
        {
            sources = assocMaps.owners.erase(sources);
            continue;
        }
        sources++;
    }
}

void moveAssociationToPending(const std::string& endpointPath,
                              AssociationMaps& assocMaps,
                              sdbusplus::asio::object_server& server)
{
    FindAssocResults associationData;

    // Check which associations this path is an endpoint of, and
    // then add them to the pending associations map and remove
    // the associations objects.
    findAssociations(endpointPath, assocMaps, associationData);

    for (const auto& [owner, association] : associationData)
    {
        const auto& forwardPath = endpointPath;
        const auto& forwardType = std::get<forwardTypePos>(association);
        const auto& reversePath = std::get<reversePathPos>(association);
        const auto& reverseType = std::get<reverseTypePos>(association);

        addPendingAssociation(forwardPath, forwardType, reversePath,
                              reverseType, owner, assocMaps);

        // Remove both sides of the association from assocMaps.ifaces
        removeAssociationIfacesEntry(forwardPath + '/' + forwardType,
                                     reversePath, assocMaps, server);
        removeAssociationIfacesEntry(reversePath + '/' + reverseType,
                                     forwardPath, assocMaps, server);

        // Remove both sides of the association from assocMaps.owners
        removeAssociationOwnersEntry(forwardPath + '/' + forwardType,
                                     reversePath, owner, assocMaps, server);
        removeAssociationOwnersEntry(reversePath + '/' + reverseType,
                                     forwardPath, owner, assocMaps, server);
    }
}

max_stars_repo_name: sotaoverride/backup

max_issues_repo_name: sotaoverride/backup

max_forks_repo_name: sotaoverride/backup


text:
//==============================================================================
//         Copyright 2003 - 2011 LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2014 LRI    UMR 8623 CNRS/Univ Paris Sud XI
//         Copyright 2012 - 2014 MetaScale SAS
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef BOOST_SIMD_SWAR_FUNCTIONS_DETAILS_SLIDE_PATTERN_HPP_INCLUDED
#define BOOST_SIMD_SWAR_FUNCTIONS_DETAILS_SLIDE_PATTERN_HPP_INCLUDED

#include <boost/simd/include/functions/simd/slide.hpp>
#include <boost/dispatch/attributes.hpp>

#include <boost/preprocessor/arithmetic/dec.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>

namespace boost { namespace simd { namespace details
{
  //============================================================================
  // slide pattern
  //============================================================================
  template<int N>
  struct slide_pattern
  {
    template<typename T, typename P>
    static BOOST_FORCEINLINE T process(T const& a0, P const&)
    {
      return slide<N>(a0);
    }

    template<typename T, typename P>
    static BOOST_FORCEINLINE T process(T const& a0, T const& a1, P const&)
    {
      return slide<N>(a0,a1);
    }
  };

#define M2(z,n,t) -1
#define M1(z,n,t) (t + n)

#define M0(z,n,t)                                                              \
template<typename Permutation>                                                 \
struct  default_matcher::match##t < BOOST_PP_ENUM(t,M1,BOOST_PP_INC(n))        \
                                  , Permutation                                \
                                  >                                            \
      : slide_pattern<BOOST_PP_INC(n)>                                         \
{};                                                                            \
                                                                               \
template<typename Permutation>                                                 \
struct  default_matcher::match##t< BOOST_PP_ENUM( BOOST_PP_SUB(t               \
                                                              ,BOOST_PP_INC(n) \
                                                              )                \
                                                , M1                           \
                                                , BOOST_PP_INC(n)              \
                                                )                              \
                              , BOOST_PP_ENUM ( BOOST_PP_INC(n)                \
                                              , M2                             \
                                              , BOOST_PP_INC(n)                \
                                              )                                \
                              , Permutation                                    \
                              >                                                \
      : slide_pattern<BOOST_PP_INC(n)>                                         \
{};                                                                            \
/**/

  //============================================================================
  // Cardinal 4 slide patterns
  //============================================================================
  BOOST_PP_REPEAT(3,M0,4)

  //============================================================================
  // Cardinal 8 slide patterns
  //============================================================================
  BOOST_PP_REPEAT(7,M0,8)

  //============================================================================
  // Cardinal 16 slide patterns
  //============================================================================
  BOOST_PP_REPEAT(15,M0,16)

#undef M0
#undef M1
#undef M2

} } }

#endif

ext: hpp


text:
#define TAOJSON
#include "request.h"

#include <algorithm>
#include <iterator>
#include <memory>
#include <sstream>
using namespace std;
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/tokenizer.hpp>
using namespace boost;
#include "drumlin/thread.h"
#include "drumlin/application.h"
#include "drumlin/exception.h"
#include "drumlin/socket.h"
using namespace drumlin;
#include "response.h"
#include "factory.h"
#include "server.h"
#include "pleg.h"

namespace Pleg {

/**
 * @brief Request::Request : only constructor
 * @param parent Server*
 */
Request::Request(Pleg::Server *_server)
    : ThreadWorker(ThreadType_http,(Object*)_server),SocketHandler(),connection_type(this)
{
    server = _server;
}

/**
 * @brief Request::~Request
 */
Request::~Request()
{
    if(nullptr != response)
        delete response;
}

/**
 * @brief Request::run : the thread function
 */
void Request::work(Object *,Event *)
{
    getSocketRef()
        .setTag(getThread())
        .setHandler(this)
        .setConnection(this)
        .reading()
    ;
}

void Request::connection_start()
{
    std::lock_guard<std::recursive_mutex> l(m_critical_section);
    m_thread = new Thread(string("Request:")+posix_time::to_iso_string(posix_time::microsec_clock::universal_time()));
    Debug() << "Starting thread " << this << *m_thread;
    m_thread->setWorker(this);
    app->addThread(m_thread);
}

void Request::error(boost::system::error_code ec)
{
    Critical() << ec.message();
    close();
}

void Request::close()
{
    getSocketRef().setClosing(true);
    signalTermination();
}

/**
 * @brief Request::readyProcessImpl : process HTTP request packet if not seen already
 * @return bool
 */
bool Request::readyProcess(Socket*)
{
    return verb == verbs_type::NONE || moreHeaders;
}

/**
 * @brief Request::processTransmissionImpl : do HTTP protocol parse
 * @return
 */
bool Request::processTransmission(Socket *socket)
{
    vector<string> lines;
    byte_array bytes(socket->peekData(SocketFlushBehaviours::CoalesceAndFlush));
    string str(bytes.string());
    string::size_type pos(string::npos);
    while((pos=str.find("\r\n"))!=string::npos)str.replace(pos,2,"¬");
    algorithm::split(lines,str,algorithm::is_any_of("¬"),algorithm::token_compress_on);
    for(string &line : lines){
        if(verb == verbs_type::NONE) {
            vector<string> parts;
            algorithm::split(parts,line,algorithm::is_any_of(" "),algorithm::token_compress_on);
            if(std::distance(parts.begin(),parts.end())<3){
                Critical() << "Bad HTTP";
                return false;
            }
            algorithm::trim(parts[2]);
            if(parts[2].compare("HTTP/1.1") && parts[2].compare("HTTP/1.0")){
                Critical() << "Outmoded HTTP";
                return false;
            }
            string verbp(parts[0]);
            bool ok = false;
            verb = (verbs_type)metaEnum<verbs_type>().toEnum(verbp,&ok);
            if(!ok){
                Critical() << "Bad HTTP verb";
                return false;
            }
            algorithm::trim(parts[1]);
            url = parts[1];
        }else{
            if(moreHeaders) {
                if(!line.length()){
                    moreHeaders = false;
                }else{
                    vector<string> parts;
                    algorithm::split(parts,line,algorithm::is_any_of(":"),algorithm::token_compress_on);
                    if(std::distance(parts.begin(),parts.end())>1){
                        algorithm::trim(parts[0]);
                        algorithm::trim(parts[1]);
                        headers.insert({parts[0],parts[1]});
                    }
                }
            }else if(verb == verbs_type::POST){
                body.append(line);
            }
        }
        //Debug() << line;
    }
    if(verb != verbs_type::NONE && !moreHeaders){
        if(!getHeader("X-Method").compare("PATCH")){
            verb = verbs_type::PATCH;
        }
        Debug() << metaEnum<verbs_type>().toString(verb);
        for(headers_type::value_type & hdr : headers){
            Debug().getStream() << hdr.first << ":" << hdr.second;
        }
        return true;
    }
    return false;
}

/**
 * @brief Request::replyImpl : the heart of the HTTP service
 * HEAD : return quickly
 * PATCH : unhandled - server control messages
 * GET, POST : factory-create response and service request, complete socket
 */
bool Request::reply(Socket *) {
    response = Factory::Response::create(this);
    response->service();
    switch(verb){
    case GET:
        getServer()->select_route(this,dynamic_cast<Get*>(response),&relevance);
        break;
    case POST:
        getServer()->select_route(this,dynamic_cast<Post*>(response),&relevance);
        break;
    case PATCH:
        getServer()->select_route(this,dynamic_cast<Patch*>(response),&relevance);
        break;
    case HEAD:
        getServer()->select_route(this,dynamic_cast<Head*>(response),&relevance);
        break;
    case OPTIONS:
        getServer()->select_route(this,dynamic_cast<Options*>(response),&relevance);
        break;
    case CATCH:
        getServer()->select_route(this,dynamic_cast<Catch*>(response),&relevance);
        break;
    default:
        break;
    }
    if(!delayed){
        end();
        return true;
    }else{
        return false;
    }
}

/**
 * @brief Request::completingImpl : write a debug string
 * @param bytes quint32 number of bytes written
 */
void Request::completing(Socket *socket)
{
    if(socket->writeQueueLength())
        return;
    close();
}

void Request::error(Socket *,boost::system::error_code &ec)
{
    Critical() << ec.message();
    close();
}

/**
 * @brief Request::end : end the request
 */
void Request::end()
{
    Debug() << "finished";
    string_list msg;
    msg << metaEnum<verbs_type>().toString(verb) << url << "finished.";
    response->headers << "Access-Control-Allow-Origin: *";
    string headers(algorithm::join(response->headers,"\r\n"));
    std::stringstream ss;
    ss << "HTTP/1.1 " << response->getStatusCode() << "\r\n";
    ss << headers << "\r\n";
    if(string::npos == headers.find("Content-Length")){
        ss << "Content-Length: " << socket().bytesToWrite() << "\r\n";
    }
    ss << "\r\n";
    socket().write(ss.str(),true);
    socket().writing();
}

void Request::shutdown()
{
    close();
}

/**
 * @brief Request::writeToStream : for the status update
 * @param stream std::ostream
 */
void Request::writeToStream(std::ostream &stream)const
{
    string_list list;
    list << metaEnum<verbs_type>().toString(verb) << url << "HTTP/1.1";
    stream << algorithm::join(list," ");
}

void Request::getStatus(json::value *status)const{
    if(response)
        response->getStatus(status);
}

/**
 * @brief Request::eventFilter : deal with bluetooth events
 * @param obj QObject*
 * @param event QEvent*
 * @return bool
 */
bool Request::event(Event *pevent)
{
    quietDebug() << this << __func__ << metaEnum<EventType>().toString((EventType)pevent->type());
    if((guint32)pevent->type() > (guint32)Event_first
            && (guint32)pevent->type() < (guint32)Event_last){
        switch(pevent->type()){
        case EventType::GstStreamPort:
        {
            getSocketRef().write("Opened port:"+getRelevanceRef().arguments.at("port"));
            getSocketRef().setFinished(true);
            end();
            break;
        }
        case EventType::GstStreamFile:
        {
            getSocketRef().write("Writing file:"+getRelevanceRef().arguments.at("filepath"));
            Patch patch(this);
            patch._status();
            getSocketRef().setFinished(true);
            end();
            break;
        }
        default:
            return false;
        }
        return true;
    }
    return false;
}

} // namespace Pleg

ext: cpp

max_stars_repo_name: cephalicmarble/pleg

max_issues_repo_name: cephalicmarble/pleg

max_forks_repo_name: cephalicmarble/pleg


text:
/*
 * Distributed under the Boost Software License, Version 1.0.
 *    (See accompanying file LICENSE_1_0.txt or copy at
 *          http://www.boost.org/LICENSE_1_0.txt)
 *
 * (C) Copyright 2013 Andrey Semashev
 */
/*!
 * \file   thread_specific/at_thread_exit.hpp
 *
 * \brief  This header defines \c at_thread_exit function.
 */

#ifndef BOOST_SYNC_THREAD_SPECIFIC_AT_THREAD_EXIT_HPP_INCLUDED_
#define BOOST_SYNC_THREAD_SPECIFIC_AT_THREAD_EXIT_HPP_INCLUDED_

#include <boost/sync/detail/config.hpp>
#include <boost/sync/detail/tss.hpp>
#include <boost/sync/detail/header.hpp>

#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif

namespace boost {

namespace sync {

namespace detail {

template< typename Function >
void at_thread_exit_trampoline(void* p)
{
    Function* const fun = static_cast< Function* >(p);
    (*fun)();
    delete fun;
}

} // namespace detail

/*!
 * Registers a function to be called at the current thread termination. The function must not accept any arguments, its
 * return value is ignored. The function must not throw exceptions. If multiple functions are registered by the thread,
 * these functions will be invoked in the order reverse of their registration.
 *
 * \param fun The function to be called at thread termination.
 */
template< typename Function >
inline void at_thread_exit(Function const& fun)
{
    Function* p = new Function(fun);
    try
    {
        sync::detail::add_thread_exit_callback(&sync::detail::at_thread_exit_trampoline< Function >, p);
    }
    catch (...)
    {
        delete p;
        throw;
    }
}

} // namespace sync

} // namespace boost

#include <boost/sync/detail/footer.hpp>

#endif // BOOST_SYNC_THREAD_SPECIFIC_AT_THREAD_EXIT_HPP_INCLUDED_

max_stars_repo_name: ballisticwhisper/boost

max_issues_repo_name: ballisticwhisper/boost

max_forks_repo_name: ballisticwhisper/boost


text:
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
 * Copyright (c) 2018 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

#include <memory>
#include <sstream>
#include <string>

#include <boost/asio/ip/host_name.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/functional/hash.hpp>
#include <boost/system/error_code.hpp>

#include "VppContractManager.hpp"
#include "VppEndPointGroupManager.hpp"
#include "VppEndPointManager.hpp"
#include "VppExtItfManager.hpp"
#include "VppIdGen.hpp"
#include "VppLog.hpp"
#include "VppManager.hpp"
#include "VppRouteManager.hpp"
#include "VppSecurityGroupManager.hpp"

#include <opflexagent/EndpointManager.h>

using std::bind;
using boost::asio::placeholders::error;

namespace VPP
{
/**
 * An owner of the objects VPP learns during boot-up
 */
static const std::string BOOT_KEY = "__boot__";

VppManager::VppManager(opflexagent::Agent &agent_,
                       opflexagent::IdGenerator &idGen_,
                       VOM::HW::cmd_q *q,
                       VOM::stat_reader *sr)
    : m_runtime(agent_, idGen_)
    , m_task_queue(agent_.getAgentIOService())
    , stopping(false)
{
    VOM::HW::init(q, sr);
    VOM::OM::init();

    m_runtime.system_name = boost::asio::ip::host_name();
    m_runtime.agent.getFramework().registerPeerStatusListener(this);
}

VppManager::~VppManager()
{
    VLOGE << "VppManager exiting";
}

void
VppManager::start()
{
    VLOGI << "start vpp manager; mode:"
          << (int)m_runtime.agent.getRendererForwardingMode();

    /*
     * create the update delegators
     */
    m_runtime.is_transport_mode =
        (opflex::ofcore::OFConstants::TRANSPORT_MODE ==
         m_runtime.agent.getRendererForwardingMode());
    m_epm = std::make_shared<EndPointManager>(m_runtime);
    m_epgm = std::make_shared<EndPointGroupManager>(m_runtime);
    m_sgm = std::make_shared<SecurityGroupManager>(m_runtime.agent);
    m_cm = std::make_shared<ContractManager>(m_runtime);
    m_rdm = std::make_shared<RouteManager>(m_runtime);
    m_eim = std::make_shared<ExtItfManager>(m_runtime);

    initPlatformConfig();

    /*
     * make sure the first event in the task Q is the blocking
     * connection initiation to VPP ...
     */
    m_task_queue.dispatch("init-connection",
                          bind(&VppManager::handleInitConnection, this));

    /**
     * DO BOOT
     */

    /**
     * ... followed by vpp boot dump
     */
    m_task_queue.dispatch("boot-dump", bind(&VppManager::handleBoot, this));

    /**
     * ... followed by uplink configuration
     */
    m_task_queue.dispatch("uplink-configure",
                          bind(&VppManager::handleUplinkConfigure, this));

    /**
     * ... followed by cross connect configuration
     */
    m_task_queue.dispatch("xconnect-configure",
                          bind(&VppManager::handleXConnectConfigure, this));
}

void
VppManager::handleCloseConnection()
{
    if (!hw_connected) return;

    VOM::interface::disable_events();
    VOM::HW::disconnect();

    VLOGD << "Close VPP connection";
}

void
VppManager::handleInitConnection()
{
    if (stopping) return;

    VLOGD << "Open VPP connection";

    while (VOM::HW::connect() != true)
        ;

    hw_connected = true;

    /**
     * We are insterested in getting interface events from VPP
     */
    VOM::interface::enable_events(*this);

    /**
     * Scehdule a timer to Poll for HW livensss
     */
    m_poll_timer.reset(
        new boost::asio::deadline_timer(m_runtime.agent.getAgentIOService()));
    m_poll_timer->expires_from_now(boost::posix_time::seconds(3));
    m_poll_timer->async_wait(bind(&VppManager::handleHWPollTimer, this, error));

    /**
     * Scehdule a timer for HW stats
     */
    m_stats_timer.reset(
        new boost::asio::deadline_timer(m_runtime.agent.getAgentIOService()));
    m_stats_timer->expires_from_now(boost::posix_time::seconds(5));
    m_stats_timer->async_wait(
        bind(&VppManager::handleHWStatsTimer, this, error));
}

void
VppManager::handleUplinkConfigure()
{
    if (stopping) return;

    m_runtime.uplink.configure(m_runtime.system_name);
}

void
VppManager::handleXConnectConfigure()
{
    if (stopping) return;

    m_xconnect.configure_xconnect();
}

void
VppManager::handleSweepTimer(const boost::system::error_code &ec)
{
    if (stopping || ec) return;

    VLOGI << "sweep boot data";

    /*
     * the sweep timer was not cancelled, continue with purging old state.
     */
    if (hw_connected)
        VOM::OM::sweep(BOOT_KEY);
    else if (!stopping)
    {
        m_sweep_timer.reset(new boost::asio::deadline_timer(
            m_runtime.agent.getAgentIOService()));
        m_sweep_timer->expires_from_now(boost::posix_time::seconds(30));
        m_sweep_timer->async_wait(
            bind(&VppManager::handleSweepTimer, this, error));
    }
}

void
VppManager::handleHWPollTimer(const boost::system::error_code &ec)
{
    if (stopping || ec) return;

    if (hw_connected && VOM::HW::poll())
    {
        /*
         * re-scehdule a timer to Poll for HW liveness
         */
        m_poll_timer.reset(new boost::asio::deadline_timer(
            m_runtime.agent.getAgentIOService()));
        m_poll_timer->expires_from_now(boost::posix_time::seconds(3));
        m_poll_timer->async_wait(
            bind(&VppManager::handleHWPollTimer, this, error));
        return;
    }

    hw_connected = false;
    VOM::HW::disconnect();
    VLOGD << "Reconnecting ....";
    if (VOM::HW::connect())
    {
        VLOGD << "Replay the state after reconnecting ...";
        VOM::OM::replay();
        hw_connected = true;
    }

    if (!stopping)
    {
        m_poll_timer.reset(new boost::asio::deadline_timer(
            m_runtime.agent.getAgentIOService()));
        m_poll_timer->expires_from_now(boost::posix_time::seconds(1));
        m_poll_timer->async_wait(
            bind(&VppManager::handleHWPollTimer, this, error));
    }
    else
    {
        VOM::HW::disconnect();
    }
}

void
VppManager::handleHWStatsTimer(const boost::system::error_code &ec)
{
    if (stopping || ec) return;

    VLOGD << "stats reading";

    VOM::HW::read_stats();

    m_stats_timer.reset(
        new boost::asio::deadline_timer(m_runtime.agent.getAgentIOService()));
    m_stats_timer->expires_from_now(boost::posix_time::seconds(5));
    m_stats_timer->async_wait(
        bind(&VppManager::handleHWStatsTimer, this, error));
}

void
VppManager::handleBoot()
{
    if (stopping) return;

    /**
     * Read the state from VPP
     */
    VOM::OM::populate(BOOT_KEY);
}

void
VppManager::registerModbListeners()
{
    // Initialize policy listeners
    m_runtime.agent.getEndpointManager().registerListener(this);
    m_runtime.agent.getServiceManager().registerListener(this);
    m_runtime.agent.getExtraConfigManager().registerListener(this);
    m_runtime.agent.getPolicyManager().registerListener(this);
}

void
VppManager::stop()
{
    stopping = true;

    m_runtime.agent.getEndpointManager().unregisterListener(this);
    m_runtime.agent.getServiceManager().unregisterListener(this);
    m_runtime.agent.getExtraConfigManager().unregisterListener(this);
    m_runtime.agent.getPolicyManager().unregisterListener(this);

    if (m_stats_timer)
    {
        m_stats_timer->cancel();
    }

    if (m_sweep_timer)
    {
        m_sweep_timer->cancel();
    }

    if (m_poll_timer)
    {
        m_poll_timer->cancel();
    }

    m_task_queue.dispatch("close-connection",
                          bind(&VppManager::handleCloseConnection, this));

    VLOGD << "stop VppManager";
}

void
VppManager::setVirtualRouter(bool virtualRouterEnabled,
                             bool routerAdv,
                             const std::string &virtualRouterMac)
{
    if (virtualRouterEnabled)
    {
        m_runtime.vr = std::make_shared<VirtualRouter>(virtualRouterMac);
    }
}

void
VppManager::endpointUpdated(const std::string &uuid)
{
    if (stopping) return;

    m_task_queue.dispatch(uuid,
                          bind(&EndPointManager::handle_update, m_epm, uuid));
}

void
VppManager::externalEndpointUpdated(const std::string &uuid)
{
    if (stopping) return;

    m_task_queue.dispatch(
        uuid, bind(&EndPointManager::handle_external_update, m_epm, uuid));
}

void
VppManager::remoteEndpointUpdated(const std::string &uuid)
{
    if (stopping) return;

    m_task_queue.dispatch(
        uuid, bind(&EndPointManager::handle_remote_update, m_epm, uuid));
}

void
VppManager::serviceUpdated(const std::string &uuid)
{
    if (stopping) return;

    VLOGI << "Service Update Not supported ";
}

void
VppManager::rdConfigUpdated(const opflex::modb::URI &rdURI)
{
    m_task_queue.dispatch(
        rdURI.toString(),
        bind(&RouteManager::handle_domain_update, m_rdm, rdURI));
}

void
VppManager::egDomainUpdated(const opflex::modb::URI &egURI)
{
    if (stopping) return;

    m_task_queue.dispatch(
        egURI.toString(),
        bind(&EndPointGroupManager::handle_update, m_epgm, egURI));
}

void
VppManager::domainUpdated(opflex::modb::class_id_t cid,
                          const opflex::modb::URI &domURI)
{
    if (stopping) return;

    m_task_queue.dispatch(
        domURI.toString(),
        bind(&VppManager::handleDomainUpdate, this, cid, domURI));
}

void
VppManager::secGroupSetUpdated(const EndpointListener::uri_set_t &secGrps)
{
    if (stopping) return;
    m_task_queue.dispatch(
        "setSecGrp:",
        std::bind(&SecurityGroupManager::handle_set_update, m_sgm, secGrps));
}

void
VppManager::secGroupUpdated(const opflex::modb::URI &uri)
{
    if (stopping) return;
    m_task_queue.dispatch(
        "secGrp:", std::bind(&SecurityGroupManager::handle_update, m_sgm, uri));
}

void
VppManager::contractUpdated(const opflex::modb::URI &contractURI)
{
    if (stopping) return;
    m_task_queue.dispatch(
        contractURI.toString(),
        bind(&ContractManager::handle_update, m_cm, contractURI));
}

void
VppManager::externalInterfaceUpdated(const opflex::modb::URI &uri)
{
    if (stopping) return;
    m_task_queue.dispatch(uri.toString(),
                          bind(&ExtItfManager::handle_update, m_eim, uri));
}

void
VppManager::localRouteUpdated(const opflex::modb::URI &uri)
{
    if (stopping) return;
    m_task_queue.dispatch(uri.toString(),
                          bind(&RouteManager::handle_route_update, m_rdm, uri));
}

void
VppManager::handle_interface_event(std::vector<VOM::interface::event> e)
{
    if (stopping) return;
    m_task_queue.dispatch("InterfaceEvent",
                          bind(&VppManager::handleInterfaceEvent, this, e));
}

void
VppManager::configUpdated(const opflex::modb::URI &configURI)
{
    VLOGI << "Config Updated ";
    if (stopping) return;
    m_runtime.agent.getAgentIOService().dispatch(
        bind(&VppManager::handleConfigUpdate, this, configURI));
}

void
VppManager::portStatusUpdate(const std::string &portName,
                             uint32_t portNo,
                             bool fromDesc)
{
    if (stopping) return;
    m_runtime.agent.getAgentIOService().dispatch(
        bind(&VppManager::handlePortStatusUpdate, this, portName, portNo));
}

void
VppManager::peerStatusUpdated(const std::string &, int, PeerStatus peerStatus)
{
    if (stopping) return;
}

void
VppManager::handleDomainUpdate(opflex::modb::class_id_t cid,
                               const opflex::modb::URI &domURI)
{
    if (stopping) return;

    VLOGD << "Updating domain: " << domURI;

    switch (cid)
    {
    case modelgbp::gbp::RoutingDomain::CLASS_ID:
        m_rdm->handle_domain_update(domURI);
        break;
    case modelgbp::gbp::Subnet::CLASS_ID:
        if (!modelgbp::gbp::Subnet::resolve(m_runtime.agent.getFramework(),
                                            domURI))
        {
            VLOGD << "Cleaning up for Subnet: " << domURI;
        }
        break;
    case modelgbp::gbp::BridgeDomain::CLASS_ID:
        if (!modelgbp::gbp::BridgeDomain::resolve(
                m_runtime.agent.getFramework(), domURI))
        {
            VLOGD << "Cleaning up for BD: " << domURI;
            m_runtime.id_gen.erase(cid, domURI);
        }
        break;
    case modelgbp::gbp::FloodDomain::CLASS_ID:
        if (!modelgbp::gbp::FloodDomain::resolve(m_runtime.agent.getFramework(),
                                                 domURI))
        {
            VLOGD << "Cleaning up for FD: " << domURI;
            m_runtime.id_gen.erase(cid, domURI);
        }
        break;
    case modelgbp::gbp::L3ExternalNetwork::CLASS_ID:
        if (!modelgbp::gbp::L3ExternalNetwork::resolve(
                m_runtime.agent.getFramework(), domURI))
        {
            VLOGD << "Cleaning up for L3ExtNet: " << domURI;
            m_runtime.id_gen.erase(cid, domURI);
        }
        break;
    }
}

void
VppManager::handleInterfaceEvent(std::vector<VOM::interface::event> events)
{
    if (stopping) return;

    for (auto &e : events)
    {
        VLOGD << "Interface Event: " << e.itf.to_string()
              << " state: " << e.state.to_string();
    }
}

void
VppManager::initPlatformConfig()
{
    boost::optional<std::shared_ptr<modelgbp::platform::Config>> config =
        modelgbp::platform::Config::resolve(
            m_runtime.agent.getFramework(),
            m_runtime.agent.getPolicyManager().getOpflexDomain());
}

void
VppManager::handleConfigUpdate(const opflex::modb::URI &configURI)
{
    VLOGD << "Updating platform config " << configURI;
    if (stopping) return;

    initPlatformConfig();

    /**
     * Now that we are known to be opflex connected,
     * Scehdule a timer to sweep the state we read when we first connected
     * to VPP.
     */
    m_sweep_timer.reset(
        new boost::asio::deadline_timer(m_runtime.agent.getAgentIOService()));
    m_sweep_timer->expires_from_now(boost::posix_time::seconds(30));
    m_sweep_timer->async_wait(bind(&VppManager::handleSweepTimer, this, error));
}

void
VppManager::handlePortStatusUpdate(const std::string &portName, uint32_t)
{
    VLOGD << "Port-status update for " << portName;
    if (stopping) return;
}

Uplink &
VppManager::uplink()
{
    return m_runtime.uplink;
}
CrossConnect &
VppManager::crossConnect()
{
    return m_xconnect;
}

}; // namespace opflexagent

/*
 * Local Variables:
 * eval: (c-set-style "llvm.org")
 * End:
 */

max_stars_repo_name: FDio/opflexvpp

max_issues_repo_name: FDio/opflexvpp

max_forks_repo_name: FDio/opflexvpp


text:
#include <iostream>
#include <string>

#include "bryllite-common.hpp"
#include "bryllite-core.hpp"

#include <boost/asio.hpp>
#include <boost/bind.hpp>

// udp echo client
int main( int argc, char** argv )
{
	using udp = boost::asio::ip::udp;

	log( "Hello, Bryllite! %s", bryllite::version() ) ;

	std::string host = ( argc >=2 ) ? argv[1] : "127.0.0.1" ;
	unsigned short port = ( argc >= 3 ) ? atoi(argv[2]) : 9000 ;

	enum { max_buffer_len = 4096 };
	char _request[ max_buffer_len + 1 ];
	char _reply[ max_buffer_len + 1 ];

	try
	{
		boost::asio::io_context ioc ;
		udp::endpoint _endpoint( boost::asio::ip::address::from_string(host), port );
		udp::socket _socket( ioc, udp::endpoint( udp::v4(), 0 ) );

		bryllite::timer ts ;
		while( ts.laptime() <= 60000 ) {
			std::cout << "Enter message to send: " ;
			std::cin.getline( _request, max_buffer_len );
			size_t request_len = strlen( _request );

			_socket.send_to( boost::asio::buffer( _request, request_len ), _endpoint );
			udp::endpoint _sender;
			size_t reply_length = _socket.receive_from( boost::asio::buffer( _reply, max_buffer_len ), _sender );

			std::cout << "Reply: " ;
			std::cout.write( _reply, reply_length );
			std::cout << std::endl ;
		}
	}
	catch( std::exception& e )
	{
		elog( "Exception: e=%s", e.what() ) ;
	}
	catch( ... )
	{
		elog( "Unknown exception" ) ;
	}

	return 0 ;
}

max_stars_repo_name: bryllite/bcp-concept-prototype

max_issues_repo_name: bryllite/bcp-concept-prototype

max_forks_repo_name: bryllite/bcp-concept-prototype


text:
#include <iostream>
#include <boost\type_index.hpp>

using boost::typeindex::type_id_with_cvr;

#define BUILD_FUNC_TEMPLATE(name, T_type) \
	template<typename T> \
	void name(T_type val){ \
		std::cout << "\tparam = " << type_id_with_cvr<decltype(val)>().pretty_name() << std::endl; \
		std::cout << "\tT     = " << type_id_with_cvr<T>().pretty_name() << std::endl; \
	}

#define CALL_FUNC(func_name, param) \
	std::cout << "\t->pass= " << #param << "\ttype: " << type_id_with_cvr<decltype(param)>().pretty_name() <<"\n";\
	func_name(param)

#define CALL_FUNC_TEMPLATE(func_name) \
	std::cout << #func_name << std::endl; \
	CALL_FUNC(func_name, 7);\
	CALL_FUNC(func_name, x); \
	CALL_FUNC(func_name, cx); \
	CALL_FUNC(func_name, rx); \
	std::cout << "====================================\n"

#define CALL_FUNC_TEMPLATE_WITHOUT_rvalue(func_name) \
	std::cout << #func_name << std::endl; \
	CALL_FUNC(func_name, x); \
	CALL_FUNC(func_name, cx); \
	CALL_FUNC(func_name, rx); \
	std::cout << "====================================\n"

BUILD_FUNC_TEMPLATE(just_T, T)
BUILD_FUNC_TEMPLATE(const_T, const T)
BUILD_FUNC_TEMPLATE(ref_T, T&)
BUILD_FUNC_TEMPLATE(const_ref_T, const T&)
BUILD_FUNC_TEMPLATE(uref_T, T&&)

//BUILD_FUNC_TEMPLATE(pass_array, int[])

template<typename T>
void pass_array(T& val) {
		std::cout << "\tparam = " << type_id_with_cvr<decltype(val)>().pretty_name() << std::endl;
		std::cout << "\tT     = " << type_id_with_cvr<T>().pretty_name() << std::endl;
}

int main() {
	int x = 27;
	const int cx = x;
	const int& rx = x;

	CALL_FUNC_TEMPLATE(just_T);
	CALL_FUNC_TEMPLATE(const_T);
	CALL_FUNC_TEMPLATE_WITHOUT_rvalue(ref_T);
	CALL_FUNC_TEMPLATE(const_ref_T);

	CALL_FUNC_TEMPLATE(uref_T);

	int array[5];
	CALL_FUNC(pass_array, array);

	//CALL_FUNC_TEMPLATE(const_uref_T); //should move parameter

	std::getchar();
	return 0;
}


text:
#ifndef ASLAM_BACKEND_MATRIX_EXPRESSION_HPP
#define ASLAM_BACKEND_MATRIX_EXPRESSION_HPP

#include <Eigen/Core>
#include <aslam/backend/JacobianContainer.hpp>
#include <boost/shared_ptr.hpp>
#include <set>
#include "EuclideanExpression.hpp"
#include "HomogeneousExpression.hpp"
#include "TransformationExpression.hpp"

namespace aslam {
namespace backend {

class MatrixExpressionNode;
class EuclideanExpression;

class MatrixExpression {
  public:
    /// \brief initialize from an existing node.
    MatrixExpression(boost::shared_ptr<MatrixExpressionNode> root);

    /// \brief Initialize from an existing node. The node will not be deleted.
    MatrixExpression(MatrixExpressionNode* root);

    virtual ~MatrixExpression();

    /// \brief Evaluate the full transformation matrix.
    Eigen::Matrix3d toMatrix3x3();

    /// \brief Evaluate the Jacobians in the form (1 - (S \delta v)^\times) \bar C
    void evaluateJacobians(JacobianContainer& outJacobians) const;

    EuclideanExpression operator*(const EuclideanExpression& p) const;

    void getDesignVariables(DesignVariable::set_t& designVariables) const;

    boost::shared_ptr<MatrixExpressionNode> root() { return _root; }

  private:
    MatrixExpression();
    boost::shared_ptr<MatrixExpressionNode> _root;
};

}  // namespace backend
}  // namespace aslam

#endif /* ASLAM_BACKEND_MATRIX_EXPRESSION_HPP */

max_stars_repo_name: chengfzy/kalibr

max_issues_repo_name: chengfzy/kalibr

max_forks_repo_name: chengfzy/kalibr


text:
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.

#include <boost/python.hpp>

void export_actor();
void export_blueprint();
void export_client();
void export_control();
void export_transform();
void export_world();

BOOST_PYTHON_MODULE(libcarla) {
  using namespace boost::python;
  scope().attr("__path__") = "libcarla";
  export_transform();
  export_control();
  export_blueprint();
  export_actor();
  export_world();
  export_client();
}

max_stars_repo_name: nsubiron/libcarla

max_issues_repo_name: nsubiron/libcarla

max_forks_repo_name: nsubiron/libcarla