<commit_before>/*
 * Copyright (C) 20011 Francesco Nwokeka <francesco.nwokeka@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License version 2 as
 * published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "../common/global-presence.h"
#include "globalpresenceservice.h"
#include "globalpresencesource.h"

GlobalPresenceSource::GlobalPresenceSource(QObject* parent)
    : DataContainer(parent)
    , m_globalPresence(new GlobalPresence(parent))
{
    // name of the source
    setObjectName("GlobalPresence");

    // global presence source data
    setData("currentPresence", "");
    setData("requestedPresence", "");
    setData("presenceMessage", "");
}

GlobalPresenceSource::~GlobalPresenceSource()
{
}

Plasma::Service* GlobalPresenceSource::createService()
{
    return new GlobalPresenceService(this);
}

GlobalPresence *GlobalPresenceSource::globalPresence() const
{
    return m_globalPresence;
}

void GlobalPresenceSource::onCurrentPresenceChanged(Tp::Presence newPresence)
{
    switch (newPresence.type()) {
        case Tp::ConnectionPresenceTypeAvailable:
            setData("currentPresence", "online");
            break;
        case Tp::ConnectionPresenceTypeAway:
            setData("currentPresence", "away");
            break;
        case Tp::ConnectionPresenceTypeExtendedAway:
            setData("currentPresence", "away-extended");
            break;
        case Tp::ConnectionPresenceTypeBusy:
            setData("currentPresence", "busy");
            break;
        case Tp::ConnectionPresenceTypeHidden:
            setData("currentPresence", "invisible");
            break;
        case Tp::ConnectionPresenceTypeOffline:
            setData("currentPresence", "offline");
            break;
        default:
            setData("currentPresence", "offline");
            break;
    }

    setData("presenceMessage", newPresence.statusMessage());
}

void GlobalPresenceSource::setGlobalPresenceAccountManager(const Tp::AccountManagerPtr& accountMgr)
{
    if (!accountMgr || !accountMgr->isValid()) {
        kWarning() << "GlobalPresenceSource::setGlobalPresenceAccountManager Invalid account manager pointer";
        return;
    }

    m_globalPresence->setAccountManager(accountMgr);

    // setup connections and initialise with current data.
    connect(m_globalPresence, SIGNAL(currentPresenceChanged(Tp::Presence)), this, SLOT(onCurrentPresenceChanged(Tp::Presence)));
    onCurrentPresenceChanged(m_globalPresence->currentPresence());
}<commit_msg>Call checkForUpdate() when global presence changes.<commit_after>/*
 * Copyright (C) 20011 Francesco Nwokeka <francesco.nwokeka@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License version 2 as
 * published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "../common/global-presence.h"
#include "globalpresenceservice.h"
#include "globalpresencesource.h"

GlobalPresenceSource::GlobalPresenceSource(QObject* parent)
    : DataContainer(parent)
    , m_globalPresence(new GlobalPresence(parent))
{
    // name of the source
    setObjectName("GlobalPresence");

    // global presence source data
    setData("currentPresence", "");
    setData("requestedPresence", "");
    setData("presenceMessage", "");
}

GlobalPresenceSource::~GlobalPresenceSource()
{
}

Plasma::Service* GlobalPresenceSource::createService()
{
    return new GlobalPresenceService(this);
}

GlobalPresence *GlobalPresenceSource::globalPresence() const
{
    return m_globalPresence;
}

void GlobalPresenceSource::onCurrentPresenceChanged(Tp::Presence newPresence)
{
    switch (newPresence.type()) {
        case Tp::ConnectionPresenceTypeAvailable:
            setData("currentPresence", "online");
            break;
        case Tp::ConnectionPresenceTypeAway:
            setData("currentPresence", "away");
            break;
        case Tp::ConnectionPresenceTypeExtendedAway:
            setData("currentPresence", "away-extended");
            break;
        case Tp::ConnectionPresenceTypeBusy:
            setData("currentPresence", "busy");
            break;
        case Tp::ConnectionPresenceTypeHidden:
            setData("currentPresence", "invisible");
            break;
        case Tp::ConnectionPresenceTypeOffline:
            setData("currentPresence", "offline");
            break;
        default:
            setData("currentPresence", "offline");
            break;
    }

    setData("presenceMessage", newPresence.statusMessage());
    checkForUpdate();
}

void GlobalPresenceSource::setGlobalPresenceAccountManager(const Tp::AccountManagerPtr& accountMgr)
{
    if (!accountMgr || !accountMgr->isValid()) {
        kWarning() << "GlobalPresenceSource::setGlobalPresenceAccountManager Invalid account manager pointer";
        return;
    }

    m_globalPresence->setAccountManager(accountMgr);

    // setup connections and initialise with current data.
    connect(m_globalPresence, SIGNAL(currentPresenceChanged(Tp::Presence)), this, SLOT(onCurrentPresenceChanged(Tp::Presence)));
    onCurrentPresenceChanged(m_globalPresence->currentPresence());
}<|endoftext|>


<commit_before>// Copyright (C) 2014 David Helkowski
// License GNU AGPLv3

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<libgen.h>

// Text to print before every hexidecimal byte representation
#define HEX_PREFIX "~"

// Characters to show normally instead of in hex
#define OK_CHARACTERS " {}\"'=-()<>,./_![]:&;?"

// Comment this out to disable acceptance of alpha-numeric characters
#define ALPHA_NUM

// Minimum number of sequential acceptable character needed to show text instead of hex
#define MIN_SEQUENCE 3

void phex( unsigned char let );
unsigned char let_okay( unsigned char let );

unsigned char accept[ 256 ];

int main( int argc, char *argv[] ) {
    FILE *data_handle = 0;
    bool showhelp = 0;
    if( argc < 2 ) {
        if( isatty( STDIN_FILENO ) ) {
            showhelp = 1;
        }
    }

    if( argc > 1 ) {
        if( !strncmp( argv[1], "--help", 6 ) ) showhelp = 1;
        data_handle = fopen( argv[1], "r" );
    }

    if( showhelp ) {
        char *base = basename( argv[0] );
        printf("=== Text Hack ===\nTakes input data and outputs specific characters as regular text and hex for other characters.\n\n");

        printf("Characters configured to be output normally:\n");
        #ifdef ALPHA_NUM
        printf("  Alphanumerics\n" );
        #endif
        printf("  %s\n\n", OK_CHARACTERS );

        printf("Usage:\n  %s [filename]\n  %s < filename\n", base, base );

        return 0;
    }

    if( !data_handle ) {
        return 1;
    }

    long pos = 0;

    unsigned char stack[20];
    for( int i=0;i<20;i++ ) {
        stack[i] = 0;
    }
    for( int i=0;i<256;i++ ) {
        accept[i] = 0;
    }
    unsigned char accept_these[] = OK_CHARACTERS;
    for( int i=0;i<256;i++ ) {
        unsigned char let = accept_these[ i ];
        if( !let ) break;
        accept[ let ] = 1;
    }
    unsigned char ok_cnt = 0;
    while( 1 ) {
        unsigned char let = fgetc( data_handle );

        //printf(".");
        //unsigned char ok = let_okay( let );
        //if( ok ) printf("%c", let );
        //else phex( let );

        pos++;

        // shift out the lowest char
        unsigned char n_ago = stack[ 0 ];

        for( int i=0;i<(MIN_SEQUENCE-1);i++ ) {
            stack[ i ] = stack[ i + 1 ];
        }

        // push the new character onto the stack and pop the last one
        stack[ MIN_SEQUENCE - 1 ] = let;

        unsigned char num_ok = 0;
        if( let_okay( n_ago ) ) {
            num_ok++;
            for( int i=0;i<=(MIN_SEQUENCE-1);i++ ) {
                if( let_okay( stack[ i ] ) ) num_ok++;
                else i=100;
            }
        }
        else {
            ok_cnt = 0;
        }

        if( ( num_ok + ok_cnt ) >= MIN_SEQUENCE ) {
            printf( "%c", n_ago );
            ok_cnt++;
        }
        else {
            phex( n_ago );
            ok_cnt = 0;
        }

        if( feof( data_handle ) ) break;
        if( pos > 40000 ) break;
    }
    fclose( data_handle );
}

unsigned char let_okay( unsigned char let ) {
    unsigned char ok = 0;
    if( accept[ let ] ) ok = 1;
    #ifdef ALPHA_NUM
    if( let >= 'a' && let <= 'z' ) ok = 1;
    if( let >= 'A' && let <= 'Z' ) ok = 1;
    if( let >= '0' && let <= '9' ) ok = 1;
    #endif
    return ok;
}

void phex( unsigned char let ) {
    unsigned char low = let % 16;
    let -= low;
    let /= 16;
    // let is now just high portion
    unsigned char hexmap[] = "0123456789ABCDEF";
    //if( !let ) printf("~%c",hexmap[low]);
    //else
    printf( HEX_PREFIX "%c%c",hexmap[let],hexmap[low]);

    //printf("(%hu,%hu[%c,%c])    ",let,low,hexmap[let],hexmap[low]);
}<commit_msg>Fix redirected input. Add error output when specified file does not exist. Correct potential bug with prefix character being interpreted as input to printf. Simplify phex function.<commit_after>// Copyright (C) 2014 David Helkowski
// License GNU AGPLv3

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<libgen.h>

// Text to print before every hexidecimal byte representation
#define HEX_PREFIX '~'

// Characters to show normally instead of in hex
#define OK_CHARACTERS " {}\"'=-()<>,./_![]:&;?"

// Comment this out to disable acceptance of alpha-numeric characters
#define ALPHA_NUM

// Minimum number of sequential acceptable character needed to show text instead of hex
#define MIN_SEQUENCE 3

void phex( unsigned char let );
unsigned char let_okay( unsigned char let );

unsigned char accept[ 256 ];

int main( int argc, char *argv[] ) {
    FILE *data_handle = 0;
    bool showhelp = 0;
    if( argc < 2 ) {
        if( isatty( STDIN_FILENO ) ) {
            showhelp = 1;
        }
        else {
            fprintf(stderr, "Reading input from redirection\n" );
            data_handle = stdin;
        }
    }

    if( argc > 1 ) {
        if( !strncmp( argv[1], "--help", 6 ) ) showhelp = 1;
        fprintf(stderr, "Using file '%s' for input\n", argv[1] );
        data_handle = fopen( argv[1], "r" );
        if( !data_handle ) {
            fprintf(stderr, "File does not exist\n" );
            return 1;
        }
    }

    if( showhelp ) {
        char *base = basename( argv[0] );
        printf("=== Text Hack ===\nTakes input data and outputs specific characters as regular text and hex for other characters.\n\n");

        printf("Characters configured to be output normally:\n");
        #ifdef ALPHA_NUM
        printf("  Alphanumerics\n" );
        #endif
        printf("  %s\n\n", OK_CHARACTERS );

        printf("Usage:\n  %s [filename]\n  %s < filename\n", base, base );

        return 0;
    }

    if( !data_handle ) {
        return 1;
    }

    long pos = 0;

    unsigned char stack[20];
    memset( stack, 0, 20 );

    // accept is a global
    memset( accept, 0, 256 );

    unsigned char accept_these[] = OK_CHARACTERS;
    for( int i=0; i < sizeof( accept_these); i++ ) {
        unsigned char let = accept_these[ i ];
        accept[ let ] = 1;
    }
    unsigned char ok_cnt = 0;
    while( 1 ) {
        unsigned char let = fgetc( data_handle );

        //printf(".");
        //unsigned char ok = let_okay( let );
        //if( ok ) printf("%c", let );
        //else phex( let );

        pos++;

        // shift out the lowest char
        unsigned char n_ago = stack[ 0 ];

        for( int i=0;i<(MIN_SEQUENCE-1);i++ ) {
            stack[ i ] = stack[ i + 1 ];
        }

        // push the new character onto the stack and pop the last one
        stack[ MIN_SEQUENCE - 1 ] = let;

        unsigned char num_ok = 0;
        if( let_okay( n_ago ) ) {
            num_ok++;
            for( int i=0;i<=(MIN_SEQUENCE-1);i++ ) {
                if( let_okay( stack[ i ] ) ) num_ok++;
                else i=100;
            }
        }
        else {
            ok_cnt = 0;
        }

        if( ( num_ok + ok_cnt ) >= MIN_SEQUENCE ) {
            printf( "%c", n_ago );
            ok_cnt++;
        }
        else {
            phex( n_ago );
            ok_cnt = 0;
        }

        if( feof( data_handle ) ) break;
        if( pos > 40000 ) break;
    }
    fclose( data_handle );
}

unsigned char let_okay( unsigned char let ) {
    unsigned char ok = 0;
    if( accept[ let ] ) ok = 1;
    #ifdef ALPHA_NUM
    if( let >= 'a' && let <= 'z' ) ok = 1;
    if( let >= 'A' && let <= 'Z' ) ok = 1;
    if( let >= '0' && let <= '9' ) ok = 1;
    #endif
    return ok;
}

void phex( unsigned char let ) {
    printf( "%c%02X", HEX_PREFIX, let );
}<|endoftext|>


<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Wilsen Hernandez. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
#ifndef _BILIST_HPP_
#define _BILIST_HPP_
#include <iostream>
#include "Binode.hpp"

template<class T>
class Bilist
{
    private:
        Binode<T> *_first, *_last;
        int _length;

    public:
        Bilist() : _first(NULL), _last(NULL), _length(0) {};
        Bilist(const Bilist&);
        ~Bilist() { clear(); };

        bool empty() const { return _length == 0; };
        int size() const { return _length; };
        bool sorted() const;
        T front() const;
        T back() const;

        void push_front(T);
        void push_back(T);
        void pop_front();
        void pop_back();
        void erase(int);
        void change(T, int);
        void clear();
        void reverse();
        void sort();

        void operator=(const Bilist&);
        bool operator>(const Bilist&);
        bool operator<(const Bilist&);
        bool operator==(const Bilist&);
        bool operator>=(const Bilist&);
        bool operator<=(const Bilist&);
};

template<class T>
Bilist<T>::Bilist(const Bilist& arg)
{
    Binode<T> *argpivot = arg._first;
    Binode<T> *iprev = NULL;
    Binode<T> *add = NULL;
    _first = NULL;
    _length = arg._length;

    while(argpivot)
    {
        add = new Binode<T>(argpivot->key());
        if (_first)
        {
            add->set_prev(iprev);
            iprev->set_next(add);
        }
        else
            _first = add;

        iprev = add;
        argpivot = argpivot->next();
    }
    _last = add;
}

template<class T>
T Bilist<T>::front() const
{
    if (_first)
        return _first->key();

    throw "Empty list";
}

template<class T>
T Bilist<T>::back() const
{
    if(_last)
        return _last->key();

    throw "Empty list";
}

template<class T>
void Bilist<T>::push_front(T e)
{
    Binode<T> *add = new Binode<T>(e);

    if(_length == 0)
        _last = add;
    else
    {
        add->set_next(_first);
        _first->set_prev(add);
    }

    _first = add;
    _length++;
}

template<class T>
void Bilist<T>::push_back(T e)
{
    Binode<T> *add = new Binode<T>(e);

    if(_length == 0)
        _first = add;
    else
    {
        add->set_prev(_last);
        _last->set_next(add);
    }

    _last = add;
    _length++;
}

template<class T>
void Bilist<T>::pop_front()
{
    if (!empty())
    {
        Binode<T> *aux = _first;
        _first = aux->next();
        _first->set_prev(NULL);
        _length--;
        delete aux;
    }
    else
        throw "Empty list";
}

template<class T>
void Bilist<T>::pop_back()
{
    if (!empty())
    {
        Binode<T> *aux = _last;
        _last = aux->prev();
        _last->set_next(NULL);
        _length--;
        delete aux;
    }
    else
        throw "Empty list";
}

template<class T>
void Bilist<T>::erase(int index)
{
    if (empty())
        throw "Empty list";
    else if (index < 1 || index > _length + 1)
        throw "Index out of bounds";
    else
    {
        Binode<T> *aux;
        if (index == 1)
        {
            aux = _first;
            _first = aux->next();
            _first->set_prev(NULL);
        }
        else if (index == _length)
        {
            aux = _last;
            _last = aux->prev();
            _last->set_next(NULL);
        }
        else
        {
            Binode<T> *pivot = _first;
            for (int i = 1; i < index; i++)
                pivot = pivot->next();

            aux = pivot;
            aux->next()->set_prev(aux->prev());
            aux->prev()->set_next(aux->next());
        }
        delete aux;
        _length--;
    }
}

template<class T>
void Bilist<T>::clear()
{
    Binode<T> *pivot = _first;
    Binode<T> *aux;
    while (pivot)
    {
        aux = pivot;
        pivot = pivot->next();
        delete aux;
    }
    _first = NULL;
    _last = NULL;
    _length = 0;
}

#endif
<commit_msg>Reverse done<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Wilsen Hernandez. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
#ifndef _BILIST_HPP_
#define _BILIST_HPP_
#include <iostream>
#include "Binode.hpp"

template<class T>
class Bilist
{
    private:
        Binode<T> *_first, *_last;
        int _length;

    public:
        Bilist() : _first(NULL), _last(NULL), _length(0) {};
        Bilist(const Bilist&);
        ~Bilist() { clear(); };

        bool empty() const { return _length == 0; };
        int size() const { return _length; };
        bool sorted() const;
        T front() const;
        T back() const;

        void push_front(T);
        void push_back(T);
        void pop_front();
        void pop_back();
        void erase(int);
        void change(T, int);
        void clear();
        void reverse();
        void sort();

        void operator=(const Bilist&);
        bool operator>(const Bilist&);
        bool operator<(const Bilist&);
        bool operator==(const Bilist&);
        bool operator>=(const Bilist&);
        bool operator<=(const Bilist&);
};

template<class T>
Bilist<T>::Bilist(const Bilist& arg)
{
    Binode<T> *argpivot = arg._first;
    Binode<T> *iprev = NULL;
    Binode<T> *add = NULL;
    _first = NULL;
    _length = arg._length;

    while(argpivot)
    {
        add = new Binode<T>(argpivot->key());
        if (_first)
        {
            add->set_prev(iprev);
            iprev->set_next(add);
        }
        else
            _first = add;

        iprev = add;
        argpivot = argpivot->next();
    }
    _last = add;
}

template<class T>
T Bilist<T>::front() const
{
    if (_first)
        return _first->key();

    throw "Empty list";
}

template<class T>
T Bilist<T>::back() const
{
    if(_last)
        return _last->key();

    throw "Empty list";
}

template<class T>
void Bilist<T>::push_front(T e)
{
    Binode<T> *add = new Binode<T>(e);

    if(_length == 0)
        _last = add;
    else
    {
        add->set_next(_first);
        _first->set_prev(add);
    }

    _first = add;
    _length++;
}

template<class T>
void Bilist<T>::push_back(T e)
{
    Binode<T> *add = new Binode<T>(e);

    if(_length == 0)
        _first = add;
    else
    {
        add->set_prev(_last);
        _last->set_next(add);
    }

    _last = add;
    _length++;
}

template<class T>
void Bilist<T>::pop_front()
{
    if (!empty())
    {
        Binode<T> *aux = _first;
        _first = aux->next();
        _first->set_prev(NULL);
        _length--;
        delete aux;
    }
    else
        throw "Empty list";
}

template<class T>
void Bilist<T>::pop_back()
{
    if (!empty())
    {
        Binode<T> *aux = _last;
        _last = aux->prev();
        _last->set_next(NULL);
        _length--;
        delete aux;
    }
    else
        throw "Empty list";
}

template<class T>
void Bilist<T>::erase(int index)
{
    if (empty())
        throw "Empty list";
    else if (index < 1 || index > _length + 1)
        throw "Index out of bounds";
    else
    {
        Binode<T> *aux;
        if (index == 1)
        {
            aux = _first;
            _first = aux->next();
            _first->set_prev(NULL);
        }
        else if (index == _length)
        {
            aux = _last;
            _last = aux->prev();
            _last->set_next(NULL);
        }
        else
        {
            Binode<T> *pivot = _first;
            for (int i = 1; i < index; i++)
                pivot = pivot->next();

            aux = pivot;
            aux->next()->set_prev(aux->prev());
            aux->prev()->set_next(aux->next());
        }
        delete aux;
        _length--;
    }
}

template<class T>
void Bilist<T>::clear()
{
    Binode<T> *pivot = _first;
    Binode<T> *aux;
    while (pivot)
    {
        aux = pivot;
        pivot = pivot->next();
        delete aux;
    }
    _first = NULL;
    _last = NULL;
    _length = 0;
}

template<class T>
void Bilist<T>::reverse()
{
    Binode<T> *current = _first;
    Binode<T> *temp = NULL;

    if (current)
        _last = _first;

    while (current)
    {
        temp = current->prev();
        current->set_prev(current->next());
        current->set_next(temp);
        current = current->prev();
    }

    if (temp)
        _first = temp->prev();
}

#endif
<|endoftext|>


<commit_before>//
//  WebRequestExample.cpp
//  ExampleApp
//
//  Created by eeGeo on 30/04/2013.
//  Copyright (c) 2013 eeGeo. All rights reserved.
//

#include "WebRequestExample.h"
#include <map>
#include <string>

using namespace Eegeo::Web;

namespace {
    class ExternalHandlerType_NotPartOfPublicAPI : public IWebLoadRequestCompletionCallback
    {
        void operator()(IWebLoadRequest& webLoadRequest)
        {
            int* userData = (int*)webLoadRequest.GetUserData();
            const std::string& url = webLoadRequest.GetUrl();
            size_t responseBodySize = webLoadRequest.GetResourceData().size();

            Eegeo_TTY("\nFinished Https POST of %s in a non member function of calling type, with user data %d - resource size of %ld\n",
                      url.c_str(), *userData, responseBodySize);

            delete userData;

            Eegeo_TTY("\nIs our fake token a valid key? Response was: %s\n", &webLoadRequest.GetResourceData()[0]);
        }
    };
    ExternalHandlerType_NotPartOfPublicAPI externalHandler;
}

namespace Examples
{
    WebRequestExample::WebRequestExample(IWebLoadRequestFactory& webRequestFactory)
    :TWebLoadRequestCompletionCallback<WebRequestExample>(this, &WebRequestExample::RequestComplete)
    ,webRequestFactory(webRequestFactory)
    {
    }

    void WebRequestExample::Start()
    {
        Eegeo_TTY("Making 3 Http GETs with integer labels as user data using a member as the handler...\n");
        webRequestFactory.CreateGet("http://appstore.eegeo.com", *this, new int(1))->Load();
        webRequestFactory.CreateGet("http://non-existent-example-host-1234.com", *this, new int(2))->Load();
        webRequestFactory.CreateGet("http://wikipedia.org", *this, new int(3))->Load();
        webRequestFactory.CreateGet("http://d2xvsc8j92rfya.cloudfront.net/non_existent_resource.hcff", *this, new int(4))->Load();

        std::map<std::string, std::string> postData;
        postData["token"] = "123456789";
        Eegeo_TTY("Making Https POST to Eegeo appstore with invalid key (123456789), with integer labels as user data using a non-member as the handler...\n");
        webRequestFactory.CreatePost("https://appstore.eegeo.com/validate", externalHandler, new int(5678), postData)->Load();
    }

    void WebRequestExample::RequestComplete(IWebLoadRequest& webLoadRequest)
    {
        int* userData = (int*)webLoadRequest.GetUserData();
        const std::string& url = webLoadRequest.GetUrl();
        size_t responseBodySize = webLoadRequest.GetResourceData().size();
        int result = webLoadRequest.HttpStatusCode();

        Eegeo_TTY("\nFinished Http GET of %s in a member function of calling type, result was %d, with user data %d - resource size of %ld\n",
                  url.c_str(), result, *userData, responseBodySize);

        delete userData;
    }
}
<commit_msg>Add http header example<commit_after>//
//  WebRequestExample.cpp
//  ExampleApp
//
//  Created by eeGeo on 30/04/2013.
//  Copyright (c) 2013 eeGeo. All rights reserved.
//

#include "WebRequestExample.h"
#include <map>
#include <string>

using namespace Eegeo::Web;

namespace {
    class ExternalHandlerType_NotPartOfPublicAPI : public IWebLoadRequestCompletionCallback
    {
        void operator()(IWebLoadRequest& webLoadRequest)
        {
            int* userData = (int*)webLoadRequest.GetUserData();
            const std::string& url = webLoadRequest.GetUrl();
            size_t responseBodySize = webLoadRequest.GetResourceData().size();

            Eegeo_TTY("\nFinished Https POST of %s in a non member function of calling type, with user data %d - resource size of %ld\n",
                      url.c_str(), *userData, responseBodySize);

            delete userData;

            Eegeo_TTY("\nIs our fake token a valid key? Response was: %s\n", &webLoadRequest.GetResourceData()[0]);
        }
    };
    ExternalHandlerType_NotPartOfPublicAPI externalHandler;
}

namespace Examples
{
    WebRequestExample::WebRequestExample(IWebLoadRequestFactory& webRequestFactory)
    :TWebLoadRequestCompletionCallback<WebRequestExample>(this, &WebRequestExample::RequestComplete)
    ,webRequestFactory(webRequestFactory)
    {
    }

    void WebRequestExample::Start()
    {
        Eegeo_TTY("Making 3 Http GETs with integer labels as user data using a member as the handler...\n");
        webRequestFactory.CreateGet("http://appstore.eegeo.com", *this, new int(1))->Load();
        webRequestFactory.CreateGet("http://non-existent-example-host-1234.com", *this, new int(2))->Load();
        webRequestFactory.CreateGet("http://wikipedia.org", *this, new int(3))->Load();
        webRequestFactory.CreateGet("http://d2xvsc8j92rfya.cloudfront.net/non_existent_resource.hcff", *this, new int(4))->Load();

        std::map<std::string, std::string> postData;
        postData["token"] = "123456789";
        Eegeo_TTY("Making Https POST to Eegeo appstore with invalid key (123456789), with integer labels as user data using a non-member as the handler...\n");
        webRequestFactory.CreatePost("https://appstore.eegeo.com/validate", externalHandler, new int(5678), postData)->Load();

        std::map<std::string, std::string> httpHeaders;
        httpHeaders["X-MyCustom-Header"] = "Hello World";
        webRequestFactory.CreateGet("http://wikipedia.org", *this, new int(4), httpHeaders)->Load();
    }

    void WebRequestExample::RequestComplete(IWebLoadRequest& webLoadRequest)
    {
        int* userData = (int*)webLoadRequest.GetUserData();
        const std::string& url = webLoadRequest.GetUrl();
        size_t responseBodySize = webLoadRequest.GetResourceData().size();
        int result = webLoadRequest.HttpStatusCode();

        Eegeo_TTY("\nFinished Http GET of %s in a member function of calling type, result was %d, with user data %d - resource size of %ld\n",
                  url.c_str(), result, *userData, responseBodySize);

        delete userData;
    }
}
<|endoftext|>


<commit_before>// The libMesh Finite Element Library.
// Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include "libmesh/libmesh_config.h"

#ifdef LIBMESH_HAVE_TRIANGLE

// Local includes
#include "libmesh/mesh_triangle_holes.h"

namespace libMesh
{

  //
  // PolygonHole member functions
  //
  TriangleInterface::PolygonHole::PolygonHole(Point center, Real radius, unsigned int n_points)
    : _center(center),
      _radius(radius),
      _n_points(n_points)
  {}

  unsigned int TriangleInterface::PolygonHole::n_points() const
  {
    return _n_points;
  }

  Point TriangleInterface::PolygonHole::point(const unsigned int n) const
  {
    // The nth point lies at the angle theta = 2 * pi * n / _n_points
    const Real theta = static_cast<Real>(n) * 2.0 * libMesh::pi / static_cast<Real>(_n_points);

    return Point(_center(0) + _radius*std::cos(theta), // x=r*cos(theta)
		 _center(1) + _radius*std::sin(theta), // y=r*sin(theta)
		 0.);
  }

  Point TriangleInterface::PolygonHole::inside() const
  {
    // The center of the hole is definitely inside.
    return _center;
  }

  //
  // ArbitraryHole member functions
  //
  TriangleInterface::ArbitraryHole::ArbitraryHole(const Point center,
						  const std::vector<Point>& points)
    : 	_center(center),
	_points(points)
  {}

  unsigned int TriangleInterface::ArbitraryHole::n_points() const
  {
    return _points.size();
  }

  Point TriangleInterface::ArbitraryHole::point(const unsigned int n) const
    {
      libmesh_assert_less (n, _points.size());
      return _points[n];
    }

  Point  TriangleInterface::ArbitraryHole::inside() const
  {
    return _center;
  }

} // namespace libMesh

#endif // LIBMESH_HAVE_TRIANGLE
<commit_msg>Changes in mesh_triangle_holes.C for -Wshadow.<commit_after>// The libMesh Finite Element Library.
// Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include "libmesh/libmesh_config.h"

#ifdef LIBMESH_HAVE_TRIANGLE

// Local includes
#include "libmesh/mesh_triangle_holes.h"

namespace libMesh
{

  //
  // PolygonHole member functions
  //
  TriangleInterface::PolygonHole::PolygonHole(Point center, Real radius, unsigned int n_points_in)
    : _center(center),
      _radius(radius),
      _n_points(n_points_in)
  {}

  unsigned int TriangleInterface::PolygonHole::n_points() const
  {
    return _n_points;
  }

  Point TriangleInterface::PolygonHole::point(const unsigned int n) const
  {
    // The nth point lies at the angle theta = 2 * pi * n / _n_points
    const Real theta = static_cast<Real>(n) * 2.0 * libMesh::pi / static_cast<Real>(_n_points);

    return Point(_center(0) + _radius*std::cos(theta), // x=r*cos(theta)
		 _center(1) + _radius*std::sin(theta), // y=r*sin(theta)
		 0.);
  }

  Point TriangleInterface::PolygonHole::inside() const
  {
    // The center of the hole is definitely inside.
    return _center;
  }

  //
  // ArbitraryHole member functions
  //
  TriangleInterface::ArbitraryHole::ArbitraryHole(const Point center,
						  const std::vector<Point>& points)
    : 	_center(center),
	_points(points)
  {}

  unsigned int TriangleInterface::ArbitraryHole::n_points() const
  {
    return _points.size();
  }

  Point TriangleInterface::ArbitraryHole::point(const unsigned int n) const
    {
      libmesh_assert_less (n, _points.size());
      return _points[n];
    }

  Point  TriangleInterface::ArbitraryHole::inside() const
  {
    return _center;
  }

} // namespace libMesh

#endif // LIBMESH_HAVE_TRIANGLE
<|endoftext|>


<commit_before>/*  This file is part of the KDE project
    Copyright (C) 2006 Matthias Kretz <kretz@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include "globalconfig.h"
#include <QSet>
#include <QList>
#include "factory.h"
#include "objectdescription.h"
#include "phonondefs_p.h"

namespace Phonon
{
GlobalConfig::GlobalConfig( QObject *parent )
	: QObject( parent )
	, m_config( KSharedConfig::openConfig( "phononrc", false, false ) )
{
}

GlobalConfig::~GlobalConfig()
{
}

QList<int> GlobalConfig::audioOutputDeviceListFor( Phonon::Category category ) const
{
	const KConfigGroup configGroup( const_cast<KSharedConfig*>( m_config.data() ), "AudioOutputDevice" );

	QSet<int> deviceIndexes;
	QObject *backendObject = Factory::self()->backend();
	pBACKEND_GET1( QSet<int>, deviceIndexes, "objectDescriptionIndexes", ObjectDescriptionType, Phonon::AudioOutputDeviceType );

	QList<int> defaultList = deviceIndexes.toList();
	qSort( defaultList );
	QList<int> deviceList = configGroup.readEntry<QList<int> >( QLatin1String( "Category" ) +
			QString::number( static_cast<int>( category ) ), defaultList );

	return deviceList;
}

int GlobalConfig::audioOutputDeviceFor( Phonon::Category category ) const
{
	return audioOutputDeviceListFor( category ).first();
}

} // namespace Phonon

#include "globalconfig.moc"

// vim: sw=4 ts=4 noet
<commit_msg>- separate device lists per backend - merge the device lists returned by the backend and KConfig<commit_after>/*  This file is part of the KDE project
    Copyright (C) 2006 Matthias Kretz <kretz@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include "globalconfig.h"
#include <QSet>
#include <QList>
#include "factory.h"
#include "objectdescription.h"
#include "phonondefs_p.h"

namespace Phonon
{
GlobalConfig::GlobalConfig( QObject *parent )
	: QObject( parent )
	, m_config( KSharedConfig::openConfig( "phononrc", false, false ) )
{
}

GlobalConfig::~GlobalConfig()
{
}

QList<int> GlobalConfig::audioOutputDeviceListFor( Phonon::Category category ) const
{
	//The devices need to be stored independently for every backend
	//FIXME: backendName() is a translated string
	const KConfigGroup configGroup( const_cast<KSharedConfig*>( m_config.data() ),
			QLatin1String( "AudioOutputDevice" ) + Factory::self()->backendName() );

	//First we lookup the available devices directly from the backend
	QSet<int> deviceIndexes;
	QObject *backendObject = Factory::self()->backend();
	pBACKEND_GET1( QSet<int>, deviceIndexes, "objectDescriptionIndexes", ObjectDescriptionType, Phonon::AudioOutputDeviceType );
	QList<int> defaultList = deviceIndexes.toList();
	qSort( defaultList );

	//Now the list from the phononrc file
	QList<int> deviceList = configGroup.readEntry<QList<int> >( QLatin1String( "Category" ) +
			QString::number( static_cast<int>( category ) ), defaultList );

	QMutableListIterator<int> i( deviceList );
	while( i.hasNext() )
		if( 0 == defaultList.removeAll( i.next() ) )
			//if there are devices in phononrc that the backend doesn't report, remove them from the list
			i.remove();
	//if the backend reports more devices that are not in phononrc append them to the list
	deviceList += defaultList;

	return deviceList;
}

int GlobalConfig::audioOutputDeviceFor( Phonon::Category category ) const
{
	return audioOutputDeviceListFor( category ).first();
}

} // namespace Phonon

#include "globalconfig.moc"

// vim: sw=4 ts=4 noet
<|endoftext|>


<commit_before>/*
Copyright (c) 2016, oasi-adamay
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of glsCV nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdafx.h"

/*-----------------------------------------------------------------------------
include
*/
#include "glsMacro.h"
#include "GlsMat.h"
#include "glsShader.h"

