?? shortmsg.c
字號:
/*
* Copyright (c) 2000-2008
* Author: Weiming Zhou
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*/
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include "CapiGlobal.h"
#include "DoubleList.h"
#define MAX_PHONE_NUMBER_LEN 16
typedef struct SHORTMSG_st {
time_t time;
char pszSrcPhone[MAX_PHONE_NUMBER_LEN];
char pszTagPhone[MAX_PHONE_NUMBER_LEN];
char * pszMsg;
INT nState;
} SHORTMSG;
typedef struct SHORTMSGCACHE_st {
DOUBLELIST *pList;
} SHORTMSGCACHE;
/** 短信息發送的回調函數指針定義
@param SHORTMSG - 指向一條短信息的指針
@return INT - CAPI_FAILED表示發送失敗,CAPI_SUCCESS表示發送成功
*/
typedef INT (*SHORTMSGSENDFUNC)(SHORTMSG *pMsg);
/** 短信息CACHE的創建函數
@return SHORTMSGCACHE * -成功返回創建的短信息CACHE對象指針,
失敗返回NULL。
*/
SHORTMSGCACHE *ShortMsgCache_Create()
{
SHORTMSGCACHE *pCache;
pCache = (SHORTMSGCACHE *)malloc(sizeof(SHORTMSGCACHE));
if ( pCache != NULL )
{
pCache->pList = DoubleList_Create();
if ( pCache->pList == NULL )
{
free(pCache);
pCache = NULL;
}
}
return pCache;
}
/** 短信息CACHE釋放的回調函數,用來釋放一條短信息
@param void *p - 指向一條短信息SHORTMSG的指針
@return void - 無
*/
void ShortMsgDestroy(void *p)
{
SHORTMSG *pMsg = (SHORTMSG *)p;
if ( pMsg != NULL )
{
if ( pMsg->pszMsg != NULL )
{
free( pMsg->pszMsg );
}
free(pMsg);
}
}
/** 短信息CACAE的釋放函數,將鏈表中保存的短信息全部釋放掉
@param SHORTMSGCACHE *pCache - 要釋放的短信息CACHE對象指針
@return void - 無
*/
void ShortMsgCache_Destroy(SHORTMSGCACHE *pCache)
{
if ( pCache != NULL )
{
DoubleList_Destroy(pCache->pList, ShortMsgDestroy);
free(pCache);
}
}
/** 短信息CACHE接收函數,將接收到的短信息存入鏈表中
@param SHORTMSGCACHE *pCache - 短信息CACHE對象指針
@param SHORTMSG *pMsg - 短信息指針,指向一條短信息
@return INT - CAPI_FAILED表示失敗,CAPI_SUCCESS表示成功。
*/
INT ShortMsgCache_Recv(SHORTMSGCACHE *pCache, SHORTMSG *pMsg)
{
return DoubleList_InsertTail(pCache->pList, (void *)pMsg);
}
/** 短消息發送函數,從CACHE里取出一條信息發送出去
發送如果失敗會將信息重新插入鏈表尾部。
@param SHORTMSGCACHE *pCache - 短信息CACHE對象指針
@param SHORTMSGSENDFUNC SendFunc - 發送短信息的回調函數
@return INT - CAPI_FAILED表示失敗,CAPI_SUCCESS表示成功。
*/
INT ShortMsgCache_Send(SHORTMSGCACHE *pCache, SHORTMSGSENDFUNC SendFunc)
{
SHORTMSG *pMsg;
pMsg = DoubleList_PopHead(pCache->pList);
if ( pMsg == NULL )
{
return CAPI_FAILED;
}
if ( (*SendFunc)(pMsg) != CAPI_SUCCESS )
{
DoubleList_InsertTail(pCache->pList, (void *)pMsg);
return CAPI_FAILED;
}
else
{
ShortMsgDestroy(pMsg);
}
return CAPI_SUCCESS;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -