<commit_before>#include "kglpainter.h"
#include <math.h>
#include <QtCore/QDebug>
class KGLPainterPrivate
{
public :
        QColor color;
float lineWidth;
float pointSize;
GLenum polygonMode;
KGLPointList pointList;

};
KGLPainter::KGLPainter(QObject * parent)
    :QObject(parent)
{
    d = new KGLPainterPrivate;
    d->color = Qt::white;
    d->lineWidth = 1;
    d->pointSize = 1;
}

KGLPainter::~KGLPainter()
{
    delete d;
}

//============Parameter Function
void KGLPainter::setColor(const QColor &col){
    d->color = col;
}
void KGLPainter::setLineWidth(float width){
    d->lineWidth = width;

}
void KGLPainter::setPointSize(float size){
    d->pointSize=size;
    glPointSize(d->pointSize);
}
void KGLPainter::setPolygonMode(GLenum mode){
    d->polygonMode = mode;
    glPolygonMode(GL_FRONT_AND_BACK,mode);
}
void KGLPainter::createRect(const QRectF &rect)
{
    d->pointList.clear();
    d->pointList.append(KGLPoint(rect.x(), rect.y(),d->color,QPointF(0 , 0)));
    d->pointList.append(KGLPoint(rect.x() + rect.width(), rect.y(),d->color, QPointF(1 , 0)));
    d->pointList.append(KGLPoint(rect.x() + rect.width(), rect.y() + rect.height(),d->color, QPointF(1 , 1)));
    d->pointList.append(KGLPoint(rect.x(), rect.y() + rect.height(),d->color, QPointF(0 , 1)));

}
void KGLPainter::createRect(float x, float y, float w, float h){
    createRect(QRectF(x,y,w,h));}

void KGLPainter::createLine(const QLineF &line )
{

    d->pointList.clear();
    d->pointList.append(KGLPoint(line.x1(), line.y1(),Qt::white));
    d->pointList.append(KGLPoint(line.x2(), line.y2(),Qt::white));

}
void KGLPainter::createLine(float x1, float y1, float x2, float y2){
    createLine(QLineF(x1,y1,x2,y2));
}

void KGLPainter::createCircle(const QPointF &center, float radius, float step)
{
    if ( step <3)
    {
        qDebug()<<"cannot create it. Use createline...";
        return;
    }
    d->pointList.clear();
    d->pointList.append(
            KGLPoint(center.x(),center.y(),d->color,QPointF(center.x() ,center.y())));

    float radStep = 2*M_PI/step;

    for(float i=0; i<=2*M_PI+1; i+=radStep)
    {
        float cosr = (float)cos(i);
        float sinr = (float)sin(i);

        float x = cosr*radius + center.x();
        float y = sinr*radius + center.y();
        d->pointList.append(KGLPoint(x,y,d->color,QPointF(cosr ,sinr)));
    }

}
void KGLPainter::createCircle(float cx, float cy, float radius, float step){
    createCircle(QPointF(cx,cy),radius,step);
}
void KGLPainter::createPolygon(const QPolygonF & polygon)
{
    d->pointList.clear();
    foreach(QPointF p, polygon)
        d->pointList.append(KGLPoint(p.x(),p.y(),d->color,QPointF(p.x() ,p.y())));
}
void KGLPainter::draw(GLenum mode)
{
    glLineWidth(d->lineWidth);
    glPointSize(d->pointSize);
    glPolygonMode(GL_FRONT_AND_BACK,d->polygonMode);

    /*enable client state */
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    /* send data */
    glVertexPointer(2, GL_FLOAT,sizeof(KGLPoint),d->pointList.vertexStart());
    glTexCoordPointer(2,GL_FLOAT,sizeof(KGLPoint),d->pointList.texCoordStart());
    glColorPointer(4, GL_FLOAT,sizeof(KGLPoint),d->pointList.colorStart());

    //    /* create vertex */
    glDrawArrays(mode, 0, d->pointList.size());

    /* disable client state */
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

    glLineWidth(1);
    glPointSize(1);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
}

void KGLPainter::drawRect(const QRectF &rect){
    createRect(rect);
    draw(GL_POLYGON);
}
void KGLPainter::drawRect(float x, float y, float w, float h){
    createRect(x,y,w,h);
    draw(GL_POLYGON);
}
void KGLPainter::drawLine(const QLineF &line){
    createLine(line);
    draw(GL_LINE);

}
void KGLPainter::drawLine(float x1, float y1, float x2, float y2){
    createLine(x1,y1,x2,y2);
    draw(GL_LINE);
}
void KGLPainter::drawPoint(const QPointF &point){
    glBegin(GL_POINT);
    glVertex2d(point.x(),point.y());
    glEnd();
}
void KGLPainter::drawPoint(float x, float y){
    glBegin(GL_POINT);
    glVertex2d(x,y);
    glEnd();

}
void KGLPainter::drawCircle(const QPointF &center, float radius, float step){
    createCircle(center,radius,step);
    draw(GL_TRIANGLE_FAN);
}
void KGLPainter::drawCircle(float cx,float cy, float radius, float step ){
    createCircle(cx,cy,radius,step);
    draw(GL_TRIANGLE_FAN);
}
void KGLPainter::drawPolygon(const QPolygonF & polygon){
    createPolygon(polygon);
    draw(GL_POLYGON);

}

#include "kglpainter.cpp"
<commit_msg>KGL: includes kglpainter.moc instead of kglpainter.cpp at the end of the file, prevent it from infinitely including itself<commit_after>#include "kglpainter.h"
#include <math.h>
#include <QtCore/QDebug>
class KGLPainterPrivate
{
public :
        QColor color;
float lineWidth;
float pointSize;
GLenum polygonMode;
KGLPointList pointList;

};
KGLPainter::KGLPainter(QObject * parent)
    :QObject(parent)
{
    d = new KGLPainterPrivate;
    d->color = Qt::white;
    d->lineWidth = 1;
    d->pointSize = 1;
}

KGLPainter::~KGLPainter()
{
    delete d;
}

//============Parameter Function
void KGLPainter::setColor(const QColor &col){
    d->color = col;
}
void KGLPainter::setLineWidth(float width){
    d->lineWidth = width;

}
void KGLPainter::setPointSize(float size){
    d->pointSize=size;
    glPointSize(d->pointSize);
}
void KGLPainter::setPolygonMode(GLenum mode){
    d->polygonMode = mode;
    glPolygonMode(GL_FRONT_AND_BACK,mode);
}
void KGLPainter::createRect(const QRectF &rect)
{
    d->pointList.clear();
    d->pointList.append(KGLPoint(rect.x(), rect.y(),d->color,QPointF(0 , 0)));
    d->pointList.append(KGLPoint(rect.x() + rect.width(), rect.y(),d->color, QPointF(1 , 0)));
    d->pointList.append(KGLPoint(rect.x() + rect.width(), rect.y() + rect.height(),d->color, QPointF(1 , 1)));
    d->pointList.append(KGLPoint(rect.x(), rect.y() + rect.height(),d->color, QPointF(0 , 1)));

}
void KGLPainter::createRect(float x, float y, float w, float h){
    createRect(QRectF(x,y,w,h));}

void KGLPainter::createLine(const QLineF &line )
{

    d->pointList.clear();
    d->pointList.append(KGLPoint(line.x1(), line.y1(),Qt::white));
    d->pointList.append(KGLPoint(line.x2(), line.y2(),Qt::white));

}
void KGLPainter::createLine(float x1, float y1, float x2, float y2){
    createLine(QLineF(x1,y1,x2,y2));
}

void KGLPainter::createCircle(const QPointF &center, float radius, float step)
{
    if ( step <3)
    {
        qDebug()<<"cannot create it. Use createline...";
        return;
    }
    d->pointList.clear();
    d->pointList.append(
            KGLPoint(center.x(),center.y(),d->color,QPointF(center.x() ,center.y())));

    float radStep = 2*M_PI/step;

    for(float i=0; i<=2*M_PI+1; i+=radStep)
    {
        float cosr = (float)cos(i);
        float sinr = (float)sin(i);

        float x = cosr*radius + center.x();
        float y = sinr*radius + center.y();
        d->pointList.append(KGLPoint(x,y,d->color,QPointF(cosr ,sinr)));
    }

}
void KGLPainter::createCircle(float cx, float cy, float radius, float step){
    createCircle(QPointF(cx,cy),radius,step);
}
void KGLPainter::createPolygon(const QPolygonF & polygon)
{
    d->pointList.clear();
    foreach(QPointF p, polygon)
        d->pointList.append(KGLPoint(p.x(),p.y(),d->color,QPointF(p.x() ,p.y())));
}
void KGLPainter::draw(GLenum mode)
{
    glLineWidth(d->lineWidth);
    glPointSize(d->pointSize);
    glPolygonMode(GL_FRONT_AND_BACK,d->polygonMode);

    /*enable client state */
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    /* send data */
    glVertexPointer(2, GL_FLOAT,sizeof(KGLPoint),d->pointList.vertexStart());
    glTexCoordPointer(2,GL_FLOAT,sizeof(KGLPoint),d->pointList.texCoordStart());
    glColorPointer(4, GL_FLOAT,sizeof(KGLPoint),d->pointList.colorStart());

    //    /* create vertex */
    glDrawArrays(mode, 0, d->pointList.size());

    /* disable client state */
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

    glLineWidth(1);
    glPointSize(1);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
}

void KGLPainter::drawRect(const QRectF &rect){
    createRect(rect);
    draw(GL_POLYGON);
}
void KGLPainter::drawRect(float x, float y, float w, float h){
    createRect(x,y,w,h);
    draw(GL_POLYGON);
}
void KGLPainter::drawLine(const QLineF &line){
    createLine(line);
    draw(GL_LINE);

}
void KGLPainter::drawLine(float x1, float y1, float x2, float y2){
    createLine(x1,y1,x2,y2);
    draw(GL_LINE);
}
void KGLPainter::drawPoint(const QPointF &point){
    glBegin(GL_POINT);
    glVertex2d(point.x(),point.y());
    glEnd();
}
void KGLPainter::drawPoint(float x, float y){
    glBegin(GL_POINT);
    glVertex2d(x,y);
    glEnd();

}
void KGLPainter::drawCircle(const QPointF &center, float radius, float step){
    createCircle(center,radius,step);
    draw(GL_TRIANGLE_FAN);
}
void KGLPainter::drawCircle(float cx,float cy, float radius, float step ){
    createCircle(cx,cy,radius,step);
    draw(GL_TRIANGLE_FAN);
}
void KGLPainter::drawPolygon(const QPolygonF & polygon){
    createPolygon(polygon);
    draw(GL_POLYGON);

}

#include "kglpainter.moc"

<|endoftext|>


<commit_before>#include "core.h"
#include "chip.h"

#include "network.h"
#include "ocache.h"
#include "syscall_model.h"
#include "sync_client.h"
#include "network_types.h"
#include "memory_manager.h"

#include "log.h"
#define LOG_DEFAULT_RANK   core_tid
#define LOG_DEFAULT_MODULE CORE

// externally defined vars

extern LEVEL_BASE::KNOB<Boolean> g_knob_enable_performance_modeling;
extern LEVEL_BASE::KNOB<Boolean> g_knob_enable_dcache_modeling;
extern LEVEL_BASE::KNOB<Boolean> g_knob_enable_icache_modeling;

extern LEVEL_BASE::KNOB<UInt32> g_knob_cache_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_line_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_associativity;
extern LEVEL_BASE::KNOB<UInt32> g_knob_mutation_interval;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_threshold_hit;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_threshold_miss;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_associativity;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_max_search_depth;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_threshold_hit;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_threshold_miss;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_associativity;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_max_search_depth;

using namespace std;

