随笔 - 74, 文章 - 0, 评论 - 26, 引用 - 0
数据加载中……

system V消息机制

#ifndef MSG_H
#define MSG_H
//msgid
#define LISTEN_THREAD  7
#define CENTER_THREAD  0
#define SEND_THREAD   2
#define REV_THREAD   3
#define TIME_THREAD   4
//lp
#define EXIT    0
#define SEND_SGIP_SUBMIT 1
#define SEND_SGIP_BIND
#define SEND_SGIP_R
#define SEND_SGIP_UNBIND
#define SEND_SGIP_UNBIND_R
#define REV_SGIP_SOCKET
//wp
#define SEND_SUCCESS
#define PACK_FAIL
#define SEND_FAIL
enum mgnt_cmd_type
{
 event_login         = 0,
  event_logout,
  event_sip_init_para,
  event_log_init_para,
  event_sip_clean,
  event_set_dtmf_mode,
  event_set_dhcp,
  event_set_pppoe,
  
  event_pstn_call_out,
  event_sip_call_out,
  event_answer_sipcall,
  event_release_sipcall,
  event_loadBMP_init,
  
  
  event_pstn_call_in=20,
  event_sip_call_in,
  event_remote_release_call,
  event_remote_establish_call,
  event_remote_cancelcall,
  event_login_return,
  event_remote_ignore,

  event_set_pstn_ring,
  event_set_sip_ring,
  event_set_alarm_ring,
  event_set_ring_volume
  
};

typedef struct msgbuf
{
 long   msgtype;
 unsigned long msgid;
 unsigned long lp;
 unsigned long wp;
}MSGBuf, *pMSGBuf;


int vvMSGSend(long thread_id, unsigned long msgid, unsigned long lp, unsigned long wp);
int vvMSGRecv(long thread_id, struct msgbuf *msg, int is_wait);


#ifndef _WINDOWS

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>

#define MSG_FILE_NAME    "/rw/"      //"/mnt/"
#define MSG_FLAG   (IPC_CREAT  | 00666)
//| IPC_EXCL
 


typedef struct sendMsg
{
 int sd;
 void *content;
}SendMsg, *pSendMsg;


#endif

#endif //MSG_H





#include "vvmsg.h"
#include <ps_log.h>

#ifndef _WINDOWS
#include <phone_Interface.h>
#include <pthread.h>
#include <basegdi.h>
#include <keyboard.h>
//#include "hash.h"
extern  pthread_t g_incomingthread;
//extern  hash_table table;
#endif

 

int vvMSGSend(long thread_id, unsigned long msgid, unsigned long lp, unsigned long wp)

 struct msgbuf bmsg;
#ifndef _WINDOWS
 key_t key;

 int msg_id;
 bmsg.msgtype = thread_id;
 bmsg.msgid = msgid;
 bmsg.lp = lp;
 bmsg.wp = wp;

 if((key = ftok(MSG_FILE_NAME,'a')) == -1)
 {
  return -1;
 }

 if((msg_id = msgget(key,MSG_FLAG)) == -1)
 {
  return -1;
 }

 if (msgsnd(msg_id, &bmsg, sizeof(struct msgbuf), IPC_NOWAIT) == -1)
 {
  return -1;
 }
#endif
 return 1;

}

int vvMSGRecv(long thread_id, struct msgbuf *msg, int is_wait)
{
 #ifndef _WINDOWS
 key_t key;  
 int msg_id;
 if((key = ftok(MSG_FILE_NAME,'a')) == -1)
 {
  printf("Recv msg error 1!\n");
  return -1;
 }
 if((msg_id = msgget(key,MSG_FLAG)) == -1)
 {
  printf("Recv msg error 2!\n");
  return -1;
 }
 if (is_wait != 1)
 {
  if (msgrcv(msg_id, msg, sizeof(struct msgbuf), thread_id, IPC_NOWAIT) == -1)
  {
   printf("Recv msg error 3!\n");
   return -1;
  } 
 }
 else
 {
  if (msgrcv(msg_id, msg, sizeof(struct msgbuf), thread_id, 0) == -1)
  {
   //printf("Recv msg error 4!\n");
   return -1;
  }
 }
  #endif
 return 1;

}

