improve documentation, rationalize some callbacks name.

lp-gen-wrapper functional.
This commit is contained in:
Simon Morlat 2013-10-01 21:59:54 +02:00
parent 122c5bbcbd
commit 77d6169624
10 changed files with 328 additions and 110 deletions

View file

@ -314,7 +314,7 @@ LinphoneChatMessage* linphone_chat_room_create_message_2(
* @param ud user data for the status cb.
* @note The LinphoneChatMessage must not be destroyed until the the callback is called.
*/
void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb, void* ud) {
void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb, void* ud) {
msg->cb=status_cb;
msg->cb_ud=ud;
msg->state=LinphoneChatMessageStateInProgress;
@ -329,7 +329,7 @@ const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState
case LinphoneChatMessageStateIdle:return "LinphoneChatMessageStateIdle";
case LinphoneChatMessageStateInProgress:return "LinphoneChatMessageStateInProgress";
case LinphoneChatMessageStateDelivered:return "LinphoneChatMessageStateDelivered";
case LinphoneChatMessageStateNotDelivered:return "LinphoneChatMessageStateNotDelivered";
case LinphoneChatMessageStateNotDelivered:return "LinphoneChatMessageStateNotDelivered";
default: return "Unknown state";
}

View file

@ -89,17 +89,17 @@ LINPHONE_PUBLIC const char *linphone_publish_state_to_string(LinphonePublishStat
/**
* Callback prototype for notifying the application about notification received from the network.
**/
typedef void (*LinphoneEventIncomingNotifyCb)(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body);
typedef void (*LinphoneCoreIncomingNotifyCb)(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body);
/**
* Callback prototype for notifying the application about changes of subscription states, including arrival of new subscriptions.
**/
typedef void (*LinphoneSubscriptionStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state);
typedef void (*LinphoneCoreSubscriptionStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state);
/**
* Callback prototype for notifying the application about changes of publish states.
**/
typedef void (*LinphonePublishStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state);
typedef void (*LinphoneCorePublishStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state);
/**
* Create an outgoing subscription, specifying the destination resource, the event name, and an optional content body.

View file

@ -376,7 +376,7 @@ float linphone_call_log_get_quality(LinphoneCallLog *cl){
/**
* return true if video was enabled at the end of the call
*/
LinphoneCallStatus linphone_call_log_video_enabled(LinphoneCallLog *cl) {
bool_t linphone_call_log_video_enabled(LinphoneCallLog *cl) {
return cl->video_enabled;
}
/** @} */
@ -5352,7 +5352,7 @@ void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
}else ms_set_mtu(0);//use mediastreamer2 default value
}
void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneCoreWaitingCallback cb, void *user_context){
lc->wait_cb=cb;
lc->wait_ctx=user_context;
}

View file