#include "glsFft.h"
#include "glsCopy.h"	//tiled / untiled
#include "glsMerge.h"

#define _USE_MATH_DEFINES
#include <math.h>

#ifdef _DEBUG
//#if 1
#include "Timer.h"
#define _TMR_(...)  Timer tmr(__VA_ARGS__)
#else
#define _TMR_(...)
#endif

namespace gls
{

// glsFft shader
class glsShaderFft : public glsShaderBase
{
protected:
	string FragmentShaderCode(void);
	list<string> UniformNameList(void);

public:
	glsShaderFft(void) :glsShaderBase(__FUNCTION__){}

};

//-----------------------------------------------------------------------------
//global
glsShaderFft ShaderFft;

//-----------------------------------------------------------------------------
//glsShaderFft
string glsShaderFft::FragmentShaderCode(void){
	const char fragmentShaderCode[] = TO_STR(
#version 330 core\n
precision highp float;\n
uniform sampler2D	texSrc0;\n
uniform sampler2D	texSrc1;\n
uniform sampler2D	texW;\n
uniform  int i_flag;	//bit0:(0:holizontal 1:vertical)\n
uniform  int i_N;\n
uniform  int i_p;\n
uniform  int i_q;\n
uniform  float f_xscl;\n
uniform  float f_yscl;\n
uniform  float f_xconj;\n
uniform  float f_yconj;\n
\n
layout (location = 0) out vec2 dst0;\n
layout (location = 1) out vec2 dst1;\n
\n
#define FLAG_DIR	 (1<<0)\n
\n
\n
int insertZeroBits(\n
	const int src,\n
	const int idx,\n
	const int num\n
	)\n
{\n
	int ret = src << num;\n
	ret &= ~((1 << (idx + num)) - 1);\n
	ret |= src & ((1 << idx) - 1);\n
	return ret;\n
}\n
\n
void main(void)\n
{\n
	int p = i_p;\n
	int q = i_q;\n
	int N = i_N;\n
	int dir = ((i_flag & FLAG_DIR)==0) ?0:1;\n
	float xscl = f_xscl;\n
	float yscl = f_yscl;\n
	float xconj = f_xconj;\n
	float yconj = f_yconj;\n
\n
	int n;\n
	vec2 x0;\n
	vec2 x1;\n
	vec2 w;\n
\n
	n= int(gl_FragCoord[dir]);\n
	int iw = (n >> q) << q;\n
	int ix0 = insertZeroBits(n, q, 1);\n
	int ix1 = ix0 + (1 << q);\n
	w = texelFetch(texW,ivec2(iw,0),0).rg;\n
\n
\n
	if(dir ==0){\n
		if(ix0 < N/2) x0 = texelFetch(texSrc0,ivec2(ix0,gl_FragCoord.y),0).rg;\n
		else x0 = texelFetch(texSrc1,ivec2(ix0-N/2,gl_FragCoord.y),0).rg;\n
\n
		if(ix1 < N/2) x1 = texelFetch(texSrc0,ivec2(ix1,gl_FragCoord.y),0).rg;\n
		else x1 = texelFetch(texSrc1,ivec2(ix1-N/2,gl_FragCoord.y),0).rg;\n
	}\n
	else{\n
		if(ix0 < N/2) x0 = texelFetch(texSrc0,ivec2(gl_FragCoord.x,ix0),0).rg;\n
		else x0 = texelFetch(texSrc1,ivec2(gl_FragCoord.x,ix0-N/2),0).rg;\n
\n
		if(ix1 < N/2) x1 = texelFetch(texSrc0,ivec2(gl_FragCoord.x,ix1),0).rg;\n
		else x1 = texelFetch(texSrc1,ivec2(gl_FragCoord.x,ix1-N/2),0).rg;\n
	}\n
\n
//	x0 = x0*xscl;\n
//	x1 = x1*xscl;\n
	x0.g = x0.g*xconj;\n
	x1.g = x1.g*xconj;\n
\n
	vec2 tmp;\n
	tmp.r = x1.r * w.r - x1.g * w.g;\n
	tmp.g = x1.r * w.g + x1.g * w.r;\n
\n
	vec2 y0;\n
	vec2 y1;\n
\n
	y0 = x0 + tmp;\n
	y1 = x0 - tmp;\n
\n
	y0 = y0*yscl;\n
	y1 = y1*yscl;\n
	y0.g = y0.g*yconj;\n
	y1.g = y1.g*yconj;\n
\n
	dst0 = y0;\n
	dst1 = y1;\n
\n
}\n
);
	return fragmentShaderCode;
}

list<string> glsShaderFft::UniformNameList(void){
	list<string> lst;
	lst.push_back("texSrc0");
	lst.push_back("texSrc1");
	lst.push_back("texW");
	lst.push_back("i_flag");
	lst.push_back("i_N");
	lst.push_back("i_p");
	lst.push_back("i_q");
	lst.push_back("f_xscl");
	lst.push_back("f_yscl");
	lst.push_back("f_xconj");
	lst.push_back("f_yconj");
	return lst;
}

//---------------------------------------------------------------------------
//value is power of 2
static bool IsPow2(unsigned int x){
	return (((x)&(x - 1)) == 0);
}

//-----------------------------------------------------------------------------
void fft(const GlsMat& _src, GlsMat& dst, int flag){
	GLS_Assert(_src.channels() == 2 || _src.channels() == 1);
	GLS_Assert(_src.depth() == CV_32F);

	int N = _src.cols;
	GLS_Assert(IsPow2(N));

	Size blkNum(2,2);
	vector<vector<GlsMat>> _dst0 = vector<vector<GlsMat>>(blkNum.height, vector<GlsMat>(blkNum.width));
	vector<vector<GlsMat>> _dst1 = vector<vector<GlsMat>>(blkNum.height, vector<GlsMat>(blkNum.width));

	GlsMat src;
	if (_src.channels() == 1){
		// to complex mat
		vector<GlsMat> tmp(2);
		tmp[0] = _src;
		gls::merge(tmp, src);
	}
	else{
		src = _src;
	}

	gls::tiled(src, _dst0, blkNum);
	for (int by = 0; by < blkNum.height; by++){
		for (int bx = 0; bx < blkNum.width; bx++){
			_dst1[by][bx] = GlsMat(Size(src.cols / blkNum.width, src.rows / blkNum.height), src.type());
		}
	}

	GlsMat texW(Size(N / 2, 1), src.type());

	//---------------------------------
	// upload twidle texture
	{
		_TMR_("-twidle:  \t");

		Mat w(Size(N / 2, 1), CV_32FC2);
#ifdef _OPENMP
#pragma omp parallel for
#endif
		for (int n = 0; n < N / 2; n++){
			float jw = (float)(-2 * M_PI * n / N);
			Vec2f val(cos(jw), sin(jw));
			w.at<Vec2f>(0, n) = val;
		}
		texW.upload(w);

		//vector<vec2> w(N / 2);
		// --- twidle ----
		//#ifdef _OPENMP
		//#pragma omp parallel for
		//#endif
		//for (int n = 0; n < N / 2; n++){
		//	float jw = (float)(-2 * M_PI * n / N);
		//	w[n][0] = cos(jw);
		//	w[n][1] = sin(jw);
		//}
		//void* data = &w[0];

		//glBindTexture(GL_TEXTURE_2D, texW);
		//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei)w.size(), 1, texture.glFormat(), texture.glType(), data);
		//glBindTexture(GL_TEXTURE_2D, 0);
	}

	vector<vector<GlsMat>>* texbuf[2] = { &_dst0, &_dst1 };

	//Execute
	int bank = 0;

	{
		_TMR_("-execute:\t");

		int Q = 0;
		while ((1 << Q) < N){ Q++; }

		vector<GlsMat> texSrc(2);
		vector<GlsMat> texDst(2);

		// --- FFT rows ----
		for (int p = 0, q = Q - 1; q >= 0; p++, q--, bank = bank ^ 1) {
			for (int i = 0; i < 2; i++){
				for (int j = 0; j < 2; j++){
					texSrc[j] = (*texbuf[bank])[i][j];
					texDst[j] = (*texbuf[bank ^ 1])[i][j];
				}
				float yscl = ((flag & GLS_FFT_SCALE) && (q == 0)) ? 1.0f / (float)N : 1.0f;
				float xscl = 1.0f;
				float xconj = ((flag & GLS_FFT_INVERSE) && (p == 0)) ? -1.0f : 1.0f;
				float yconj = 1.0f;
				ShaderFft.Execute(texSrc[0], texSrc[1], texW, 0, N, p, q, xscl, yscl, xconj, yconj, texDst[0], texDst[1]);

			}
		}
		// --- FFT cols ----
		for (int p = 0, q = Q - 1; q >= 0; p++, q--, bank = bank ^ 1) {
			for (int j = 0; j < 2; j++){
				for (int i = 0; i < 2; i++){
					texSrc[i] = (*texbuf[bank])[i][j];
					texDst[i] = (*texbuf[bank ^ 1])[i][j];
				}
				float yscl = ((flag & GLS_FFT_SCALE) && (q == 0)) ? 1.0f / (float)N : 1.0f;
				float xscl = 1.0f;
				float xconj = 1.0f;
				float yconj = ((flag & GLS_FFT_INVERSE) && (q == 0)) ? -1.0f : 1.0f;
				ShaderFft.Execute(texSrc[0], texSrc[1], texW, 1, N, p, q, xscl, yscl, xconj, yconj, texDst[0], texDst[1]);
			}
		}
	}

	if (flag & GLS_FFT_SHIFT){
		(*texbuf[bank ^ 1])[0][0] = (*texbuf[bank])[1][1];
		(*texbuf[bank ^ 1])[0][1] = (*texbuf[bank])[1][0];
		(*texbuf[bank ^ 1])[1][0] = (*texbuf[bank])[0][1];
		(*texbuf[bank ^ 1])[1][1] = (*texbuf[bank])[0][0];
		bank = bank ^ 1;
	}

	gls::untiled(*texbuf[bank], dst);
}

void fft(const Mat& src, Mat& dst, int flag){
	CV_Assert(src.type() == CV_32FC2);
	CV_Assert(src.cols == src.rows);

	int N = src.cols;
	CV_Assert(IsPow2(N));

	GlsMat _src(src.size(), src.type());
	GlsMat _dst;

	//---------------------------------
	//upload
	_src.upload(src);

	//---------------------------------
	//fft
	gls::fft(_src, _dst,flag);

	//---------------------------------
	//download
	_dst.download(dst);

}

}//namespace gls

