#include "coda.h"
int creacoda(int key)
{
int coda;
if ((coda = msgget(key,IPC_CREAT | PERMESSI)) != -1)
{
//printf("\n Coda ID :: %d \n",coda);
return(coda);
}
else
{
printf("\nErrore nella creazione della coda di messaggi\n");
return(-1);
}
}
void delcoda(int codaid)
{
if (msgctl(codaid,IPC_RMID,(struct msqid_ds *)0) == -1)
printf("\n Errore di rimozione coda \n");
}
void sms_send(int id, sms *mesgptr)
{
if (msgsnd(id, (char *)&(mesgptr->mesg_type), mesgptr->mesg_len, IPC_NOWAIT) < 0 )
printf("\n Errore invio sms \n");
}
int sms_rcv(int id, sms *mesgptr)
{
int n;
n = msgrcv(id, (char *)&(mesgptr->mesg_type), MAX, mesgptr->mesg_type, 0);
if ((mesgptr->mesg_len = n ) < 0) printf("\n Errore ricezione sms \n");
else return n;
}
void crea_sms(int pid, int punti, int sem_id, sms *mesgptr)
{
sprintf(mesgptr->mesg_data,"%d %d %d",pid,punti,sem_id);
mesgptr->mesg_len = strlen(mesgptr->mesg_data);
mesgptr->mesg_type= 1;
}
void salva_sms(notes v,int i, sms *mesgptr,int end)
{
char stringapunti[10];
char stringapid[10];
char stringasem_id[10];
mesgptr->mesg_data[end] = '\0';
sscanf(mesgptr->mesg_data,"%s %s %s",stringapid,stringapunti,stringasem_id);
v[i].pid = atoi(stringapid);
v[i].punti = atoi(stringapunti);
v[i].sem_id = atoi(stringasem_id);
}