/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>

#include "Canvas.h"
#include "Directory.h"
#include "Filter.h"
#include "EtherPix.h"
#include "Loveletter.h"
#include "Mgrs.h"
#include "ModuleMgr.h"
#include "ModuleMgr_impl.h"
#include "OpPrinter.h"
#include "OpSplitter.h"
#include "Output.h"
#include "PlatformInit.h"
#include "Player.h"
#include "Pong.h"
#include "Printer.h"
#include "Priority.h"
#include "RateLimiter.h"
#include "Resizer.h"
#include "Scaler.h"
#include "SipPhone.h"
#include "SyncNameSplitter.h"
#include "SyncPrinter.h"
#include "Tetris.h"
#include "Transformer.h"
#include "Udp4Phone.h"
#include "Udp4Receiver.h"
#include "Udp4Sender.h"
#include "Udp4SyncReceiver.h"
#include "Udp6Phone.h"
#include "Udp6Receiver.h"
#include "Udp6Sender.h"
#include "Udp6SyncReceiver.h"

using namespace Blinker;

void run(const std::string &dirConfig)
{
  Directory cfg(dirConfig);

  SipPhone::init(dirConfig);

  Mgrs mgrs;

#define MODULEMGR(TYPE, CLASS) \
  ModuleMgr<TYPE> CLASS(#CLASS, mgrs, cfg.getSubdir(#CLASS))

  MODULEMGR(Canvas,           canvases);
  MODULEMGR(Filter,           filters);
  MODULEMGR(EtherPix,         etherpixes);
  MODULEMGR(Loveletter,       loveletters);
  MODULEMGR(OpPrinter,        opprinters);
  MODULEMGR(OpSplitter,       opsplitters);
  MODULEMGR(Output,           outputs);
  MODULEMGR(Player,           players);
  MODULEMGR(Pong,             pongs);
  MODULEMGR(Printer,          printers);
  MODULEMGR(Priority,         priorities);
  MODULEMGR(Resizer,          resizers);
  MODULEMGR(RateLimiter,      ratelimiters);
  MODULEMGR(Scaler,           scalers);
  MODULEMGR(SipPhone,         sipphones);
  MODULEMGR(SyncNameSplitter, syncnamesplitters);
  MODULEMGR(SyncPrinter,      syncprinters);
  MODULEMGR(Tetris,           tetrises);
  MODULEMGR(Transformer,      transformers);
  MODULEMGR(Udp4Phone,        udp4phones);
  MODULEMGR(Udp4Receiver,     udp4receivers);
  MODULEMGR(Udp4Sender,       udp4senders);
  MODULEMGR(Udp4SyncReceiver, udp4syncreceivers);
  MODULEMGR(Udp6Phone,        udp6phones);
  MODULEMGR(Udp6Receiver,     udp6receivers);
  MODULEMGR(Udp6Sender,       udp6senders);
  MODULEMGR(Udp6SyncReceiver, udp6syncreceivers);

#undef MODULEMGR

  mgrs.m_callMgr.run();
}

int main(int argc, const char *argv[])
{
  const char * dirConfig;

  if (argc < 2) {
    std::cerr << "Blinker" << std::endl
              << "configuration:" BLINKER_CONFIG << std::endl
              << "usage: " << argv[0] << " config-directory" << std::endl;
    return 2;
  }
  dirConfig = argv[1];

  srand(time(NULL));
  PlatformInit pfInit;

  run(dirConfig);

  return 0;
}