<commit_msg>fft radix4対応前　リファクタリング<commit_after>/*
Copyright (c) 2016, oasi-adamay
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of glsCV nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdafx.h"

/*-----------------------------------------------------------------------------
include
*/
#include "glsMacro.h"
#include "GlsMat.h"
#include "glsShader.h"

#include "glsFft.h"
#include "glsCopy.h"	//tiled / untiled
#include "glsMerge.h"

#define _USE_MATH_DEFINES
#include <math.h>

#ifdef _DEBUG
//#if 1
#include "Timer.h"
#define _TMR_(...)  Timer tmr(__VA_ARGS__)
#else
#define _TMR_(...)
#endif

namespace gls
{

// glsFft shader
class glsShaderFftRadix2 : public glsShaderBase
{
protected:
	string FragmentShaderCode(void);
	list<string> UniformNameList(void);

public:
	glsShaderFftRadix2(void) :glsShaderBase(__FUNCTION__){}

};

//-----------------------------------------------------------------------------
//global
glsShaderFftRadix2 ShaderFftRadix2;

//-----------------------------------------------------------------------------
//glsShaderFftRadix2
// Stockham,DIT radix2
string glsShaderFftRadix2::FragmentShaderCode(void){
	const char fragmentShaderCode[] = TO_STR(
#version 330 core\n
precision highp float;\n
uniform sampler2D	texSrc0;\n
uniform sampler2D	texSrc1;\n
uniform sampler2D	texW;\n
uniform  int i_flag;	//bit0:(0:holizontal 1:vertical)\n
uniform  int i_N;\n
uniform  int i_p;\n
uniform  int i_q;\n
uniform  float f_xscl;\n
uniform  float f_yscl;\n
uniform  float f_xconj;\n
uniform  float f_yconj;\n
\n
layout (location = 0) out vec2 dst0;\n
layout (location = 1) out vec2 dst1;\n
\n
#define FLAG_DIR	 (1<<0)\n
\n
\n
int insertZeroBits(\n
	const int src,\n
	const int idx,\n
	const int num\n
	)\n
{\n
	int ret = src << num;\n
	ret &= ~((1 << (idx + num)) - 1);\n
	ret |= src & ((1 << idx) - 1);\n
	return ret;\n
}\n
\n
void main(void)\n
{\n
	int p = i_p;\n
	int q = i_q;\n
	int N = i_N;\n
	int dir = ((i_flag & FLAG_DIR)==0) ?0:1;\n
	float xscl = f_xscl;\n
	float yscl = f_yscl;\n
	float xconj = f_xconj;\n
	float yconj = f_yconj;\n
\n
	int n;\n
	vec2 x0;\n
	vec2 x1;\n
	vec2 w;\n
\n
	n= int(gl_FragCoord[dir]);\n
	int iw = (n >> q) << q;\n
	int ix0 = insertZeroBits(n, q, 1);\n
	int ix1 = ix0 + (1 << q);\n
	w = texelFetch(texW,ivec2(iw,0),0).rg;\n
\n
\n
	if(dir ==0){\n
		if(ix0 < N/2) x0 = texelFetch(texSrc0,ivec2(ix0,gl_FragCoord.y),0).rg;\n
		else x0 = texelFetch(texSrc1,ivec2(ix0-N/2,gl_FragCoord.y),0).rg;\n
\n
		if(ix1 < N/2) x1 = texelFetch(texSrc0,ivec2(ix1,gl_FragCoord.y),0).rg;\n
		else x1 = texelFetch(texSrc1,ivec2(ix1-N/2,gl_FragCoord.y),0).rg;\n
	}\n
	else{\n
		if(ix0 < N/2) x0 = texelFetch(texSrc0,ivec2(gl_FragCoord.x,ix0),0).rg;\n
		else x0 = texelFetch(texSrc1,ivec2(gl_FragCoord.x,ix0-N/2),0).rg;\n
\n
		if(ix1 < N/2) x1 = texelFetch(texSrc0,ivec2(gl_FragCoord.x,ix1),0).rg;\n
		else x1 = texelFetch(texSrc1,ivec2(gl_FragCoord.x,ix1-N/2),0).rg;\n
	}\n
\n
//	x0 = x0*xscl;\n
//	x1 = x1*xscl;\n
	x0.g = x0.g*xconj;\n
	x1.g = x1.g*xconj;\n
\n
	vec2 tmp;\n
	tmp.r = x1.r * w.r - x1.g * w.g;\n
	tmp.g = x1.r * w.g + x1.g * w.r;\n
\n
	vec2 y0;\n
	vec2 y1;\n
\n
	y0 = x0 + tmp;\n
	y1 = x0 - tmp;\n
\n
	y0 = y0*yscl;\n
	y1 = y1*yscl;\n
	y0.g = y0.g*yconj;\n
	y1.g = y1.g*yconj;\n
\n
	dst0 = y0;\n
	dst1 = y1;\n
\n
}\n
);
	return fragmentShaderCode;
}

list<string> glsShaderFftRadix2::UniformNameList(void){
	list<string> lst;
	lst.push_back("texSrc0");
	lst.push_back("texSrc1");
	lst.push_back("texW");
	lst.push_back("i_flag");
	lst.push_back("i_N");
	lst.push_back("i_p");
	lst.push_back("i_q");
	lst.push_back("f_xscl");
	lst.push_back("f_yscl");
	lst.push_back("f_xconj");
	lst.push_back("f_yconj");
	return lst;
}

//---------------------------------------------------------------------------
//value is power of 2
static bool IsPow2(unsigned int x){
	return (((x)&(x - 1)) == 0);
}

//-----------------------------------------------------------------------------
void fft(const GlsMat& _src, GlsMat& dst, int flag){
	GLS_Assert(_src.channels() == 2 || _src.channels() == 1);
	GLS_Assert(_src.depth() == CV_32F);

	int N = _src.cols;
	GLS_Assert(IsPow2(N));

	GlsMat src;
	if (_src.channels() == 1){
		// to complex mat
		vector<GlsMat> tmp(2);
		tmp[0] = _src;
		gls::merge(tmp, src);
	}
	else{
		src = _src;
	}

	Size blkNum(2,2);
	vector<vector<GlsMat>> _dst0 = vector<vector<GlsMat>>(blkNum.height, vector<GlsMat>(blkNum.width));
	vector<vector<GlsMat>> _dst1 = vector<vector<GlsMat>>(blkNum.height, vector<GlsMat>(blkNum.width));

	gls::tiled(src, _dst0, blkNum);
	for (int by = 0; by < blkNum.height; by++){
		for (int bx = 0; bx < blkNum.width; bx++){
			_dst1[by][bx] = GlsMat(Size(src.cols / blkNum.width, src.rows / blkNum.height), src.type());
		}
	}

	GlsMat texW(Size(N / 2, 1), src.type());

	//---------------------------------
	// upload twidle texture
	{
		_TMR_("-twidle:  \t");

		Mat w(Size(N / 2, 1), CV_32FC2);
#ifdef _OPENMP
//#pragma omp parallel for
#pragma omp parallel for if(N>=256)
#endif
		for (int n = 0; n < N / 2; n++){
			float jw = (float)(-2 * M_PI * n / N);
			Vec2f val(cos(jw), sin(jw));
			w.at<Vec2f>(0, n) = val;
		}
		texW.upload(w);

		//vector<vec2> w(N / 2);
		// --- twidle ----
		//#ifdef _OPENMP
		//#pragma omp parallel for
		//#endif
		//for (int n = 0; n < N / 2; n++){
		//	float jw = (float)(-2 * M_PI * n / N);
		//	w[n][0] = cos(jw);
		//	w[n][1] = sin(jw);
		//}
		//void* data = &w[0];

		//glBindTexture(GL_TEXTURE_2D, texW);
		//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei)w.size(), 1, texture.glFormat(), texture.glType(), data);
		//glBindTexture(GL_TEXTURE_2D, 0);
	}

	vector<vector<GlsMat>>* texbuf[2] = { &_dst0, &_dst1 };

	//Execute
	int bank = 0;

	{
		_TMR_("-execute:\t");

		int Q = 0;
		while ((1 << Q) < N){ Q++; }

		vector<GlsMat> texSrc(2);
		vector<GlsMat> texDst(2);

		// --- FFT rows ----
		for (int p = 0, q = Q - 1; q >= 0; p++, q--, bank = bank ^ 1) {
			for (int i = 0; i < 2; i++){
				for (int j = 0; j < 2; j++){
					texSrc[j] = (*texbuf[bank])[i][j];
					texDst[j] = (*texbuf[bank ^ 1])[i][j];
				}
				float yscl = ((flag & GLS_FFT_SCALE) && (q == 0)) ? 1.0f / (float)N : 1.0f;
				float xscl = 1.0f;
				float xconj = ((flag & GLS_FFT_INVERSE) && (p == 0)) ? -1.0f : 1.0f;
				float yconj = 1.0f;
				ShaderFftRadix2.Execute(texSrc[0], texSrc[1], texW, 0, N, p, q, xscl, yscl, xconj, yconj, texDst[0], texDst[1]);

			}
		}
		// --- FFT cols ----
		for (int p = 0, q = Q - 1; q >= 0; p++, q--, bank = bank ^ 1) {
			for (int j = 0; j < 2; j++){
				for (int i = 0; i < 2; i++){
					texSrc[i] = (*texbuf[bank])[i][j];
					texDst[i] = (*texbuf[bank ^ 1])[i][j];
				}
				float yscl = ((flag & GLS_FFT_SCALE) && (q == 0)) ? 1.0f / (float)N : 1.0f;
				float xscl = 1.0f;
				float xconj = 1.0f;
				float yconj = ((flag & GLS_FFT_INVERSE) && (q == 0)) ? -1.0f : 1.0f;
				ShaderFftRadix2.Execute(texSrc[0], texSrc[1], texW, 1, N, p, q, xscl, yscl, xconj, yconj, texDst[0], texDst[1]);
			}
		}
	}

	if (flag & GLS_FFT_SHIFT){
		(*texbuf[bank ^ 1])[0][0] = (*texbuf[bank])[1][1];
		(*texbuf[bank ^ 1])[0][1] = (*texbuf[bank])[1][0];
		(*texbuf[bank ^ 1])[1][0] = (*texbuf[bank])[0][1];
		(*texbuf[bank ^ 1])[1][1] = (*texbuf[bank])[0][0];
		bank = bank ^ 1;
	}

	gls::untiled(*texbuf[bank], dst);
}

void fft(const Mat& src, Mat& dst, int flag){
	CV_Assert(src.type() == CV_32FC2);
	CV_Assert(src.cols == src.rows);

	int N = src.cols;
	CV_Assert(IsPow2(N));

	GlsMat _src(src.size(), src.type());
	GlsMat _dst;

	//---------------------------------
	//upload
	_src.upload(src);

	//---------------------------------
	//fft
	gls::fft(_src, _dst,flag);

	//---------------------------------
	//download
	_dst.download(dst);

}

}//namespace gls