@ -251,7 +251,7 @@ LINPHONE_PUBLIC LinphoneAddress *linphone_call_log_get_to(LinphoneCallLog *cl);
LINPHONE_PUBLIC LinphoneAddress *linphone_call_log_get_remote_address(LinphoneCallLog *cl);
LINPHONE_PUBLIC LinphoneCallDir linphone_call_log_get_dir(LinphoneCallLog *cl);
LINPHONE_PUBLIC LinphoneCallStatus linphone_call_log_get_status(LinphoneCallLog *cl);
LINPHONE_PUBLIC LinphoneCallStatus linphone_call_log_video_enabled(LinphoneCallLog *cl);
LINPHONE_PUBLIC bool_t linphone_call_log_video_enabled(LinphoneCallLog *cl);
LINPHONE_PUBLIC time_t linphone_call_log_get_start_date(LinphoneCallLog *cl);
LINPHONE_PUBLIC int linphone_call_log_get_duration(LinphoneCallLog *cl);
LINPHONE_PUBLIC float linphone_call_log_get_quality(LinphoneCallLog *cl);
@ -501,7 +501,7 @@ LINPHONE_PUBLIC const LinphoneCallStats *linphone_call_get_video_stats(LinphoneC
/** Callback prototype */
typedef void (*LinphoneCallCbFunc)(struct _LinphoneCall *call,void * user_data);
typedef void (*LinphoneCallCbFunc)(LinphoneCall *call,void * user_data);
/**
* LinphoneCallState enum represents the different state a call can reach into.
@ -849,7 +849,7 @@ typedef enum _LinphoneChatMessageStates {
*@param status LinphoneChatMessageState
*@param ud application user data
*/
typedef void (*LinphoneChatMessageStateChangeCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
typedef void (*LinphoneChatMessageStateChangedCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path);
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
@ -860,7 +860,7 @@ LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_message(LinphoneC
LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_message_2(LinphoneChatRoom *cr, const char* message, const char* external_body_url, LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming);
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr);
LINPHONE_PUBLIC void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
LINPHONE_PUBLIC void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud);
LINPHONE_PUBLIC void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb,void* ud);
LINPHONE_PUBLIC void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
LINPHONE_PUBLIC MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message);
LINPHONE_PUBLIC void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr);
@ -925,106 +925,165 @@ const char *linphone_global_state_to_string(LinphoneGlobalState gs);
* @param gstate the global state
* @param message informational message.
*/
typedef void (*LinphoneGlobalStateCb)(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message);
/**Call state notification callback prototype*/
typedef void (*LinphoneCallStateCb)(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message);
/**Call encryption changed callback prototype*/
typedef void (*CallEncryptionChangedCb)(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token);
typedef void (*LinphoneCoreGlobalStateChangedCb )(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message);
/**
* Call state notification callback.
* @param lc the LinphoneCore
* @param call the call object whose state is changed.
* @param cstate the new state of the call
* @param message an informational message about the state.
*/
typedef void (*LinphoneCoreCallStateChangedCb)(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message);
/**
* Call encryption changed callback.
* @param lc the LinphoneCore
* @param call the call on which encryption is changed.
* @param on whether encryption is activated.
* @param authentication_token an authentication_token, currently set for ZRTP kind of encryption only.
*/
typedef void (*LinphoneCoreCallEncryptionChangedCb)(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token);
/** @ingroup Proxies
* Registration state notification callback prototype
* */
typedef void (*LinphoneRegistrationStateCb)(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message);
/** Callback prototype */
typedef void (*LinphoneCoreRegistrationStateChangedCb)(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message);
/** Callback prototype
* @deprecated
*/
typedef void (*ShowInterfaceCb)(LinphoneCore *lc);
/** Callback prototype */
/** Callback prototype
* @deprecated
*/
typedef void (*DisplayStatusCb)(LinphoneCore *lc, const char *message);
/** Callback prototype */
/** Callback prototype
* @deprecated
*/
typedef void (*DisplayMessageCb)(LinphoneCore *lc, const char *message);
/** Callback prototype */
/** Callback prototype
* @deprecated
*/
typedef void (*DisplayUrlCb)(LinphoneCore *lc, const char *message, const char *url);
/** Callback prototype */
/** Callback prototype
*/
typedef void (*LinphoneCoreCbFunc)(LinphoneCore *lc,void * user_data);
/**
* Report status change for a friend previously \link linphone_core_add_friend() added \endlink to #LinphoneCore.
* @param lc #LinphoneCore object .
* @param lf Updated #LinphoneFriend .
*/
typedef void (*NotifyPresenceReceivedCb)(LinphoneCore *lc, LinphoneFriend * lf);
typedef void (*LinphoneCoreNotifyPresenceReceivedCb)(LinphoneCore *lc, LinphoneFriend * lf);
/**
* Reports that a new subscription request has been received and wait for a decision.
* <br> Status on this subscription request is notified by \link linphone_friend_set_inc_subscribe_policy() changing policy \endlink for this friend
* @param lc #LinphoneCore object
* @param lf #LinphoneFriend corresponding to the subscriber
* @param url of the subscriber
* Status on this subscription request is notified by \link linphone_friend_set_inc_subscribe_policy() changing policy \endlink for this friend
* @param lc #LinphoneCore object
* @param lf #LinphoneFriend corresponding to the subscriber
* @param url of the subscriber
* Callback prototype
* */
typedef void (*NewSubscribtionRequestCb)(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
/** Callback prototype */
typedef void (*AuthInfoRequestedCb)(LinphoneCore *lc, const char *realm, const char *username);
/** Callback prototype */
typedef void (*CallLogUpdatedCb)(LinphoneCore *lc, struct _LinphoneCallLog *newcl);
*/
typedef void (*LinphoneCoreNewSubscribtionRequestCb)(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
/**
* Callback for requesting authentication information to application or user.
* @param lc the LinphoneCore
* @param realm the realm (domain) on which authentication is required.
* @param username the username that needs to be authenticated.
* Application shall reply to this callback using linphone_core_add_auth_info().
*/
typedef void (*LinphoneCoreAuthInfoRequestedCb)(LinphoneCore *lc, const char *realm, const char *username);
/**
* Callback to notify a new call-log entry has been added.
* This is done typically when a call terminates.
* @param lc the LinphoneCore
* @param newcl the new call log entry added.
*/
typedef void (*LinphoneCoreCallLogUpdatedCb)(LinphoneCore *lc, LinphoneCallLog *newcl);
/**
* Callback prototype
* @deprecated use #MessageReceived instead.
* @deprecated use #LinphoneMessageReceived instead.
*
* @param lc #LinphoneCore object
* @param room #LinphoneChatRoom involved in this conversation. Can be be created by the framework in case \link #LinphoneAddress the from \endlink is not present in any chat room.
* @param from #LinphoneAddress from
* @param message incoming message
* */
typedef void (*TextMessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
*/
typedef void (*LinphoneCoreTextMessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
/**
* Chat message callback prototype
*
* @param lc #LinphoneCore object
* @param room #LinphoneChatRoom involved in this conversation. Can be be created by the framework in case \link #LinphoneAddress the from \endlink is not present in any chat room.
* @param LinphoneChatMessage incoming message
* */
typedef void (*MessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message);
*/
typedef void (*LinphoneCoreMessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message);
/** Callback prototype */
typedef void (*DtmfReceivedCb)(LinphoneCore* lc, LinphoneCall *call, int dtmf);
/** Callback prototype */
typedef void (*ReferReceivedCb)(LinphoneCore *lc, const char *refer_to);
/** Callback prototype */
typedef void (*BuddyInfoUpdatedCb)(LinphoneCore *lc, LinphoneFriend *lf);
/** Callback prototype for in progress transfers. The new_call_state is the state of the call resulting of the transfer, at the other party. */
typedef void (*LinphoneTransferStateChangedCb)(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state);
/** Callback prototype for receiving quality statistics for calls*/
typedef void (*CallStatsUpdatedCb)(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats);
/**
* Callback for being notified of DTMFs received.
* @param lc the linphone core
* @param call the call that received the dtmf
* @param dtmf the ascii code of the dtmf
*/
typedef void (*LinphoneCoreDtmfReceivedCb)(LinphoneCore* lc, LinphoneCall *call, int dtmf);
/** Callback prototype */
typedef void (*LinphoneCoreReferReceivedCb)(LinphoneCore *lc, const char *refer_to);
/** Callback prototype */
typedef void (*LinphoneCoreBuddyInfoUpdatedCb)(LinphoneCore *lc, LinphoneFriend *lf);
/**
* Callback for notifying progresses of transfers.
* @param lc the LinphoneCore
* @param transfered the call that was transfered
* @param new_call_state the state of the call to transfer target at the far end.
*/
typedef void (*LinphoneCoreTransferStateChangedCb)(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state);
/**
* Callback for receiving quality statistics for calls.
* @param lc the LinphoneCore
* @param call the call
* @param stats the call statistics.
*/
typedef void (*LinphoneCoreCallStatsUpdatedCb)(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats);
/**
* Callback prototype for receiving info messages.
* @param lc the LinphoneCore
* @param call the call whose info message belongs to.
* @param msg the info message.
*/
typedef void (*LinphoneCoreInfoReceivedCb)(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg);
/** Callback prototype for receiving info messages*/
typedef void (*LinphoneInfoReceivedCb)(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg);
/**
* This structure holds all callbacks that the application should implement.
* None is mandatory.
**/
typedef struct _LinphoneCoreVTable{
LinphoneGlobalStateCb global_state_changed; /**<Notifies global state changes*/
LinphoneRegistrationStateCb registration_state_changed;/**<Notifies registration state changes*/
LinphoneCallStateCb call_state_changed;/**<Notifies call state changes*/
NotifyPresenceReceivedCb notify_presence_recv; /**< Notify received presence events*/
NewSubscribtionRequestCb new_subscription_request; /**< Notify about pending presence subscription request */
AuthInfoRequestedCb auth_info_requested; /**< Ask the application some authentication information */
CallLogUpdatedCb call_log_updated; /**< Notifies that call log list has been updated */
MessageReceivedCb message_received; /** a message is received, can be text or external body*/
DtmfReceivedCb dtmf_received; /**< A dtmf has been received received */
ReferReceivedCb refer_received; /**< An out of call refer was received */
CallEncryptionChangedCb call_encryption_changed; /**<Notifies on change in the encryption of call streams */
LinphoneTransferStateChangedCb transfer_state_changed; /**<Notifies when a transfer is in progress */
BuddyInfoUpdatedCb buddy_info_updated; /**< a LinphoneFriend's BuddyInfo has changed*/
CallStatsUpdatedCb call_stats_updated; /**<Notifies on refreshing of call's statistics. */
LinphoneInfoReceivedCb info_received; /**<Notifies an incoming informational message received.*/
LinphoneSubscriptionStateChangedCb subscription_state_changed; /**<Notifies subscription state change */
LinphoneEventIncomingNotifyCb notify_received; /**< Notifies a an event notification, see linphone_core_subscribe() */
LinphonePublishStateChangedCb publish_state_changed;/**Notifies publish state change (only from #LinphoneEvent api)*/
LinphoneCoreGlobalStateChangedCb global_state_changed; /**<Notifies global state changes*/
LinphoneCoreRegistrationStateChangedCb registration_state_changed;/**<Notifies registration state changes*/
LinphoneCoreCallStateChangedCb call_state_changed;/**<Notifies call state changes*/
LinphoneCoreNotifyPresenceReceivedCb notify_presence_recv; /**< Notify received presence events*/
LinphoneCoreNewSubscribtionRequestCb new_subscription_request; /**< Notify about pending presence subscription request */
LinphoneCoreAuthInfoRequestedCb auth_info_requested; /**< Ask the application some authentication information */
LinphoneCoreCallLogUpdatedCb call_log_updated; /**< Notifies that call log list has been updated */
LinphoneCoreMessageReceivedCb message_received; /** a message is received, can be text or external body*/
LinphoneCoreDtmfReceivedCb dtmf_received; /**< A dtmf has been received received */
LinphoneCoreReferReceivedCb refer_received; /**< An out of call refer was received */
LinphoneCoreCallEncryptionChangedCb call_encryption_changed; /**<Notifies on change in the encryption of call streams */
LinphoneCoreTransferStateChangedCb transfer_state_changed; /**<Notifies when a transfer is in progress */
LinphoneCoreBuddyInfoUpdatedCb buddy_info_updated; /**< a LinphoneFriend's BuddyInfo has changed*/
LinphoneCoreCallStatsUpdatedCb call_stats_updated; /**<Notifies on refreshing of call's statistics. */
LinphoneCoreInfoReceivedCb info_received; /**<Notifies an incoming informational message received.*/
LinphoneCoreSubscriptionStateChangedCb subscription_state_changed; /**<Notifies subscription state change */
LinphoneCoreIncomingNotifyCb notify_received; /**< Notifies a an event notification, see linphone_core_subscribe() */
LinphoneCorePublishStateChangedCb publish_state_changed;/**Notifies publish state change (only from #LinphoneEvent api)*/
DisplayStatusCb display_status; /**< @deprecated Callback that notifies various events with human readable text.*/
DisplayMessageCb display_message;/**< @deprecated Callback to display a message to the user */
DisplayMessageCb display_warning;/**< @deprecated Callback to display a warning to the user */
DisplayUrlCb display_url; /**< @deprecated */
ShowInterfaceCb show; /**< @deprecated Notifies the application that it should show up*/
TextMessageReceivedCb text_received; /** @deprecated, use #message_received instead <br> A text message has been received */
LinphoneCoreTextMessageReceivedCb text_received; /** @deprecated, use #message_received instead <br> A text message has been received */
} LinphoneCoreVTable;
/**
@ -1052,7 +1111,7 @@ typedef enum _LinphoneWaitingState{
LinphoneWaitingProgress,
LinphoneWaitingFinished
} LinphoneWaitingState;
typedef void * (*LinphoneWaitingCallback)(LinphoneCore *lc, void *context, LinphoneWaitingState ws, const char *purpose, float progress);
typedef void * (*LinphoneCoreWaitingCallback)(LinphoneCore *lc, void *context, LinphoneWaitingState ws, const char *purpose, float progress);
/* THE main API */
@ -1598,7 +1657,7 @@ the config file with your own sections */
LINPHONE_PUBLIC struct _LpConfig *linphone_core_get_config(LinphoneCore *lc);
/*set a callback for some blocking operations, it takes you informed of the progress of the operation*/
void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context);
void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneCoreWaitingCallback cb, void *user_context);
/*returns the list of registered SipSetup (linphonecore plugins) */
const MSList * linphone_core_get_sip_setups(LinphoneCore *lc);
@ -1606,15 +1665,15 @@ const MSList * linphone_core_get_sip_setups(LinphoneCore *lc);
LINPHONE_PUBLIC void linphone_core_destroy(LinphoneCore *lc);
/*for advanced users:*/
typedef RtpTransport * (*LinphoneRtpTransportFactoryFunc)(void *data, int port);
typedef RtpTransport * (*LinphoneCoreRtpTransportFactoryFunc)(void *data, int port);
struct _LinphoneRtpTransportFactories{
LinphoneRtpTransportFactoryFunc audio_rtp_func;
LinphoneCoreRtpTransportFactoryFunc audio_rtp_func;
void *audio_rtp_func_data;
LinphoneRtpTransportFactoryFunc audio_rtcp_func;
LinphoneCoreRtpTransportFactoryFunc audio_rtcp_func;
void *audio_rtcp_func_data;
LinphoneRtpTransportFactoryFunc video_rtp_func;
LinphoneCoreRtpTransportFactoryFunc video_rtp_func;
void *video_rtp_func_data;
LinphoneRtpTransportFactoryFunc video_rtcp_func;
LinphoneCoreRtpTransportFactoryFunc video_rtcp_func;
void *video_rtcp_func_data;
};
typedef struct _LinphoneRtpTransportFactories LinphoneRtpTransportFactories;

View file

@ -131,7 +131,7 @@ struct _LinphoneChatMessage {
LinphoneChatRoom* chat_room;
LinphoneChatMessageDir dir;
char* message;
LinphoneChatMessageStateChangeCb cb;
LinphoneChatMessageStateChangedCb cb;
void* cb_ud;
void* message_userdata;
char* external_body_url;
@ -614,7 +614,7 @@ struct _LinphoneCore
char *rec_file;
time_t prevtime;
int audio_bw;
LinphoneWaitingCallback wait_cb;
LinphoneCoreWaitingCallback wait_cb;
void *wait_ctx;
unsigned long video_window_id;
unsigned long preview_window_id;

View file

@ -147,6 +147,8 @@ void CplusplusGenerator::writeHelpComment(const std::string &comment, int ntabs)
}
void CplusplusGenerator::writeMethod(Method *method){
if (method->isCallback()) return;
Argument *retarg=method->getReturnArg();
const list<Argument*> &args=method->getArgs();
list<Argument*>::const_iterator it;
@ -204,20 +206,24 @@ void JavascriptGenerator::generate(Project *proj){
for_each(classes.begin(),classes.end(),bind1st(mem_fun(&JavascriptGenerator::writeClass),this));
}
string JavascriptGenerator::getEnumName(Class *klass){
string enum_name=klass->getName();
if (strncasecmp(enum_name.c_str(),mCurProj->getName().c_str(),mCurProj->getName().size())==0){
//since enum is part of the namespace, drop the namespace part of the enum if any.
enum_name.erase(0,mCurProj->getName().size());
}
return enum_name;
}
void JavascriptGenerator::writeEnum(Class *klass){
if (klass->getType()!=Type::Enum) return;
ostringstream filename;
list<ConstField*> members=klass->getConstFields();
list<ConstField*>::iterator it;
string enum_name=klass->getName();
string enum_name=getEnumName(klass);
int value=0;
if (strncasecmp(enum_name.c_str(),mCurProj->getName().c_str(),mCurProj->getName().size())==0){
//since enum is part of the namespace, drop the namespace part of the enum if any.
enum_name.erase(0,mCurProj->getName().size());
}
filename<<to_lower(mCurProj->getName())<<"/"<<to_lower(enum_name)<<".js";
mOutfile.open(filename.str().c_str());
if (!mOutfile.is_open()){
@ -262,6 +268,8 @@ void JavascriptGenerator::writeClass(Class *klass){
if (klass->getType()==Type::Enum) {
return;
}
const list<Method*> &methods=klass->getMethods();
if (methods.empty()) return;//skip empty classes
filename<<to_lower(mCurProj->getName())<<"/"<<to_lower(klass->getName())<<".js";
mOutfile.open(filename.str().c_str());
@ -273,9 +281,6 @@ void JavascriptGenerator::writeClass(Class *klass){
mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<<endl;
mOutfile<<endl;
const list<Method*> &methods=klass->getMethods();
//if (!mCurProj->getName().empty())
// mOutfile<<"namespace "<<mCurProj->getName()<<"{"<<endl<<endl;
mOutfile<<"/**"<<endl;
@ -287,6 +292,7 @@ void JavascriptGenerator::writeClass(Class *klass){
for_each(properties.begin(),properties.end(),bind1st(mem_fun(&JavascriptGenerator::writeProperty),this));
mOutfile<<endl;
for_each(methods.begin(),methods.end(),bind1st(mem_fun(&JavascriptGenerator::writeMethod),this));
for_each(methods.begin(),methods.end(),bind1st(mem_fun(&JavascriptGenerator::writeEvent),this));
//if (!mCurProj->getName().empty())
// mOutfile<<"} //end of namespace "<<mCurProj->getName()<<endl;
mOutfile<<endl;
@ -306,26 +312,39 @@ void JavascriptGenerator::writeType(Type *type){
mOutfile<<"boolean";
break;
case Type::Class:
case Type::Enum:
mOutfile<<"external:"<<type->getName();
break;
case Type::Enum:
mOutfile<<mCurProj->getName()<<"."<<getEnumName(mCurProj->getClass(type->getName()));
break;
case Type::Void:
mOutfile<<"void";
break;
case Type::Callback:
break;
case Type::Array:
mOutfile<<"Array.<Object>";
break;
}
}
void JavascriptGenerator::writeArgument(Argument *arg, bool isReturn){
if (!isReturn){
mOutfile<<" * @param {";
writeType(arg->getType());
mOutfile<<"} "<<arg->getName()<<" - "<<arg->getHelp()<<endl;
}else{
mOutfile<<" * @returns {";
writeType(arg->getType());
mOutfile<<"} "<<arg->getHelp()<<endl;
void JavascriptGenerator::writeArgument(Argument *arg, ArgKind kind){
switch(kind){
case Normal:
mOutfile<<" * @param {";
writeType(arg->getType());
mOutfile<<"} "<<arg->getName()<<" - "<<arg->getHelp()<<endl;
break;
case Return:
mOutfile<<" * @returns {";
writeType(arg->getType());
mOutfile<<"} "<<arg->getHelp()<<endl;
break;
case PropertyArg:
mOutfile<<" * @property {";
writeType(arg->getType());
mOutfile<<"} "<<arg->getName()<<" - "<<arg->getHelp()<<endl;
break;
}
}
@ -368,6 +387,7 @@ void JavascriptGenerator::writeMethod(Method *method){
const list<Argument*> &args=method->getArgs();
list<Argument*>::const_iterator it;
if (method->isCallback()) return;
if (method->getPropertyBehaviour()!=Method::None) return;
if (method->getName()=="ref" || method->getName()=="unref") return;
@ -379,7 +399,37 @@ void JavascriptGenerator::writeMethod(Method *method){
for(it=args.begin();it!=args.end();++it){
writeArgument(*it);
}
writeArgument(retarg,true);
writeArgument(retarg,Return);
mOutfile<<"**/"<<endl;
mOutfile<<endl;
}
string JavascriptGenerator::getEventHelp(const string &help){
size_t i=help.find("Callback");
if (i==string::npos){
i=help.find("callback");
if (i==string::npos) return help;
}
string res(help);
res.replace(i,8,"event");
return res;
}
void JavascriptGenerator::writeEvent(Method* event){
const list<Argument*> &args=event->getArgs();
list<Argument*>::const_iterator it;
if (!event->isCallback()) return;
mOutfile<<"/**"<<endl;
writeHelpComment(getEventHelp(event->getHelp()),0);
mOutfile<<endl;
mOutfile<<" * @event external:"<<mCurClass->getName()<<"#"<<event->getName()<<endl;
mOutfile<<" * @type {object}"<<endl;
for(it=args.begin();it!=args.end();++it){
writeArgument(*it,PropertyArg);
}
mOutfile<<"**/"<<endl;
mOutfile<<endl;
}

View file

@ -54,11 +54,15 @@ private:
void writeClass(Class *klass);
void writeEnum(Class *klass);
void writeType(Type *type);
void writeArgument(Argument *arg, bool isReturn=false);
enum ArgKind { Normal, Return, PropertyArg};
void writeArgument(Argument *arg, ArgKind kind=Normal);
void writeTabs(int ntabs);
void writeHelpComment(const std::string &comment, int ntabs);
void writeProperty(Property *prop);
void writeMethod(Method *method);
void writeEvent(Method *event);
string getEventHelp(const string &ref);
string getEnumName(Class *klass);
ofstream mOutfile;
Project *mCurProj;
Class *mCurClass;

View file

@ -234,7 +234,7 @@ static void parseFunction(Project *proj, xmlNode *node){
if (!args.empty()) first_arg=args.front();
if (!first_arg){
cout<<"Could not determine first argument of "<<name<<endl;
cerr<<"Could not determine first argument of "<<name<<endl;
return;
}
if (first_arg->getType()->getBasicType()!=Type::Class) return;
@ -250,6 +250,84 @@ static void parseFunction(Project *proj, xmlNode *node){
}
}
static string findCommon(const string &c1, const string & c2){
size_t i;
ostringstream res;
for(i=0;i<c1.size() && i<c2.size();++i){
if (tolower(c1[i])==tolower(c2[i]))
res<<(char)c1[i];
else break;
}
return res.str();
}
static string extractCallbackName(const string &c_name, const string & classname){
string prefix=findCommon(c_name,classname);
string res=c_name.substr(prefix.size(),string::npos);
res[0]=tolower(res[0]);
size_t pos=res.find("Cb");
if (pos!=string::npos) res=res.substr(0,pos);
return res;
}
static void parseCallback(Project *proj, XmlNode node){
string argsstring=node.getChild("argsstring").getText();
string name=node.getChild("name").getText();
list<XmlNode> params=node.getChildRecursive("parameterlist").getChildren("parameteritem");
list<XmlNode>::iterator it=params.begin();
string rettype=node.getChild("type").getText();
argsstring=argsstring.substr(argsstring.find('(')+1,string::npos);
bool cont=true;
list<Argument*> args;
Type *firstArgType=NULL;
rettype=rettype.substr(0,rettype.find('('));
Argument *retarg=new Argument(Type::getType(rettype),"",false,rettype.find('*')!=string::npos);
do{
size_t comma=argsstring.find(',');
size_t end=argsstring.find(')');
if (comma!=string::npos && comma<end) end=comma;
else cont=false;
string arg=argsstring.substr(0,end);
bool isConst=false;
bool isPointer=false;
size_t endtype=arg.find('*');
if (endtype==string::npos) endtype=arg.rfind(' ');
else isPointer=true;
string typestring=arg.substr(0,endtype+1);
Type *type=Type::getType(typestring);
if (type==NULL) return;
if (firstArgType==NULL) firstArgType=type;
//find const attribute if any
if (typestring.find("const")!=string::npos)
isConst=true;
string argname=arg.substr(endtype+1,end);
argsstring=argsstring.substr(end+1,string::npos);
Argument *argobj=new Argument(type,makeMethodName(argname),isConst,isPointer);
if (it!=params.end()){
argobj->setHelp((*it).getChild("parameterdescription").getChild("para").getText());
++it;
}
args.push_back(argobj);
}while(cont);
if (firstArgType->getBasicType()!=Type::Class) return;
Class *klass=proj->getClass(firstArgType->getName());
Method *callback=new Method("", retarg, extractCallbackName(name,klass->getName()), args, false, false, true);
//cout<<"Found callback "<<callback->getName()<<" with "<<args.size()<<" arguments."<<endl;
callback->setHelp(node.getChild("detaileddescription").getChild("para").getText());
klass->addMethod(callback);
}
static void parseEnum(Project *proj, XmlNode node){
string name=node.getChild("name").getText();
if (name[0]=='_') name.erase(0,1);
@ -272,9 +350,8 @@ static void parseTypedef(Project *proj, xmlNode *node){
string name=tdef.getChild("name").getText();
if (typecontent.find("enum")==0){
Type::addType(Type::Enum,name);
}else if (typecontent.find("void(*")==0){
// callbacks function, not really well parsed by doxygen
Type::addType(Type::Callback,name);
}else if (typecontent.find("(*")!=string::npos){
parseCallback(proj,node);
}else
proj->getClass(name)->setHelp(getHelpBody(node));
}
@ -288,6 +365,10 @@ static void parseMemberDef(Project *proj, xmlNode *node){
if (member.getChild("briefdescription").getText().empty() &&
member.getChild("detaileddescription").getChild("para").getText().empty())
return;
if (member.getProp("id").find("group__")!=0)
return;
if (member.getChild("detaileddescription").getChildRecursive("xreftitle").getText()=="Deprecated")
return;
kind=member.getProp("kind");
if (kind=="function"){

View file

@ -25,6 +25,8 @@ Type Type::sIntegerType(Type::Integer);
Type Type::sVoidType(Type::Void);
Type Type::sBooleanType(Type::Boolean);
Type Type::sFloatType(Type::Float);
Type Type::sArrayType(Type::Array);
std::map<string,Type*> Type::mTypes;
const char *Type::sBasicTypeNames[]={
"Void",
@ -35,6 +37,7 @@ const char *Type::sBasicTypeNames[]={
"Enum",
"Class",
"Callback",
"Array",
"undef",
"undef"
};

View file

@ -44,7 +44,8 @@ public:
String,
Enum,
Class,
Callback
Callback,
Array
};
static const char *sBasicTypeNames[];
static Type* addType(BasicType bt, const string &name){
@ -58,18 +59,23 @@ public:
return ret;
}
static Type *getType(const std::string &tname){
if (tname.find("(")!=string::npos) return NULL; //arrives when parsing function pointer declared inside function prototype
if (strstr(tname.c_str(),"char")!=0 && strchr(tname.c_str(),'*')!=0){
return &sStringType;
}else if (tname.find("int")==0){
}else if (tname.find("int")!=string::npos){
return &sIntegerType;
}else if (tname.find("float")==0){
}else if (tname.find("size_t")!=string::npos){
return &sIntegerType;
}else if (tname.find("float")!=string::npos){
return &sFloatType;
}else if (tname.find("bool_t")==0){
}else if (tname.find("bool_t")!=string::npos){
return &sBooleanType;
}else if (tname.find("void")!=string::npos){
return &sVoidType;
}else if (tname.find("enum")==0){
}else if (tname.find("enum")!=string::npos){
return addType(Enum,tname.c_str()+strlen("enum "));
}else if (tname.find("MSList")!=string::npos){
return &sArrayType;
}else{/*an object?*/
string tmp=tname;
@ -109,6 +115,7 @@ private:
static Type sVoidType;
static Type sBooleanType;
static Type sFloatType;
static Type sArrayType;
static std::map<string,Type*> mTypes;
};
@ -153,13 +160,14 @@ public:
Read,
Write
};
Method(const std::string &uid, Argument* return_arg, const std::string &name, const list<Argument*> &args, bool isConst, bool isStatic){
Method(const std::string &uid, Argument* return_arg, const std::string &name, const list<Argument*> &args, bool isConst, bool isStatic, bool isCallback=false){
mUid=uid;
mReturn=return_arg;
mName=name;
mArgs=args;
mConst=isConst;
mStatic=isStatic;
mIsCallback=isCallback;
analyseProperties();
}
void setHelp(const std::string &help){
@ -180,6 +188,9 @@ public:
bool isStatic()const{
return mStatic;
}
bool isCallback()const{
return mIsCallback;
}
const string &getHelp(){
return mHelp;
}
@ -235,6 +246,7 @@ private:
PropertyBehaviour mPropertyBehaviour;
bool mConst;
bool mStatic;
bool mIsCallback;
};
class Property{
@ -307,7 +319,7 @@ public:
}
}
if (isMatching){
cout<<"enum prefix: "<<prefix<<endl;
//cout<<"enum prefix: "<<prefix<<endl;
return prefix;
}
}
@ -431,8 +443,17 @@ public:
list<Class*> classes=getClasses();
for_each(classes.begin(),classes.end(),mem_fun(&Class::computeProperties));
}
void addCallback(Method *callback){
list<Method*>::iterator it=find_if(mCallbacks.begin(),mCallbacks.end(),name_matcher<Method>(callback->getName()));
if (it==mCallbacks.end())
mCallbacks.push_back(callback);
}
const list<Method*> &getCallbacks()const{
return mCallbacks;
}
private:
map<string,Class*> mClasses;
list<Method*> mCallbacks;
string mName;
};