#include "charm++.h"
#include <stdio.h>

#include "server.top.h"
#include "server.h"

int grpid, methodId;

void handler(char *msg)
{
  // send message to the callback method
  CallbackMsg *callbackMsg = new (MsgIndex(CallbackMsg)) CallbackMsg;
  GeneralSendMsgBranch(methodId, callbackMsg, CMyPe(), -1, grpid);
}

server::server(Msg *msg)
{
  CcsRegisterHandler("migrate", (CmiHandler) handler);
  CPrintf("Migrate Handler registered on processor %d\n", CMyPe());
  delete msg;
}

void
server::Register(RegMsg *msg)
{
  grpid = msg->grpid;
  methodId = msg->methodId;
  CPrintf("Callback registered on processor %d\n", CMyPe());
  delete msg;
}

#include "server.bot.h"