<|endoftext|>


<commit_before>/**
 * @file emst_test.cpp
 *
 * Test file for EMST methods.
 */
#include <mlpack/core.hpp>
#include <mlpack/methods/emst/dtb.hpp>
#include <boost/test/unit_test.hpp>

using namespace mlpack;
using namespace mlpack::emst;

BOOST_AUTO_TEST_SUITE(EMSTTest);

/**
 * Simple emst test with small, synthetic dataset.  This is an
 * exhaustive test, which checks that each method for performing the calculation
 * (dual-tree, single-tree, naive) produces the correct results.  The dataset is
 * in one dimension for simplicity -- the correct functionality of distance
 * functions is not tested here.
 */
BOOST_AUTO_TEST_CASE(exhaustive_synthetic_test)
{
  // Set up our data.
  arma::mat data(1, 11);
  data[0] = 0.05; // Row addressing is unnecessary (they are all 0).
  data[1] = 0.37;
  data[2] = 0.15;
  data[3] = 1.25;
  data[4] = 5.05;
  data[5] = -0.22;
  data[6] = -2.00;
  data[7] = -1.30;
  data[8] = 0.45;
  data[9] = 0.91;
  data[10] = 1.00;

  // Now perform the actual calculation.
  arma::mat results;

  DualTreeBoruvka<> dtb(data);
  dtb.ComputeMST(results);

  // Now the exhaustive check for correctness.
  BOOST_REQUIRE(results(0, 0) == 1);
  BOOST_REQUIRE(results(0, 1) == 8);
  BOOST_REQUIRE_CLOSE(results(0, 2), 0.08, 1e-5);

  BOOST_REQUIRE(results(1, 0) == 9);
  BOOST_REQUIRE(results(1, 1) == 10);
  BOOST_REQUIRE_CLOSE(results(1, 2), 0.09, 1e-5);

  BOOST_REQUIRE(results(2, 0) == 0);
  BOOST_REQUIRE(results(2, 1) == 2);
  BOOST_REQUIRE_CLOSE(results(2, 2), 0.1, 1e-5);

  BOOST_REQUIRE(results(3, 0) == 1);
  BOOST_REQUIRE(results(3, 1) == 2);
  BOOST_REQUIRE_CLOSE(results(3, 2), 0.22, 1e-5);

  BOOST_REQUIRE(results(4, 0) == 3);
  BOOST_REQUIRE(results(4, 1) == 10);
  BOOST_REQUIRE_CLOSE(results(4, 2), 0.25, 1e-5);

  BOOST_REQUIRE(results(5, 0) == 0);
  BOOST_REQUIRE(results(5, 1) == 5);
  BOOST_REQUIRE_CLOSE(results(5, 2), 0.27, 1e-5);

  BOOST_REQUIRE(results(6, 0) == 8);
  BOOST_REQUIRE(results(6, 1) == 9);
  BOOST_REQUIRE_CLOSE(results(6, 2), 0.46, 1e-5);

  BOOST_REQUIRE(results(7, 0) == 6);
  BOOST_REQUIRE(results(7, 1) == 7);
  BOOST_REQUIRE_CLOSE(results(7, 2), 0.7, 1e-5);

  BOOST_REQUIRE(results(8, 0) == 5);
  BOOST_REQUIRE(results(8, 1) == 7);
  BOOST_REQUIRE_CLOSE(results(8, 2), 1.08, 1e-5);

  BOOST_REQUIRE(results(9, 0) == 3);
  BOOST_REQUIRE(results(9, 1) == 4);
  BOOST_REQUIRE_CLOSE(results(9, 2), 3.8, 1e-5);
}

