You are on page 1of 3

#include<omnetpp.

h>
#include<string.h>
#include <winsock.h>
#include <stdio.h>
#include <mysql.h>

MYSQL *pConnection;
MYSQL_RES *pResult=NULL;
MYSQL_ROW Row;
char Query[256];
class Server:public cSimpleModule
{

void initialize();
void handleMessage(cMessage *msg);
void rcv();
void checkValid(int id,string tpc);
void getValue(int id);

};

Define_Module(Server);
void Server::initialize()
{
pConnection = mysql_init(NULL);

mysql_real_connect(pConnection,"localhost","root","root","project",0,NULL,0);

if(strcmp("tic",getName())==0)
{
cMessage *msg=new cMessage("Hammad");
send (msg,"out");
ev << "hello .....temp is updated" << endl;
}
}

void Server::rcv(cMessage *msg)
{

}

void Server::checkValid(int id,string tpc)
{
string tps=sprintf(Query, "select tp from server where id='%d'",id);
mysql_query(pConnection, Query);
if (tps>tpc)
m=0;
else
m=1;
send(m,"out");
}
void Server::getValue(int id)
{
string temp=sprintf(Query, "select temp from server where id='%d'",id);
send(temp,"out");
}


void Server::handleMessage(cMessage *msg)
{
send(msg,"out");


//char *a = new char[msg];
char a[]="hammad" ;
sprintf(Query, "INSERT into a values ('%s\')",a);
mysql_query(pConnection, Query);

}

You might also like