/* 
 * File:   main.cpp
 * Author: Sunao Hara (hara@okayama-u.ac.jp)
 *
 * Created on 2013/08/20, 18:10
 */

#include <julius/juliuslib.h>

#include "Julius.h"
#include "JuliusServer.h"
#include "JuliusOutputEventServer.h"

/*int _main(int argc, char *argv[])
{
    Junius::CJulius* julius;
    Junius::CJuliusOutputEventServer* jOutput;

    julius = new Junius::CJulius();
    julius->init(argc, argv);

    jOutput = new Junius::CJuliusOutputEventServer(julius);
    julius->setJuliusOutput((Junius::IJuliusOutput *)jOutput);

    julius->startService();
    
    jOutput->run();

    delete jOutput;
    julius->stopService();
    delete julius;

    return 0;
}*/

int main2(int argc, char *argv[])
{
    Junius::CJulius* julius;
    Junius::CJuliusOutputEventServer* jOutput;

    julius = new Junius::CJulius();
    julius->init(argc, argv);

    julius->initPushInput();

    jOutput = new Junius::CJuliusOutputEventServer(julius);
    julius->setJuliusOutput((Junius::IJuliusOutput *)jOutput);

    jOutput->runAsyncThread();
    sleep(2);
    {
        const char* filename = "sample.le";
        SP16 buf[4096];
        size_t nRead = 0;

        julius->beginPushInput();

        fprintf(stderr, "PipeLine\n");
        FILE *fp = fopen(filename, "rb");
        while ((nRead = fread(buf, sizeof (SP16), 4096, fp)) > 0) {
            fprintf(stderr, "%d, ", (int) nRead);
            julius->addPushInput(buf, nRead);
        }
        fclose(fp);

        julius->endPushInput();
    }

    jOutput->terminateAsyncThread();
    jOutput->waitAsyncThread();

    delete jOutput;
    delete julius;

    return 0;
}

int main(int argc, char *argv[])
{
    Junius::CJuliusServer* julius;

    julius = new Junius::CJuliusServer(argc, argv);

    fprintf(stderr, "Wait port 10500...\n");
    julius->run();

    delete julius;

    return 0;
}