/**
 * Test the dual tree method against the naive computation.
 *
 * Errors are produced if the results are not identical.
 */
BOOST_AUTO_TEST_CASE(dual_tree_vs_naive)
{
  arma::mat input_data;

  // Hard-coded filename: bad!
  // Code duplication: also bad!
  if (!data::Load("test_data_3_1000.csv", input_data))
    BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");

  // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
  arma::mat dual_data = arma::trans(input_data);
  arma::mat naive_data = arma::trans(input_data);

  // Reset parameters from last test.
  DualTreeBoruvka<> dtb(dual_data);

  arma::mat dual_results;
  dtb.ComputeMST(dual_results);

  // Set naive mode.
  DualTreeBoruvka<> dtb_naive(naive_data, true);

  arma::mat naive_results;
  dtb_naive.ComputeMST(naive_results);

  BOOST_REQUIRE(dual_results.n_cols == naive_results.n_cols);
  BOOST_REQUIRE(dual_results.n_rows == naive_results.n_rows);

  for (size_t i = 0; i < dual_results.n_rows; i++)
  {
    BOOST_REQUIRE(dual_results(i, 0) == naive_results(i, 0));
    BOOST_REQUIRE(dual_results(i, 1) == naive_results(i, 1));
    BOOST_REQUIRE_CLOSE(dual_results(i, 2), naive_results(i, 2), 1e-5);
  }
}

