<commit_before>/*******************************************************************************/
/* Bela Csound Rendering functions                                             */
/*                                                                             */
/*******************************************************************************/

#include <Bela.h>
#include <Midi.h>
#include <csound/csound.hpp>
#include <vector>
#include <sstream>

#define ANCHNS 8

static int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev);
static int CloseMidiInDevice(CSOUND *csound, void *userData);
static int ReadMidiData(CSOUND *csound, void *userData, unsigned char *mbuf,
			int nbytes);

struct CsChan {
  std::vector<MYFLT> data;
  std::stringstream name;
};

struct CsData {
  Csound *csound;
  int blocksize;
  int res;
  int count;
  CsChan channel[ANCHNS];
};

static CsData gCsData;

bool setup(BelaContext *context, void *Data)
{
  Csound *csound;
  const char *csdfile = "my.csd"; /* CSD name */
  const char *midiDev = "-Mhw:1,0,0"; /* MIDI device */
  const char *args[] = { "csound", csdfile, "-iadc", "-odac", "-+rtaudio=null",
			 "--realtime", "--daemon", midiDev };
  int numArgs = (int) (sizeof(args)/sizeof(char *));

  if(context->audioInChannels != context->audioOutChannels) {
    printf("Error: number of audio inputs != number of audio outputs.\n");
    return false;
  }

  /* setup Csound */
  csound = new Csound();
  gCsData.csound = csound;
  csound->SetHostImplementedAudioIO(1,0);
  csound->SetHostImplementedMIDIIO(1);
  csound->SetExternalMidiInOpenCallback(OpenMidiInDevice);
  csound->SetExternalMidiReadCallback(ReadMidiData);
  csound->SetExternalMidiInCloseCallback(CloseMidiInDevice);
  if((gCsData.res = csound->Compile(numArgs, args)) != 0) {
     printf("Error: Csound could not compile CSD file.\n");
    return false;
  }
  gCsData.blocksize = csound->GetKsmps()*csound->GetNchnls();
  gCsData.count = 0;

  /* set up the channels */
  for(int i; i < ANCHNS; i++) {
    gCsData.channel[i].data.resize(csound->GetKsmps());
    gCsData.channel[i].name << "analogue" << i+1;
  }

 return true;
}

void render(BelaContext *context, void *Data)
{
  if(gCsData.res == 0) {
    int n,i,k,count, frmcount,blocksize,res;
    Csound *csound = gCsData.csound;
    MYFLT scal = csound->Get0dBFS();
    MYFLT* audioIn = csound->GetSpin();
    MYFLT* audioOut = csound->GetSpout();
    int nchnls = csound->GetNchnls();
    int chns = nchnls < context->audioOutChannels ?
      nchnls : context->audioOutChannels;
    int an_chns = context->analogInChannels > ANCHNS ?
      ANCHNS : context->analogInChannels;
    CsChan *channel = &(gCsData.channel[0]);
    float frm = 0, incr = ((float) context->analogFrames)/context->audioFrames;
    int an_chans = context->analogInChannels;
    count = gCsData.count;
    blocksize = gCsData.blocksize;

    /* processing loop */
    for(n = 0; n < context->audioFrames; n++, frm+=incr, count+=nchnls){
      if(count == blocksize) {
	/* set the channels */
	for(i = 0; i < an_chns; i++) {
          csound->SetChannel(channel[i].name.str().c_str(),
			     &(channel[i].data[0]));
	}
	/* run csound */
	if((res = csound->PerformKsmps()) == 0) count = 0;
	else break;
      }
      /* read/write audio data */
      for(i = 0; i < chns; i++){
	audioIn[count+i] = audioRead(context,n,i);
	audioWrite(context,n,i,audioOut[count+i]/scal);
      }

      /* read analogue data
         analogue frame pos frm gets incremented according to the
         ratio analogFrames/audioFrames.
      */
      frmcount = count/nchnls;
      for(i = 0; i < an_chns; i++) {
	k = (int) frm;
        channel[i].data[frmcount] = analogRead(context,k,i);
      }
    }
    gCsData.res = res;
    gCsData.count = count;
  }
}

void cleanup(BelaContext *context, void *Data)
{
  delete gCsData.csound;
}

/** MIDI Input functions
 */
int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev) {
  Midi *midi = new Midi;
  midi->readFrom(dev);
  midi->enableParser(false);
  *userData = (void *) midi;
}

int CloseMidiInDevice(CSOUND *csound, void *userData) {
  delete (Midi *) userData;
}

int ReadMidiData(CSOUND *csound, void *userData,
		 unsigned char *mbuf, int nbytes) {
  int n = 0, byte;
  Midi midi = (Midi *) userData;

  while((byte = midi->getInput()) >= 0) {
    *mbuf++ = (unsigned char) byte;
    if(++n == nbytes) break;
  }

  return n;
}
<commit_msg>license notice and duplicate declaration<commit_after>/*
    BelaCsound.cpp:

    Copyright (C) 2017 V Lazzarini

    This file is part of Csound.

    The Csound 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.

    Csound 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 Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/
#include <Bela.h>
#include <Midi.h>
#include <csound/csound.hpp>
#include <vector>
#include <sstream>

#define ANCHNS 8

static int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev);
static int CloseMidiInDevice(CSOUND *csound, void *userData);
static int ReadMidiData(CSOUND *csound, void *userData, unsigned char *mbuf,
			int nbytes);

struct CsChan {
  std::vector<MYFLT> data;
  std::stringstream name;
};

struct CsData {
  Csound *csound;
  int blocksize;
  int res;
  int count;
  CsChan channel[ANCHNS];
};

static CsData gCsData;

bool setup(BelaContext *context, void *Data)
{
  Csound *csound;
  const char *csdfile = "my.csd"; /* CSD name */
  const char *midiDev = "-Mhw:1,0,0"; /* MIDI device */
  const char *args[] = { "csound", csdfile, "-iadc", "-odac", "-+rtaudio=null",
			 "--realtime", "--daemon", midiDev };
  int numArgs = (int) (sizeof(args)/sizeof(char *));

  if(context->audioInChannels != context->audioOutChannels) {
    printf("Error: number of audio inputs != number of audio outputs.\n");
    return false;
  }

  /* setup Csound */
  csound = new Csound();
  gCsData.csound = csound;
  csound->SetHostImplementedAudioIO(1,0);
  csound->SetHostImplementedMIDIIO(1);
  csound->SetExternalMidiInOpenCallback(OpenMidiInDevice);
  csound->SetExternalMidiReadCallback(ReadMidiData);
  csound->SetExternalMidiInCloseCallback(CloseMidiInDevice);
  if((gCsData.res = csound->Compile(numArgs, args)) != 0) {
    printf("Error: Csound could not compile CSD file.\n");
    return false;
  }
  gCsData.blocksize = csound->GetKsmps()*csound->GetNchnls();
  gCsData.count = 0;

  /* set up the channels */
  for(int i; i < ANCHNS; i++) {
    gCsData.channel[i].data.resize(csound->GetKsmps());
    gCsData.channel[i].name << "analogue" << i+1;
  }

  return true;
}

void render(BelaContext *context, void *Data)
{
  if(gCsData.res == 0) {
    int n,i,k,count, frmcount,blocksize,res;
    Csound *csound = gCsData.csound;
    MYFLT scal = csound->Get0dBFS();
    MYFLT* audioIn = csound->GetSpin();
    MYFLT* audioOut = csound->GetSpout();
    int nchnls = csound->GetNchnls();
    int chns = nchnls < context->audioOutChannels ?
      nchnls : context->audioOutChannels;
    int an_chns = context->analogInChannels > ANCHNS ?
      ANCHNS : context->analogInChannels;
    CsChan *channel = &(gCsData.channel[0]);
    float frm = 0.f, incr = ((float) context->analogFrames)/context->audioFrames;
    count = gCsData.count;
    blocksize = gCsData.blocksize;

    /* processing loop */
    for(n = 0; n < context->audioFrames; n++, frm+=incr, count+=nchnls){
      if(count == blocksize) {
	/* set the channels */
	for(i = 0; i < an_chns; i++) {
          csound->SetChannel(channel[i].name.str().c_str(),
			     &(channel[i].data[0]));
	}
	/* run csound */
	if((res = csound->PerformKsmps()) == 0) count = 0;
	else break;
      }
      /* read/write audio data */
      for(i = 0; i < chns; i++){
	audioIn[count+i] = audioRead(context,n,i);
	audioWrite(context,n,i,audioOut[count+i]/scal);
      }
      /* read analogue data
         analogue frame pos frm gets incremented according to the
         ratio analogFrames/audioFrames.
      */
      frmcount = count/nchnls;
      for(i = 0; i < an_chns; i++) {
	k = (int) frm;
        channel[i].data[frmcount] = analogRead(context,k,i);
      }
    }
    gCsData.res = res;
    gCsData.count = count;
  }
}

void cleanup(BelaContext *context, void *Data)
{
  delete gCsData.csound;
}

/** MIDI Input functions
 */
int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev) {
  Midi *midi = new Midi;
  midi->readFrom(dev);
  midi->enableParser(false);
  *userData = (void *) midi;
}

int CloseMidiInDevice(CSOUND *csound, void *userData) {
  delete (Midi *) userData;
}

int ReadMidiData(CSOUND *csound, void *userData,
		 unsigned char *mbuf, int nbytes) {
  int n = 0, byte;
  Midi midi = (Midi *) userData;

  while((byte = midi->getInput()) >= 0) {
    *mbuf++ = (unsigned char) byte;
    if(++n == nbytes) break;
  }

  return n;
}
<|endoftext|>


<commit_before>/*******************************************************************************/
/* Bela Csound Rendering functions                                             */
/*                                                                             */
/*******************************************************************************/

#include <Bela.h>
#include <Midi.h>
#include <csound/csound.hpp>
#include <vector>
#include <sstream>

#define ANCHNS 8

static int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev);
static int CloseMidiInDevice(CSOUND *csound, void *userData);
static int ReadMidiData(CSOUND *csound, void *userData, unsigned char *mbuf,
			int nbytes);

struct CsChan {
  std::vector<MYFLT> data;
  std::stringstream name;
};

struct CsData {
  Csound *csound;
  int blocksize;
  int res;
  int count;
  CsChan channel[ANCHNS];
};

CsData gCsData;

bool setup(BelaContext *context, void *Data)
{
  Csound *csound;
  const char *csdfile = "my.csd"; /* CSD name */
  const char *midiDev = "-Mhw:1,0,0"; /* MIDI device */
  const char *args[] = { "csound", csdfile, "-iadc", "-odac", "-+rtaudio=null",
			 "--realtime", "--daemon", midiDev };
  int numArgs = (int) (sizeof(args)/sizeof(char *));

  if(context->audioInChannels != context->audioOutChannels) {
    printf("Number of audio inputs != number of audio outputs.\n");
    return false;
  }

  /* setup Csound */
  csound = new Csound();
  csound->SetHostImplementedAudioIO(1,0);
  csound->SetHostImplementedMIDIIO(1);
  csound->SetExternalMidiInOpenCallback(OpenMidiInDevice);
  csound->SetExternalMidiReadCallback(ReadMidiData);
  csound->SetExternalMidiInCloseCallback(CloseMidiInDevice);
  gCsData.csound = csound;
  gCsData.res = csound->Compile(numArgs, args);
  gCsData.blocksize = csound->GetKsmps()*csound->GetNchnls();
  gCsData.count = 0;

  /* set up the channels */
  for(int i; i < ANCHNS; i++) {
    gCsData.channel[i].data.resize(csound->GetKsmps());
    gCsData.channel[i].name << "analogue" << i+1;
  }

  if(gCsData.res != 0) return false;
  else return true;
}