int Core::coreInit(int tid, int num_mod)
{
   core_tid = tid;
   core_num_mod = num_mod;

   network = new Network(this);

   if ( g_knob_enable_performance_modeling )
   {
      perf_model = new PerfModel("performance modeler");
      LOG_PRINT("Instantiated performance model.");
   } else
   {
      perf_model = (PerfModel *) NULL;
   }

   if ( g_knob_enable_dcache_modeling || g_knob_enable_icache_modeling )
   {
		ocache = new OCache("organic cache",
                          g_knob_cache_size.Value() * k_KILO,
                          g_knob_line_size.Value(),
                          g_knob_associativity.Value(),
                          g_knob_mutation_interval.Value(),
                          g_knob_dcache_threshold_hit.Value(),
                          g_knob_dcache_threshold_miss.Value(),
                          g_knob_dcache_size.Value() * k_KILO,
                          g_knob_dcache_associativity.Value(),
                          g_knob_dcache_max_search_depth.Value(),
                          g_knob_icache_threshold_hit.Value(),
                          g_knob_icache_threshold_miss.Value(),
                          g_knob_icache_size.Value() * k_KILO,
                          g_knob_icache_associativity.Value(),
                          g_knob_icache_max_search_depth.Value());

     	LOG_PRINT("instantiated organic cache model");

	} else
   {
      ocache = (OCache *) NULL;
   }

   if ( g_config->isSimulatingSharedMemory() ) {

      assert( g_knob_enable_dcache_modeling );

      LOG_PRINT("instantiated memory manager model");
      memory_manager = new MemoryManager(this, ocache);

   } else {

      memory_manager = (MemoryManager *) NULL;
      LOG_PRINT("No Memory Manager being used");

   }

   syscall_model = new SyscallMdl(network);
//   InitLock(&dcache_lock);
   sync_client = new SyncClient(this);

   return 0;
}

int Core::coreSendW(int sender, int receiver, char *buffer, int size)
{
   // Create a net packet
   NetPacket packet;
   packet.sender= sender;
   packet.receiver= receiver;
   packet.type = USER;
   packet.length = size;
   packet.data = buffer;

   /*
   packet.data = new char[size];
   for(int i = 0; i < size; i++)
      packet.data[i] = buffer[i];
   */

   SInt32 sent = network->netSend(packet);

   assert(sent == size);

   return sent == size ? 0 : -1;
}

int Core::coreRecvW(int sender, int receiver, char *buffer, int size)
{
   NetPacket packet;
   NetMatch match;

   match.senders.push_back(sender);
   match.types.push_back(USER);

   packet = network->netRecv(match);

   LOG_PRINT("Got packet: from %i, to %i, type %i, len %i", packet.sender, packet.receiver, (SInt32)packet.type, packet.length);

   assert((unsigned)size == packet.length);

   memcpy(buffer, packet.data, size);

   // De-allocate dynamic memory
   // Is this the best place to de-allocate packet.data ??
   delete [] (Byte*)packet.data;

   return (unsigned)size == packet.length ? 0 : -1;
}

void Core::fini(int code, void *v, ostream& out)
{
   if ( g_knob_enable_performance_modeling )
     {
        out << "General:\n";
        perf_model->fini(code, v, out);
        network->outputSummary(out);
     }

   if ( g_knob_enable_dcache_modeling || g_knob_enable_icache_modeling )
      ocache->fini(code,v,out);

   delete sync_client;
   delete syscall_model;
   delete ocache;
   delete perf_model;
   delete network;
}

// organic cache wrappers

bool Core::icacheRunLoadModel(IntPtr i_addr, UInt32 size)
{ return ocache->runICacheLoadModel(i_addr, size).first; }

/*
 * dcacheRunModel (mem_operation_t operation, IntPtr d_addr, char* data_buffer, UInt32 data_size)
 *
 * Arguments:
 *   d_addr :: address of location we want to access (read or write)
 *   shmem_req_t :: READ or WRITE
 *   data_buffer :: buffer holding data for WRITE or buffer which must be written on a READ
 *   data_size :: size of data we must read/write
 *
 * Return Value:
 *   hit :: Say whether there has been at least one cache hit or not
 */
bool Core::dcacheRunModel(mem_operation_t operation, IntPtr d_addr, char* data_buffer, UInt32 data_size)
{
	shmem_req_t shmem_operation;

	if (operation == LOAD) {
		shmem_operation = READ;
	}
	else {
		shmem_operation = WRITE;
	}

	if (g_config->isSimulatingSharedMemory()) {
                LOG_PRINT("%s - ADDR: %x, data_size: %u, END!!", ((operation==LOAD) ? " READ " : " WRITE "), d_addr, data_size);

		bool all_hits = true;

		if (data_size <= 0) {
			return (true);
			// TODO: this is going to affect the statistics even though no shared_mem action is taking place
		}

		IntPtr begin_addr = d_addr;
		IntPtr end_addr = d_addr + data_size;
	  	IntPtr begin_addr_aligned = begin_addr - (begin_addr % ocache->dCacheLineSize());
		IntPtr end_addr_aligned = end_addr - (end_addr % ocache->dCacheLineSize());
		char *curr_data_buffer_head = data_buffer;

		//TODO set the size parameter correctly, based on the size of the data buffer
		//TODO does this spill over to another line? should shared_mem test look at other DRAM entries?
		for (IntPtr curr_addr_aligned = begin_addr_aligned ; curr_addr_aligned <= end_addr_aligned /* Note <= */; curr_addr_aligned += ocache->dCacheLineSize())
		{
			// Access the cache one line at a time
			UInt32 curr_offset;
			UInt32 curr_size;

			// Determine the offset
			// TODO fix curr_size calculations
			// FIXME: Check if all this is correct
			if (curr_addr_aligned == begin_addr_aligned) {
				curr_offset = begin_addr % ocache->dCacheLineSize();
			}
			else {
				curr_offset = 0;
			}

			// Determine the size
			if (curr_addr_aligned == end_addr_aligned) {
				curr_size = (end_addr % ocache->dCacheLineSize()) - (curr_offset);
				if (curr_size == 0) {
					continue;
				}
			}
			else {
				curr_size = ocache->dCacheLineSize() - (curr_offset);
			}

                        LOG_PRINT("Start InitiateSharedMemReq: ADDR: %x, offset: %u, curr_size: %u", curr_addr_aligned, curr_offset, curr_size);

			if (!memory_manager->initiateSharedMemReq(shmem_operation, curr_addr_aligned, curr_offset, curr_data_buffer_head, curr_size)) {
				// If it is a LOAD operation, 'initiateSharedMemReq' causes curr_data_buffer_head to be automatically filled in
				// If it is a STORE operation, 'initiateSharedMemReq' reads the data from curr_data_buffer_head
				all_hits = false;
			}

                        LOG_PRINT("End InitiateSharedMemReq: ADDR: %u, offset: %u, curr_size: %u", curr_addr_aligned, curr_offset, curr_size);

			// Increment the buffer head
			curr_data_buffer_head += curr_size;
		}

                LOG_PRINT("%s - ADDR: %x, data_size: %u, END!!", ((operation==LOAD) ? " READ " : " WRITE "), d_addr, data_size);

		return all_hits;

	}
	else
	{
	   // run this if we aren't using shared_memory
		// FIXME: I am not sure this is right
		// What if the initial data for this address is in some other core's DRAM (which is on some other host machine)
		if(operation == LOAD)
			return ocache->runDCacheLoadModel(d_addr, data_size).first;
		else
			return ocache->runDCacheStoreModel(d_addr, data_size).first;
   }
}

void Core::debugSetCacheState(IntPtr address, CacheState::cstate_t cstate, char *c_data)
{
	memory_manager->debugSetCacheState(address, cstate, c_data);
}

bool Core::debugAssertCacheState(IntPtr address, CacheState::cstate_t expected_cstate, char *expected_data)
{
	return memory_manager->debugAssertCacheState(address, expected_cstate, expected_data);
}

void Core::debugSetDramState(IntPtr address, DramDirectoryEntry::dstate_t dstate, vector<UInt32> sharers_list, char *d_data)
{
	memory_manager->debugSetDramState(address, dstate, sharers_list, d_data);
}

bool Core::debugAssertDramState(IntPtr address, DramDirectoryEntry::dstate_t dstate, vector<UInt32> sharers_list, char *d_data)
{
	return memory_manager->debugAssertDramState(address, dstate, sharers_list, d_data);
}

<commit_msg>[core] Fix a log message format.<commit_after>#include "core.h"
#include "chip.h"

#include "network.h"
#include "ocache.h"
#include "syscall_model.h"
#include "sync_client.h"
#include "network_types.h"
#include "memory_manager.h"

#include "log.h"
#define LOG_DEFAULT_RANK   core_tid
#define LOG_DEFAULT_MODULE CORE

// externally defined vars

extern LEVEL_BASE::KNOB<Boolean> g_knob_enable_performance_modeling;
extern LEVEL_BASE::KNOB<Boolean> g_knob_enable_dcache_modeling;
extern LEVEL_BASE::KNOB<Boolean> g_knob_enable_icache_modeling;

extern LEVEL_BASE::KNOB<UInt32> g_knob_cache_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_line_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_associativity;
extern LEVEL_BASE::KNOB<UInt32> g_knob_mutation_interval;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_threshold_hit;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_threshold_miss;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_associativity;
extern LEVEL_BASE::KNOB<UInt32> g_knob_dcache_max_search_depth;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_threshold_hit;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_threshold_miss;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_size;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_associativity;
extern LEVEL_BASE::KNOB<UInt32> g_knob_icache_max_search_depth;

using namespace std;

int Core::coreInit(int tid, int num_mod)
{
   core_tid = tid;
   core_num_mod = num_mod;

   network = new Network(this);

   if ( g_knob_enable_performance_modeling )
   {
      perf_model = new PerfModel("performance modeler");
      LOG_PRINT("Instantiated performance model.");
   } else
   {
      perf_model = (PerfModel *) NULL;
   }

   if ( g_knob_enable_dcache_modeling || g_knob_enable_icache_modeling )
   {
		ocache = new OCache("organic cache",
                          g_knob_cache_size.Value() * k_KILO,
                          g_knob_line_size.Value(),
                          g_knob_associativity.Value(),
                          g_knob_mutation_interval.Value(),
                          g_knob_dcache_threshold_hit.Value(),
                          g_knob_dcache_threshold_miss.Value(),
                          g_knob_dcache_size.Value() * k_KILO,
                          g_knob_dcache_associativity.Value(),
                          g_knob_dcache_max_search_depth.Value(),
                          g_knob_icache_threshold_hit.Value(),
                          g_knob_icache_threshold_miss.Value(),
                          g_knob_icache_size.Value() * k_KILO,
                          g_knob_icache_associativity.Value(),
                          g_knob_icache_max_search_depth.Value());

     	LOG_PRINT("instantiated organic cache model");

	} else
   {
      ocache = (OCache *) NULL;
   }

   if ( g_config->isSimulatingSharedMemory() ) {

      assert( g_knob_enable_dcache_modeling );

      LOG_PRINT("instantiated memory manager model");
      memory_manager = new MemoryManager(this, ocache);

   } else {

      memory_manager = (MemoryManager *) NULL;
      LOG_PRINT("No Memory Manager being used");

   }

   syscall_model = new SyscallMdl(network);
//   InitLock(&dcache_lock);
   sync_client = new SyncClient(this);

   return 0;
}

int Core::coreSendW(int sender, int receiver, char *buffer, int size)
{
   // Create a net packet
   NetPacket packet;
   packet.sender= sender;
   packet.receiver= receiver;
   packet.type = USER;
   packet.length = size;
   packet.data = buffer;

   /*
   packet.data = new char[size];
   for(int i = 0; i < size; i++)
      packet.data[i] = buffer[i];
   */

   SInt32 sent = network->netSend(packet);

   assert(sent == size);

   return sent == size ? 0 : -1;
}

int Core::coreRecvW(int sender, int receiver, char *buffer, int size)
{
   NetPacket packet;
   NetMatch match;

   match.senders.push_back(sender);
   match.types.push_back(USER);

   packet = network->netRecv(match);

   LOG_PRINT("Got packet: from %i, to %i, type %i, len %i", packet.sender, packet.receiver, (SInt32)packet.type, packet.length);

   assert((unsigned)size == packet.length);

   memcpy(buffer, packet.data, size);

   // De-allocate dynamic memory
   // Is this the best place to de-allocate packet.data ??
   delete [] (Byte*)packet.data;

   return (unsigned)size == packet.length ? 0 : -1;
}