BOOST_AUTO_TEST_SUITE_END();
<commit_msg>Update for transposition of output.<commit_after>/**
 * @file emst_test.cpp
 *
 * Test file for EMST methods.
 */
#include <mlpack/core.hpp>
#include <mlpack/methods/emst/dtb.hpp>
#include <boost/test/unit_test.hpp>

using namespace mlpack;
using namespace mlpack::emst;

BOOST_AUTO_TEST_SUITE(EMSTTest);

/**
 * Simple emst test with small, synthetic dataset.  This is an
 * exhaustive test, which checks that each method for performing the calculation
 * (dual-tree, single-tree, naive) produces the correct results.  The dataset is
 * in one dimension for simplicity -- the correct functionality of distance
 * functions is not tested here.
 */
BOOST_AUTO_TEST_CASE(exhaustive_synthetic_test)
{
  // Set up our data.
  arma::mat data(1, 11);
  data[0] = 0.05; // Row addressing is unnecessary (they are all 0).
  data[1] = 0.37;
  data[2] = 0.15;
  data[3] = 1.25;
  data[4] = 5.05;
  data[5] = -0.22;
  data[6] = -2.00;
  data[7] = -1.30;
  data[8] = 0.45;
  data[9] = 0.91;
  data[10] = 1.00;

  // Now perform the actual calculation.
  arma::mat results;

  DualTreeBoruvka<> dtb(data);
  dtb.ComputeMST(results);

  // Now the exhaustive check for correctness.
  BOOST_REQUIRE(results(0, 0) == 1);
  BOOST_REQUIRE(results(1, 0) == 8);
  BOOST_REQUIRE_CLOSE(results(2, 0), 0.08, 1e-5);

  BOOST_REQUIRE(results(0, 1) == 9);
  BOOST_REQUIRE(results(1, 1) == 10);
  BOOST_REQUIRE_CLOSE(results(2, 1), 0.09, 1e-5);

  BOOST_REQUIRE(results(0, 2) == 0);
  BOOST_REQUIRE(results(1, 2) == 2);
  BOOST_REQUIRE_CLOSE(results(2, 2), 0.1, 1e-5);

  BOOST_REQUIRE(results(0, 3) == 1);
  BOOST_REQUIRE(results(1, 3) == 2);
  BOOST_REQUIRE_CLOSE(results(2, 3), 0.22, 1e-5);

  BOOST_REQUIRE(results(0, 4) == 3);
  BOOST_REQUIRE(results(1, 4) == 10);
  BOOST_REQUIRE_CLOSE(results(2, 4), 0.25, 1e-5);

  BOOST_REQUIRE(results(0, 5) == 0);
  BOOST_REQUIRE(results(1, 5) == 5);
  BOOST_REQUIRE_CLOSE(results(2, 5), 0.27, 1e-5);

  BOOST_REQUIRE(results(0, 6) == 8);
  BOOST_REQUIRE(results(1, 6) == 9);
  BOOST_REQUIRE_CLOSE(results(2, 6), 0.46, 1e-5);

  BOOST_REQUIRE(results(0, 7) == 6);
  BOOST_REQUIRE(results(1, 7) == 7);
  BOOST_REQUIRE_CLOSE(results(2, 7), 0.7, 1e-5);

  BOOST_REQUIRE(results(0, 8) == 5);
  BOOST_REQUIRE(results(1, 8) == 7);
  BOOST_REQUIRE_CLOSE(results(2, 8), 1.08, 1e-5);

  BOOST_REQUIRE(results(0, 9) == 3);
  BOOST_REQUIRE(results(1, 9) == 4);
  BOOST_REQUIRE_CLOSE(results(2, 9), 3.8, 1e-5);
}