void render(BelaContext *context, void *Data)
{
  if(gCsData.res == 0) {
    int n,i,k,count, frmcount,blocksize,res;
    Csound *csound = gCsData.csound;
    MYFLT scal = csound->Get0dBFS();
    MYFLT* audioIn = csound->GetSpin();
    MYFLT* audioOut = csound->GetSpout();
    int nchnls = csound->GetNchnls();
    int chns = nchnls < context->audioOutChannels ?
      nchnls : context->audioOutChannels;
    int an_chns = context->analogInChannels > ANCHNS ?
      ANCHNS : context->analogInChannels;
    CsChan *channel = &(gCsData.channel[0]);
    float frm = 0, incr = ((float) context->analogFrames)/context->audioFrames;
    int an_chans = context->analogInChannels;
    count = gCsData.count;
    blocksize = gCsData.blocksize;

    /* this is called when Csound is not running */
    if(count < 0) {
      for(n = 0; n < context->audioFrames; n++){
	for(i = 0; i < context->audioOutChannels; i++){
	  audioWrite(context,n,i,0);
	}
      }
      return;
    }

    /* this is where Csound is called */
    for(n = 0; n < context->audioFrames; n++, frm+=incr, count+=nchnls){
      if(count == blocksize) {
	/* set the channels */
	for(i = 0; i < an_chns; i++) {
          csound->SetChannel(channel[i].name.str().c_str(),
			     &(channel[i].data[0]));
	}
	/* run csound */
	if((res = csound->PerformKsmps()) == 0) count = 0;
	else {
	  count = -1;
	  break;
	}
      }
      /* read/write audio data */
      for(i = 0; i < chns; i++){
	audioIn[count+i] = audioRead(context,n,i);
	audioWrite(context,n,i,audioOut[count+i]/scal);
      }

      /* read analogue data
         analogue frame pos gets incremented according to the
         ratio analogFrames/audioFrames.
      */
      frmcount = count/nchnls;
      for(i = 0; i < an_chns; i++) {
	k = (int) frm;
        channel[i].data[frmcount] = analogRead(context,k,i);
      }
    }
    gCsData.res = res;
    gCsData.count = count;
  }
}

void cleanup(BelaContext *context, void *Data)
{
  delete gCsData.csound;
}

/** MIDI Input functions
 */
int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev) {
  Midi *midi = new Midi;
  midi->readFrom(dev);
  midi->enableParser(false);
  *userData = (void *) midi;
}

int CloseMidiInDevice(CSOUND *csound, void *userData) {
  delete (Midi *) userData;
}

int ReadMidiData(CSOUND *csound, void *userData,
		 unsigned char *mbuf, int nbytes) {
  int n = 0;
  Midi midi = (Midi *) userData;

  while((byte = midi->getInput()) >= 0) {
    *mbuf++ = (unsigned char) byte;
    if(++n == nbytes) break;
  }

  return n;
}
<commit_msg>marking as static<commit_after>/*******************************************************************************/
/* Bela Csound Rendering functions                                             */
/*                                                                             */
/*******************************************************************************/

#include <Bela.h>
#include <Midi.h>
#include <csound/csound.hpp>
#include <vector>
#include <sstream>

#define ANCHNS 8

static int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev);
static int CloseMidiInDevice(CSOUND *csound, void *userData);
static int ReadMidiData(CSOUND *csound, void *userData, unsigned char *mbuf,
			int nbytes);

struct CsChan {
  std::vector<MYFLT> data;
  std::stringstream name;
};

struct CsData {
  Csound *csound;
  int blocksize;
  int res;
  int count;
  CsChan channel[ANCHNS];
};

static CsData gCsData;

bool setup(BelaContext *context, void *Data)
{
  Csound *csound;
  const char *csdfile = "my.csd"; /* CSD name */
  const char *midiDev = "-Mhw:1,0,0"; /* MIDI device */
  const char *args[] = { "csound", csdfile, "-iadc", "-odac", "-+rtaudio=null",
			 "--realtime", "--daemon", midiDev };
  int numArgs = (int) (sizeof(args)/sizeof(char *));

  if(context->audioInChannels != context->audioOutChannels) {
    printf("Number of audio inputs != number of audio outputs.\n");
    return false;
  }

  /* setup Csound */
  csound = new Csound();
  csound->SetHostImplementedAudioIO(1,0);
  csound->SetHostImplementedMIDIIO(1);
  csound->SetExternalMidiInOpenCallback(OpenMidiInDevice);
  csound->SetExternalMidiReadCallback(ReadMidiData);
  csound->SetExternalMidiInCloseCallback(CloseMidiInDevice);
  gCsData.csound = csound;
  gCsData.res = csound->Compile(numArgs, args);
  gCsData.blocksize = csound->GetKsmps()*csound->GetNchnls();
  gCsData.count = 0;

  /* set up the channels */
  for(int i; i < ANCHNS; i++) {
    gCsData.channel[i].data.resize(csound->GetKsmps());
    gCsData.channel[i].name << "analogue" << i+1;
  }

  if(gCsData.res != 0) return false;
  else return true;
}

void render(BelaContext *context, void *Data)
{
  if(gCsData.res == 0) {
    int n,i,k,count, frmcount,blocksize,res;
    Csound *csound = gCsData.csound;
    MYFLT scal = csound->Get0dBFS();
    MYFLT* audioIn = csound->GetSpin();
    MYFLT* audioOut = csound->GetSpout();
    int nchnls = csound->GetNchnls();
    int chns = nchnls < context->audioOutChannels ?
      nchnls : context->audioOutChannels;
    int an_chns = context->analogInChannels > ANCHNS ?
      ANCHNS : context->analogInChannels;
    CsChan *channel = &(gCsData.channel[0]);
    float frm = 0, incr = ((float) context->analogFrames)/context->audioFrames;
    int an_chans = context->analogInChannels;
    count = gCsData.count;
    blocksize = gCsData.blocksize;

    /* this is called when Csound is not running */
    if(count < 0) {
      for(n = 0; n < context->audioFrames; n++){
	for(i = 0; i < context->audioOutChannels; i++){
	  audioWrite(context,n,i,0);
	}
      }
      return;
    }

    /* this is where Csound is called */
    for(n = 0; n < context->audioFrames; n++, frm+=incr, count+=nchnls){
      if(count == blocksize) {
	/* set the channels */
	for(i = 0; i < an_chns; i++) {
          csound->SetChannel(channel[i].name.str().c_str(),
			     &(channel[i].data[0]));
	}
	/* run csound */
	if((res = csound->PerformKsmps()) == 0) count = 0;
	else {
	  count = -1;
	  break;
	}
      }
      /* read/write audio data */
      for(i = 0; i < chns; i++){
	audioIn[count+i] = audioRead(context,n,i);
	audioWrite(context,n,i,audioOut[count+i]/scal);
      }

      /* read analogue data
         analogue frame pos gets incremented according to the
         ratio analogFrames/audioFrames.
      */
      frmcount = count/nchnls;
      for(i = 0; i < an_chns; i++) {
	k = (int) frm;
        channel[i].data[frmcount] = analogRead(context,k,i);
      }
    }
    gCsData.res = res;
    gCsData.count = count;
  }
}

void cleanup(BelaContext *context, void *Data)
{
  delete gCsData.csound;
}

/** MIDI Input functions
 */
int OpenMidiInDevice(CSOUND *csound, void **userData, const char *dev) {
  Midi *midi = new Midi;
  midi->readFrom(dev);
  midi->enableParser(false);
  *userData = (void *) midi;
}

int CloseMidiInDevice(CSOUND *csound, void *userData) {
  delete (Midi *) userData;
}

int ReadMidiData(CSOUND *csound, void *userData,
		 unsigned char *mbuf, int nbytes) {
  int n = 0;
  Midi midi = (Midi *) userData;

  while((byte = midi->getInput()) >= 0) {
    *mbuf++ = (unsigned char) byte;
    if(++n == nbytes) break;
  }

  return n;
}
<|endoftext|>


<commit_before>/* ***  Author:  Joe Listro and Sam Poquette
*  Last Update:  April 13, 2017
*     Filename:  source.cpp
*  Description:  Accepts input in the form of a text file and replaces any bad words then saves to a file and outputs the result to a console.
*
*  Certification of Authenticity:
*     I certify that this assignment is entirely my own work.
**********************************************************************/

#include <iostream>
#include <stdlib.h>
#include <string>
#include <Windows.h>
#include "resource.h"
#include "resource1.h"

using namespace std;

void leeroy()
{
	string input;

	cout << "Leeroy\n";
	cin >> input;

	if (input == "Jenkins" || input == "jenkins")
		PlaySound((char*)IDR_WAVE1, NULL, SND_RESOURCE | SND_ASYNC);

	system("pause");
}

void menu()
{
	system("cls");

	char input;

	cout << "**********MAIN MENU**********\nB - BleepBot\nT = TrumpMode (Bigly!)\nL - ???\n\nE - Exit\n\n";
	cin >> input;
	if (input == 'b' || input == 'B')
	{
		system("cls");
		//bleepBot();
		menu();
	}
	else if (input == 'T' || input == 't')
	{
		system("cls");
		//trumpMode();
		menu();
	}
	else if (input == 'L' || input == 'l')
	{
		system("cls");
		leeroy();
		menu();
	}
	else if (input == 'E' || input == 'e')
	{
		exit(EXIT_SUCCESS);
	}
	else
	{
		system("cls");
		menu();
	}
}

int main()
{
	menu();
}<commit_msg>updated menu<commit_after>/* ***  Author:  Joe Listro and Sam Poquette
*  Last Update:  April 13, 2017
*     Filename:  source.cpp
*  Description:  Accepts input in the form of a text file and replaces any bad words then saves to a file and outputs the result to a console.
*
*  Certification of Authenticity:
*     I certify that this assignment is entirely my own work.
**********************************************************************/

#include <iostream>
#include <stdlib.h>
#include <string>
#include <Windows.h>
#include "resource.h"
#include "resource1.h"

using namespace std;

void leeroy()
{
	string input;

	cout << "Leeroy\n";
	cin >> input;

	if (input == "Jenkins" || input == "jenkins")
		PlaySound((char*)IDR_WAVE1, NULL, SND_RESOURCE | SND_ASYNC);

	system("pause");
}

void menu()
{
	system("cls");

	char input;

	cout << "**********MAIN MENU**********\nB - BleepBot\nT = TrumpMode (Bigly!)\nL - ???\n\nE - Exit\n\n";
	cin >> input;
	if (input == 'b' || input == 'B')
	{
		system("cls");

		//string badWords = fileInput();
		//cout << convertBadWords(badWords);

		system("pause");
		menu();
	}
	else if (input == 'T' || input == 't')
	{
		system("cls");
		//string trumpWords = fileInput();
		//cout << convertTrumpWords(trumpWords);

		system("pause");
		menu();
	}
	else if (input == 'L' || input == 'l')
	{
		system("cls");
		leeroy();
		menu();
	}
	else if (input == 'E' || input == 'e')
	{
		exit(EXIT_SUCCESS);
	}
	else
	{
		system("cls");
		menu();
	}
}

int main()
{
	menu();
}<|endoftext|>


<commit_before>//////////////////////////////////////////////////////////////////////////////
// Licensed to Qualys, Inc. (QUALYS) under one or more
// contributor license agreements.  See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// QUALYS licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License.  You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
/// @file
/// @brief IronBee --- Engine Manager Channel Test Functions
///
/// @author Sam Baskinger <sbaskinger@qualys.com>
//////////////////////////////////////////////////////////////////////////////

