diff --git a/Makefile.am b/Makefile.am index 07b8ee02..f28b870e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -610,7 +610,9 @@ if MBIMMODEM mbim_sources = drivers/mbimmodem/mbim.h \ drivers/mbimmodem/mbim.c \ drivers/mbimmodem/mbim-desc.h \ - drivers/mbimmodem/mbim-desc.c + drivers/mbimmodem/mbim-desc.c \ + drivers/mbimmodem/mbim-message.h \ + drivers/mbimmodem/mbim-message.c builtin_modules += mbimmodem builtin_sources += $(mbim_sources) \ diff --git a/drivers/mbimmodem/mbim-message.c b/drivers/mbimmodem/mbim-message.c new file mode 100644 index 00000000..85993fdc --- /dev/null +++ b/drivers/mbimmodem/mbim-message.c @@ -0,0 +1,62 @@ +/* + * + * oFono - Open Source Telephony + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "mbim-message.h" + +struct mbim_message { + int ref_count; +}; + +struct mbim_message *mbim_message_new(const uint8_t *uuid, uint32_t cid) +{ + struct mbim_message *msg; + + msg = l_new(struct mbim_message, 1); + + return mbim_message_ref(msg); +} + +struct mbim_message *mbim_message_ref(struct mbim_message *msg) +{ + if (unlikely(!msg)) + return NULL; + + __sync_fetch_and_add(&msg->ref_count, 1); + + return msg; +} + +void mbim_message_unref(struct mbim_message *msg) +{ + if (unlikely(!msg)) + return; + + if (__sync_sub_and_fetch(&msg->ref_count, 1)) + return; + + l_free(msg); +} diff --git a/drivers/mbimmodem/mbim-message.h b/drivers/mbimmodem/mbim-message.h new file mode 100644 index 00000000..595b4caa --- /dev/null +++ b/drivers/mbimmodem/mbim-message.h @@ -0,0 +1,28 @@ +/* + * + * oFono - Open Source Telephony + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +struct mbim_message; + +struct mbim_message *mbim_message_new(const uint8_t *uuid, uint32_t cid); +struct mbim_message *mbim_message_ref(struct mbim_message *msg); +void mbim_message_unref(struct mbim_message *msg);