void Core::fini(int code, void *v, ostream& out)
{
   if ( g_knob_enable_performance_modeling )
     {
        out << "General:\n";
        perf_model->fini(code, v, out);
        network->outputSummary(out);
     }

   if ( g_knob_enable_dcache_modeling || g_knob_enable_icache_modeling )
      ocache->fini(code,v,out);

   delete sync_client;
   delete syscall_model;
   delete ocache;
   delete perf_model;
   delete network;
}

// organic cache wrappers

bool Core::icacheRunLoadModel(IntPtr i_addr, UInt32 size)
{ return ocache->runICacheLoadModel(i_addr, size).first; }

/*
 * dcacheRunModel (mem_operation_t operation, IntPtr d_addr, char* data_buffer, UInt32 data_size)
 *
 * Arguments:
 *   d_addr :: address of location we want to access (read or write)
 *   shmem_req_t :: READ or WRITE
 *   data_buffer :: buffer holding data for WRITE or buffer which must be written on a READ
 *   data_size :: size of data we must read/write
 *
 * Return Value:
 *   hit :: Say whether there has been at least one cache hit or not
 */
bool Core::dcacheRunModel(mem_operation_t operation, IntPtr d_addr, char* data_buffer, UInt32 data_size)
{
	shmem_req_t shmem_operation;

	if (operation == LOAD) {
		shmem_operation = READ;
	}
	else {
		shmem_operation = WRITE;
	}

	if (g_config->isSimulatingSharedMemory()) {
                LOG_PRINT("%s - ADDR: %x, data_size: %u, END!!", ((operation==LOAD) ? " READ " : " WRITE "), d_addr, data_size);

		bool all_hits = true;

		if (data_size <= 0) {
			return (true);
			// TODO: this is going to affect the statistics even though no shared_mem action is taking place
		}

		IntPtr begin_addr = d_addr;
		IntPtr end_addr = d_addr + data_size;
	  	IntPtr begin_addr_aligned = begin_addr - (begin_addr % ocache->dCacheLineSize());
		IntPtr end_addr_aligned = end_addr - (end_addr % ocache->dCacheLineSize());
		char *curr_data_buffer_head = data_buffer;

		//TODO set the size parameter correctly, based on the size of the data buffer
		//TODO does this spill over to another line? should shared_mem test look at other DRAM entries?
		for (IntPtr curr_addr_aligned = begin_addr_aligned ; curr_addr_aligned <= end_addr_aligned /* Note <= */; curr_addr_aligned += ocache->dCacheLineSize())
		{
			// Access the cache one line at a time
			UInt32 curr_offset;
			UInt32 curr_size;

			// Determine the offset
			// TODO fix curr_size calculations
			// FIXME: Check if all this is correct
			if (curr_addr_aligned == begin_addr_aligned) {
				curr_offset = begin_addr % ocache->dCacheLineSize();
			}
			else {
				curr_offset = 0;
			}

			// Determine the size
			if (curr_addr_aligned == end_addr_aligned) {
				curr_size = (end_addr % ocache->dCacheLineSize()) - (curr_offset);
				if (curr_size == 0) {
					continue;
				}
			}
			else {
				curr_size = ocache->dCacheLineSize() - (curr_offset);
			}

                        LOG_PRINT("Start InitiateSharedMemReq: ADDR: %x, offset: %u, curr_size: %u", curr_addr_aligned, curr_offset, curr_size);

			if (!memory_manager->initiateSharedMemReq(shmem_operation, curr_addr_aligned, curr_offset, curr_data_buffer_head, curr_size)) {
				// If it is a LOAD operation, 'initiateSharedMemReq' causes curr_data_buffer_head to be automatically filled in
				// If it is a STORE operation, 'initiateSharedMemReq' reads the data from curr_data_buffer_head
				all_hits = false;
			}

                        LOG_PRINT("End InitiateSharedMemReq: ADDR: %x, offset: %u, curr_size: %u", curr_addr_aligned, curr_offset, curr_size);

			// Increment the buffer head
			curr_data_buffer_head += curr_size;
		}

                LOG_PRINT("%s - ADDR: %x, data_size: %u, END!!", ((operation==LOAD) ? " READ " : " WRITE "), d_addr, data_size);

		return all_hits;

	}
	else
	{
	   // run this if we aren't using shared_memory
		// FIXME: I am not sure this is right
		// What if the initial data for this address is in some other core's DRAM (which is on some other host machine)
		if(operation == LOAD)
			return ocache->runDCacheLoadModel(d_addr, data_size).first;
		else
			return ocache->runDCacheStoreModel(d_addr, data_size).first;
   }
}

void Core::debugSetCacheState(IntPtr address, CacheState::cstate_t cstate, char *c_data)
{
	memory_manager->debugSetCacheState(address, cstate, c_data);
}

bool Core::debugAssertCacheState(IntPtr address, CacheState::cstate_t expected_cstate, char *expected_data)
{
	return memory_manager->debugAssertCacheState(address, expected_cstate, expected_data);
}

void Core::debugSetDramState(IntPtr address, DramDirectoryEntry::dstate_t dstate, vector<UInt32> sharers_list, char *d_data)
{
	memory_manager->debugSetDramState(address, dstate, sharers_list, d_data);
}

bool Core::debugAssertDramState(IntPtr address, DramDirectoryEntry::dstate_t dstate, vector<UInt32> sharers_list, char *d_data)
{
	return memory_manager->debugAssertDramState(address, dstate, sharers_list, d_data);
}

<|endoftext|>


<commit_before>#include "includes.h"

uint64_t toint(const std::string & s, const int & base){
    // Changees strings to uint64_t
    uint64_t value = 0;
    switch (base){
        case 2:
            for(const unsigned char & c : s){
                value = (value << 1) + (static_cast <uint8_t> (c) - '\x30');
            }
            break;
        case 8:
            std::stringstream(s) >> std::oct >> value;
            break;
        case 10:
            std::stringstream(s) >> std::dec >> value;
            break;
        case 16:
            std::stringstream(s) >> std::hex >> value;    // Thanks to Oli Charlesworth @ stackoverflow
            break;
        case 256:
            for(const unsigned char & c : s){
                value = (value << 8) + static_cast <uint8_t> (c);
            }
            break;
        default:
            std::stringstream s; s << std::dec << base;
            throw std::runtime_error("Error: toint() undefined for base: " + s.str());
            break;
    };
    return value;
}

std::string little_end(const std::string & str, const unsigned int & base){
    // Changes a string to its little endian form
    int s = 8 * (base == 2) + 2 * (base == 16) + (base == 256);
    std::string t = "";
    for (uint32_t x = 0; x < str.size() / s; x++){
        t = str.substr(s * x, s)+ t;
    }
    return t;
}

// Changes a binary string to its hexadecimal equivalent
std::string bintohex(const std::string & in, bool caps){
    if (in.size() & 3){
        throw std::runtime_error("Error: input string length not a multiple of 4.");
    }
    std::string out(in.size() >> 2, '0');
    for(unsigned int i = 0, j = 0; i < in.size(); i += 4, j++){
        unsigned char c = 0;
        for(uint8_t k = 0; k < 4; k++){
            c = (c << 1) | (in[i + k] == '1');
        }

        if (caps){
            out[j] = "0123456789ABCDEF"[c];
        }
        else{
            out[j] = "0123456789abcdef"[c];
        }
    }
    return out;
}

std::string binify(const std::string & in, unsigned int size){
    std::string out(in.size() << 3, 0);
    unsigned int i = 0;
    for(unsigned char const & c : in){
        std::string bin = binify(c);
        for(unsigned char const & b : bin){
            out[i++] = b;
        }
    }
    if (out.size() < size){
        out = std::string(size - out.size(), '0') + out;
    }
    return out;
}

std::string binify(unsigned char c){
    std::string out(8, '0');
    uint8_t i = 7;
    while (c){
        out[i--] = "01"[c & 1];
        c >>= 1;
    }
    return out;
}

// convert a string from binary to ASCII
std::string unbinify(const std::string & in){
    if (in.size() & 7){
        throw std::runtime_error("Error: input string length not a multiple of 8.");
    }

    std::string out(in.size() >> 3, 0);
    for(unsigned int i = 0, j = 0; i < in.size(); i += 8, j++){
        unsigned char c = 0;
        for(uint8_t k = 0; k < 8; k++){
            c = (c << 1) + (in[i + k] == '1');
        }
        out[j] = c;
    }

    return out;
}

// Changes an ASCII string to an ASCII string containing the
// hexadecimal representation of the original chars
std::string hexlify(const std::string & in, bool caps){
    std::string out(in.size() << 1, '0');
    unsigned int i = 0;
    for(unsigned char const & c : in){
        std::string h = hexlify(c, caps);
        out[i++] = h[0];
        out[i++] = h[1];
    }

    return out;
}

std::string hexlify(const char in, bool caps){
    return makehex(static_cast <uint8_t> (in), 2, caps);
}

std::string unhexlify(const std::string & in){
    // Reverse hexlify
    if (in.size() & 1){
        throw std::runtime_error("Error: input string of odd length.");
    }
    std::string out(in.size() >> 1, 0);
    for(unsigned int x = 0; x < in.size(); x += 2){
        if (('0' <= in[x]) && (in[x] <= '9')){
            out[x >> 1] = static_cast <uint8_t> ((in[x] - '0') << 4);
        }
        else if(('a' <= in[x]) && (in[x] <= 'f')){
            out[x >> 1] = static_cast <uint8_t> ((in[x] - 'a' + 10) << 4);
        }
        else if(('A' <= in[x]) && (in[x] <= 'F')){
            out[x >> 1] = static_cast <uint8_t> ((in[x] - 'A' + 10) << 4);
        }
        else{
            throw std::runtime_error("Error: Invalid character found: " + std::string(1, in[x]));
        }
        if (('0' <= in[x + 1]) && (in[x + 1] <= '9')){
            out[x >> 1] |= static_cast <uint8_t> (in[x + 1] - '0');
        }
        else if(('a' <= in[x + 1]) && (in[x + 1] <= 'f')){
            out[x >> 1] |= static_cast <uint8_t> (in[x + 1] - 'a' + 10);
        }
        else if(('A' <= in[x + 1]) && (in[x + 1] <= 'F')){
            out[x >> 1] |= static_cast <uint8_t> (in[x + 1] - 'A' + 10);
        }
        else{
            throw std::runtime_error("Error: Invalid character found: " + std::string(1, in[x + 1]));
        }
    }
    return out;
}

std::string pkcs5(const std::string & data, const unsigned int & blocksize){
    // Adds PKCS5 Padding
    int pad = ((blocksize - data.size()) % blocksize) % blocksize;
    std::string padding(pad, static_cast <char> (pad));
    return data + padding;
}

std::string remove_pkcs5(std::string data){
    // Removes PKCS Padding
    uint8_t pad = static_cast <uint8_t> (data[data.size() - 1]);
    std::string padding(pad, static_cast <char> (pad));
    if ((pad < data.size()) && (padding == data.substr(data.size() - pad, pad)))
        data = data.substr(0, data.size() - pad);
    return data;
}

// adds characters to the front of the string
std::string zfill(const std::string & str, const unsigned int & n, const char fill){
    if (n > str.size()){
        return std::string(n - str.size(), fill) + str;
    }
    return str;
}

// Left rotate a string
std::string ROL(const std::string & str, const std::size_t bits){
    std::string out;
    if (str.size()){
        out = (str + str).substr(bits >> 3, str.size());
        const std::size_t push = bits & 7;
        if (push){
            const std::size_t pull = 8 - push;
            const char mask = (1 << push) - 1;
            const char top = (out[0] >> pull) & mask;

            for(std::string::size_type i = 1; i < out.size(); i++){
                out[i - 1] = (out[i - 1] << push) | ((out[i] >> pull) & mask);
            }
            out.back() = (out.back() << push) | top;
        }
    }

    return out;
}