#include "gtest/gtest.h"
#include "base_fixture.h"

#include <ironbee/engine_manager.h>
#include <ironbee/engine_manager_control_channel.h>

#include <boost/filesystem.hpp>
#include <boost/thread.hpp>

class EngMgrCtrlChanTest : public BaseFixture
{
public:
    void SetUp()
    {
        BaseFixture::SetUp();
        ASSERT_EQ(
            IB_OK,
            ib_manager_create(
                &m_ib_manager,
                &ibt_ibserver,
                10
            )
        );
    }

    virtual void TearDown()
    {
        ib_manager_destroy(m_ib_manager);
        BaseFixture::TearDown();
    }

    ib_manager_t* EngineManager() const
    {
        return m_ib_manager;
    }

private:
    ib_manager_t* m_ib_manager;
};

TEST_F(EngMgrCtrlChanTest, init) {
    ib_engine_manager_control_channel_t* channel;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );
}

TEST_F(EngMgrCtrlChanTest, socket_path)
{
    ib_engine_manager_control_channel_t* channel;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    /* Check that a default is defined. */
    ASSERT_TRUE(
        ib_engine_manager_control_channel_socket_path_get(channel)
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "path")
    );

    /* Check the custom one. */
    ASSERT_STREQ(
        "path",
        ib_engine_manager_control_channel_socket_path_get(channel)
    );
}

TEST_F(EngMgrCtrlChanTest, start_stop)
{
    ib_engine_manager_control_channel_t* channel;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "./tmp.sock")
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_start(channel)
    );

    /* Check that the file exists and is not a normal file or dir. */
    ASSERT_TRUE(boost::filesystem::is_other("./tmp.sock"));

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_stop(channel)
    );

    ASSERT_FALSE(boost::filesystem::exists("./tmp.sock"));
}

TEST_F(EngMgrCtrlChanTest, send_echo)
{
    ib_engine_manager_control_channel_t* channel;
    const char* response;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "./tmp.sock")
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_echo_register(channel)
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_start(channel)
    );

    ASSERT_TRUE(boost::filesystem::is_other("./tmp.sock"));

    boost::packaged_task<ib_status_t> pt(
        boost::bind(
            ib_engine_manager_control_send,
            "./tmp.sock",
            "echo hi, how are you?",
            MainMM(),
            &response
        )
    );
    boost::shared_future<ib_status_t> fut(pt.get_future());
    boost::thread thr(boost::move(pt));

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_recv(
            channel,
            true
        )
    );

    thr.join();
    ASSERT_EQ(IB_OK, fut.get());

    ASSERT_STREQ(
        "hi, how are you?",
        response
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_stop(channel)
    );

    ASSERT_FALSE(boost::filesystem::exists("./tmp.sock"));
}

TEST_F(EngMgrCtrlChanTest, diag_version)
{
    ib_engine_manager_control_channel_t* channel;
    const char* response;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "./tmp.sock")
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_manager_diag_register(channel)
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_start(channel)
    );

    ASSERT_TRUE(boost::filesystem::is_other("./tmp.sock"));

    boost::packaged_task<ib_status_t> pt(
        boost::bind(
            ib_engine_manager_control_send,
            "./tmp.sock",
            "version",
            MainMM(),
            &response
        )
    );
    boost::shared_future<ib_status_t> fut(pt.get_future());
    boost::thread thr(boost::move(pt));

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_recv(
            channel,
            true
        )
    );

    thr.join();
    ASSERT_EQ(IB_OK, fut.get());

    ASSERT_STREQ(IB_VERSION, response);

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_stop(channel)
    );

    ASSERT_FALSE(boost::filesystem::exists("./tmp.sock"));
}
<commit_msg>test_engine_manager_control_channel.cpp: Initialize every class member.  CID 11010.<commit_after>//////////////////////////////////////////////////////////////////////////////
// Licensed to Qualys, Inc. (QUALYS) under one or more
// contributor license agreements.  See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// QUALYS licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License.  You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
/// @file
/// @brief IronBee --- Engine Manager Channel Test Functions
///
/// @author Sam Baskinger <sbaskinger@qualys.com>
//////////////////////////////////////////////////////////////////////////////

#include "gtest/gtest.h"
#include "base_fixture.h"

#include <ironbee/engine_manager.h>
#include <ironbee/engine_manager_control_channel.h>

#include <boost/filesystem.hpp>
#include <boost/thread.hpp>

class EngMgrCtrlChanTest : public BaseFixture
{
public:
    void SetUp()
    {
        BaseFixture::SetUp();
        ASSERT_EQ(
            IB_OK,
            ib_manager_create(
                &m_ib_manager,
                &ibt_ibserver,
                10
            )
        );
    }

    virtual void TearDown()
    {
        ib_manager_destroy(m_ib_manager);
        BaseFixture::TearDown();
    }

    ib_manager_t* EngineManager() const
    {
        return m_ib_manager;
    }

    EngMgrCtrlChanTest(): BaseFixture(), m_ib_manager(NULL)
    {
    }

private:
    ib_manager_t* m_ib_manager;
};

TEST_F(EngMgrCtrlChanTest, init) {
    ib_engine_manager_control_channel_t* channel;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );
}

TEST_F(EngMgrCtrlChanTest, socket_path)
{
    ib_engine_manager_control_channel_t* channel;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    /* Check that a default is defined. */
    ASSERT_TRUE(
        ib_engine_manager_control_channel_socket_path_get(channel)
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "path")
    );

    /* Check the custom one. */
    ASSERT_STREQ(
        "path",
        ib_engine_manager_control_channel_socket_path_get(channel)
    );
}

TEST_F(EngMgrCtrlChanTest, start_stop)
{
    ib_engine_manager_control_channel_t* channel;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "./tmp.sock")
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_start(channel)
    );

    /* Check that the file exists and is not a normal file or dir. */
    ASSERT_TRUE(boost::filesystem::is_other("./tmp.sock"));

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_stop(channel)
    );

    ASSERT_FALSE(boost::filesystem::exists("./tmp.sock"));
}

TEST_F(EngMgrCtrlChanTest, send_echo)
{
    ib_engine_manager_control_channel_t* channel;
    const char* response;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "./tmp.sock")
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_echo_register(channel)
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_start(channel)
    );

    ASSERT_TRUE(boost::filesystem::is_other("./tmp.sock"));

    boost::packaged_task<ib_status_t> pt(
        boost::bind(
            ib_engine_manager_control_send,
            "./tmp.sock",
            "echo hi, how are you?",
            MainMM(),
            &response
        )
    );
    boost::shared_future<ib_status_t> fut(pt.get_future());
    boost::thread thr(boost::move(pt));

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_recv(
            channel,
            true
        )
    );

    thr.join();
    ASSERT_EQ(IB_OK, fut.get());

    ASSERT_STREQ(
        "hi, how are you?",
        response
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_stop(channel)
    );

    ASSERT_FALSE(boost::filesystem::exists("./tmp.sock"));
}

TEST_F(EngMgrCtrlChanTest, diag_version)
{
    ib_engine_manager_control_channel_t* channel;
    const char* response;

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_create(
            &channel,
            MainMM(),
            EngineManager()
        )
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_socket_path_set(channel, "./tmp.sock")
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_manager_diag_register(channel)
    );

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_start(channel)
    );

    ASSERT_TRUE(boost::filesystem::is_other("./tmp.sock"));

    boost::packaged_task<ib_status_t> pt(
        boost::bind(
            ib_engine_manager_control_send,
            "./tmp.sock",
            "version",
            MainMM(),
            &response
        )
    );
    boost::shared_future<ib_status_t> fut(pt.get_future());
    boost::thread thr(boost::move(pt));

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_recv(
            channel,
            true
        )
    );

    thr.join();
    ASSERT_EQ(IB_OK, fut.get());

    ASSERT_STREQ(IB_VERSION, response);

    ASSERT_EQ(
        IB_OK,
        ib_engine_manager_control_channel_stop(channel)
    );

    ASSERT_FALSE(boost::filesystem::exists("./tmp.sock"));
}
<|endoftext|>


<commit_before><commit_msg>fix http stream finish<commit_after><|endoftext|>


<commit_before><commit_msg>fix compiler warning in test of tiglGetCurveParameter<commit_after><|endoftext|>


<commit_before><commit_msg>New waypoints colours have been included. refs #60<commit_after><|endoftext|>


<commit_before><commit_msg>INTEGRATION: CWS frmcontrols03 (1.21.52); FILE MERGED 2004/03/02 09:51:21 fs 1.21.52.2: #i24387# proper im/export of a rich text control 2004/02/17 15:38:38 fs 1.21.52.1: #i24387# import text paragraphs of a rich text control<commit_after><|endoftext|>


<commit_before>//
//  rv-dump.cc
//

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cinttypes>
#include <cstdarg>
#include <cerrno>
#include <cassert>
#include <algorithm>
#include <functional>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <set>

#include <unistd.h>

#include "host-endian.h"
#include "types.h"
#include "bits.h"
#include "format.h"
#include "meta.h"
#include "util.h"
#include "cmdline.h"
#include "color.h"
#include "codec.h"
#include "strings.h"
#include "disasm.h"
#include "elf.h"
#include "elf-file.h"
#include "elf-format.h"

using namespace riscv;

struct rv_parse_elf
{
	elf_file elf;
	std::string filename;
	std::map<addr_t,uint32_t> continuations;
	ssize_t continuation_num = 1;

	bool enable_color = false;
	bool elf_header = false;
	bool elf_header_ext = false;
	bool section_headers = false;
	bool program_headers = false;
	bool symbol_table = false;
	bool disassebly = false;
	bool relocations = false;
	bool decode_pseudo = false;
	bool help_or_error = false;

	const char* colorize(const char *type)
	{
		if (!enable_color || !isatty(fileno(stdout))) {
			return "";
		} else if (strcmp(type, "header") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_END;
		} else if (strcmp(type, "title") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_SEP _COLOR_FG_CYAN _COLOR_END;
		} else if (strcmp(type, "legend") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_SEP _COLOR_FG_MAGENTA _COLOR_END;
		} else if (strcmp(type, "opcode") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_SEP _COLOR_FG_CYAN _COLOR_END;
		} else if (strcmp(type, "address") == 0) {
			return _COLOR_BEGIN _COLOR_FG_YELLOW _COLOR_END;
		} else if (strcmp(type, "label") == 0) {
			return _COLOR_BEGIN _COLOR_FG_GREEN _COLOR_END;
		} else if (strcmp(type, "reset") == 0) {
			return _COLOR_RESET;
		}
		return "";
	}