/**
 * Test the dual tree method against the naive computation.
 *
 * Errors are produced if the results are not identical.
 */
BOOST_AUTO_TEST_CASE(dual_tree_vs_naive)
{
  arma::mat input_data;

  // Hard-coded filename: bad!
  // Code duplication: also bad!
  if (!data::Load("test_data_3_1000.csv", input_data))
    BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");

  // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
  arma::mat dual_data = arma::trans(input_data);
  arma::mat naive_data = arma::trans(input_data);

  // Reset parameters from last test.
  DualTreeBoruvka<> dtb(dual_data);

  arma::mat dual_results;
  dtb.ComputeMST(dual_results);

  // Set naive mode.
  DualTreeBoruvka<> dtb_naive(naive_data, true);

  arma::mat naive_results;
  dtb_naive.ComputeMST(naive_results);

  BOOST_REQUIRE(dual_results.n_cols == naive_results.n_cols);
  BOOST_REQUIRE(dual_results.n_rows == naive_results.n_rows);

  for (size_t i = 0; i < dual_results.n_cols; i++)
  {
    BOOST_REQUIRE(dual_results(0, i) == naive_results(0, i));
    BOOST_REQUIRE(dual_results(1, i) == naive_results(1, i));
    BOOST_REQUIRE_CLOSE(dual_results(2, i), naive_results(2, i), 1e-5);
  }
}

BOOST_AUTO_TEST_SUITE_END();
<|endoftext|>


<commit_before>/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/SkTArray.h"

namespace skiagm {

class HairlinesGM : public GM {
protected:

    SkString onShortName() override {
        return SkString("hairlines");
    }

    SkISize onISize() override { return SkISize::Make(1250, 1250); }

    void onOnceBeforeDraw() override {
        {
            SkPath* lineAnglesPath = &fPaths.push_back();
            enum {
                kNumAngles = 15,
                kRadius = 40,
            };
            for (int i = 0; i < kNumAngles; ++i) {
                SkScalar angle = SK_ScalarPI * SkIntToScalar(i) / kNumAngles;
                SkScalar x = kRadius * SkScalarCos(angle);
                SkScalar y = kRadius * SkScalarSin(angle);
                lineAnglesPath->moveTo(x, y);
                lineAnglesPath->lineTo(-x, -y);
            }
        }

        {
            SkPath* kindaTightQuad = &fPaths.push_back();
            kindaTightQuad->moveTo(0, -10 * SK_Scalar1);
            kindaTightQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -10 * SK_Scalar1, 0);
        }

        {
            SkPath* tightQuad = &fPaths.push_back();
            tightQuad->moveTo(0, -5 * SK_Scalar1);
            tightQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -5 * SK_Scalar1, 0);
        }

        {
            SkPath* tighterQuad = &fPaths.push_back();
            tighterQuad->moveTo(0, -2 * SK_Scalar1);
            tighterQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -2 * SK_Scalar1, 0);
        }

        {
            SkPath* unevenTighterQuad = &fPaths.push_back();
            unevenTighterQuad->moveTo(0, -1 * SK_Scalar1);
            SkPoint p;
            p.set(-2 * SK_Scalar1 + 3 * SkIntToScalar(102) / 4, SkIntToScalar(75));
            unevenTighterQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), p.fX, p.fY);
        }

        {
            SkPath* reallyTightQuad = &fPaths.push_back();
            reallyTightQuad->moveTo(0, -1 * SK_Scalar1);
            reallyTightQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -1 * SK_Scalar1, 0);
        }

        {
            SkPath* closedQuad = &fPaths.push_back();
            closedQuad->moveTo(0, -0);
            closedQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), 0, 0);
        }

        {
            SkPath* unevenClosedQuad = &fPaths.push_back();
            unevenClosedQuad->moveTo(0, -0);
            unevenClosedQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100),
                                     SkIntToScalar(75), SkIntToScalar(75));
        }

        // Two problem cases for gpu hairline renderer found by shapeops testing. These used
        // to assert that the computed bounding box didn't contain all the vertices.
        {
            SkPath* problem1 = &fPaths.push_back();
            problem1->moveTo(SkIntToScalar(4), SkIntToScalar(6));
            problem1->cubicTo(SkIntToScalar(5), SkIntToScalar(6),
                              SkIntToScalar(5), SkIntToScalar(4),
                              SkIntToScalar(4), SkIntToScalar(0));
            problem1->close();
        }

        {
            SkPath* problem2 = &fPaths.push_back();
            problem2->moveTo(SkIntToScalar(5), SkIntToScalar(1));
            problem2->lineTo(4.32787323f, 1.67212653f);
            problem2->cubicTo(2.75223875f, 3.24776125f,
                              3.00581908f, 4.51236057f,
                              3.7580452f, 4.37367964f);
            problem2->cubicTo(4.66472578f, 3.888381f,
                              5.f, 2.875f,
                              5.f, 1.f);
            problem2->close();
        }

        // Three paths that show the same bug (missing end caps)
        {
            // A caret (crbug.com/131770)
            SkPath* bug0 = &fPaths.push_back();
            bug0->moveTo(6.5f,5.5f);
            bug0->lineTo(3.5f,0.5f);
            bug0->moveTo(0.5f,5.5f);
            bug0->lineTo(3.5f,0.5f);
        }

        {
            // An X (crbug.com/137317)
            SkPath* bug1 = &fPaths.push_back();

            bug1->moveTo(1, 1);
            bug1->lineTo(6, 6);
            bug1->moveTo(1, 6);
            bug1->lineTo(6, 1);
        }

        {
            // A right angle (crbug.com/137465 and crbug.com/256776)
            SkPath* bug2 = &fPaths.push_back();

            bug2->moveTo(5.5f, 5.5f);
            bug2->lineTo(5.5f, 0.5f);
            bug2->lineTo(0.5f, 0.5f);
        }

        {
            // Arc example to test imperfect truncation bug (crbug.com/295626)
            constexpr SkScalar kRad = SkIntToScalar(2000);
            constexpr SkScalar kStartAngle = 262.59717f;
            constexpr SkScalar kSweepAngle = SkScalarHalf(17.188717f);

            SkPath* bug = &fPaths.push_back();

            // Add a circular arc
            SkRect circle = SkRect::MakeLTRB(-kRad, -kRad, kRad, kRad);
            bug->addArc(circle, kStartAngle, kSweepAngle);

            // Now add the chord that should cap the circular arc
            SkPoint p0 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle)),
                           kRad * SkScalarSin(SkDegreesToRadians(kStartAngle)) };

            SkPoint p1 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle + kSweepAngle)),
                           kRad * SkScalarSin(SkDegreesToRadians(kStartAngle + kSweepAngle)) };

            bug->moveTo(p0);
            bug->lineTo(p1);
        }
    }

    void onDraw(SkCanvas* canvas) override {
        constexpr SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
        constexpr SkScalar kWidths[] = { 0, 0.5f, 1.5f };

        enum {
            kMargin = 5,
        };
        int wrapX = 1250 - kMargin;

        SkScalar maxH = 0;
        canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin));
        canvas->save();

        SkScalar x = SkIntToScalar(kMargin);
        for (int p = 0; p < fPaths.count(); ++p) {
            for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
                for (int aa = 0; aa < 2; ++aa) {
                    for (size_t w = 0; w < SK_ARRAY_COUNT(kWidths); w++) {
                        const SkRect& bounds = fPaths[p].getBounds();

                        if (x + bounds.width() > wrapX) {
                            canvas->restore();
                            canvas->translate(0, maxH + SkIntToScalar(kMargin));
                            canvas->save();
                            maxH = 0;
                            x = SkIntToScalar(kMargin);
                        }

                        SkPaint paint;
                        paint.setARGB(kAlphaValue[a], 0, 0, 0);
                        paint.setAntiAlias(SkToBool(aa));
                        paint.setStyle(SkPaint::kStroke_Style);
                        paint.setStrokeWidth(kWidths[w]);

                        canvas->save();
                        canvas->translate(-bounds.fLeft, -bounds.fTop);
                        canvas->drawPath(fPaths[p], paint);
                        canvas->restore();

                        maxH = std::max(maxH, bounds.height());

                        SkScalar dx = bounds.width() + SkIntToScalar(kMargin);
                        x += dx;
                        canvas->translate(dx, 0);
                    }
                }
            }
        }
        canvas->restore();
    }

private:
    SkTArray<SkPath> fPaths;
    typedef GM INHERITED;
};

static void draw_squarehair_tests(SkCanvas* canvas, SkScalar width, SkPaint::Cap cap, bool aa) {
    SkPaint paint;
    paint.setStrokeCap(cap);
    paint.setStrokeWidth(width);
    paint.setAntiAlias(aa);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawLine(10, 10, 20, 10, paint);
    canvas->drawLine(30, 10, 30, 20, paint);
    canvas->drawLine(40, 10, 50, 20, paint);
    SkPath path;
    path.moveTo(60, 10);
    path.quadTo(60, 20, 70, 20);
    path.conicTo(70, 10, 80, 10, 0.707f);
    canvas->drawPath(path, paint);
    path.reset();
    path.moveTo(90, 10);
    path.cubicTo(90, 20, 100, 20, 100, 10);
    path.lineTo(110, 10);
    canvas->drawPath(path, paint);
    canvas->translate(0, 30);
}

DEF_SIMPLE_GM(squarehair, canvas, 240, 360) {
    const bool aliases[] = { false, true };
    const SkScalar widths[] = { 0, 0.999f, 1, 1.001f };
    const SkPaint::Cap caps[] = { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap };
    for (auto alias : aliases) {
        canvas->save();
        for (auto width : widths) {
            for (auto cap : caps) {
                draw_squarehair_tests(canvas, width, cap, alias);
            }
        }
        canvas->restore();
        canvas->translate(120, 0);
    }
}

//////////////////////////////////////////////////////////////////////////////

DEF_GM( return new HairlinesGM; )

}
<commit_msg>Add new GM to test hairline subdivision.<commit_after>/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/SkTArray.h"

namespace skiagm {

class HairlinesGM : public GM {
protected:

    SkString onShortName() override {
        return SkString("hairlines");
    }

    SkISize onISize() override { return SkISize::Make(1250, 1250); }