void *skype_thread_start(void *arg)
{
 #ifndef _WINDOWS
 MSGBuf msg;
 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,0);//设置线程属性
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,0);
 for (;;)
 {
  pthread_testcancel();//设置取消点
  if (vvMSGRecv((long)g_incomingthread, &msg, 1) == -1)
   continue;
  
  // analysis the message
  switch (msg.msgid)
  {
   ps_show_str(log_DEBUG, "vvmsg event!!!!!!!!!!!!!!!%d\r\n", msg.msgid);
  case event_login:
   {
    userLogin();
    
   }
   break;
  case event_logout:
   {
    userLogout();
   }
  case event_sip_clean:
   {
    SipClean();
   }
   break;
  case event_sip_init_para:
   {
    ps_show_str(log_DEBUG, "event before################UpdateSipInitPara\r\n");
    UpdateSipInitPara();
    ps_show_str(log_DEBUG, "event after##################UpdateSipInitPara\r\n");
   }
   break;
  case event_log_init_para:
   {
    UpdateLogInitPara();
   }
   break;
  case event_set_dtmf_mode:
   {
    int i = (int)msg.lp;
    ps_show_str(log_DEBUG, "event_set_dtmf_mode########################%d\r\n", i);
    SetDTMFMode(i);
   }
   break;
  case event_set_dhcp:
   {
    SetDHCP();
   }
   break;
  case event_set_pppoe:
   {
    SetPPPOE();
   }
   break;

  case event_pstn_call_out:
   {
    pstncall((char*)msg.lp);
   }
   break;
  case event_sip_call_out:
   {
    
    sipcall((char*)msg.lp);
   }
   break;

  case event_answer_sipcall:
   {
    callmgr_answercall((LINE_ID_T *)msg.lp);
   }
   break;
        case event_release_sipcall:
   {
    callmgr_releasecall((LINE_ID_T *)msg.lp);
   }
   break;
  case event_loadBMP_init:
   {
    CreateSysBmp();
    
   }
   break;
   

 

 

 

 

 

 

 

  case event_pstn_call_in:
   {
    LINE_ID_T *line = (LINE_ID_T *)msg.wp;
    sipcome_create(line);
   }
   break;
  case event_sip_call_in:
   {
    LINE_ID_T *line = (LINE_ID_T *)msg.wp;
    sipcome_create(line);
   }
   break;
 
  case event_remote_establish_call:
   {
    
    LINE_ID_T *line = (LINE_ID_T *)msg.wp;
    pstnchat_create(line);
    if(g_Hwnd[HWND_CALLOUT]!=0)
    calling_destroy(g_Hwnd[HWND_CALLOUT]);
    
   }
   break;
  case event_remote_cancelcall:
   {
    if(g_Hwnd[HWND_CALLIN]!=0)
   SendMessage(g_Hwnd[HWND_CALLIN],MSG_KEYDOWN,KEY_SW_RSK,0);
   }
   break;
  case event_remote_release_call:
   {
    if(g_Hwnd[HWND_CHAT]!=0)
    SendMessage(g_Hwnd[HWND_CHAT],MSG_KEYDOWN,KEY_SW_RSK,0);
   }
   break;
  case event_login_return:
   {
    printf("sfds0000000000000000000000000000000dssssssss^^^^^^^^^^^^^^^^^\r\n");
    if(g_Hwnd[HWND_MAINSCREEN]!=0)
    {
     UpdateWindow(g_Hwnd[HWND_MAINSCREEN],1);
    // SetFocusChild(g_Hwnd[HWND_MAINSCREEN]);
    // ShowWindow(g_Hwnd[HWND_MAINSCREEN], SW_SHOW);
    }
   }
   break;
  case event_remote_ignore:
   {
    if(g_Hwnd[HWND_CALLOUT]!=0)
    SendMessage(g_Hwnd[HWND_CALLOUT],MSG_KEYDOWN,KEY_SW_RSK,0); 
   }
   break;
  case event_set_pstn_ring:
   {
    SetPstnRing((int)msg.lp);
   }
   break;
  case event_set_sip_ring:
   {
    SetSipRing((int)msg.lp);
   }
   break;
  case event_set_ring_volume:
   {
    SetRingVolume((int)msg.lp);
   }
   break;
  }

 }
 #endif
}

附(创建线程):if (pthread_create(&g_incomingthread, NULL, skype_thread_start, NULL))
  return -1;

posted on 2006-06-27 09:23 井泉 阅读(281) 评论(0)  编辑 收藏 引用 所属分类: c code


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理