// and two strings, up to the last character of the shorter string
std::string and_strings(const std::string & str1, const std::string & str2){
    std::string::size_type end = std::min(str1.size(), str2.size());
    std::string out = str1.substr(0, end);
    for(std::string::size_type i = 0; i < end; i++){
        out[i] &= str2[i];
    }
    return out;
}

// or two strings, up to the last character of the shorter string
std::string or_strings(const std::string & str1, const std::string & str2){
    std::string::size_type end = std::min(str1.size(), str2.size());
    std::string out = str1.substr(0, end);
    for(std::string::size_type i = 0; i < end; i++){
        out[i] |= str2[i];
    }
    return out;
}

// xor the contents of 2 strings, up to the last character of the shorter string
std::string xor_strings(const std::string & str1, const std::string & str2){
    std::string::size_type end = std::min(str1.size(), str2.size());
    std::string out = str1.substr(0, end);
    for(std::string::size_type i = 0; i < end; i++){
        out[i] ^= str2[i];
    }
    return out;
}
<commit_msg>Fix #5<commit_after>#include "includes.h"

uint64_t toint(const std::string & s, const int & base){
    // Changees strings to uint64_t
    uint64_t value = 0;
    switch (base){
        case 2:
            for(const unsigned char & c : s){
                value = (value << 1) + (static_cast <uint8_t> (c) - '\x30');
            }
            break;
        case 8:
            std::stringstream(s) >> std::oct >> value;
            break;
        case 10:
            std::stringstream(s) >> std::dec >> value;
            break;
        case 16:
            std::stringstream(s) >> std::hex >> value;    // Thanks to Oli Charlesworth @ stackoverflow
            break;
        case 256:
            for(const unsigned char & c : s){
                value = (value << 8) + static_cast <uint8_t> (c);
            }
            break;
        default:
            std::stringstream s; s << std::dec << base;
            throw std::runtime_error("Error: toint() undefined for base: " + s.str());
            break;
    };
    return value;
}

std::string little_end(const std::string & str, const unsigned int & base){
    // Changes a string to its little endian form
    int s = 8 * (base == 2) + 2 * (base == 16) + (base == 256);
    std::string t = "";
    for (uint32_t x = 0; x < str.size() / s; x++){
        t = str.substr(s * x, s)+ t;
    }
    return t;
}

// Changes a binary string to its hexadecimal equivalent
std::string bintohex(const std::string & in, bool caps){
    if (in.size() & 3){
        throw std::runtime_error("Error: input string length not a multiple of 4.");
    }
    std::string out(in.size() >> 2, '0');
    for(unsigned int i = 0, j = 0; i < in.size(); i += 4, j++){
        unsigned char c = 0;
        for(uint8_t k = 0; k < 4; k++){
            c = (c << 1) | (in[i + k] == '1');
        }

        if (caps){
            out[j] = "0123456789ABCDEF"[c];
        }
        else{
            out[j] = "0123456789abcdef"[c];
        }
    }
    return out;
}

std::string binify(const std::string & in, unsigned int size){
    std::string out(in.size() << 3, 0);
    unsigned int i = 0;
    for(unsigned char const & c : in){
        std::string bin = binify(c);
        for(unsigned char const & b : bin){
            out[i++] = b;
        }
    }
    if (out.size() < size){
        out = std::string(size - out.size(), '0') + out;
    }
    return out;
}

std::string binify(unsigned char c){
    std::string out(8, '0');
    uint8_t i = 7;
    while (c){
        out[i--] = "01"[c & 1];
        c >>= 1;
    }
    return out;
}

// convert a string from binary to ASCII
std::string unbinify(const std::string & in){
    if (in.size() & 7){
        throw std::runtime_error("Error: input string length not a multiple of 8.");
    }

    std::string out(in.size() >> 3, 0);
    for(unsigned int i = 0, j = 0; i < in.size(); i += 8, j++){
        unsigned char c = 0;
        for(uint8_t k = 0; k < 8; k++){
            c = (c << 1) + (in[i + k] == '1');
        }
        out[j] = c;
    }

    return out;
}

// Changes an ASCII string to an ASCII string containing the
// hexadecimal representation of the original chars
std::string hexlify(const std::string & in, bool caps){
    std::string out(in.size() << 1, '0');
    unsigned int i = 0;
    for(unsigned char const & c : in){
        std::string h = hexlify(c, caps);
        out[i++] = h[0];
        out[i++] = h[1];
    }

    return out;
}

std::string hexlify(const char in, bool caps){
    return makehex(static_cast <uint8_t> (in), 2, caps);
}

std::string unhexlify(const std::string & in){
    // Reverse hexlify
    if (in.size() & 1){
        throw std::runtime_error("Error: input string of odd length.");
    }
    std::string out(in.size() >> 1, 0);
    for(unsigned int x = 0; x < in.size(); x += 2){
        if (('0' <= in[x]) && (in[x] <= '9')){
            out[x >> 1] = static_cast <uint8_t> ((in[x] - '0') << 4);
        }
        else if(('a' <= in[x]) && (in[x] <= 'f')){
            out[x >> 1] = static_cast <uint8_t> ((in[x] - 'a' + 10) << 4);
        }
        else if(('A' <= in[x]) && (in[x] <= 'F')){
            out[x >> 1] = static_cast <uint8_t> ((in[x] - 'A' + 10) << 4);
        }
        else{
            throw std::runtime_error("Error: Invalid character found: " + std::string(1, in[x]));
        }
        if (('0' <= in[x + 1]) && (in[x + 1] <= '9')){
            out[x >> 1] |= static_cast <uint8_t> (in[x + 1] - '0');
        }
        else if(('a' <= in[x + 1]) && (in[x + 1] <= 'f')){
            out[x >> 1] |= static_cast <uint8_t> (in[x + 1] - 'a' + 10);
        }
        else if(('A' <= in[x + 1]) && (in[x + 1] <= 'F')){
            out[x >> 1] |= static_cast <uint8_t> (in[x + 1] - 'A' + 10);
        }
        else{
            throw std::runtime_error("Error: Invalid character found: " + std::string(1, in[x + 1]));
        }
    }
    return out;
}

std::string pkcs5(const std::string & data, const unsigned int & blocksize){
    // Adds PKCS5 Padding
    int pad = blocksize - (data.size() % blocksize);
    std::string padding(pad, static_cast <char> (pad));
    return data + padding;
}

std::string remove_pkcs5(std::string data){
    // Removes PKCS Padding
    uint8_t pad = static_cast <uint8_t> (data[data.size() - 1]);
    if ((pad > data.size()) ||
        (std::string(pad, static_cast <char> (pad)) != data.substr(data.size() - pad, pad))) {
        throw std::runtime_error("Error: Could not remove pkcs5 padding.");
    }
    data.resize(data.size() - pad);
    return data;
}

// adds characters to the front of the string
std::string zfill(const std::string & str, const unsigned int & n, const char fill){
    if (n > str.size()){
        return std::string(n - str.size(), fill) + str;
    }
    return str;
}

// Left rotate a string
std::string ROL(const std::string & str, const std::size_t bits){
    std::string out;
    if (str.size()){
        out = (str + str).substr(bits >> 3, str.size());
        const std::size_t push = bits & 7;
        if (push){
            const std::size_t pull = 8 - push;
            const char mask = (1 << push) - 1;
            const char top = (out[0] >> pull) & mask;

            for(std::string::size_type i = 1; i < out.size(); i++){
                out[i - 1] = (out[i - 1] << push) | ((out[i] >> pull) & mask);
            }
            out.back() = (out.back() << push) | top;
        }
    }

    return out;
}

// and two strings, up to the last character of the shorter string
std::string and_strings(const std::string & str1, const std::string & str2){
    std::string::size_type end = std::min(str1.size(), str2.size());
    std::string out = str1.substr(0, end);
    for(std::string::size_type i = 0; i < end; i++){
        out[i] &= str2[i];
    }
    return out;
}

// or two strings, up to the last character of the shorter string
std::string or_strings(const std::string & str1, const std::string & str2){
    std::string::size_type end = std::min(str1.size(), str2.size());
    std::string out = str1.substr(0, end);
    for(std::string::size_type i = 0; i < end; i++){
        out[i] |= str2[i];
    }
    return out;
}

// xor the contents of 2 strings, up to the last character of the shorter string
std::string xor_strings(const std::string & str1, const std::string & str2){
    std::string::size_type end = std::min(str1.size(), str2.size());
    std::string out = str1.substr(0, end);
    for(std::string::size_type i = 0; i < end; i++){
        out[i] ^= str2[i];
    }
    return out;
}
<|endoftext|>


<commit_before>#include <gtest/gtest.h>
#include "exp.h"

int main( int argc , char **argv )
{
    testing :: InitGoogleTest( &argc , argv ) ;
    return RUN_ALL_TESTS( ) ;
}
<commit_msg>Delete mainExp.cpp<commit_after><|endoftext|>


<commit_before>#include <qi/messaging/publisher.hpp>

int main(int argc, char *argv[])
{
  // Create the publisher, giving it a name that helps to track it
  qi::Publisher publisher("time");

  // Connect the publisher to the master
  const std::string masterAddress = "127.0.0.1:5555";
  publisher.connect(masterAddress);

  // Advertise the Topic, giving it a name and an int type
  publisher.advertiseTopic<int>("time/hour");

  // Publish the hour to the Topic, sending an int
  publisher.publish("time/hour", 10)
}
<commit_msg>Fix publisher example<commit_after>#include <qi/messaging/publisher.hpp>