	const char* symlookup(addr_t addr, bool nearest)
	{
		static char symbol_tmpname[256];
		auto sym = elf.sym_by_addr((Elf64_Addr)addr);
		auto bli = continuations.find(addr);
		if (sym && bli != continuations.end()) {
				snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"LOC_%06" PRIu32 ":<%s>", bli->second, elf.sym_name(sym));
			return symbol_tmpname;
		}
		if (sym) {
			snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"<%s>", elf.sym_name(sym));
			return symbol_tmpname;
		}
		if (bli != continuations.end()) {
			snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"LOC_%06" PRIu32, bli->second);
			return symbol_tmpname;
		}
		if (nearest) {
			sym = elf.sym_by_nearest_addr((Elf64_Addr)addr);
			if (sym) {
				int64_t offset = int64_t(addr) - sym->st_value;
				snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"<%s%s0x%" PRIx64 ">", elf.sym_name(sym),
					offset < 0 ? "-" : "+", offset < 0 ? -offset : offset);
				return symbol_tmpname;
			}
		}
		return nullptr;
	}

	void scan_continuations(addr_t start, addr_t end, addr_t pc_bias)
	{
		disasm dec;
		addr_t pc = start;
		addr_t pc_offset;
		addr_t addr = 0;
		while (pc < end) {
			dec.pc = pc;
			dec.inst = inst_fetch(pc, pc_offset);
			decode_inst_rv64(dec, dec.inst);
			switch (dec.op) {
				case rv_op_jal:
				case rv_op_jalr:
					if (pc + pc_offset < end) {
						addr = pc - pc_bias + pc_offset;
						if (continuations.find(addr) == continuations.end()) {
							continuations.insert(std::pair<addr_t,uint32_t>(addr, continuation_num++));
						}
					}
					break;
				default:
					break;
			}
			switch (dec.codec) {
				case rv_codec_sb:
					addr = pc - pc_bias + dec.imm;
					if (continuations.find(addr) == continuations.end()) {
						continuations.insert(std::pair<addr_t,uint32_t>(addr, continuation_num++));
					}
					break;
				default:
					break;
			}
			pc += pc_offset;
		}
	}

	void print_disassembly(addr_t start, addr_t end, addr_t pc_bias, addr_t gp)
	{
		disasm dec;
		std::deque<disasm> dec_hist;
		addr_t pc = start;
		addr_t pc_offset;
		while (pc < end) {
			dec.pc = pc;
			dec.inst = inst_fetch(pc, pc_offset);
			decode_inst_rv64(dec, dec.inst);
			if (decode_pseudo) decode_pseudo_inst(dec);
			disasm_inst_print(dec, dec_hist, pc, pc_bias, gp,
				std::bind(&rv_parse_elf::symlookup, this, std::placeholders::_1, std::placeholders::_2),
				std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
			pc += pc_offset;
		}
	}

	void print_disassembly()
	{
		const Elf64_Sym *gp_sym = elf.sym_by_name("_gp");
		for (size_t i = 0; i < elf.shdrs.size(); i++) {
			Elf64_Shdr &shdr = elf.shdrs[i];
			if (shdr.sh_flags & SHF_EXECINSTR) {
				addr_t offset = (addr_t)elf.sections[i].buf.data();
				printf("%sSection[%2lu] %-111s%s\n", colorize("title"), i, elf.shdr_name(i), colorize("reset"));
				scan_continuations(offset, offset + shdr.sh_size, offset - shdr.sh_addr);
				print_disassembly(offset, offset + shdr.sh_size, offset- shdr.sh_addr,
					addr_t(gp_sym ? gp_sym->st_value : 0));
				printf("\n");
			}
		}
	}

	void parse_commandline(int argc, const char *argv[])
	{
		cmdline_option options[] =
		{
			{ "-c", "--color", cmdline_arg_type_none,
				"Enable Color",
				[&](std::string s) { return (enable_color = true); } },
			{ "-e", "--print-elf-header", cmdline_arg_type_none,
				"Print ELF header",
				[&](std::string s) { return (elf_header = true); } },
			{ "-x", "--print-elf-header-ext", cmdline_arg_type_none,
				"Print ELF header (extended)",
				[&](std::string s) { return (elf_header = elf_header_ext = true); } },
			{ "-s", "--print-section-headers", cmdline_arg_type_none,
				"Print Section headers",
				[&](std::string s) { return (section_headers = true); } },
			{ "-p", "--print-program-headers", cmdline_arg_type_none,
				"Print Program headers",
				[&](std::string s) { return (program_headers = true); } },
			{ "-t", "--print-symbol-table", cmdline_arg_type_none,
				"Print Symbol Table",
				[&](std::string s) { return (symbol_table = true); } },
			{ "-r", "--print-relocations", cmdline_arg_type_none,
				"Print Relocations",
				[&](std::string s) { return (relocations = true); } },
			{ "-d", "--print-disassembly", cmdline_arg_type_none,
				"Print Disassembly",
				[&](std::string s) { return (disassebly = true); } },
			{ "-P", "--pseudo", cmdline_arg_type_none,
				"Decode Pseudoinstructions",
				[&](std::string s) { return (decode_pseudo = true); } },
			{ "-h", "--print-headers", cmdline_arg_type_none,
				"Print All Headers",
				[&](std::string s) { return (elf_header = section_headers = program_headers = symbol_table = true); } },
			{ "-a", "--print-all", cmdline_arg_type_none,
				"Print All Headers and Disassembly",
				[&](std::string s) { return (elf_header = section_headers = program_headers = symbol_table = disassebly = true); } },
			{ "-h", "--help", cmdline_arg_type_none,
				"Show help",
				[&](std::string s) { return (help_or_error = true); } },
			{ nullptr, nullptr, cmdline_arg_type_none,   nullptr, nullptr }
		};

		auto result = cmdline_option::process_options(options, argc, argv);
		if (!result.second) {
			help_or_error = true;
		} else if (result.first.size() != 1 && !help_or_error) {
			printf("%s: wrong number of arguments\n", argv[0]);
			help_or_error = true;
		}

		if ((help_or_error |= !elf_header && !section_headers &&
			!program_headers && !symbol_table && !disassebly))
		{
			printf("usage: %s [<options>] <elf_file>\n", argv[0]);
			cmdline_option::print_options(options);
			exit(9);
		}

		filename = result.first[0];
	}

	void print_heading(std::string heading)
	{
		printf("\n%s---[ %s ]", colorize("header"), heading.c_str());
		for (size_t i = 0; i < 116 - heading.length(); i++) printf("-");
		printf("%s\n\n", colorize("reset"));
	}

	void run()
	{
		elf.load(filename);
		if (elf_header) {
			print_heading("ELF Header");
			elf_print_header_info(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (elf_header_ext) {
			elf_print_header_ext_info(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (section_headers) {
			print_heading("Section Headers");
			elf_print_section_headers(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (program_headers) {
			print_heading("Program Headers");
			elf_print_program_headers(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (symbol_table) {
			print_heading("Symbol Table");
			elf_print_symbol_table(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (relocations && elf.ehdr.e_machine == EM_RISCV) {
			print_heading("Relocations");
			elf_print_relocations(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (disassebly && elf.ehdr.e_machine == EM_RISCV) {
			print_heading("Disassembly");
			print_disassembly();
		}
	}
};

int rv_dump_main(int argc, const char *argv[])
{
	rv_parse_elf elf_parser;
	elf_parser.parse_commandline(argc, argv);
	elf_parser.run();
	return 0;
}
<commit_msg>[dump] Don't include symbol table when all headers are selected<commit_after>//
//  rv-dump.cc
//

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cinttypes>
#include <cstdarg>
#include <cerrno>
#include <cassert>
#include <algorithm>
#include <functional>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <set>

#include <unistd.h>

#include "host-endian.h"
#include "types.h"
#include "bits.h"
#include "format.h"
#include "meta.h"
#include "util.h"
#include "cmdline.h"
#include "color.h"
#include "codec.h"
#include "strings.h"
#include "disasm.h"
#include "elf.h"
#include "elf-file.h"
#include "elf-format.h"

using namespace riscv;

struct rv_parse_elf
{
	elf_file elf;
	std::string filename;
	std::map<addr_t,uint32_t> continuations;
	ssize_t continuation_num = 1;

	bool enable_color = false;
	bool elf_header = false;
	bool elf_header_ext = false;
	bool section_headers = false;
	bool program_headers = false;
	bool symbol_table = false;
	bool disassebly = false;
	bool relocations = false;
	bool decode_pseudo = false;
	bool help_or_error = false;

	const char* colorize(const char *type)
	{
		if (!enable_color || !isatty(fileno(stdout))) {
			return "";
		} else if (strcmp(type, "header") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_END;
		} else if (strcmp(type, "title") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_SEP _COLOR_FG_CYAN _COLOR_END;
		} else if (strcmp(type, "legend") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_SEP _COLOR_FG_MAGENTA _COLOR_END;
		} else if (strcmp(type, "opcode") == 0) {
			return _COLOR_BEGIN _COLOR_BOLD _COLOR_SEP _COLOR_FG_CYAN _COLOR_END;
		} else if (strcmp(type, "address") == 0) {
			return _COLOR_BEGIN _COLOR_FG_YELLOW _COLOR_END;
		} else if (strcmp(type, "label") == 0) {
			return _COLOR_BEGIN _COLOR_FG_GREEN _COLOR_END;
		} else if (strcmp(type, "reset") == 0) {
			return _COLOR_RESET;
		}
		return "";
	}

	const char* symlookup(addr_t addr, bool nearest)
	{
		static char symbol_tmpname[256];
		auto sym = elf.sym_by_addr((Elf64_Addr)addr);
		auto bli = continuations.find(addr);
		if (sym && bli != continuations.end()) {
				snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"LOC_%06" PRIu32 ":<%s>", bli->second, elf.sym_name(sym));
			return symbol_tmpname;
		}
		if (sym) {
			snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"<%s>", elf.sym_name(sym));
			return symbol_tmpname;
		}
		if (bli != continuations.end()) {
			snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"LOC_%06" PRIu32, bli->second);
			return symbol_tmpname;
		}
		if (nearest) {
			sym = elf.sym_by_nearest_addr((Elf64_Addr)addr);
			if (sym) {
				int64_t offset = int64_t(addr) - sym->st_value;
				snprintf(symbol_tmpname, sizeof(symbol_tmpname),
					"<%s%s0x%" PRIx64 ">", elf.sym_name(sym),
					offset < 0 ? "-" : "+", offset < 0 ? -offset : offset);
				return symbol_tmpname;
			}
		}
		return nullptr;
	}

	void scan_continuations(addr_t start, addr_t end, addr_t pc_bias)
	{
		disasm dec;
		addr_t pc = start;
		addr_t pc_offset;
		addr_t addr = 0;
		while (pc < end) {
			dec.pc = pc;
			dec.inst = inst_fetch(pc, pc_offset);
			decode_inst_rv64(dec, dec.inst);
			switch (dec.op) {
				case rv_op_jal:
				case rv_op_jalr:
					if (pc + pc_offset < end) {
						addr = pc - pc_bias + pc_offset;
						if (continuations.find(addr) == continuations.end()) {
							continuations.insert(std::pair<addr_t,uint32_t>(addr, continuation_num++));
						}
					}
					break;
				default:
					break;
			}
			switch (dec.codec) {
				case rv_codec_sb:
					addr = pc - pc_bias + dec.imm;
					if (continuations.find(addr) == continuations.end()) {
						continuations.insert(std::pair<addr_t,uint32_t>(addr, continuation_num++));
					}
					break;
				default:
					break;
			}
			pc += pc_offset;
		}
	}

	void print_disassembly(addr_t start, addr_t end, addr_t pc_bias, addr_t gp)
	{
		disasm dec;
		std::deque<disasm> dec_hist;
		addr_t pc = start;
		addr_t pc_offset;
		while (pc < end) {
			dec.pc = pc;
			dec.inst = inst_fetch(pc, pc_offset);
			decode_inst_rv64(dec, dec.inst);
			if (decode_pseudo) decode_pseudo_inst(dec);
			disasm_inst_print(dec, dec_hist, pc, pc_bias, gp,
				std::bind(&rv_parse_elf::symlookup, this, std::placeholders::_1, std::placeholders::_2),
				std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
			pc += pc_offset;
		}
	}

	void print_disassembly()
	{
		const Elf64_Sym *gp_sym = elf.sym_by_name("_gp");
		for (size_t i = 0; i < elf.shdrs.size(); i++) {
			Elf64_Shdr &shdr = elf.shdrs[i];
			if (shdr.sh_flags & SHF_EXECINSTR) {
				addr_t offset = (addr_t)elf.sections[i].buf.data();
				printf("%sSection[%2lu] %-111s%s\n", colorize("title"), i, elf.shdr_name(i), colorize("reset"));
				scan_continuations(offset, offset + shdr.sh_size, offset - shdr.sh_addr);
				print_disassembly(offset, offset + shdr.sh_size, offset- shdr.sh_addr,
					addr_t(gp_sym ? gp_sym->st_value : 0));
				printf("\n");
			}
		}
	}

	void parse_commandline(int argc, const char *argv[])
	{
		cmdline_option options[] =
		{
			{ "-c", "--color", cmdline_arg_type_none,
				"Enable Color",
				[&](std::string s) { return (enable_color = true); } },
			{ "-e", "--print-elf-header", cmdline_arg_type_none,
				"Print ELF header",
				[&](std::string s) { return (elf_header = true); } },
			{ "-x", "--print-elf-header-ext", cmdline_arg_type_none,
				"Print ELF header (extended)",
				[&](std::string s) { return (elf_header = elf_header_ext = true); } },
			{ "-s", "--print-section-headers", cmdline_arg_type_none,
				"Print Section headers",
				[&](std::string s) { return (section_headers = true); } },
			{ "-p", "--print-program-headers", cmdline_arg_type_none,
				"Print Program headers",
				[&](std::string s) { return (program_headers = true); } },
			{ "-t", "--print-symbol-table", cmdline_arg_type_none,
				"Print Symbol Table",
				[&](std::string s) { return (symbol_table = true); } },
			{ "-r", "--print-relocations", cmdline_arg_type_none,
				"Print Relocations",
				[&](std::string s) { return (relocations = true); } },
			{ "-d", "--print-disassembly", cmdline_arg_type_none,
				"Print Disassembly",
				[&](std::string s) { return (disassebly = true); } },
			{ "-P", "--pseudo", cmdline_arg_type_none,
				"Decode Pseudoinstructions",
				[&](std::string s) { return (decode_pseudo = true); } },
			{ "-h", "--print-headers", cmdline_arg_type_none,
				"Print All Headers",
				[&](std::string s) { return (elf_header = section_headers = program_headers = true); } },
			{ "-a", "--print-all", cmdline_arg_type_none,
				"Print All Headers and Disassembly",
				[&](std::string s) { return (elf_header = section_headers = program_headers = symbol_table = disassebly = true); } },
			{ "-h", "--help", cmdline_arg_type_none,
				"Show help",
				[&](std::string s) { return (help_or_error = true); } },
			{ nullptr, nullptr, cmdline_arg_type_none,   nullptr, nullptr }
		};

		auto result = cmdline_option::process_options(options, argc, argv);
		if (!result.second) {
			help_or_error = true;
		} else if (result.first.size() != 1 && !help_or_error) {
			printf("%s: wrong number of arguments\n", argv[0]);
			help_or_error = true;
		}

		if ((help_or_error |= !elf_header && !section_headers &&
			!program_headers && !symbol_table && !disassebly))
		{
			printf("usage: %s [<options>] <elf_file>\n", argv[0]);
			cmdline_option::print_options(options);
			exit(9);
		}

		filename = result.first[0];
	}

	void print_heading(std::string heading)
	{
		printf("\n%s---[ %s ]", colorize("header"), heading.c_str());
		for (size_t i = 0; i < 116 - heading.length(); i++) printf("-");
		printf("%s\n\n", colorize("reset"));
	}

	void run()
	{
		elf.load(filename);
		if (elf_header) {
			print_heading("ELF Header");
			elf_print_header_info(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (elf_header_ext) {
			elf_print_header_ext_info(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (section_headers) {
			print_heading("Section Headers");
			elf_print_section_headers(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (program_headers) {
			print_heading("Program Headers");
			elf_print_program_headers(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (symbol_table) {
			print_heading("Symbol Table");
			elf_print_symbol_table(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (relocations && elf.ehdr.e_machine == EM_RISCV) {
			print_heading("Relocations");
			elf_print_relocations(elf, std::bind(&rv_parse_elf::colorize, this, std::placeholders::_1));
		}
		if (disassebly && elf.ehdr.e_machine == EM_RISCV) {
			print_heading("Disassembly");
			print_disassembly();
		}
	}
};

int rv_dump_main(int argc, const char *argv[])
{
	rv_parse_elf elf_parser;
	elf_parser.parse_commandline(argc, argv);
	elf_parser.run();
	return 0;
}
<|endoftext|>


<commit_before>#include "videosourcefactory.h"
#include "iobserver.h"
#include "iobservable.h"
#include <thread>
#include <chrono>
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>

gg::Device device;
gg::ColourSpace colour;
size_t test_duration; // seconds
float frame_rate_to_check;
std::string report_filename("");

using namespace std::chrono;
typedef std::vector< time_point<system_clock> > timestamps;

//!
//! \brief This gg::IObserver implementor
//! records a timestamp every time it is
//! updated.
//!
//! It can then be used to check the frame
//! rate of the gg::IObservable it was
//! attached to.
//!
class FrameRateTimer : public gg::IObserver
{
protected:
    timestamps _timestamps;

public:
    void update(gg::VideoFrame & frame) override
    {
        _timestamps.push_back(system_clock::now());
    }

    //!
    //! \brief Get statistics based on currently
    //! available timestamp collection
    //! \param max_frame_rate fps
    //! \param min_frame_rate fps
    //! \param avg_frame_rate fps
    //! \param n_timestamps
    //! \return \c true if timestamps are available
    //! AND meaningful, such that the computations
    //! can be carried out, \c false otherwise
    //!
    bool statistics(float & max_frame_rate,
                    float & min_frame_rate,
                    float & avg_frame_rate,
                    size_t & n_timestamps)
    {
        // TODO
        return false;
    }

    //!
    //! \brief Output collected timestamps, as well
    //! as computed statistics to CSV file with \c
    //! filename
    //! \param filename nop if empty
    //! \sa statistics()
    //! \throw in case (non-empty) \c filename not
    //! pointing to a valid file, writeable by user
    //!
    void report(std::string filename)
    {
        // TODO
    }
};

bool parse_args(int argc, char * argv[])
{
    if (argc < 5)
        return false;

    if (std::strcmp(argv[1], "DVI") == 0)
        device = gg::DVI2PCIeDuo_DVI;
    else if (std::strcmp(argv[1], "SDI") == 0)
        device = gg::DVI2PCIeDuo_SDI;
    else
        return false;

    if (std::strcmp(argv[2], "BGRA") == 0)
        colour = gg::BGRA;
    else if (std::strcmp(argv[2], "I420") == 0)
        colour = gg::I420;
    else
        return false;

    int test_duration_ = std::atoi(argv[3]);
    if (test_duration_ <= 0)
        return false;
    else
        test_duration = test_duration_;

    double frame_rate_to_check_ = std::atof(argv[4]);
    if (frame_rate_to_check_ <= 0.0)
        return false;
    else
        frame_rate_to_check = frame_rate_to_check_;

    if (argc >= 6)
        report_filename = std::string(argv[5]);

    return true;
}

void synopsis(int argc, char * argv[])
{
    printf("%s  DVI | SDI  BGRA | I420  <test_duration>"
           "  <frame_rate_to_check>  [ <report_filename> ]"
           "\n",
           argv[0]);
}

int main(int argc, char * argv[])
{
    if (not parse_args(argc, argv))
    {
        synopsis(argc, argv);
        return EXIT_FAILURE;
    }

//    gg::VideoSourceFactory & source_fac = gg::VideoSourceFactory::get_instance();
//    IVideoSource * epiphan = source_fac.get_device(device, colour);

    FrameRateTimer timer;
//    epiphan->attach(timer);

//    std::this_thread::sleep_for(std::chrono::seconds(duration));

//    epiphan->detach(timer);

    float max_fr, min_fr, avg_fr;
    size_t n_timestamps;
    if (not timer.statistics(max_fr, min_fr, avg_fr, n_timestamps))
        return EXIT_FAILURE;

    timer.report(report_filename);

    return ( avg_fr >= frame_rate_to_check and
             min_fr >= frame_rate_to_check ) ? EXIT_SUCCESS : EXIT_FAILURE;
}
<commit_msg>Issue #117: implemented statistics function of FrameRateTimer<commit_after>#include "videosourcefactory.h"
#include "iobserver.h"
#include "iobservable.h"
#include <thread>
#include <chrono>
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>

gg::Device device;
gg::ColourSpace colour;
size_t test_duration; // seconds
float frame_rate_to_check;
std::string report_filename("");

using namespace std::chrono;
typedef std::vector< time_point<system_clock> > timestamps;

//!
//! \brief This gg::IObserver implementor
//! records a timestamp every time it is
//! updated.
//!
//! It can then be used to check the frame
//! rate of the gg::IObservable it was
//! attached to.
//!
class FrameRateTimer : public gg::IObserver
{
protected:
    timestamps _timestamps;

public:
    void update(gg::VideoFrame & frame) override
    {
        _timestamps.push_back(system_clock::now());
    }

    //!
    //! \brief Get statistics based on currently
    //! available timestamp collection
    //! \param max_frame_rate fps
    //! \param min_frame_rate fps
    //! \param avg_frame_rate fps
    //! \param n_timestamps
    //! \return \c true if timestamps are available
    //! AND meaningful, such that the computations
    //! can be carried out, \c false otherwise
    //!
    bool statistics(float & max_frame_rate,
                    float & min_frame_rate,
                    float & avg_frame_rate,
                    size_t & n_timestamps)
    {
        if (_timestamps.empty() or _timestamps.size() < 10)
            return false;

        n_timestamps = _timestamps.size();

        // unit: sec
        float min_duration = std::numeric_limits<float>::max(),
              max_duration = std::numeric_limits<float>::min(),
              sum_durations = 0.0;
        for (size_t i = 0; i < _timestamps.size() - 1; i++)
        {
            duration<float> difference = _timestamps[i + 1] - _timestamps[i];
            float cur_duration = difference.count();
            sum_durations += cur_duration;
            if (cur_duration < min_duration)
                min_duration = cur_duration;
            else if (cur_duration > max_duration)
                max_duration = cur_duration;
        }

        if (min_duration <= 0.0 or max_duration <= 0.0
            or sum_durations <= 0.0)
            return false;

        max_frame_rate = 1.0 / min_duration;
        min_frame_rate = 1.0 / max_duration;
        avg_frame_rate = (n_timestamps - 1) / sum_durations;

        return true;
    }

    //!
    //! \brief Output collected timestamps, as well
    //! as computed statistics to CSV file with \c
    //! filename
    //! \param filename nop if empty
    //! \sa statistics()
    //! \throw in case (non-empty) \c filename not
    //! pointing to a valid file, writeable by user
    //!
    void report(std::string filename)
    {
        // TODO
    }
};

bool parse_args(int argc, char * argv[])
{
    if (argc < 5)
        return false;

    if (std::strcmp(argv[1], "DVI") == 0)
        device = gg::DVI2PCIeDuo_DVI;
    else if (std::strcmp(argv[1], "SDI") == 0)
        device = gg::DVI2PCIeDuo_SDI;
    else
        return false;

    if (std::strcmp(argv[2], "BGRA") == 0)
        colour = gg::BGRA;
    else if (std::strcmp(argv[2], "I420") == 0)
        colour = gg::I420;
    else
        return false;

    int test_duration_ = std::atoi(argv[3]);
    if (test_duration_ <= 0)
        return false;
    else
        test_duration = test_duration_;

    double frame_rate_to_check_ = std::atof(argv[4]);
    if (frame_rate_to_check_ <= 0.0)
        return false;
    else
        frame_rate_to_check = frame_rate_to_check_;

    if (argc >= 6)
        report_filename = std::string(argv[5]);

    return true;
}

void synopsis(int argc, char * argv[])
{
    printf("%s  DVI | SDI  BGRA | I420  <test_duration>"
           "  <frame_rate_to_check>  [ <report_filename> ]"
           "\n",
           argv[0]);
}

int main(int argc, char * argv[])
{
    if (not parse_args(argc, argv))
    {
        synopsis(argc, argv);
        return EXIT_FAILURE;
    }

//    gg::VideoSourceFactory & source_fac = gg::VideoSourceFactory::get_instance();
//    IVideoSource * epiphan = source_fac.get_device(device, colour);

    FrameRateTimer timer;
//    epiphan->attach(timer);

//    std::this_thread::sleep_for(std::chrono::seconds(duration));

//    epiphan->detach(timer);

    float max_fr, min_fr, avg_fr;
    size_t n_timestamps;
    if (not timer.statistics(max_fr, min_fr, avg_fr, n_timestamps))
        return EXIT_FAILURE;

    timer.report(report_filename);

    return ( avg_fr >= frame_rate_to_check and
             min_fr >= frame_rate_to_check ) ? EXIT_SUCCESS : EXIT_FAILURE;
}
<|endoftext|>


<commit_before>#include "videosourcefactory.h"
#include "iobserver.h"
#include "iobservable.h"
#include <thread>
#include <chrono>
#include <iostream>
#include <cstring>

gg::Device device;
gg::ColourSpace colour;
size_t test_duration; // seconds
float frame_rate_to_check;
std::string report_filename("");

//!
//! \brief This gg::IObserver implementor
//! records a timestamp every time it is
//! updated.
//!
//! It can then be used to check the frame
//! rate of the gg::IObservable it was
//! attached to.
//!
class FrameRateTimer : public gg::IObserver
{
public:
    void update(gg::VideoFrame & frame) override
    {
        // TODO
    }

    //!
    //! \brief Get statistics based on currently
    //! available timestamp collection
    //! \param max_frame_rate fps
    //! \param min_frame_rate fps
    //! \param avg_frame_rate fps
    //! \param n_timestamps
    //! \return \c true if timestamps are available
    //! AND meaningful, such that the computations
    //! can be carried out, \c false otherwise
    //!
    bool statistics(float & max_frame_rate,
                    float & min_frame_rate,
                    float & avg_frame_rate,
                    size_t & n_timestamps)
    {
        // TODO
        return false;
    }

    //!
    //! \brief Output collected timestamps, as well
    //! as computed statistics to CSV file with \c
    //! filename
    //! \param filename nop if empty
    //! \sa statistics()
    //! \throw in case (non-empty) \c filename not
    //! pointing to a valid file, writeable by user
    //!
    void report(std::string filename)
    {
        // TODO
    }
};

bool parse_args(int argc, char * argv[])
{
    if (argc < 5)
        return false;

    if (std::strcmp(argv[1], "DVI") == 0)
        device = gg::DVI2PCIeDuo_DVI;
    else if (std::strcmp(argv[1], "SDI") == 0)
        device = gg::DVI2PCIeDuo_SDI;
    else
        return false;

    if (std::strcmp(argv[2], "BGRA") == 0)
        colour = gg::BGRA;
    else if (std::strcmp(argv[2], "I420") == 0)
        colour = gg::I420;
    else
        return false;

    int test_duration_ = std::atoi(argv[3]);
    if (test_duration_ <= 0)
        return false;
    else
        test_duration = test_duration_;

    double frame_rate_to_check_ = std::atof(argv[4]);
    if (frame_rate_to_check_ <= 0.0)
        return false;
    else
        frame_rate_to_check = frame_rate_to_check_;

    if (argc >= 6)
        report_filename = std::string(argv[5]);

    return true;
}

void synopsis(int argc, char * argv[])
{
    printf("%s  DVI | SDI  BGRA | I420  <test_duration>"
           "  <frame_rate_to_check>  [ <report_filename> ]"
           "\n",
           argv[0]);
}

int main(int argc, char * argv[])
{
    if (not parse_args(argc, argv))
    {
        synopsis(argc, argv);
        return EXIT_FAILURE;
    }

//    gg::VideoSourceFactory & source_fac = gg::VideoSourceFactory::get_instance();
//    IVideoSource * epiphan = source_fac.get_device(device, colour);

    FrameRateTimer timer;
//    epiphan->attach(timer);

//    std::this_thread::sleep_for(std::chrono::seconds(duration));

//    epiphan->detach(timer);

    float max_fr, min_fr, avg_fr;
    size_t n_timestamps;
    if (not timer.statistics(max_fr, min_fr, avg_fr, n_timestamps))
        return EXIT_FAILURE;

    timer.report(report_filename);

    return ( avg_fr >= frame_rate_to_check and
             min_fr >= frame_rate_to_check ) ? EXIT_SUCCESS : EXIT_FAILURE;
}
<commit_msg>Issue #117: added vector for collecting timestamps<commit_after>#include "videosourcefactory.h"
#include "iobserver.h"
#include "iobservable.h"
#include <thread>
#include <chrono>
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>

gg::Device device;
gg::ColourSpace colour;
size_t test_duration; // seconds
float frame_rate_to_check;
std::string report_filename("");

using namespace std::chrono;
typedef std::vector< time_point<system_clock> > timestamps;

//!
//! \brief This gg::IObserver implementor
//! records a timestamp every time it is
//! updated.
//!
//! It can then be used to check the frame
//! rate of the gg::IObservable it was
//! attached to.
//!
class FrameRateTimer : public gg::IObserver
{
protected:
    timestamps _timestamps;

public:
    void update(gg::VideoFrame & frame) override
    {
        // TODO
    }

    //!
    //! \brief Get statistics based on currently
    //! available timestamp collection
    //! \param max_frame_rate fps
    //! \param min_frame_rate fps
    //! \param avg_frame_rate fps
    //! \param n_timestamps
    //! \return \c true if timestamps are available
    //! AND meaningful, such that the computations
    //! can be carried out, \c false otherwise
    //!
    bool statistics(float & max_frame_rate,
                    float & min_frame_rate,
                    float & avg_frame_rate,
                    size_t & n_timestamps)
    {
        // TODO
        return false;
    }

    //!
    //! \brief Output collected timestamps, as well
    //! as computed statistics to CSV file with \c
    //! filename
    //! \param filename nop if empty
    //! \sa statistics()
    //! \throw in case (non-empty) \c filename not
    //! pointing to a valid file, writeable by user
    //!
    void report(std::string filename)
    {
        // TODO
    }
};

bool parse_args(int argc, char * argv[])
{
    if (argc < 5)
        return false;

    if (std::strcmp(argv[1], "DVI") == 0)
        device = gg::DVI2PCIeDuo_DVI;
    else if (std::strcmp(argv[1], "SDI") == 0)
        device = gg::DVI2PCIeDuo_SDI;
    else
        return false;

    if (std::strcmp(argv[2], "BGRA") == 0)
        colour = gg::BGRA;
    else if (std::strcmp(argv[2], "I420") == 0)
        colour = gg::I420;
    else
        return false;

    int test_duration_ = std::atoi(argv[3]);
    if (test_duration_ <= 0)
        return false;
    else
        test_duration = test_duration_;

    double frame_rate_to_check_ = std::atof(argv[4]);
    if (frame_rate_to_check_ <= 0.0)
        return false;
    else
        frame_rate_to_check = frame_rate_to_check_;

    if (argc >= 6)
        report_filename = std::string(argv[5]);

    return true;
}

void synopsis(int argc, char * argv[])
{
    printf("%s  DVI | SDI  BGRA | I420  <test_duration>"
           "  <frame_rate_to_check>  [ <report_filename> ]"
           "\n",
           argv[0]);
}

int main(int argc, char * argv[])
{
    if (not parse_args(argc, argv))
    {
        synopsis(argc, argv);
        return EXIT_FAILURE;
    }

//    gg::VideoSourceFactory & source_fac = gg::VideoSourceFactory::get_instance();
//    IVideoSource * epiphan = source_fac.get_device(device, colour);

    FrameRateTimer timer;
//    epiphan->attach(timer);

//    std::this_thread::sleep_for(std::chrono::seconds(duration));

//    epiphan->detach(timer);

    float max_fr, min_fr, avg_fr;
    size_t n_timestamps;
    if (not timer.statistics(max_fr, min_fr, avg_fr, n_timestamps))
        return EXIT_FAILURE;

    timer.report(report_filename);

    return ( avg_fr >= frame_rate_to_check and
             min_fr >= frame_rate_to_check ) ? EXIT_SUCCESS : EXIT_FAILURE;
}
<|endoftext|>


<commit_before>#include <ast/op-expr.hh>

namespace ast
{
    OpExpr::OpExpr(const yy::location& location,
                   Expr* lexpr,
                   OpExpr::Operator op,
                   Expr* rexpr)
        : Expr(location)
        , lexpr_(lexpr)
        , rexpr_(rexpr)
        , op_(op)
    {}

    OpExpr::~OpExpr()
    {
        delete lexpr_;
        delete rexpr_;
    }

    const Expr* OpExpr::left_expr_get() const
    {
        return lexpr_;
    }

    Expr* OpExpr::left_expr_get()
    {
        return lexpr_;
    }

    const Expr* OpExpr::right_expr_get() const
    {
        return rexpr_;
    }

    Expr* OpExpr::right_expr_get()
    {
        return rexpr_;
    }

    OpExpr::Operator OpExpr::op_get() const
    {
        return op_;
    }

    std::string OpExpr::op_to_string() const
    {
        switch (op_)
        {
            case PLUS:
                return "+";
            case MINUS:
                return "-";
            case MULT:
                return "*";
            case DIV:
                return "/";
            case FDIV:
                return "//";
            case MOD:
                return "%";
            case POW:
                return "**";
            case RSHIFT:
                return ">>";
            case LSHIFT:
                return "<<";
            case XOR:
                return "^";
            case BOOL_AND:
                return "and";
            case BOOL_OR:
                return "or";
            case BIT_AND:
                return "&";
            case BIT_OR:
                return "|";
            case EQ:
                return "==";
            case NEQ:
                return "!=";
            case GT:
                return ">";
            case GE:
                return ">=";
            case LT:
                return "<";
            case LE:
                return "<=";
            case IN:
                return "in";
            case IS:
                return "is";
            case NOT_IN:
                return "not in";
            case IS_NOT:
                return "is not";
        }

        return "";
    }

    std::string OpExpr::to_cpp() const
    {
        switch (op_)
        {
            case PLUS:
                return "__add__";
            case MINUS:
                return "__sub__";
            case MULT:
                return "__mul__";
            case DIV:
                return "__divmod__";
            case FDIV:
                return "__floordiv__";
            case MOD:
                return "__mod__";
            case POW:
                return "__pow__";
            case RSHIFT:
                return "__lshift__";
            case LSHIFT:
                return "__rshift__";
            case XOR:
                return "__xor__";
            case BIT_AND:
                return "__and__";
            case BIT_OR:
                return "__or__";
            case EQ:
                return "__eq__";
            case NEQ:
                return "__ne__";
            case GT:
                return "__gt__";
            case GE:
                return "__ge__";
            case LT:
                return "__lt__";
            case LE:
                return "__le__";
            default:
                assert(false && "Internal compiler error");
                break;
        }

        return "";
    }

    void OpExpr::set_left_expr(Expr* expr)
    {
        if (lexpr_ == nullptr)
        {
            lexpr_ = expr;
            return;
        }

        OpExpr* e = dynamic_cast<OpExpr*> (lexpr_);

        if (e)
            e->set_left_expr(expr);
    }

    void OpExpr::accept(Visitor& v)
    {
        v(*this);
    }

    void OpExpr::accept(ConstVisitor& v) const
    {
        v(*this);
    }
} // namespace ast
<commit_msg>[AST] Change operation C++ name of operators<commit_after>#include <ast/op-expr.hh>

namespace ast
{
    OpExpr::OpExpr(const yy::location& location,
                   Expr* lexpr,
                   OpExpr::Operator op,
                   Expr* rexpr)
        : Expr(location)
        , lexpr_(lexpr)
        , rexpr_(rexpr)
        , op_(op)
    {}

    OpExpr::~OpExpr()
    {
        delete lexpr_;
        delete rexpr_;
    }

    const Expr* OpExpr::left_expr_get() const
    {
        return lexpr_;
    }

    Expr* OpExpr::left_expr_get()
    {
        return lexpr_;
    }

    const Expr* OpExpr::right_expr_get() const
    {
        return rexpr_;
    }

    Expr* OpExpr::right_expr_get()
    {
        return rexpr_;
    }

    OpExpr::Operator OpExpr::op_get() const
    {
        return op_;
    }

    std::string OpExpr::op_to_string() const
    {
        switch (op_)
        {
            case PLUS:
                return "+";
            case MINUS:
                return "-";
            case MULT:
                return "*";
            case DIV:
                return "/";
            case FDIV:
                return "//";
            case MOD:
                return "%";
            case POW:
                return "**";
            case RSHIFT:
                return ">>";
            case LSHIFT:
                return "<<";
            case XOR:
                return "^";
            case BOOL_AND:
                return "and";
            case BOOL_OR:
                return "or";
            case BIT_AND:
                return "&";
            case BIT_OR:
                return "|";
            case EQ:
                return "==";
            case NEQ:
                return "!=";
            case GT:
                return ">";
            case GE:
                return ">=";
            case LT:
                return "<";
            case LE:
                return "<=";
            case IN:
                return "in";
            case IS:
                return "is";
            case NOT_IN:
                return "not in";
            case IS_NOT:
                return "is not";
        }

        return "";
    }

    std::string OpExpr::to_cpp() const
    {
        switch (op_)
        {
            case PLUS:
                return "__repy::__add__";
            case MINUS:
                return "__repy::__sub__";
            case MULT:
                return "__repy::__mul__";
            case DIV:
                return "__repy::__divmod__";
            case FDIV:
                return "__repy::__floordiv__";
            case MOD:
                return "__repy::__mod__";
            case POW:
                return "__repy::__pow__";
            case RSHIFT:
                return "__repy::__lshift__";
            case LSHIFT:
                return "__repy::__rshift__";
            case XOR:
                return "__repy::__xor__";
            case BIT_AND:
                return "__repy::__and__";
            case BIT_OR:
                return "__repy::__or__";
            case EQ:
                return "__repy::__eq__";
            case NEQ:
                return "__repy::__ne__";
            case GT:
                return "__repy::__gt__";
            case GE:
                return "__repy::__ge__";
            case LT:
                return "__repy::__lt__";
            case LE:
                return "__repy::__le__";
            default:
                assert(false && "Internal compiler error");
                break;
        }

        return "";
    }

    void OpExpr::set_left_expr(Expr* expr)
    {
        if (lexpr_ == nullptr)
        {
            lexpr_ = expr;
            return;
        }

        OpExpr* e = dynamic_cast<OpExpr*> (lexpr_);

        if (e)
            e->set_left_expr(expr);
    }

    void OpExpr::accept(Visitor& v)
    {
        v(*this);
    }

    void OpExpr::accept(ConstVisitor& v) const
    {
        v(*this);
    }
} // namespace ast
<|endoftext|>


<commit_before>/*
	Kopete , The KDE Instant Messenger

	Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <duncan@kde.org>

	Viva Chile Mierda!
	Started at Wed Dec 26 03:12:10 CLST 2001, Santiago de Chile

    Kopete    (c) 2002 by the Kopete developers  <kopete-devel@kde.org>

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

#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "kopete.h"

#include <dcopclient.h>
#include "kopeteiface.h"

static const char *description =
	I18N_NOOP("Kopete, the KDE Instant Messenger");

#define KOPETE_VERSION "0.5"

static KCmdLineOptions options[] =
{
  { 0, 0, 0 }
};

int main(int argc, char *argv[])
{
	KAboutData aboutData( "kopete", I18N_NOOP("Kopete"),
		KOPETE_VERSION, description, KAboutData::License_GPL,
		"(c) 2001,2002, Duncan Mac-Vicar Prett\n(c) 2002, The Kopete Development Team", "kopete-devel@kde.org", "http://kopete.kde.org");

	aboutData.addAuthor ( "Duncan Mac-Vicar Prett", I18N_NOOP("Original author, core developer"), "duncan@kde.org", "http://www.mac-vicar.com" );
	aboutData.addAuthor ( "Nick Betcher", I18N_NOOP("Core developer, fastest plugin developer on earth."), "nbetcher@kde.org", "http://www.kdedevelopers.net" );
	aboutData.addAuthor ( "Ryan Cumming", I18N_NOOP("Core developer"), "bodnar42@phalynx.dhs.org" );
	aboutData.addAuthor ( "Martijn Klingens", I18N_NOOP("Core developer"), "klingens@kde.org" );
	aboutData.addAuthor ( "Richard Stellingwerff", I18N_NOOP("Developer"), "remenic@linuxfromscratch.org");
	aboutData.addAuthor ( "Daniel Stone", I18N_NOOP("Core developer, Jabber plugin"), "dstone@kde.org", "http://raging.dropbear.id.au/daniel/");
	aboutData.addAuthor ( "Till Gerken", I18N_NOOP("Core developer, Jabber plugin"), "till@tantalo.net");
	aboutData.addAuthor ( "Olivier Goffart", I18N_NOOP("Core developer"), "ogoffart@tiscalinet.be");
	aboutData.addAuthor ( "Hendrik vom Lehn", I18N_NOOP("Developer"), "hennevl@hennevl.de", "http://www.hennevl.de");
	aboutData.addAuthor ( "Stefan Gehn", I18N_NOOP("Developer"), "sgehn@gmx.net", "http://metz81.mine.nu" );
	aboutData.addAuthor ( "Andres Krapf", I18N_NOOP("Developer"), "dae@chez.com" );
	aboutData.addAuthor ( "Gav Wood", I18N_NOOP("Winpopup plugin"), "gjw102@york.ac.uk" );
    aboutData.addAuthor ( "Zack Rusin", I18N_NOOP("Core developer, Gadu plugin"), "zack@kde.org" );

	aboutData.addCredit ( "Luciash d' Being", I18N_NOOP("Icon Author") );
	aboutData.addCredit ( "Vladimir Shutoff", I18N_NOOP("SIM icq library") );
    aboutData.addCredit ( "Herwin Jan Steehouwer", I18N_NOOP("KxEngine icq code") );
	aboutData.addCredit ( "Olaf Lueg", I18N_NOOP("Kmerlin MSN code") );
	aboutData.addCredit ( "Neil Stevens", I18N_NOOP("TAim engine AIM code") );
	aboutData.addCredit ( "Justin Karneges", I18N_NOOP("Psi Jabber code") );

	KCmdLineArgs::init( argc, argv, &aboutData );
	KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
	KUniqueApplication::addCmdLineOptions();

	Kopete kopete;
	kapp->dcopClient()->setDefaultObject( (new KopeteIface())->objId() ); // Has to be called before exec
	kopete.exec();
}
/*
 * Local variables:
 * c-indentation-style: k&r
 * c-basic-offset: 8
 * indent-tabs-mode: t
 * End:
 */
// vim: set noet ts=4 sts=4 sw=4:

<commit_msg>mention my small contributions<commit_after>/*
	Kopete , The KDE Instant Messenger

	Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <duncan@kde.org>

	Viva Chile Mierda!
	Started at Wed Dec 26 03:12:10 CLST 2001, Santiago de Chile

    Kopete    (c) 2002 by the Kopete developers  <kopete-devel@kde.org>

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

#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "kopete.h"

#include <dcopclient.h>
#include "kopeteiface.h"

static const char *description =
	I18N_NOOP("Kopete, the KDE Instant Messenger");

#define KOPETE_VERSION "0.5"

static KCmdLineOptions options[] =
{
  { 0, 0, 0 }
};

int main(int argc, char *argv[])
{
	KAboutData aboutData( "kopete", I18N_NOOP("Kopete"),
		KOPETE_VERSION, description, KAboutData::License_GPL,
		"(c) 2001,2002, Duncan Mac-Vicar Prett\n(c) 2002, The Kopete Development Team", "kopete-devel@kde.org", "http://kopete.kde.org");

	aboutData.addAuthor ( "Duncan Mac-Vicar Prett", I18N_NOOP("Original author, core developer"), "duncan@kde.org", "http://www.mac-vicar.com" );
	aboutData.addAuthor ( "Nick Betcher", I18N_NOOP("Core developer, fastest plugin developer on earth."), "nbetcher@kde.org", "http://www.kdedevelopers.net" );
	aboutData.addAuthor ( "Ryan Cumming", I18N_NOOP("Core developer"), "bodnar42@phalynx.dhs.org" );
	aboutData.addAuthor ( "Martijn Klingens", I18N_NOOP("Core developer"), "klingens@kde.org" );
	aboutData.addAuthor ( "Richard Stellingwerff", I18N_NOOP("Developer"), "remenic@linuxfromscratch.org");
	aboutData.addAuthor ( "Daniel Stone", I18N_NOOP("Core developer, Jabber plugin"), "dstone@kde.org", "http://raging.dropbear.id.au/daniel/");
	aboutData.addAuthor ( "Till Gerken", I18N_NOOP("Core developer, Jabber plugin"), "till@tantalo.net");
	aboutData.addAuthor ( "Olivier Goffart", I18N_NOOP("Core developer"), "ogoffart@tiscalinet.be");
	aboutData.addAuthor ( "Hendrik vom Lehn", I18N_NOOP("Developer"), "hennevl@hennevl.de", "http://www.hennevl.de");
	aboutData.addAuthor ( "Stefan Gehn", I18N_NOOP("Developer"), "sgehn@gmx.net", "http://metz81.mine.nu" );
	aboutData.addAuthor ( "Andres Krapf", I18N_NOOP("Developer"), "dae@chez.com" );
	aboutData.addAuthor ( "Gav Wood", I18N_NOOP("Winpopup plugin"), "gjw102@york.ac.uk" );
    aboutData.addAuthor ( "Zack Rusin", I18N_NOOP("Core developer, Gadu plugin"), "zack@kde.org" );
	aboutData.addAuthor ( "Carsten Pfeiffer", I18N_NOOP("Misc Bugfixes and Enhancelets"), "pfeiffer@kde.org" );

	aboutData.addCredit ( "Luciash d' Being", I18N_NOOP("Icon Author") );
	aboutData.addCredit ( "Vladimir Shutoff", I18N_NOOP("SIM icq library") );
    aboutData.addCredit ( "Herwin Jan Steehouwer", I18N_NOOP("KxEngine icq code") );
	aboutData.addCredit ( "Olaf Lueg", I18N_NOOP("Kmerlin MSN code") );
	aboutData.addCredit ( "Neil Stevens", I18N_NOOP("TAim engine AIM code") );
	aboutData.addCredit ( "Justin Karneges", I18N_NOOP("Psi Jabber code") );

	KCmdLineArgs::init( argc, argv, &aboutData );
	KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
	KUniqueApplication::addCmdLineOptions();

	Kopete kopete;
	kapp->dcopClient()->setDefaultObject( (new KopeteIface())->objId() ); // Has to be called before exec
	kopete.exec();
}
/*
 * Local variables:
 * c-indentation-style: k&r
 * c-basic-offset: 8
 * indent-tabs-mode: t
 * End:
 */
// vim: set noet ts=4 sts=4 sw=4:

<|endoftext|>


<commit_before>/*
    Kopete , The KDE Instant Messenger
    Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <duncan@kde.org>

    Viva Chile Mierda!
    Started at Wed Dec 26 03:12:10 CLST 2001, Santiago de Chile

    Kopete    (c) 2002 by the Kopete developers  <kopete-devel@kde.org>

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

#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "kopete.h"

#include <dcopclient.h>
#include "kopeteiface.h"

static const char *description =
	I18N_NOOP("Kopete, the KDE Instant Messenger");

#define KOPETE_VERSION "0.5.8cvs >= 20021020"

static KCmdLineOptions options[] =
{
  { 0, 0, 0 }
};

int main(int argc, char *argv[])
{
	KAboutData aboutData( "kopete", I18N_NOOP("Kopete"),
		KOPETE_VERSION, description, KAboutData::License_GPL,
		"(c) 2001,2002, Duncan Mac-Vicar Prett\n(c) 2002, The Kopete Development Team", "kopete-devel@kde.org", "http://kopete.kde.org");

	aboutData.addAuthor ( "Duncan Mac-Vicar Prett", I18N_NOOP("Original author, core developer"), "duncan@kde.org", "http://www.mac-vicar.com" );
	aboutData.addAuthor ( "Nick Betcher", I18N_NOOP("Core developer, fastest plugin developer on earth."), "nbetcher@kde.org", "http://www.kdedevelopers.net" );
	aboutData.addAuthor ( "Ryan Cumming", I18N_NOOP("Core developer"), "ryan@kde.org" );
	aboutData.addAuthor ( "Martijn Klingens", I18N_NOOP("Core developer"), "klingens@kde.org" );
	aboutData.addAuthor ( "Richard Stellingwerff", I18N_NOOP("Developer"), "remenic@linuxfromscratch.org");
	aboutData.addAuthor ( "Daniel Stone", I18N_NOOP("Core developer, Jabber plugin"), "dstone@kde.org", "http://raging.dropbear.id.au/daniel/");
	aboutData.addAuthor ( "Till Gerken", I18N_NOOP("Core developer, Jabber plugin"), "till@tantalo.net");
	aboutData.addAuthor ( "Olivier Goffart", I18N_NOOP("Core developer"), "ogoffart@tiscalinet.be");
	aboutData.addAuthor ( "Hendrik vom Lehn", I18N_NOOP("Developer"), "hennevl@hennevl.de", "http://www.hennevl.de");
	aboutData.addAuthor ( "Stefan Gehn", I18N_NOOP("Developer"), "metz@gehn.net", "http://metz.gehn.net" );
	aboutData.addAuthor ( "Andres Krapf", I18N_NOOP("Developer"), "dae@chez.com" );
	aboutData.addAuthor ( "Gav Wood", I18N_NOOP("Winpopup plugin"), "gjw102@york.ac.uk" );
	aboutData.addAuthor ( "Zack Rusin", I18N_NOOP("Core developer, Gadu plugin"), "zack@kde.org" );
	aboutData.addAuthor ( "Carsten Pfeiffer", I18N_NOOP("Misc Bugfixes and Enhancelets"), "pfeiffer@kde.org" );

	aboutData.addCredit ( "Luciash d' Being", I18N_NOOP("Icon Author") );
	aboutData.addCredit ( "Vladimir Shutoff", I18N_NOOP("SIM icq library") );
	aboutData.addCredit ( "Herwin Jan Steehouwer", I18N_NOOP("KxEngine icq code") );
	aboutData.addCredit ( "Olaf Lueg", I18N_NOOP("Kmerlin MSN code") );
	aboutData.addCredit ( "Neil Stevens", I18N_NOOP("TAim engine AIM code") );
	aboutData.addCredit ( "Justin Karneges", I18N_NOOP("Psi Jabber code") );

	KCmdLineArgs::init( argc, argv, &aboutData );
	KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
	KUniqueApplication::addCmdLineOptions();

	Kopete kopete;
	kapp->dcopClient()->setDefaultObject( (new KopeteIface())->objId() ); // Has to be called before exec
	kopete.exec();
}
/*
 * Local variables:
 * c-indentation-style: k&r
 * c-basic-offset: 8
 * indent-tabs-mode: t
 * End:
 */
// vim: set noet ts=4 sts=4 sw=4:

<commit_msg>oops, forgot something<commit_after>/*
    Kopete , The KDE Instant Messenger
    Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <duncan@kde.org>

    Viva Chile Mierda!
    Started at Wed Dec 26 03:12:10 CLST 2001, Santiago de Chile

    Kopete    (c) 2002 by the Kopete developers  <kopete-devel@kde.org>

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

#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "kopete.h"

#include <dcopclient.h>
#include "kopeteiface.h"

static const char *description =
	I18N_NOOP("Kopete, the KDE Instant Messenger");

#define KOPETE_VERSION "0.5.8cvs >= 20021020"

static KCmdLineOptions options[] =
{
	{ "noplugins", I18N_NOOP("Do not load plugins"), 0 },
	{ 0, 0, 0 }
};

int main(int argc, char *argv[])
{
	KAboutData aboutData( "kopete", I18N_NOOP("Kopete"),
		KOPETE_VERSION, description, KAboutData::License_GPL,
		"(c) 2001,2002, Duncan Mac-Vicar Prett\n(c) 2002, The Kopete Development Team", "kopete-devel@kde.org", "http://kopete.kde.org");

	aboutData.addAuthor ( "Duncan Mac-Vicar Prett", I18N_NOOP("Original author, core developer"), "duncan@kde.org", "http://www.mac-vicar.com" );
	aboutData.addAuthor ( "Nick Betcher", I18N_NOOP("Core developer, fastest plugin developer on earth."), "nbetcher@kde.org", "http://www.kdedevelopers.net" );
	aboutData.addAuthor ( "Ryan Cumming", I18N_NOOP("Core developer"), "ryan@kde.org" );
	aboutData.addAuthor ( "Martijn Klingens", I18N_NOOP("Core developer"), "klingens@kde.org" );
	aboutData.addAuthor ( "Richard Stellingwerff", I18N_NOOP("Developer"), "remenic@linuxfromscratch.org");
	aboutData.addAuthor ( "Daniel Stone", I18N_NOOP("Core developer, Jabber plugin"), "dstone@kde.org", "http://raging.dropbear.id.au/daniel/");
	aboutData.addAuthor ( "Till Gerken", I18N_NOOP("Core developer, Jabber plugin"), "till@tantalo.net");
	aboutData.addAuthor ( "Olivier Goffart", I18N_NOOP("Core developer"), "ogoffart@tiscalinet.be");
	aboutData.addAuthor ( "Hendrik vom Lehn", I18N_NOOP("Developer"), "hennevl@hennevl.de", "http://www.hennevl.de");
	aboutData.addAuthor ( "Stefan Gehn", I18N_NOOP("Developer"), "metz@gehn.net", "http://metz.gehn.net" );
	aboutData.addAuthor ( "Andres Krapf", I18N_NOOP("Developer"), "dae@chez.com" );
	aboutData.addAuthor ( "Gav Wood", I18N_NOOP("Winpopup plugin"), "gjw102@york.ac.uk" );
	aboutData.addAuthor ( "Zack Rusin", I18N_NOOP("Core developer, Gadu plugin"), "zack@kde.org" );
	aboutData.addAuthor ( "Carsten Pfeiffer", I18N_NOOP("Misc Bugfixes and Enhancelets"), "pfeiffer@kde.org" );

	aboutData.addCredit ( "Luciash d' Being", I18N_NOOP("Icon Author") );
	aboutData.addCredit ( "Vladimir Shutoff", I18N_NOOP("SIM icq library") );
	aboutData.addCredit ( "Herwin Jan Steehouwer", I18N_NOOP("KxEngine icq code") );
	aboutData.addCredit ( "Olaf Lueg", I18N_NOOP("Kmerlin MSN code") );
	aboutData.addCredit ( "Neil Stevens", I18N_NOOP("TAim engine AIM code") );
	aboutData.addCredit ( "Justin Karneges", I18N_NOOP("Psi Jabber code") );

	KCmdLineArgs::init( argc, argv, &aboutData );
	KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
	KUniqueApplication::addCmdLineOptions();

	Kopete kopete;
	kapp->dcopClient()->setDefaultObject( (new KopeteIface())->objId() ); // Has to be called before exec
	kopete.exec();
}
/*
 * Local variables:
 * c-indentation-style: k&r
 * c-basic-offset: 8
 * indent-tabs-mode: t
 * End:
 */
// vim: set noet ts=4 sts=4 sw=4:

<|endoftext|>


<commit_before>/*
Copyright (C) 2017 - Gbor "Razzie" Grzsny
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
*/

#include <Box2D/Box2D.h>
#include "common/GameObjectState.hpp"
#include "gameworld/GameObject.hpp"

void GameObject::fill(GameObjectState& state) const
{
	state.player_id = player_id;
	state.object_id = object_id;
	state.position_x = body->GetPosition().x;
	state.position_y = body->GetPosition().y;
	state.radius = radius;
	state.velocity_x = body->GetLinearVelocity().x;
	state.velocity_y = body->GetLinearVelocity().y;
}

void GameObject::apply(const GameObjectState& state)
{
	b2Vec2 position(state.position_x, state.position_y);
	b2Vec2 velocity(state.velocity_x, state.velocity_y);

	if ((position - body->GetPosition()).LengthSquared() > velocity.LengthSquared() * 0.25f)
		body->SetTransform(position, 0.f);

	body->SetLinearVelocity(velocity);
}
<commit_msg>Better syncing of black game objects<commit_after>/*
Copyright (C) 2017 - Gbor "Razzie" Grzsny
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
*/

#include <Box2D/Box2D.h>
#include "common/Config.hpp"
#include "common/GameObjectState.hpp"
#include "gameworld/GameObject.hpp"

void GameObject::fill(GameObjectState& state) const
{
	state.player_id = player_id;
	state.object_id = object_id;
	state.position_x = body->GetPosition().x;
	state.position_y = body->GetPosition().y;
	state.radius = radius;
	state.velocity_x = body->GetLinearVelocity().x;
	state.velocity_y = body->GetLinearVelocity().y;

	if (player_id == 0 && creation > std::chrono::steady_clock::now() - std::chrono::milliseconds(GAME_SYNC_RATE))
	{
		state.position_x = root_position_x;
		state.position_y = root_position_y;
	}
}

void GameObject::apply(const GameObjectState& state)
{
	b2Vec2 position(state.position_x, state.position_y);
	b2Vec2 velocity(state.velocity_x, state.velocity_y);

	if ((position - body->GetPosition()).LengthSquared() > velocity.LengthSquared() * 0.25f)
		body->SetTransform(position, 0.f);

	body->SetLinearVelocity(velocity);
}
<|endoftext|>