TSG-14930 TFE支持发送控制报文给SAPP
This commit is contained in:
@@ -24,6 +24,8 @@ struct tfe_cmsg_tlv
|
||||
|
||||
struct tfe_cmsg
|
||||
{
|
||||
uint8_t flag;
|
||||
uint8_t ref;
|
||||
pthread_rwlock_t rwlock;
|
||||
uint16_t nr_tlvs;
|
||||
struct tfe_cmsg_tlv* tlvs[TFE_CMSG_TLV_NR_MAX];
|
||||
@@ -43,6 +45,10 @@ struct tfe_cmsg* tfe_cmsg_init()
|
||||
cmsg->size = sizeof(struct tfe_cmsg_serialize_header);
|
||||
|
||||
pthread_rwlock_init(&(cmsg->rwlock), NULL);
|
||||
|
||||
ATOMIC_ZERO(&cmsg->flag);
|
||||
ATOMIC_ZERO(&cmsg->ref);
|
||||
ATOMIC_INC(&cmsg->ref);
|
||||
return cmsg;
|
||||
}
|
||||
|
||||
@@ -50,6 +56,8 @@ void tfe_cmsg_destroy(struct tfe_cmsg *cmsg)
|
||||
{
|
||||
if(cmsg != NULL)
|
||||
{
|
||||
if ((__sync_sub_and_fetch(&cmsg->ref, 1) != 0))
|
||||
return;
|
||||
pthread_rwlock_wrlock(&cmsg->rwlock);
|
||||
for(int i = 0; i < TFE_CMSG_TLV_NR_MAX; i++)
|
||||
{
|
||||
@@ -57,9 +65,31 @@ void tfe_cmsg_destroy(struct tfe_cmsg *cmsg)
|
||||
}
|
||||
pthread_rwlock_unlock(&cmsg->rwlock);
|
||||
pthread_rwlock_destroy(&cmsg->rwlock);
|
||||
FREE(&cmsg);
|
||||
}
|
||||
}
|
||||
|
||||
FREE(&cmsg);
|
||||
void tfe_cmsg_dup(struct tfe_cmsg *cmsg)
|
||||
{
|
||||
if (cmsg == NULL)
|
||||
return;
|
||||
ATOMIC_INC(&cmsg->ref);
|
||||
}
|
||||
|
||||
void tfe_cmsg_set_flag(struct tfe_cmsg *cmsg, uint8_t flag)
|
||||
{
|
||||
if (cmsg == NULL)
|
||||
return;
|
||||
ATOMIC_SET(&cmsg->flag, flag);
|
||||
}
|
||||
|
||||
uint8_t tfe_cmsg_get_flag(struct tfe_cmsg *cmsg)
|
||||
{
|
||||
if (cmsg == NULL)
|
||||
return 0;
|
||||
uint8_t flag = 0;
|
||||
flag = ATOMIC_READ(&cmsg->flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
int tfe_cmsg_set(struct tfe_cmsg * cmsg, enum tfe_cmsg_tlv_type type, const unsigned char * value, uint16_t size)
|
||||
@@ -230,6 +260,7 @@ int tfe_cmsg_deserialize(const unsigned char *data, uint16_t len, struct tfe_cms
|
||||
}
|
||||
|
||||
cmsg = ALLOC(struct tfe_cmsg, 1);
|
||||
pthread_rwlock_init(&(cmsg->rwlock), NULL);
|
||||
offset = sizeof(struct tfe_cmsg_serialize_header);
|
||||
nr_tlvs = ntohs(header->nr_tlvs);
|
||||
for(int i = 0; i < nr_tlvs; i++)
|
||||
@@ -258,9 +289,7 @@ int tfe_cmsg_deserialize(const unsigned char *data, uint16_t len, struct tfe_cms
|
||||
offset += length;
|
||||
}
|
||||
cmsg->size = offset;
|
||||
pthread_rwlock_wrlock(&((*pcmsg)->rwlock));
|
||||
*pcmsg = cmsg;
|
||||
pthread_rwlock_unlock(&((*pcmsg)->rwlock));
|
||||
return 0;
|
||||
|
||||
error_out:
|
||||
|
||||
Reference in New Issue
Block a user