    void onOnceBeforeDraw() override {
        {
            SkPath* lineAnglesPath = &fPaths.push_back();
            enum {
                kNumAngles = 15,
                kRadius = 40,
            };
            for (int i = 0; i < kNumAngles; ++i) {
                SkScalar angle = SK_ScalarPI * SkIntToScalar(i) / kNumAngles;
                SkScalar x = kRadius * SkScalarCos(angle);
                SkScalar y = kRadius * SkScalarSin(angle);
                lineAnglesPath->moveTo(x, y);
                lineAnglesPath->lineTo(-x, -y);
            }
        }

        {
            SkPath* kindaTightQuad = &fPaths.push_back();
            kindaTightQuad->moveTo(0, -10 * SK_Scalar1);
            kindaTightQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -10 * SK_Scalar1, 0);
        }

        {
            SkPath* tightQuad = &fPaths.push_back();
            tightQuad->moveTo(0, -5 * SK_Scalar1);
            tightQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -5 * SK_Scalar1, 0);
        }

        {
            SkPath* tighterQuad = &fPaths.push_back();
            tighterQuad->moveTo(0, -2 * SK_Scalar1);
            tighterQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -2 * SK_Scalar1, 0);
        }

        {
            SkPath* unevenTighterQuad = &fPaths.push_back();
            unevenTighterQuad->moveTo(0, -1 * SK_Scalar1);
            SkPoint p;
            p.set(-2 * SK_Scalar1 + 3 * SkIntToScalar(102) / 4, SkIntToScalar(75));
            unevenTighterQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), p.fX, p.fY);
        }

        {
            SkPath* reallyTightQuad = &fPaths.push_back();
            reallyTightQuad->moveTo(0, -1 * SK_Scalar1);
            reallyTightQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), -1 * SK_Scalar1, 0);
        }

        {
            SkPath* closedQuad = &fPaths.push_back();
            closedQuad->moveTo(0, -0);
            closedQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100), 0, 0);
        }

        {
            SkPath* unevenClosedQuad = &fPaths.push_back();
            unevenClosedQuad->moveTo(0, -0);
            unevenClosedQuad->quadTo(SkIntToScalar(100), SkIntToScalar(100),
                                     SkIntToScalar(75), SkIntToScalar(75));
        }

        // Two problem cases for gpu hairline renderer found by shapeops testing. These used
        // to assert that the computed bounding box didn't contain all the vertices.
        {
            SkPath* problem1 = &fPaths.push_back();
            problem1->moveTo(SkIntToScalar(4), SkIntToScalar(6));
            problem1->cubicTo(SkIntToScalar(5), SkIntToScalar(6),
                              SkIntToScalar(5), SkIntToScalar(4),
                              SkIntToScalar(4), SkIntToScalar(0));
            problem1->close();
        }

        {
            SkPath* problem2 = &fPaths.push_back();
            problem2->moveTo(SkIntToScalar(5), SkIntToScalar(1));
            problem2->lineTo(4.32787323f, 1.67212653f);
            problem2->cubicTo(2.75223875f, 3.24776125f,
                              3.00581908f, 4.51236057f,
                              3.7580452f, 4.37367964f);
            problem2->cubicTo(4.66472578f, 3.888381f,
                              5.f, 2.875f,
                              5.f, 1.f);
            problem2->close();
        }

        // Three paths that show the same bug (missing end caps)
        {
            // A caret (crbug.com/131770)
            SkPath* bug0 = &fPaths.push_back();
            bug0->moveTo(6.5f,5.5f);
            bug0->lineTo(3.5f,0.5f);
            bug0->moveTo(0.5f,5.5f);
            bug0->lineTo(3.5f,0.5f);
        }

        {
            // An X (crbug.com/137317)
            SkPath* bug1 = &fPaths.push_back();

            bug1->moveTo(1, 1);
            bug1->lineTo(6, 6);
            bug1->moveTo(1, 6);
            bug1->lineTo(6, 1);
        }

        {
            // A right angle (crbug.com/137465 and crbug.com/256776)
            SkPath* bug2 = &fPaths.push_back();

            bug2->moveTo(5.5f, 5.5f);
            bug2->lineTo(5.5f, 0.5f);
            bug2->lineTo(0.5f, 0.5f);
        }

        {
            // Arc example to test imperfect truncation bug (crbug.com/295626)
            constexpr SkScalar kRad = SkIntToScalar(2000);
            constexpr SkScalar kStartAngle = 262.59717f;
            constexpr SkScalar kSweepAngle = SkScalarHalf(17.188717f);

            SkPath* bug = &fPaths.push_back();

            // Add a circular arc
            SkRect circle = SkRect::MakeLTRB(-kRad, -kRad, kRad, kRad);
            bug->addArc(circle, kStartAngle, kSweepAngle);

            // Now add the chord that should cap the circular arc
            SkPoint p0 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle)),
                           kRad * SkScalarSin(SkDegreesToRadians(kStartAngle)) };

            SkPoint p1 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle + kSweepAngle)),
                           kRad * SkScalarSin(SkDegreesToRadians(kStartAngle + kSweepAngle)) };

            bug->moveTo(p0);
            bug->lineTo(p1);
        }
    }

    void onDraw(SkCanvas* canvas) override {
        constexpr SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
        constexpr SkScalar kWidths[] = { 0, 0.5f, 1.5f };

        enum {
            kMargin = 5,
        };
        int wrapX = 1250 - kMargin;

        SkScalar maxH = 0;
        canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin));
        canvas->save();

        SkScalar x = SkIntToScalar(kMargin);
        for (int p = 0; p < fPaths.count(); ++p) {
            for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
                for (int aa = 0; aa < 2; ++aa) {
                    for (size_t w = 0; w < SK_ARRAY_COUNT(kWidths); w++) {
                        const SkRect& bounds = fPaths[p].getBounds();

                        if (x + bounds.width() > wrapX) {
                            canvas->restore();
                            canvas->translate(0, maxH + SkIntToScalar(kMargin));
                            canvas->save();
                            maxH = 0;
                            x = SkIntToScalar(kMargin);
                        }

                        SkPaint paint;
                        paint.setARGB(kAlphaValue[a], 0, 0, 0);
                        paint.setAntiAlias(SkToBool(aa));
                        paint.setStyle(SkPaint::kStroke_Style);
                        paint.setStrokeWidth(kWidths[w]);

                        canvas->save();
                        canvas->translate(-bounds.fLeft, -bounds.fTop);
                        canvas->drawPath(fPaths[p], paint);
                        canvas->restore();

                        maxH = std::max(maxH, bounds.height());

                        SkScalar dx = bounds.width() + SkIntToScalar(kMargin);
                        x += dx;
                        canvas->translate(dx, 0);
                    }
                }
            }
        }
        canvas->restore();
    }

private:
    SkTArray<SkPath> fPaths;
    typedef GM INHERITED;
};

static void draw_squarehair_tests(SkCanvas* canvas, SkScalar width, SkPaint::Cap cap, bool aa) {
    SkPaint paint;
    paint.setStrokeCap(cap);
    paint.setStrokeWidth(width);
    paint.setAntiAlias(aa);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawLine(10, 10, 20, 10, paint);
    canvas->drawLine(30, 10, 30, 20, paint);
    canvas->drawLine(40, 10, 50, 20, paint);
    SkPath path;
    path.moveTo(60, 10);
    path.quadTo(60, 20, 70, 20);
    path.conicTo(70, 10, 80, 10, 0.707f);
    canvas->drawPath(path, paint);
    path.reset();
    path.moveTo(90, 10);
    path.cubicTo(90, 20, 100, 20, 100, 10);
    path.lineTo(110, 10);
    canvas->drawPath(path, paint);
    canvas->translate(0, 30);
}

DEF_SIMPLE_GM(squarehair, canvas, 240, 360) {
    const bool aliases[] = { false, true };
    const SkScalar widths[] = { 0, 0.999f, 1, 1.001f };
    const SkPaint::Cap caps[] = { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap };
    for (auto alias : aliases) {
        canvas->save();
        for (auto width : widths) {
            for (auto cap : caps) {
                draw_squarehair_tests(canvas, width, cap, alias);
            }
        }
        canvas->restore();
        canvas->translate(120, 0);
    }
}

// GM to test subdivision of hairlines
static void draw_subdivided_quad(SkCanvas* canvas, int x0, int y0, int x1, int y1, SkColor color) {
    SkPaint paint;
    paint.setStrokeWidth(1);
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setColor(color);

    SkPath quad;
    quad.moveTo(0, 0);
    quad.quadTo(SkIntToScalar(x0), SkIntToScalar(y0),
                SkIntToScalar(x1), SkIntToScalar(y1));
    canvas->drawPath(quad, paint);
}

DEF_SIMPLE_GM(hairline_subdiv, canvas, 512, 256) {
    // no subdivisions
    canvas->translate(45, -25);
    draw_subdivided_quad(canvas, 334, 334, 467, 267, SK_ColorBLACK);

    // one subdivision
    canvas->translate(-185, -150);
    draw_subdivided_quad(canvas, 472, 472, 660, 378, SK_ColorRED);

    // two subdivisions
    canvas->translate(-275, -200);
    draw_subdivided_quad(canvas, 668, 668, 934, 535, SK_ColorGREEN);

    // three subdivisions
    canvas->translate(-385, -260);
    draw_subdivided_quad(canvas, 944, 944, 1320, 756, SK_ColorBLUE);
}

//////////////////////////////////////////////////////////////////////////////

DEF_GM( return new HairlinesGM; )

}
<|endoftext|>


<commit_before>/** \copyright
 * Copyright (c) 2018, Balazs Racz
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are  permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * \file OpenMRN.cpp
 *
 * Implementation that needs to be compiled for the Arduino.
 *
 * @author Balazs Racz
 * @date 24 July 2018
 */

#include <OpenMRNLite.h>

#ifdef HAVE_FILESYSTEM
#include "utils/FileUtils.hxx"
#endif

extern const char DEFAULT_WIFI_NAME[] __attribute__((weak)) = "defaultap";
extern const char DEFAULT_WIFI_PASSWORD[] __attribute__((weak)) = "defaultpw";

namespace openmrn_arduino {

OpenMRN::OpenMRN(openlcb::NodeID node_id)
{
    init(node_id);
}

} // namespace openmrn_arduino
<commit_msg>remove reference to include as it is not necessary now.<commit_after>/** \copyright
 * Copyright (c) 2018, Balazs Racz
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are  permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * \file OpenMRN.cpp
 *
 * Implementation that needs to be compiled for the Arduino.
 *
 * @author Balazs Racz
 * @date 24 July 2018
 */

#include <OpenMRNLite.h>

extern const char DEFAULT_WIFI_NAME[] __attribute__((weak)) = "defaultap";
extern const char DEFAULT_WIFI_PASSWORD[] __attribute__((weak)) = "defaultpw";

namespace openmrn_arduino {

OpenMRN::OpenMRN(openlcb::NodeID node_id)
{
    init(node_id);
}

} // namespace openmrn_arduino
<|endoftext|>