int main(int argc, char *argv[])
{
  // Create the publisher, giving it a name that helps to track it
  qi::Publisher publisher("time");

  // Connect the publisher to the master
  const std::string masterAddress = "127.0.0.1:5555";
  publisher.connect(masterAddress);

  // Advertise the Topic, giving it a name and an int type
  publisher.advertiseTopic<int>("time/hour");

  // Publish the hour to the Topic, sending an int
  publisher.publish("time/hour", 10);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: b3dcolor.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 02:24:16 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef GCC
#pragma hdrstop
#endif

#ifndef _B3D_B3DCOLOR_HXX
#include "b3dcolor.hxx"
#endif

/*************************************************************************
|*
|* Farbwert interpolieren
|*
\************************************************************************/

void B3dColor::CalcInBetween(Color& rOld1, Color& rOld2, double t)
{
    if(rOld1 != rOld2)
    {
        UINT16 nFac = (UINT16)(t * 256.0);
        UINT16 nNegFac = 256 - nFac;
        SetRed((UINT8)(((nFac * (UINT16)rOld2.GetRed())
            + (nNegFac * (UINT16)rOld1.GetRed())) >> 8));
        SetGreen((UINT8)(((nFac * (UINT16)rOld2.GetGreen())
            + (nNegFac * (UINT16)rOld1.GetGreen())) >> 8));
        SetBlue((UINT8)(((nFac * (UINT16)rOld2.GetBlue())
            + (nNegFac * (UINT16)rOld1.GetBlue())) >> 8));
        SetTransparency((UINT8)(((nFac * (UINT16)rOld2.GetTransparency())
            + (nNegFac * (UINT16)rOld1.GetTransparency())) >> 8));
    }
    else
    {
        SetColor(rOld1.GetColor());
    }
}

/*************************************************************************
|*
|* Farbwert Mittelwert finden mit 2 Farben
|*
\************************************************************************/

void B3dColor::CalcMiddle(Color& rOld1, Color& rOld2)
{
    if(rOld1 != rOld2)
    {
        SetRed((UINT8)(((UINT16)rOld1.GetRed()
            + (UINT16)rOld2.GetRed())>>1));
        SetGreen((UINT8)(((UINT16)rOld1.GetGreen()
            + (UINT16)rOld2.GetGreen())>>1));
        SetBlue((UINT8)(((UINT16)rOld1.GetBlue()
            + (UINT16)rOld2.GetBlue())>>1));
        SetTransparency((UINT8)(((UINT16)rOld1.GetTransparency()
            + (UINT16)rOld2.GetTransparency())>>1));
    }
    else
    {
        SetColor(rOld1.GetColor());
    }
}

/*************************************************************************
|*
|* Farbwert Mittelwert finden mit 3 Farben
|*
\************************************************************************/

void B3dColor::CalcMiddle(Color& rOld1, Color& rOld2, Color& rOld3)
{
    if(rOld1 != rOld2)
    {
        if(rOld1 != rOld3)
        {
            // alle 3 unterschiedlich
            SetRed((UINT8)(((UINT16)rOld1.GetRed()
                + (UINT16)rOld2.GetRed()
                + (UINT16)rOld3.GetRed()) / 3L));
            SetGreen((UINT8)(((UINT16)rOld1.GetGreen()
                + (UINT16)rOld2.GetGreen()
                + (UINT16)rOld3.GetGreen()) / 3L));
            SetBlue((UINT8)(((UINT16)rOld1.GetBlue()
                + (UINT16)rOld2.GetBlue()
                + (UINT16)rOld3.GetBlue()) / 3L));
            SetTransparency((UINT8)(((UINT16)rOld1.GetTransparency()
                + (UINT16)rOld2.GetTransparency()
                + (UINT16)rOld3.GetTransparency()) / 3L));
        }
        else
        {
            // 1 != 2, 1 == 3
            CalcMiddle(rOld1, rOld2);
        }
    }
    else
    {
        // 1 == 2
        if(rOld1 != rOld3)
        {
            CalcMiddle(rOld1, rOld3);
        }
        else
        {
            // 1==2, 1==3 -> alle gleich
            SetColor(rOld1.GetColor());
        }
    }
}

/*************************************************************************
|*
|* Ermittle den Abstand der beiden Farben im Farbraum
|* Dies geschieht OHNE Wurzelziehen, d.h. es wird als Metrik im RGB
|* Farbraum hier das Quadrat der 'echten' (gewohnten) Entfernung benutzt
|*
\************************************************************************/

ULONG B3dColor::GetDistance(Color& rOld)
{
    // Bei Gleichheit kein Abstand
    if(*this == rOld)
        return 0L;

    // Abstand ermitteln
    long nDistRed = rOld.GetRed() > GetRed() ?
        rOld.GetRed() - GetRed() :
        GetRed() - rOld.GetRed();
    long nDistGreen = rOld.GetGreen() > GetGreen() ?
        rOld.GetGreen() - GetGreen() :
        GetGreen() - rOld.GetGreen();
    long nDistBlue = rOld.GetBlue() > GetBlue() ?
        rOld.GetBlue() - GetBlue() :
        GetBlue() - rOld.GetBlue();
    return (ULONG)(nDistRed * nDistRed
        + nDistGreen * nDistGreen
        + nDistBlue * nDistBlue);
}

/*************************************************************************
|*
|* Farbaddition mit clamping
|*
\************************************************************************/

B3dColor& B3dColor::operator+= (const B3dColor& rCol)
{
    UINT16 nZwi;
    if(rCol.GetRed())
    {
        nZwi = (UINT16)GetRed() + (UINT16)rCol.GetRed();
        if(nZwi > 255)
            nZwi = 255;
        SetRed((UINT8)nZwi);
    }
    if(rCol.GetGreen())
    {
        nZwi = (UINT16)GetGreen() + (UINT16)rCol.GetGreen();
        if(nZwi > 255)
            nZwi = 255;
        SetGreen((UINT8)nZwi);
    }
    if(rCol.GetBlue())
    {
        nZwi = (UINT16)GetBlue() + (UINT16)rCol.GetBlue();
        if(nZwi > 255)
            nZwi = 255;
        SetBlue((UINT8)nZwi);
    }
    if(rCol.GetTransparency())
    {
        nZwi = (UINT16)GetTransparency() + (UINT16)rCol.GetTransparency();
        if(nZwi > 255)
            nZwi = 255;
        SetTransparency((UINT8)nZwi);
    }
    return *this;
}

/*************************************************************************
|*
|* Farbsubtraktion mit clamping
|*
\************************************************************************/

B3dColor& B3dColor::operator-= (const B3dColor& rCol)
{
    INT16 nZwi;
    if(rCol.GetRed())
    {
        nZwi = (INT16)GetRed() - (INT16)rCol.GetRed();
        if(nZwi < 0)
            nZwi = 0;
        SetRed((UINT8)nZwi);
    }
    if(rCol.GetGreen())
    {
        nZwi = (INT16)GetGreen() - (INT16)rCol.GetGreen();
        if(nZwi < 0)
            nZwi = 0;
        SetGreen((UINT8)nZwi);
    }
    if(rCol.GetBlue())
    {
        nZwi = (INT16)GetBlue() - (INT16)rCol.GetBlue();
        if(nZwi < 0)
            nZwi = 0;
        SetBlue((UINT8)nZwi);
    }
    if(rCol.GetTransparency())
    {
        nZwi = (INT16)GetTransparency() - (INT16)rCol.GetTransparency();
        if(nZwi < 0)
            nZwi = 0;
        SetTransparency((UINT8)nZwi);
    }
    return *this;
}

/*************************************************************************
|*
|* Farbaddition mit clamping, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator+ (const B3dColor& rCol) const
{
    B3dColor aSum = *this;
    aSum += rCol;
    return aSum;
}

/*************************************************************************
|*
|* Farbsubtraktion mit clamping, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator- (const B3dColor& rCol) const
{
    B3dColor aSub = *this;
    aSub -= rCol;
    return aSub;
}

/*************************************************************************
|*
|* Farbmultiplikation, d.h. Gewichtung der Farben aneinander
|*
\************************************************************************/

B3dColor& B3dColor::operator*= (const B3dColor& rCol)
{
    // urspruengliches Objekt ist die Farbe, rCol die zu berechnende
    // Gewichtung
    SetRed((UINT8)(((((UINT16)GetRed())+1)
        * (UINT16)rCol.GetRed()) >> 8));
    SetGreen((UINT8)(((((UINT16)GetGreen())+1)
        * (UINT16)rCol.GetGreen()) >> 8));
    SetBlue((UINT8)(((((UINT16)GetBlue())+1)
        * (UINT16)rCol.GetBlue()) >> 8));
    SetTransparency((UINT8)(((((UINT16)GetTransparency())+1)
        * (UINT16)rCol.GetTransparency()) >> 8));
    return *this;
}

/*************************************************************************
|*
|* Farbmultiplikation, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator* (const B3dColor& rCol) const
{
    B3dColor aMul = *this;
    aMul *= rCol;
    return aMul;
}

/*************************************************************************
|*
|* Farbmultiplikation mit Faktor im Bereich [0.0 .. 1.0]
|*
\************************************************************************/

B3dColor& B3dColor::operator*= (const double fVal)
{
    ULONG nVal = (ULONG)(fVal * 65536.0);
    SetRed((UINT8)(((ULONG)GetRed() * nVal) >> 16));
    SetGreen((UINT8)(((ULONG)GetGreen() * nVal) >> 16));
    SetBlue((UINT8)(((ULONG)GetBlue() * nVal) >> 16));
    SetTransparency((UINT8)(((ULONG)GetTransparency() * nVal) >> 16));
    return *this;
}

/*************************************************************************
|*
|* Farbmultiplikation mit Faktor, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator* (const double fVal) const
{
    B3dColor aMul = *this;
    aMul *= fVal;
    return aMul;
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.3.118); FILE MERGED 2006/09/01 17:29:59 kaib 1.3.118.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: b3dcolor.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 15:36:39 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_goodies.hxx"
#ifndef GCC
#endif

#ifndef _B3D_B3DCOLOR_HXX
#include "b3dcolor.hxx"
#endif

/*************************************************************************
|*
|* Farbwert interpolieren
|*
\************************************************************************/

void B3dColor::CalcInBetween(Color& rOld1, Color& rOld2, double t)
{
    if(rOld1 != rOld2)
    {
        UINT16 nFac = (UINT16)(t * 256.0);
        UINT16 nNegFac = 256 - nFac;
        SetRed((UINT8)(((nFac * (UINT16)rOld2.GetRed())
            + (nNegFac * (UINT16)rOld1.GetRed())) >> 8));
        SetGreen((UINT8)(((nFac * (UINT16)rOld2.GetGreen())
            + (nNegFac * (UINT16)rOld1.GetGreen())) >> 8));
        SetBlue((UINT8)(((nFac * (UINT16)rOld2.GetBlue())
            + (nNegFac * (UINT16)rOld1.GetBlue())) >> 8));
        SetTransparency((UINT8)(((nFac * (UINT16)rOld2.GetTransparency())
            + (nNegFac * (UINT16)rOld1.GetTransparency())) >> 8));
    }
    else
    {
        SetColor(rOld1.GetColor());
    }
}

/*************************************************************************
|*
|* Farbwert Mittelwert finden mit 2 Farben
|*
\************************************************************************/

void B3dColor::CalcMiddle(Color& rOld1, Color& rOld2)
{
    if(rOld1 != rOld2)
    {
        SetRed((UINT8)(((UINT16)rOld1.GetRed()
            + (UINT16)rOld2.GetRed())>>1));
        SetGreen((UINT8)(((UINT16)rOld1.GetGreen()
            + (UINT16)rOld2.GetGreen())>>1));
        SetBlue((UINT8)(((UINT16)rOld1.GetBlue()
            + (UINT16)rOld2.GetBlue())>>1));
        SetTransparency((UINT8)(((UINT16)rOld1.GetTransparency()
            + (UINT16)rOld2.GetTransparency())>>1));
    }
    else
    {
        SetColor(rOld1.GetColor());
    }
}

/*************************************************************************
|*
|* Farbwert Mittelwert finden mit 3 Farben
|*
\************************************************************************/

void B3dColor::CalcMiddle(Color& rOld1, Color& rOld2, Color& rOld3)
{
    if(rOld1 != rOld2)
    {
        if(rOld1 != rOld3)
        {
            // alle 3 unterschiedlich
            SetRed((UINT8)(((UINT16)rOld1.GetRed()
                + (UINT16)rOld2.GetRed()
                + (UINT16)rOld3.GetRed()) / 3L));
            SetGreen((UINT8)(((UINT16)rOld1.GetGreen()
                + (UINT16)rOld2.GetGreen()
                + (UINT16)rOld3.GetGreen()) / 3L));
            SetBlue((UINT8)(((UINT16)rOld1.GetBlue()
                + (UINT16)rOld2.GetBlue()
                + (UINT16)rOld3.GetBlue()) / 3L));
            SetTransparency((UINT8)(((UINT16)rOld1.GetTransparency()
                + (UINT16)rOld2.GetTransparency()
                + (UINT16)rOld3.GetTransparency()) / 3L));
        }
        else
        {
            // 1 != 2, 1 == 3
            CalcMiddle(rOld1, rOld2);
        }
    }
    else
    {
        // 1 == 2
        if(rOld1 != rOld3)
        {
            CalcMiddle(rOld1, rOld3);
        }
        else
        {
            // 1==2, 1==3 -> alle gleich
            SetColor(rOld1.GetColor());
        }
    }
}

/*************************************************************************
|*
|* Ermittle den Abstand der beiden Farben im Farbraum
|* Dies geschieht OHNE Wurzelziehen, d.h. es wird als Metrik im RGB
|* Farbraum hier das Quadrat der 'echten' (gewohnten) Entfernung benutzt
|*
\************************************************************************/

ULONG B3dColor::GetDistance(Color& rOld)
{
    // Bei Gleichheit kein Abstand
    if(*this == rOld)
        return 0L;

    // Abstand ermitteln
    long nDistRed = rOld.GetRed() > GetRed() ?
        rOld.GetRed() - GetRed() :
        GetRed() - rOld.GetRed();
    long nDistGreen = rOld.GetGreen() > GetGreen() ?
        rOld.GetGreen() - GetGreen() :
        GetGreen() - rOld.GetGreen();
    long nDistBlue = rOld.GetBlue() > GetBlue() ?
        rOld.GetBlue() - GetBlue() :
        GetBlue() - rOld.GetBlue();
    return (ULONG)(nDistRed * nDistRed
        + nDistGreen * nDistGreen
        + nDistBlue * nDistBlue);
}

/*************************************************************************
|*
|* Farbaddition mit clamping
|*
\************************************************************************/

B3dColor& B3dColor::operator+= (const B3dColor& rCol)
{
    UINT16 nZwi;
    if(rCol.GetRed())
    {
        nZwi = (UINT16)GetRed() + (UINT16)rCol.GetRed();
        if(nZwi > 255)
            nZwi = 255;
        SetRed((UINT8)nZwi);
    }
    if(rCol.GetGreen())
    {
        nZwi = (UINT16)GetGreen() + (UINT16)rCol.GetGreen();
        if(nZwi > 255)
            nZwi = 255;
        SetGreen((UINT8)nZwi);
    }
    if(rCol.GetBlue())
    {
        nZwi = (UINT16)GetBlue() + (UINT16)rCol.GetBlue();
        if(nZwi > 255)
            nZwi = 255;
        SetBlue((UINT8)nZwi);
    }
    if(rCol.GetTransparency())
    {
        nZwi = (UINT16)GetTransparency() + (UINT16)rCol.GetTransparency();
        if(nZwi > 255)
            nZwi = 255;
        SetTransparency((UINT8)nZwi);
    }
    return *this;
}

/*************************************************************************
|*
|* Farbsubtraktion mit clamping
|*
\************************************************************************/

B3dColor& B3dColor::operator-= (const B3dColor& rCol)
{
    INT16 nZwi;
    if(rCol.GetRed())
    {
        nZwi = (INT16)GetRed() - (INT16)rCol.GetRed();
        if(nZwi < 0)
            nZwi = 0;
        SetRed((UINT8)nZwi);
    }
    if(rCol.GetGreen())
    {
        nZwi = (INT16)GetGreen() - (INT16)rCol.GetGreen();
        if(nZwi < 0)
            nZwi = 0;
        SetGreen((UINT8)nZwi);
    }
    if(rCol.GetBlue())
    {
        nZwi = (INT16)GetBlue() - (INT16)rCol.GetBlue();
        if(nZwi < 0)
            nZwi = 0;
        SetBlue((UINT8)nZwi);
    }
    if(rCol.GetTransparency())
    {
        nZwi = (INT16)GetTransparency() - (INT16)rCol.GetTransparency();
        if(nZwi < 0)
            nZwi = 0;
        SetTransparency((UINT8)nZwi);
    }
    return *this;
}

/*************************************************************************
|*
|* Farbaddition mit clamping, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator+ (const B3dColor& rCol) const
{
    B3dColor aSum = *this;
    aSum += rCol;
    return aSum;
}

/*************************************************************************
|*
|* Farbsubtraktion mit clamping, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator- (const B3dColor& rCol) const
{
    B3dColor aSub = *this;
    aSub -= rCol;
    return aSub;
}

/*************************************************************************
|*
|* Farbmultiplikation, d.h. Gewichtung der Farben aneinander
|*
\************************************************************************/

B3dColor& B3dColor::operator*= (const B3dColor& rCol)
{
    // urspruengliches Objekt ist die Farbe, rCol die zu berechnende
    // Gewichtung
    SetRed((UINT8)(((((UINT16)GetRed())+1)
        * (UINT16)rCol.GetRed()) >> 8));
    SetGreen((UINT8)(((((UINT16)GetGreen())+1)
        * (UINT16)rCol.GetGreen()) >> 8));
    SetBlue((UINT8)(((((UINT16)GetBlue())+1)
        * (UINT16)rCol.GetBlue()) >> 8));
    SetTransparency((UINT8)(((((UINT16)GetTransparency())+1)
        * (UINT16)rCol.GetTransparency()) >> 8));
    return *this;
}

/*************************************************************************
|*
|* Farbmultiplikation, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator* (const B3dColor& rCol) const
{
    B3dColor aMul = *this;
    aMul *= rCol;
    return aMul;
}

/*************************************************************************
|*
|* Farbmultiplikation mit Faktor im Bereich [0.0 .. 1.0]
|*
\************************************************************************/

B3dColor& B3dColor::operator*= (const double fVal)
{
    ULONG nVal = (ULONG)(fVal * 65536.0);
    SetRed((UINT8)(((ULONG)GetRed() * nVal) >> 16));
    SetGreen((UINT8)(((ULONG)GetGreen() * nVal) >> 16));
    SetBlue((UINT8)(((ULONG)GetBlue() * nVal) >> 16));
    SetTransparency((UINT8)(((ULONG)GetTransparency() * nVal) >> 16));
    return *this;
}

/*************************************************************************
|*
|* Farbmultiplikation mit Faktor, neue Farbe erzeugen
|*
\************************************************************************/

B3dColor B3dColor::operator* (const double fVal) const
{
    B3dColor aMul = *this;
    aMul *= fVal;
    return aMul;
}

<|endoftext|>


<commit_before>// Copyright Daniel Wallin 2006. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/python.hpp>
#include <libtorrent/alert.hpp>
#include <libtorrent/alert_types.hpp>

using namespace boost::python;
using namespace libtorrent;

std::string get_buffer(read_piece_alert const& rpa)
{
    return rpa.buffer ? std::string(rpa.buffer.get(), rpa.size)
       : std::string();
}

void bind_alert()
{
    using boost::noncopyable;

    {
        scope alert_scope = class_<alert, noncopyable>("alert", no_init)
            .def("message", &alert::message)
            .def("what", &alert::what)
            .def("category", &alert::category)
#ifndef TORRENT_NO_DEPRECATE
            .def("severity", &alert::severity)
#endif
            .def("__str__", &alert::message)
            ;

#ifndef TORRENT_NO_DEPRECATE
        enum_<alert::severity_t>("severity_levels")
            .value("debug", alert::debug)
            .value("info", alert::info)
            .value("warning", alert::warning)
            .value("critical", alert::critical)
            .value("fatal", alert::fatal)
            .value("none", alert::none)
            ;
#endif

        enum_<alert::category_t>("category_t")
            .value("error_notification", alert::error_notification)
            .value("peer_notification", alert::peer_notification)
            .value("port_mapping_notification", alert::port_mapping_notification)
            .value("storage_notification", alert::storage_notification)
            .value("tracker_notification", alert::tracker_notification)
            .value("debug_notification", alert::debug_notification)
            .value("status_notification", alert::status_notification)
            .value("progress_notification", alert::progress_notification)
            .value("ip_block_notification", alert::ip_block_notification)
            .value("performance_warning", alert::performance_warning)
            .value("all_categories", alert::all_categories)
            ;

    }

    class_<torrent_alert, bases<alert>, noncopyable>(
        "torrent_alert", no_init
    )
        .def_readonly("handle", &torrent_alert::handle)
        ;

    class_<tracker_alert, bases<torrent_alert>, noncopyable>(
        "tracker_alert", no_init
    )
        .def_readonly("url", &tracker_alert::url)
        ;

    class_<read_piece_alert, bases<torrent_alert>, noncopyable>(
        "read_piece_alert", 0, no_init
    )
        .add_property("buffer", get_buffer)
        .def_readonly("piece", &read_piece_alert::piece)
        .def_readonly("size", &read_piece_alert::size)
        ;

    class_<peer_alert, bases<torrent_alert>, noncopyable>(
        "peer_alert", no_init
    )
        .def_readonly("ip", &peer_alert::ip)
        .def_readonly("pid", &peer_alert::pid)
    ;
    class_<tracker_error_alert, bases<tracker_alert>, noncopyable>(
        "tracker_error_alert", no_init
    )
        .def_readonly("msg", &tracker_error_alert::msg)
        .def_readonly("times_in_row", &tracker_error_alert::times_in_row)
        .def_readonly("status_code", &tracker_error_alert::status_code)
        ;

    class_<tracker_warning_alert, bases<tracker_alert>, noncopyable>(
        "tracker_warning_alert", no_init
    );

    class_<tracker_reply_alert, bases<tracker_alert>, noncopyable>(
        "tracker_reply_alert", no_init
    )
        .def_readonly("num_peers", &tracker_reply_alert::num_peers)
        ;

    class_<tracker_announce_alert, bases<tracker_alert>, noncopyable>(
        "tracker_announce_alert", no_init
    )
        .def_readonly("event", &tracker_reply_alert::event)
        ;

    class_<hash_failed_alert, bases<torrent_alert>, noncopyable>(
        "hash_failed_alert", no_init
    )
        .def_readonly("piece_index", &hash_failed_alert::piece_index)
        ;

    class_<peer_ban_alert, bases<peer_alert>, noncopyable>(
        "peer_ban_alert", no_init
    );

    class_<peer_error_alert, bases<peer_alert>, noncopyable>(
        "peer_error_alert", no_init
    );

    class_<invalid_request_alert, bases<peer_alert>, noncopyable>(
        "invalid_request_alert", no_init
    )
        .def_readonly("request", &invalid_request_alert::request)
        ;

    class_<peer_request>("peer_request")
        .def_readonly("piece", &peer_request::piece)
        .def_readonly("start", &peer_request::start)
        .def_readonly("length", &peer_request::length)
        .def(self == self)
        ;

    class_<torrent_finished_alert, bases<torrent_alert>, noncopyable>(
        "torrent_finished_alert", no_init
    );

    class_<piece_finished_alert, bases<torrent_alert>, noncopyable>(
        "piece_finished_alert", no_init
    )
        .def_readonly("piece_index", &piece_finished_alert::piece_index)
        ;

    class_<block_finished_alert, bases<peer_alert>, noncopyable>(
        "block_finished_alert", no_init
    )
        .def_readonly("block_index", &block_finished_alert::block_index)
        .def_readonly("piece_index", &block_finished_alert::piece_index)
        ;

    class_<block_downloading_alert, bases<peer_alert>, noncopyable>(
        "block_downloading_alert", no_init
    )
        .def_readonly("peer_speedmsg", &block_downloading_alert::peer_speedmsg)
        .def_readonly("block_index", &block_downloading_alert::block_index)
        .def_readonly("piece_index", &block_downloading_alert::piece_index)
        ;

    class_<storage_moved_alert, bases<torrent_alert>, noncopyable>(
        "storage_moved_alert", no_init
    )
        .def_readonly("path", &storaged_moved_alert::path)
        ;

    class_<storage_moved_failed_alert, bases<torrent_alert>, noncopyable>(
        "storage_moved_failed_alert", no_init
    )
        .def_readonly("error", &storage_moved_failed_alert::error)
        ;

    class_<torrent_deleted_alert, bases<torrent_alert>, noncopyable>(
        "torrent_deleted_alert", no_init
    );

    class_<torrent_paused_alert, bases<torrent_alert>, noncopyable>(
        "torrent_paused_alert", no_init
    );

    class_<torrent_checked_alert, bases<torrent_alert>, noncopyable>(
        "torrent_checked_alert", no_init
    );

    class_<url_seed_alert, bases<torrent_alert>, noncopyable>(
        "url_seed_alert", no_init
    )
        .def_readonly("url", &url_seed_alert::url)
        .def_readonly("msg", &url_seed_alert::msg)
        ;

    class_<file_error_alert, bases<torrent_alert>, noncopyable>(
        "file_error_alert", no_init
    )
        .def_readonly("file", &file_error_alert::file)
        .def_readonly("msg", &file_error_alert::msg)
        ;

    class_<metadata_failed_alert, bases<torrent_alert>, noncopyable>(
        "metadata_failed_alert", no_init
    );

    class_<metadata_received_alert, bases<torrent_alert>, noncopyable>(
        "metadata_received_alert", no_init
    );

    class_<listen_failed_alert, bases<alert>, noncopyable>(
        "listen_failed_alert", no_init
    )
        .def_readonly("endpoint", &listen_failed_alert::endpoint)
        .def_readonly("error", &listen_failed_alert::error)
        ;

    class_<listen_succeeded_alert, bases<alert>, noncopyable>(
        "listen_succeeded_alert", no_init
    )
        .def_readonly("endpoint", &listen_succeeded_alert::endpoint)
        ;

    class_<portmap_error_alert, bases<alert>, noncopyable>(
        "portmap_error_alert", no_init
    )
        .def_readonly("mapping", &portmap_error_alert::mapping)
        .def_readonly("type", &portmap_error_alert::type)
        .def_readonly("msg", &portmap_error_alert::msg)
        ;

    class_<portmap_alert, bases<alert>, noncopyable>(
        "portmap_alert", no_init
    )
        .def_readonly("mapping", &portmap_alert::mapping)
        .def_readonly("external_port", &portmap_alert::external_port)
        .def_readonly("type", &portmap_alert::type)
        ;

    class_<portmap_log_alert, bases<alert>, noncopyable>(
        "portmap_log_alert", no_init
    )
        .def_readonly("type", &portmap_log_alert::type)
        .def_readonly("msg", &portmap_log_alert::msg)
        ;

    class_<fastresume_rejected_alert, bases<torrent_alert>, noncopyable>(
        "fastresume_rejected_alert", no_init
    )
        .def_readonly("msg", &fastresume_rejected_alert::msg)
        ;

    class_<peer_blocked_alert, bases<alert>, noncopyable>(
        "peer_blocked_alert", no_init
    )
        .def_readonly("ip", &peer_blocked_alert::ip)
        ;

    class_<scrape_reply_alert, bases<tracker_alert>, noncopyable>(
        "scrape_reply_alert", no_init
    )
        .def_readonly("incomplete", &scrape_reply_alert::incomplete)
        .def_readonly("complete", &scrape_reply_alert::complete)
        ;

    class_<scrape_failed_alert, bases<tracker_alert>, noncopyable>(
        "scrape_failed_alert", no_init
    );

    class_<udp_error_alert, bases<alert>, noncopyable>(
        "udp_error_alert", no_init
    )
        .def_readonly("endpoint", &udp_error_alert::endpoint)
        .def_readonly("error", &udp_error_alert::error)
        ;

    class_<external_ip_alert, bases<alert>, noncopyable>(
        "external_ip_alert", no_init
    )
        .def_readonly("external_address", &external_ip_alert::external_address)
        ;

    class_<save_resume_data_alert, bases<torrent_alert>, noncopyable>(
        "save_resume_data_alert", no_init
    )
        .def_readonly("resume_data", &save_resume_data_alert::resume_data)
        ;

    class_<file_renamed_alert, bases<torrent_alert>, noncopyable>(
        "file_renamed_alert", no_init
    )
        .def_readonly("index", &file_renamed_alert::index)
        .def_readonly("name", &file_renamed_alert::name)
        ;

    class_<file_rename_failed_alert, bases<torrent_alert>, noncopyable>(
        "file_rename_failed_alert", no_init
    )
        .def_readonly("index", &file_rename_failed_alert::index)
        .def_readonly("error", &file_rename_failed_alert::error)
        ;

    class_<torrent_resumed_alert, bases<torrent_alert>, noncopyable>(
        "torrent_resumed_alert", no_init
	);

	class_<state_changed_alert, bases<torrent_alert>, noncopyable>(
	    "state_changed_alert", no_init
	)
	    .def_readonly("state", &state_changed_alert::state)
	    .def_readonly("prev_state", &state_changed_alert::prev_state)
	    ;

	class_<dht_reply_alert, bases<tracker_alert>, noncopyable>(
	    "dht_reply_alert", no_init
	)
	    .def_readonly("num_peers", &dht_reply_alert::num_peers)
	    ;

    class_<dht_announce_alert, bases<alert>, noncopyable>(
        "dht_announce_alert", no_init
    )
        .def_readonly("ip" &dht_announce_alert::ip)
        .def_readonly("port", &dht_announce_alert::port)
        .def_readonly("info_hash", &dht_announce_alert::info_hash)
    ;

    class_<dht_get_peers_alert, bases<alert>, noncopyable>(
        "dht_get_peers_alert", no_init
    )
        .def_readonly("info_hash", &dht_get_peers_alert::info_hash)
    ;

	class_<peer_unsnubbed_alert, bases<peer_alert>, noncopyable>(
	    "peer_unsnubbed_alert", no_init
	);

	class_<peer_snubbed_alert, bases<peer_alert>, noncopyable>(
	    "peer_snubbed_alert", no_init
	);

    class_<peer_connect_alert, bases<peer_alert>, noncopyable>(
        "peer_connect_alert", no_init
    );

    class_<peer_disconnected_alert, bases<peer_alert>, noncopyable>(
        "peer_disconnected_alert", no_init
    )
        .def_readonly("msg", &peer_disconnected_alert::msg)
        ;

    class_<request_dropped_alert, bases<peer_alert>, noncopyable>(
        "request_dropped_alert", no_init
    )
        .def_readonly("block_index", &request_dropped_alert::block_index)
        .def_readonly("piece_index", &request_dropped_alert::piece_index)
    ;

    class_<block_timeout_alert, bases<peer_alert>, noncopyable>(
        "block_timeout_alert", no_init
    )
        .def_readonly("block_index", &block_timeout_alert::block_index)
        .def_readonly("piece_index", &block_timeout_alert::piece_index)
    ;

    class_<unwanted_block_alert, bases<peer_alert>, noncopyable>(
        "unwanted_block_alert", no_init
    )
        .def_readonly("block_index", &unwanted_block_alert::block_index)
        .def_readonly("piece_index", &unwanted_block_alert::piece_index)
    ;

    class_<torrent_delete_failed_alert, bases<torrent_alert>, noncopyable>(
        "torrent_delete_failed_alert", no_init
    )
        .def_readonly("msg", &torrent_delete_failed_alert::msg)
        ;

    class_<save_resume_data_failed_alert, bases<torrent_alert>, noncopyable>(
        "save_resume_data_failed_alert", no_init
    )
        .def_readonly("msg", &save_resume_data_failed_alert::msg)
        ;

    class_<performance_alert, bases<torrent_alert>, noncopyable>(
        "performance_alert", no_init
    )
        .def_readonly("warning_code", &performance_alert::warning_code)
    ;
    enum_<performance_alert::performance_warning_t>("performance_warning_t")
        .value("outstanding_disk_buffer_limit_reached", performance_alert::outstanding_disk_buffer_limit_reached)
        .value("outstanding_request_limit_reached", performance_alert::outstanding_request_limit_reached)
        .value("upload_limit_too_low", performance_alert::upload_limit_too_low)
        .value("download_limit_too_low", performance_alert::download_limit_too_low)
    ;

}
<commit_msg>Fix some typos<commit_after>// Copyright Daniel Wallin 2006. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/python.hpp>
#include <libtorrent/alert.hpp>
#include <libtorrent/alert_types.hpp>

using namespace boost::python;
using namespace libtorrent;

std::string get_buffer(read_piece_alert const& rpa)
{
    return rpa.buffer ? std::string(rpa.buffer.get(), rpa.size)
       : std::string();
}

void bind_alert()
{
    using boost::noncopyable;

    {
        scope alert_scope = class_<alert, noncopyable>("alert", no_init)
            .def("message", &alert::message)
            .def("what", &alert::what)
            .def("category", &alert::category)
#ifndef TORRENT_NO_DEPRECATE
            .def("severity", &alert::severity)
#endif
            .def("__str__", &alert::message)
            ;

#ifndef TORRENT_NO_DEPRECATE
        enum_<alert::severity_t>("severity_levels")
            .value("debug", alert::debug)
            .value("info", alert::info)
            .value("warning", alert::warning)
            .value("critical", alert::critical)
            .value("fatal", alert::fatal)
            .value("none", alert::none)
            ;
#endif

        enum_<alert::category_t>("category_t")
            .value("error_notification", alert::error_notification)
            .value("peer_notification", alert::peer_notification)
            .value("port_mapping_notification", alert::port_mapping_notification)
            .value("storage_notification", alert::storage_notification)
            .value("tracker_notification", alert::tracker_notification)
            .value("debug_notification", alert::debug_notification)
            .value("status_notification", alert::status_notification)
            .value("progress_notification", alert::progress_notification)
            .value("ip_block_notification", alert::ip_block_notification)
            .value("performance_warning", alert::performance_warning)
            .value("all_categories", alert::all_categories)
            ;

    }

    class_<torrent_alert, bases<alert>, noncopyable>(
        "torrent_alert", no_init
    )
        .def_readonly("handle", &torrent_alert::handle)
        ;

    class_<tracker_alert, bases<torrent_alert>, noncopyable>(
        "tracker_alert", no_init
    )
        .def_readonly("url", &tracker_alert::url)
        ;

    class_<read_piece_alert, bases<torrent_alert>, noncopyable>(
        "read_piece_alert", 0, no_init
    )
        .add_property("buffer", get_buffer)
        .def_readonly("piece", &read_piece_alert::piece)
        .def_readonly("size", &read_piece_alert::size)
        ;

    class_<peer_alert, bases<torrent_alert>, noncopyable>(
        "peer_alert", no_init
    )
        .def_readonly("ip", &peer_alert::ip)
        .def_readonly("pid", &peer_alert::pid)
    ;
    class_<tracker_error_alert, bases<tracker_alert>, noncopyable>(
        "tracker_error_alert", no_init
    )
        .def_readonly("msg", &tracker_error_alert::msg)
        .def_readonly("times_in_row", &tracker_error_alert::times_in_row)
        .def_readonly("status_code", &tracker_error_alert::status_code)
        ;

    class_<tracker_warning_alert, bases<tracker_alert>, noncopyable>(
        "tracker_warning_alert", no_init
    );

    class_<tracker_reply_alert, bases<tracker_alert>, noncopyable>(
        "tracker_reply_alert", no_init
    )
        .def_readonly("num_peers", &tracker_reply_alert::num_peers)
        ;

    class_<tracker_announce_alert, bases<tracker_alert>, noncopyable>(
        "tracker_announce_alert", no_init
    )
        .def_readonly("event", &tracker_announce_alert::event)
        ;

    class_<hash_failed_alert, bases<torrent_alert>, noncopyable>(
        "hash_failed_alert", no_init
    )
        .def_readonly("piece_index", &hash_failed_alert::piece_index)
        ;

    class_<peer_ban_alert, bases<peer_alert>, noncopyable>(
        "peer_ban_alert", no_init
    );

    class_<peer_error_alert, bases<peer_alert>, noncopyable>(
        "peer_error_alert", no_init
    );

    class_<invalid_request_alert, bases<peer_alert>, noncopyable>(
        "invalid_request_alert", no_init
    )
        .def_readonly("request", &invalid_request_alert::request)
        ;

    class_<peer_request>("peer_request")
        .def_readonly("piece", &peer_request::piece)
        .def_readonly("start", &peer_request::start)
        .def_readonly("length", &peer_request::length)
        .def(self == self)
        ;

    class_<torrent_finished_alert, bases<torrent_alert>, noncopyable>(
        "torrent_finished_alert", no_init
    );

    class_<piece_finished_alert, bases<torrent_alert>, noncopyable>(
        "piece_finished_alert", no_init
    )
        .def_readonly("piece_index", &piece_finished_alert::piece_index)
        ;

    class_<block_finished_alert, bases<peer_alert>, noncopyable>(
        "block_finished_alert", no_init
    )
        .def_readonly("block_index", &block_finished_alert::block_index)
        .def_readonly("piece_index", &block_finished_alert::piece_index)
        ;

    class_<block_downloading_alert, bases<peer_alert>, noncopyable>(
        "block_downloading_alert", no_init
    )
        .def_readonly("peer_speedmsg", &block_downloading_alert::peer_speedmsg)
        .def_readonly("block_index", &block_downloading_alert::block_index)
        .def_readonly("piece_index", &block_downloading_alert::piece_index)
        ;

    class_<storage_moved_alert, bases<torrent_alert>, noncopyable>(
        "storage_moved_alert", no_init
    )
        .def_readonly("path", &storage_moved_alert::path)
        ;

    class_<storage_moved_failed_alert, bases<torrent_alert>, noncopyable>(
        "storage_moved_failed_alert", no_init
    )
        .def_readonly("error", &storage_moved_failed_alert::error)
        ;

    class_<torrent_deleted_alert, bases<torrent_alert>, noncopyable>(
        "torrent_deleted_alert", no_init
    );

    class_<torrent_paused_alert, bases<torrent_alert>, noncopyable>(
        "torrent_paused_alert", no_init
    );

    class_<torrent_checked_alert, bases<torrent_alert>, noncopyable>(
        "torrent_checked_alert", no_init
    );

    class_<url_seed_alert, bases<torrent_alert>, noncopyable>(
        "url_seed_alert", no_init
    )
        .def_readonly("url", &url_seed_alert::url)
        .def_readonly("msg", &url_seed_alert::msg)
        ;

    class_<file_error_alert, bases<torrent_alert>, noncopyable>(
        "file_error_alert", no_init
    )
        .def_readonly("file", &file_error_alert::file)
        .def_readonly("msg", &file_error_alert::msg)
        ;

    class_<metadata_failed_alert, bases<torrent_alert>, noncopyable>(
        "metadata_failed_alert", no_init
    );

    class_<metadata_received_alert, bases<torrent_alert>, noncopyable>(
        "metadata_received_alert", no_init
    );

    class_<listen_failed_alert, bases<alert>, noncopyable>(
        "listen_failed_alert", no_init
    )
        .def_readonly("endpoint", &listen_failed_alert::endpoint)
        .def_readonly("error", &listen_failed_alert::error)
        ;

    class_<listen_succeeded_alert, bases<alert>, noncopyable>(
        "listen_succeeded_alert", no_init
    )
        .def_readonly("endpoint", &listen_succeeded_alert::endpoint)
        ;

    class_<portmap_error_alert, bases<alert>, noncopyable>(
        "portmap_error_alert", no_init
    )
        .def_readonly("mapping", &portmap_error_alert::mapping)
        .def_readonly("type", &portmap_error_alert::type)
        .def_readonly("msg", &portmap_error_alert::msg)
        ;

    class_<portmap_alert, bases<alert>, noncopyable>(
        "portmap_alert", no_init
    )
        .def_readonly("mapping", &portmap_alert::mapping)
        .def_readonly("external_port", &portmap_alert::external_port)
        .def_readonly("type", &portmap_alert::type)
        ;

    class_<portmap_log_alert, bases<alert>, noncopyable>(
        "portmap_log_alert", no_init
    )
        .def_readonly("type", &portmap_log_alert::type)
        .def_readonly("msg", &portmap_log_alert::msg)
        ;

    class_<fastresume_rejected_alert, bases<torrent_alert>, noncopyable>(
        "fastresume_rejected_alert", no_init
    )
        .def_readonly("msg", &fastresume_rejected_alert::msg)
        ;

    class_<peer_blocked_alert, bases<alert>, noncopyable>(
        "peer_blocked_alert", no_init
    )
        .def_readonly("ip", &peer_blocked_alert::ip)
        ;

    class_<scrape_reply_alert, bases<tracker_alert>, noncopyable>(
        "scrape_reply_alert", no_init
    )
        .def_readonly("incomplete", &scrape_reply_alert::incomplete)
        .def_readonly("complete", &scrape_reply_alert::complete)
        ;

    class_<scrape_failed_alert, bases<tracker_alert>, noncopyable>(
        "scrape_failed_alert", no_init
    );

    class_<udp_error_alert, bases<alert>, noncopyable>(
        "udp_error_alert", no_init
    )
        .def_readonly("endpoint", &udp_error_alert::endpoint)
        .def_readonly("error", &udp_error_alert::error)
        ;

    class_<external_ip_alert, bases<alert>, noncopyable>(
        "external_ip_alert", no_init
    )
        .def_readonly("external_address", &external_ip_alert::external_address)
        ;

    class_<save_resume_data_alert, bases<torrent_alert>, noncopyable>(
        "save_resume_data_alert", no_init
    )
        .def_readonly("resume_data", &save_resume_data_alert::resume_data)
        ;

    class_<file_renamed_alert, bases<torrent_alert>, noncopyable>(
        "file_renamed_alert", no_init
    )
        .def_readonly("index", &file_renamed_alert::index)
        .def_readonly("name", &file_renamed_alert::name)
        ;

    class_<file_rename_failed_alert, bases<torrent_alert>, noncopyable>(
        "file_rename_failed_alert", no_init
    )
        .def_readonly("index", &file_rename_failed_alert::index)
        .def_readonly("error", &file_rename_failed_alert::error)
        ;

    class_<torrent_resumed_alert, bases<torrent_alert>, noncopyable>(
        "torrent_resumed_alert", no_init
	);

	class_<state_changed_alert, bases<torrent_alert>, noncopyable>(
	    "state_changed_alert", no_init
	)
	    .def_readonly("state", &state_changed_alert::state)
	    .def_readonly("prev_state", &state_changed_alert::prev_state)
	    ;

	class_<dht_reply_alert, bases<tracker_alert>, noncopyable>(
	    "dht_reply_alert", no_init
	)
	    .def_readonly("num_peers", &dht_reply_alert::num_peers)
	    ;

    class_<dht_announce_alert, bases<alert>, noncopyable>(
        "dht_announce_alert", no_init
    )
        .def_readonly("ip", &dht_announce_alert::ip)
        .def_readonly("port", &dht_announce_alert::port)
        .def_readonly("info_hash", &dht_announce_alert::info_hash)
    ;

    class_<dht_get_peers_alert, bases<alert>, noncopyable>(
        "dht_get_peers_alert", no_init
    )
        .def_readonly("info_hash", &dht_get_peers_alert::info_hash)
    ;

	class_<peer_unsnubbed_alert, bases<peer_alert>, noncopyable>(
	    "peer_unsnubbed_alert", no_init
	);

	class_<peer_snubbed_alert, bases<peer_alert>, noncopyable>(
	    "peer_snubbed_alert", no_init
	);

    class_<peer_connect_alert, bases<peer_alert>, noncopyable>(
        "peer_connect_alert", no_init
    );

    class_<peer_disconnected_alert, bases<peer_alert>, noncopyable>(
        "peer_disconnected_alert", no_init
    )
        .def_readonly("msg", &peer_disconnected_alert::msg)
        ;

    class_<request_dropped_alert, bases<peer_alert>, noncopyable>(
        "request_dropped_alert", no_init
    )
        .def_readonly("block_index", &request_dropped_alert::block_index)
        .def_readonly("piece_index", &request_dropped_alert::piece_index)
    ;

    class_<block_timeout_alert, bases<peer_alert>, noncopyable>(
        "block_timeout_alert", no_init
    )
        .def_readonly("block_index", &block_timeout_alert::block_index)
        .def_readonly("piece_index", &block_timeout_alert::piece_index)
    ;

    class_<unwanted_block_alert, bases<peer_alert>, noncopyable>(
        "unwanted_block_alert", no_init
    )
        .def_readonly("block_index", &unwanted_block_alert::block_index)
        .def_readonly("piece_index", &unwanted_block_alert::piece_index)
    ;

    class_<torrent_delete_failed_alert, bases<torrent_alert>, noncopyable>(
        "torrent_delete_failed_alert", no_init
    )
        .def_readonly("msg", &torrent_delete_failed_alert::msg)
        ;

    class_<save_resume_data_failed_alert, bases<torrent_alert>, noncopyable>(
        "save_resume_data_failed_alert", no_init
    )
        .def_readonly("msg", &save_resume_data_failed_alert::msg)
        ;

    class_<performance_alert, bases<torrent_alert>, noncopyable>(
        "performance_alert", no_init
    )
        .def_readonly("warning_code", &performance_alert::warning_code)
    ;
    enum_<performance_alert::performance_warning_t>("performance_warning_t")
        .value("outstanding_disk_buffer_limit_reached", performance_alert::outstanding_disk_buffer_limit_reached)
        .value("outstanding_request_limit_reached", performance_alert::outstanding_request_limit_reached)
        .value("upload_limit_too_low", performance_alert::upload_limit_too_low)
        .value("download_limit_too_low", performance_alert::download_limit_too_low)
    ;

}
<|endoftext|>


<commit_before>#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include "simulator.h"
#include "thread_manager.h"
#include "core_manager.h"
#include "core.h"
#include "config_file.hpp"

#include "carbon_user.h"
#include "thread_support_private.h"

CAPI_return_t CAPI_rank(int *core_id)
{
   *core_id = CarbonGetCoreId();
   return 0;
}

CAPI_return_t CAPI_Initialize(int rank)
{
   Sim()->getCoreManager()->initializeCommId(rank);
   return 0;
}

CAPI_return_t CAPI_message_send_w(CAPI_endpoint_t sender, CAPI_endpoint_t receiver,
                       char *buffer, int size)
{
   Core *core = Sim()->getCoreManager()->getCurrentCore();

   LOG_PRINT("SimSendW - sender: %d, recv: %d", sender, receiver);

   core_id_t sending_core = Config::getSingleton()->getCoreFromCommId(sender);
   core_id_t receiving_core = Config::getSingleton()->getCoreFromCommId(receiver);

   if(sending_core == INVALID_CORE_ID)
       return CAPI_SenderNotInitialized;
   if(receiving_core == INVALID_CORE_ID)
       return CAPI_ReceiverNotInitialized;

   return core ? core->coreSendW(sending_core, receiving_core, buffer, size) : CAPI_SenderNotInitialized;
}

CAPI_return_t CAPI_message_receive_w(CAPI_endpoint_t sender, CAPI_endpoint_t receiver,
                       char *buffer, int size)
{
   Core *core = Sim()->getCoreManager()->getCurrentCore();

   LOG_PRINT("SimRecvW - sender: %d, recv: %d", sender, receiver);

   core_id_t sending_core = Config::getSingleton()->getCoreFromCommId(sender);
   core_id_t receiving_core = Config::getSingleton()->getCoreFromCommId(receiver);

   if(sending_core == INVALID_CORE_ID)
       return CAPI_SenderNotInitialized;
   if(receiving_core == INVALID_CORE_ID)
       return CAPI_ReceiverNotInitialized;

   return core ? core->coreRecvW(sending_core, receiving_core, buffer, size) : CAPI_ReceiverNotInitialized;
}
<commit_msg>[capi] Print message size on send.<commit_after>#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include "simulator.h"
#include "thread_manager.h"
#include "core_manager.h"
#include "core.h"
#include "config_file.hpp"

#include "carbon_user.h"
#include "thread_support_private.h"

CAPI_return_t CAPI_rank(int *core_id)
{
   *core_id = CarbonGetCoreId();
   return 0;
}

CAPI_return_t CAPI_Initialize(int rank)
{
   Sim()->getCoreManager()->initializeCommId(rank);
   return 0;
}

CAPI_return_t CAPI_message_send_w(CAPI_endpoint_t sender, CAPI_endpoint_t receiver,
                       char *buffer, int size)
{
   Core *core = Sim()->getCoreManager()->getCurrentCore();

   LOG_PRINT("SimSendW - sender: %d, recv: %d, size: %d", sender, receiver, size);

   core_id_t sending_core = Config::getSingleton()->getCoreFromCommId(sender);
   core_id_t receiving_core = Config::getSingleton()->getCoreFromCommId(receiver);

   if(sending_core == INVALID_CORE_ID)
       return CAPI_SenderNotInitialized;
   if(receiving_core == INVALID_CORE_ID)
       return CAPI_ReceiverNotInitialized;

   return core ? core->coreSendW(sending_core, receiving_core, buffer, size) : CAPI_SenderNotInitialized;
}

CAPI_return_t CAPI_message_receive_w(CAPI_endpoint_t sender, CAPI_endpoint_t receiver,
                       char *buffer, int size)
{
   Core *core = Sim()->getCoreManager()->getCurrentCore();

   LOG_PRINT("SimRecvW - sender: %d, recv: %d", sender, receiver);

   core_id_t sending_core = Config::getSingleton()->getCoreFromCommId(sender);
   core_id_t receiving_core = Config::getSingleton()->getCoreFromCommId(receiver);

   if(sending_core == INVALID_CORE_ID)
       return CAPI_SenderNotInitialized;
   if(receiving_core == INVALID_CORE_ID)
       return CAPI_ReceiverNotInitialized;

   return core ? core->coreRecvW(sending_core, receiving_core, buffer, size) : CAPI_ReceiverNotInitialized;
}
<|endoftext|>