LinphoneCore構造体の作成方法
41961 ワード
Linphoneの新しいバージョンはLibLinphoneに対してC++の再構築をして、いくつかのC++11の新しい特性を使って、いくつかのLinphoneCall、LinphoneCore、LinphoneChatMessage、LinphoneChatRoom、LinphoneEventLog、LinphoneCallParamsなどの構造体はL_DECLARE_C_OBJECT_IMPL_WITH_XTORSマクロ定義、このマクロはsubmoduleslinphonesrcc-wrapperinternalc-tools.hは、以下のいくつかのマクロに関する.
例えばLinphoneCoreはマクロをCTYPEに置き換えCore L_に置き換えるINTERNAL_DECLARE_C_OBJECTはLinphoneCore構造体を定義した
L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONSはLinphoneCoreのいくつかの関数の定義と実現に対して.
これでLinphoneCoreで使用した構造体と関数定義が完了し,異なる構造体はC_のみである.TYPE、CONTRUCTOR、DESTRUCTORは違うだけです.プロジェクトでは、L_SET_CPP_PTR_FROM_C_OBJECTは、構造体中のweakCppPtrまたはcppPtrに付与.L_GET_CPP_PTR_FROM_C_OBJECTは、構造体中のweakCppPtrまたはcppPtrの値を取得する.L_GET_PRIVATE_FROM_C_OBJECTは、接合体中のプライベートC++クラスを取得する.L_GET_C_BACK_PTRは、C++オブジェクトを含む構造体を取得する
LinphoneCoreの作成を例に
#define L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, ...) \
L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, __VA_ARGS__) \
L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR)
例えばLinphoneCoreはマクロをCTYPEに置き換えCore L_に置き換えるINTERNAL_DECLARE_C_OBJECTはLinphoneCore構造体を定義した
static_assert(LinphonePrivate::CTypeMetaInfo<LinphoneCore>::defined, "Type is not defined.");
static_assert(
LinphonePrivate::IsDefinedBaseCppObject<
LinphonePrivate::CTypeMetaInfo<LinphoneCore>::cppType
>::value,
"Type is not declared as base object."
);
struct _LinphoneCore {
belle_sip_object_t base;
std::shared_ptr<LinphonePrivate::CTypeMetaInfo<LinphoneCore>::cppType> cppPtr;
std::weak_ptr<LinphonePrivate::CTypeMetaInfo<LinphoneCore> weakCppPtr;
int owner;
MSFactory* factory;
MSList* vtable_refs;
int vtable_notify_recursion;
LinphonePrivate::Sal *sal;
void *platform_helper;
LinphoneGlobalState state;
struct _LpConfig *config;
MSList *default_audio_codecs;
MSList *default_video_codecs;
MSList *default_text_codecs;
net_config_t net_conf;
sip_config_t sip_conf;
rtp_config_t rtp_conf;
sound_config_t sound_conf;
video_config_t video_conf;
text_config_t text_conf;
codecs_config_t codecs_conf;
ui_config_t ui_conf;
autoreplier_config_t autoreplier_conf;
LinphoneProxyConfig *default_proxy;
MSList *friends_lists;
MSList *auth_info;
struct _RingStream *ringstream;
time_t dmfs_playing_start_time;
LCCallbackObj preview_finished_cb;
MSList *queued_calls;
MSList *call_logs;
int max_call_logs;
int missed_calls;
VideoPreview *previewstream;
AudioPreview *audiostream;
struct _MSEventQueue *msevq;
LinphoneRtpTransportFactories *rtptf;
MSList *bl_reqs;
MSList *subscribers;
int minutes_away;
LinphonePresenceModel *presence_model;
void *data;
char *play_file;
char *rec_file;
uint64_t prevtime_ms;
int audio_bw;
LinphoneCoreWaitingCallback wait_cb;
void *wait_ctx;
void *video_window_id;
void *preview_window_id;
time_t netup_time;
struct _EcCalibrator *ecc;
struct _EchoTester *ect;
LinphoneTaskList hooks;
LinphoneConference *conf_ctx;
char* zrtp_secrets_cache;
char* user_certificates_path;
LinphoneVideoPolicy video_policy;
LinphoneNatPolicy *nat_policy;
LinphoneImNotifPolicy *im_notif_policy;
bool_t use_files;
bool_t apply_nat_settings;
bool_t initial_subscribes_sent;
bool_t bl_refresh;
bool_t preview_finished;
bool_t auto_net_state_mon;
bool_t network_reachable;
bool_t sip_network_reachable;
bool_t media_network_reachable;
bool_t network_reachable_to_be_notified;
bool_t use_preview_window;
bool_t network_last_status;
bool_t ringstream_autorelease;
bool_t vtables_running;
bool_t send_call_stats_periodical_updates;
bool_t forced_ice_relay;
bool_t short_turn_refresh;
MSRect qrcode_rect;
char localip[LINPHONE_IPADDR_SIZE];
int device_rotation;
int max_calls;
LinphoneTunnel *tunnel;
char* device_id;
char *logs_db_file;
char *friends_db_file;
belle_http_provider_t *http_provider;
belle_tls_crypto_config_t *http_crypto_config;
belle_http_request_listener_t *provisioning_http_listener;
MSList *tones;
LinphoneReason chat_deny_code;
char *file_transfer_server;
const char **supported_formats;
LinphoneContent *log_collection_upload_information;
LinphoneCoreCbs *current_cbs;
LinphoneRingtonePlayer *ringtoneplayer;
LinphoneVcardContext *vcard_context;
bool_t zrtp_not_available_simulation;
char *tls_cert;
char *tls_key;
LinphoneAddress *default_rls_addr;
LinphoneImEncryptionEngine *im_encryption_engine;
struct _LinphoneAccountCreatorService *default_ac_service;
MSBandwidthController *bw_controller;
belle_http_request_listener_t *update_check_http_listener;
char *update_check_current_version;
bctbx_list_t *chat_rooms;
bctbx_list_t *callsCache;
bool_t dns_set_by_app;
sqlite3 *zrtp_cache_db;
sqlite3 *logs_db;
sqlite3 *friends_db;
bool_t debug_storage;
typedef enum
{
P_Count = 100,
Limit_Time,
Priority,
User_ID,
Group_ID,
Cur_Talk_ID,
Reason_Code,
Req_NO
}_tbcptype;
typedef enum {
SOUND_IN_OFF,
SOUND_IN_ON,
SOUND_OUT_OFF,
SOUND_OUT_ON
}_soundstate;
};
L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONSはLinphoneCoreのいくつかの関数の定義と実現に対して.
static_assert(LinphonePrivate::CTypeMetaInfo<LinphoneCore>::defined, "Type is not defined.");
static_assert(
LinphonePrivate::IsDefinedBaseCppObject<
LinphonePrivate::CTypeMetaInfo<LinphoneCore>::cppType>::value,
"Type is not declared as base object."
);
struct _LinphoneCore {
belle_sip_object_t base;
std::shared_ptr<LinphonePrivate::CTypeMetaInfo<LinphoneCore>::cppType> cppPtr;
std::weak_ptr<LinphonePrivate::CTypeMetaInfo<LinphoneCore> weakCppPtr;
int owner;
MSFactory* factory;
MSList* vtable_refs;
int vtable_notify_recursion;
LinphonePrivate::Sal *sal;
void *platform_helper;
LinphoneGlobalState state;
struct _LpConfig *config;
MSList *default_audio_codecs;
MSList *default_video_codecs;
MSList *default_text_codecs;
net_config_t net_conf;
sip_config_t sip_conf;
rtp_config_t rtp_conf;
sound_config_t sound_conf;
video_config_t video_conf;
text_config_t text_conf;
codecs_config_t codecs_conf;
ui_config_t ui_conf;
autoreplier_config_t autoreplier_conf;
LinphoneProxyConfig *default_proxy;
MSList *friends_lists;
MSList *auth_info;
struct _RingStream *ringstream;
time_t dmfs_playing_start_time;
LCCallbackObj preview_finished_cb;
MSList *queued_calls;
MSList *call_logs;
int max_call_logs;
int missed_calls;
VideoPreview *previewstream;
AudioPreview *audiostream;
struct _MSEventQueue *msevq;
LinphoneRtpTransportFactories *rtptf;
MSList *bl_reqs;
MSList *subscribers;
int minutes_away;
LinphonePresenceModel *presence_model;
void *data;
char *play_file;
char *rec_file;
uint64_t prevtime_ms;
int audio_bw;
LinphoneCoreWaitingCallback wait_cb;
void *wait_ctx;
void *video_window_id;
void *preview_window_id;
time_t netup_time;
struct _EcCalibrator *ecc;
struct _EchoTester *ect;
LinphoneTaskList hooks;
LinphoneConference *conf_ctx;
char* zrtp_secrets_cache;
char* user_certificates_path;
LinphoneVideoPolicy video_policy;
LinphoneNatPolicy *nat_policy;
LinphoneImNotifPolicy *im_notif_policy;
bool_t use_files;
bool_t apply_nat_settings;
bool_t initial_subscribes_sent;
bool_t bl_refresh;
bool_t preview_finished;
bool_t auto_net_state_mon;
bool_t network_reachable;
bool_t sip_network_reachable;
bool_t media_network_reachable;
bool_t network_reachable_to_be_notified;
bool_t use_preview_window;
bool_t network_last_status;
bool_t ringstream_autorelease;
bool_t vtables_running;
bool_t send_call_stats_periodical_updates;
bool_t forced_ice_relay;
bool_t short_turn_refresh;
MSRect qrcode_rect;
char localip[LINPHONE_IPADDR_SIZE];
int device_rotation;
int max_calls;
LinphoneTunnel *tunnel;
char* device_id;
char *logs_db_file;
char *friends_db_file;
belle_http_provider_t *http_provider;
belle_tls_crypto_config_t *http_crypto_config;
belle_http_request_listener_t *provisioning_http_listener;
MSList *tones;
LinphoneReason chat_deny_code;
char *file_transfer_server;
const char **supported_formats;
LinphoneContent *log_collection_upload_information;
LinphoneCoreCbs *current_cbs;
LinphoneRingtonePlayer *ringtoneplayer;
LinphoneVcardContext *vcard_context;
bool_t zrtp_not_available_simulation;
char *tls_cert;
char *tls_key;
LinphoneAddress *default_rls_addr;
LinphoneImEncryptionEngine *im_encryption_engine;
struct _LinphoneAccountCreatorService *default_ac_service;
MSBandwidthController *bw_controller;
belle_http_request_listener_t *update_check_http_listener;
char *update_check_current_version;
bctbx_list_t *chat_rooms;
bctbx_list_t *callsCache;
bool_t dns_set_by_app;
sqlite3 *zrtp_cache_db;
sqlite3 *logs_db;
sqlite3 *friends_db;
bool_t debug_storage;
typedef enum
{
P_Count = 100,
Limit_Time,
Priority,
User_ID,
Group_ID,
Cur_Talk_ID,
Reason_Code,
Req_NO
}_tbcptype;
typedef enum {
SOUND_IN_OFF,
SOUND_IN_ON,
SOUND_OUT_OFF,
SOUND_OUT_ON
}_soundstate;
};
typedef belle_sip_object_vptr_t LinphoneCore_vptr_t;
LinphoneCore_vptr_t * LinphoneCore_vptr_get(void);
LinphoneCore *_linphone_Core_init () {
LinphoneCore *object = belle_sip_object_new(LinphoneCore);
new(&object->cppPtr) std::shared_ptr<LinphonePrivate::CTypeMetaInfo<LinphoneCore>::cppType>();
new(&object->weakCppPtr) std::weak_ptr<LinphonePrivate::CTypeMetaInfo<LinphoneCore>::cppType>();
CONSTRUCTOR(object);
return object;
}
static void _linphone_Core_uninit (LinphoneCore *object) {
_linphone_core_destructor(object);
LinphonePrivate::Wrapper::uninitBaseCppObject(object);
}
static belle_sip_interface_desc_t * LinphoneCoreinterfaces_table[]={
NULL
}
static LinphoneCore_vptr_t LinphoneCore_vptr={
LinphoneCore_type_id,
sizeof(LinphoneCore),
LinphoneCore,
False,
(belle_sip_object_get_vptr_t)belle_sip_object_t_vptr_get,
(belle_sip_interface_desc_t**)LinphoneCoreinterfaces_table
(belle_sip_object_destroy_t)_linphone_Core_uninit,
(belle_sip_object_clone_t)NULL,
(belle_sip_object_marshal_t)NULL,
(belle_sip_object_on_first_ref_t)LinphonePrivate::Wrapper::onBelleSipFirstRef,
(belle_sip_object_on_last_ref_t)LinphonePrivate::Wrapper::onBelleSipLastRef,
BELLE_SIP_DEFAULT_BUFSIZE_HINT,
False, 0
};
LinphoneCore_vptr_t LinphoneCore_vptr_get(void){
return &LinphoneCore_vptr;
}
これでLinphoneCoreで使用した構造体と関数定義が完了し,異なる構造体はC_のみである.TYPE、CONTRUCTOR、DESTRUCTORは違うだけです.プロジェクトでは、L_SET_CPP_PTR_FROM_C_OBJECTは、構造体中のweakCppPtrまたはcppPtrに付与.L_GET_CPP_PTR_FROM_C_OBJECTは、構造体中のweakCppPtrまたはcppPtrの値を取得する.L_GET_PRIVATE_FROM_C_OBJECTは、接合体中のプライベートC++クラスを取得する.L_GET_C_BACK_PTRは、C++オブジェクトを含む構造体を取得する
LinphoneCoreの作成を例に
LinphoneCore *core = L_INIT(Core); // LinphoneCore
// Core CorePrivate core
shared_ptr<Core> Core::create (LinphoneCore *cCore) {
// Do not use `make_shared` => Private constructor.
shared_ptr<Core> core = shared_ptr<Core>(new Core);
L_SET_CPP_PTR_FROM_C_OBJECT(cCore, core);
return core;
}
// Core L_GET_C_BACK_PTR LinphoneCore
LinphoneCore *Core::getCCore () const {
return L_GET_C_BACK_PTR(this);
}
void Core::enterBackground () {
L_D();// Core CorePrivate d
d->notifyEnteringBackground();
}
belle_sip_main_loop_t *CorePrivate::getMainLoop(){
L_Q(); // CorePrivate Core q
return belle_sip_stack_get_main_loop(static_cast<belle_sip_stack_t*>(q->getCCore()->sal->getStackImpl()));
}