Commit f8bc426a authored by Simon Morlat's avatar Simon Morlat
Browse files

* improved documentation

* update ms2
* javascript generator in progress
parent 643dc7f9
...@@ -535,7 +535,7 @@ LINPHONE_PUBLIC const char *linphone_call_state_to_string(LinphoneCallState cs); ...@@ -535,7 +535,7 @@ LINPHONE_PUBLIC const char *linphone_call_state_to_string(LinphoneCallState cs);
LINPHONE_PUBLIC LinphoneCore *linphone_call_get_core(const LinphoneCall *call); LINPHONE_PUBLIC LinphoneCore *linphone_call_get_core(const LinphoneCall *call);
LINPHONE_PUBLIC LinphoneCallState linphone_call_get_state(const LinphoneCall *call); LINPHONE_PUBLIC LinphoneCallState linphone_call_get_state(const LinphoneCall *call);
bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call); bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call);
LINPHONE_PUBLIC const LinphoneAddress * linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc); LINPHONE_PUBLIC const LinphoneAddress * linphone_core_get_current_call_remote_address(LinphoneCore *lc);
LINPHONE_PUBLIC const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call); LINPHONE_PUBLIC const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call);
LINPHONE_PUBLIC char *linphone_call_get_remote_address_as_string(const LinphoneCall *call); LINPHONE_PUBLIC char *linphone_call_get_remote_address_as_string(const LinphoneCall *call);
LINPHONE_PUBLIC LinphoneCallDir linphone_call_get_dir(const LinphoneCall *call); LINPHONE_PUBLIC LinphoneCallDir linphone_call_get_dir(const LinphoneCall *call);
...@@ -694,7 +694,7 @@ LINPHONE_PUBLIC bool_t linphone_proxy_config_register_enabled(const LinphoneProx ...@@ -694,7 +694,7 @@ LINPHONE_PUBLIC bool_t linphone_proxy_config_register_enabled(const LinphoneProx
LINPHONE_PUBLIC void linphone_proxy_config_refresh_register(LinphoneProxyConfig *obj); LINPHONE_PUBLIC void linphone_proxy_config_refresh_register(LinphoneProxyConfig *obj);
LINPHONE_PUBLIC const char *linphone_proxy_config_get_contact_parameters(const LinphoneProxyConfig *obj); LINPHONE_PUBLIC const char *linphone_proxy_config_get_contact_parameters(const LinphoneProxyConfig *obj);
LINPHONE_PUBLIC void linphone_proxy_config_set_contact_parameters(LinphoneProxyConfig *obj, const char *contact_params); LINPHONE_PUBLIC void linphone_proxy_config_set_contact_parameters(LinphoneProxyConfig *obj, const char *contact_params);
struct _LinphoneCore * linphone_proxy_config_get_core(const LinphoneProxyConfig *obj); LinphoneCore * linphone_proxy_config_get_core(const LinphoneProxyConfig *obj);
LINPHONE_PUBLIC bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg); LINPHONE_PUBLIC bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg);
LINPHONE_PUBLIC const char * linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg); LINPHONE_PUBLIC const char * linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg);
...@@ -744,7 +744,7 @@ LINPHONE_PUBLIC LinphonePrivacyMask linphone_proxy_config_get_privacy(const Linp ...@@ -744,7 +744,7 @@ LINPHONE_PUBLIC LinphonePrivacyMask linphone_proxy_config_get_privacy(const Linp
**/ **/
typedef struct _LinphoneAccountCreator{ typedef struct _LinphoneAccountCreator{
struct _LinphoneCore *lc; LinphoneCore *lc;
struct _SipSetupContext *ssctx; struct _SipSetupContext *ssctx;
char *username; char *username;
char *password; char *password;
...@@ -755,7 +755,7 @@ typedef struct _LinphoneAccountCreator{ ...@@ -755,7 +755,7 @@ typedef struct _LinphoneAccountCreator{
bool_t succeeded; bool_t succeeded;
}LinphoneAccountCreator; }LinphoneAccountCreator;
LinphoneAccountCreator *linphone_account_creator_new(struct _LinphoneCore *core, const char *type); LinphoneAccountCreator *linphone_account_creator_new(LinphoneCore *core, const char *type);
void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username); void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username);
void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password); void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password);
void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain); void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain);
...@@ -920,33 +920,38 @@ typedef enum _LinphoneGlobalState{ ...@@ -920,33 +920,38 @@ typedef enum _LinphoneGlobalState{
const char *linphone_global_state_to_string(LinphoneGlobalState gs); const char *linphone_global_state_to_string(LinphoneGlobalState gs);
/**
* Global state notification callback.
* @param lc
* @param gstate the global state
* @param message informational message.
*/
typedef void (*LinphoneGlobalStateCb)(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message);
/**Call state notification callback prototype*/ /**Call state notification callback prototype*/
typedef void (*LinphoneGlobalStateCb)(struct _LinphoneCore *lc, LinphoneGlobalState gstate, const char *message); typedef void (*LinphoneCallStateCb)(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message);
/**Call state notification callback prototype*/
typedef void (*LinphoneCallStateCb)(struct _LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message);
/**Call encryption changed callback prototype*/ /**Call encryption changed callback prototype*/
typedef void (*CallEncryptionChangedCb)(struct _LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token); typedef void (*CallEncryptionChangedCb)(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token);
/** @ingroup Proxies /** @ingroup Proxies
* Registration state notification callback prototype * Registration state notification callback prototype
* */ * */
typedef void (*LinphoneRegistrationStateCb)(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message); typedef void (*LinphoneRegistrationStateCb)(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message);
/** Callback prototype */ /** Callback prototype */
typedef void (*ShowInterfaceCb)(struct _LinphoneCore *lc); typedef void (*ShowInterfaceCb)(LinphoneCore *lc);
/** Callback prototype */ /** Callback prototype */
typedef void (*DisplayStatusCb)(struct _LinphoneCore *lc, const char *message); typedef void (*DisplayStatusCb)(LinphoneCore *lc, const char *message);
/** Callback prototype */ /** Callback prototype */
typedef void (*DisplayMessageCb)(struct _LinphoneCore *lc, const char *message); typedef void (*DisplayMessageCb)(LinphoneCore *lc, const char *message);
/** Callback prototype */ /** Callback prototype */
typedef void (*DisplayUrlCb)(struct _LinphoneCore *lc, const char *message, const char *url); typedef void (*DisplayUrlCb)(LinphoneCore *lc, const char *message, const char *url);
/** Callback prototype */ /** Callback prototype */
typedef void (*LinphoneCoreCbFunc)(struct _LinphoneCore *lc,void * user_data); typedef void (*LinphoneCoreCbFunc)(LinphoneCore *lc,void * user_data);
/** /**
* Report status change for a friend previously \link linphone_core_add_friend() added \endlink to #LinphoneCore. * Report status change for a friend previously \link linphone_core_add_friend() added \endlink to #LinphoneCore.
* @param lc #LinphoneCore object . * @param lc #LinphoneCore object .
* @param lf Updated #LinphoneFriend . * @param lf Updated #LinphoneFriend .
*/ */
typedef void (*NotifyPresenceReceivedCb)(struct _LinphoneCore *lc, LinphoneFriend * lf); typedef void (*NotifyPresenceReceivedCb)(LinphoneCore *lc, LinphoneFriend * lf);
/** /**
* Reports that a new subscription request has been received and wait for a decision. * 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 * <br> Status on this subscription request is notified by \link linphone_friend_set_inc_subscribe_policy() changing policy \endlink for this friend
...@@ -955,11 +960,11 @@ typedef void (*NotifyPresenceReceivedCb)(struct _LinphoneCore *lc, LinphoneFrien ...@@ -955,11 +960,11 @@ typedef void (*NotifyPresenceReceivedCb)(struct _LinphoneCore *lc, LinphoneFrien
* @param url of the subscriber * @param url of the subscriber
* Callback prototype * Callback prototype
* */ * */
typedef void (*NewSubscribtionRequestCb)(struct _LinphoneCore *lc, LinphoneFriend *lf, const char *url); typedef void (*NewSubscribtionRequestCb)(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
/** Callback prototype */ /** Callback prototype */
typedef void (*AuthInfoRequestedCb)(struct _LinphoneCore *lc, const char *realm, const char *username); typedef void (*AuthInfoRequestedCb)(LinphoneCore *lc, const char *realm, const char *username);
/** Callback prototype */ /** Callback prototype */
typedef void (*CallLogUpdatedCb)(struct _LinphoneCore *lc, struct _LinphoneCallLog *newcl); typedef void (*CallLogUpdatedCb)(LinphoneCore *lc, struct _LinphoneCallLog *newcl);
/** /**
* Callback prototype * Callback prototype
* @deprecated use #MessageReceived instead. * @deprecated use #MessageReceived instead.
...@@ -980,24 +985,24 @@ typedef void (*TextMessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, ...@@ -980,24 +985,24 @@ typedef void (*TextMessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room,
typedef void (*MessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message); typedef void (*MessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message);
/** Callback prototype */ /** Callback prototype */
typedef void (*DtmfReceivedCb)(struct _LinphoneCore* lc, LinphoneCall *call, int dtmf); typedef void (*DtmfReceivedCb)(LinphoneCore* lc, LinphoneCall *call, int dtmf);
/** Callback prototype */ /** Callback prototype */
typedef void (*ReferReceivedCb)(struct _LinphoneCore *lc, const char *refer_to); typedef void (*ReferReceivedCb)(LinphoneCore *lc, const char *refer_to);
/** Callback prototype */ /** Callback prototype */
typedef void (*BuddyInfoUpdatedCb)(struct _LinphoneCore *lc, LinphoneFriend *lf); 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. */ /** 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)(struct _LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state); typedef void (*LinphoneTransferStateChangedCb)(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state);
/** Callback prototype for receiving quality statistics for calls*/ /** Callback prototype for receiving quality statistics for calls*/
typedef void (*CallStatsUpdatedCb)(struct _LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats); typedef void (*CallStatsUpdatedCb)(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats);
/** Callback prototype for receiving info messages*/ /** Callback prototype for receiving info messages*/
typedef void (*LinphoneInfoReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg); typedef void (*LinphoneInfoReceivedCb)(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg);
/** /**
* This structure holds all callbacks that the application should implement. * This structure holds all callbacks that the application should implement.
* None is mandatory. * None is mandatory.
**/ **/
typedef struct _LinphoneVTable{ typedef struct _LinphoneCoreVTable{
LinphoneGlobalStateCb global_state_changed; /**<Notifies globlal state changes*/ LinphoneGlobalStateCb global_state_changed; /**<Notifies global state changes*/
LinphoneRegistrationStateCb registration_state_changed;/**<Notifies registration state changes*/ LinphoneRegistrationStateCb registration_state_changed;/**<Notifies registration state changes*/
LinphoneCallStateCb call_state_changed;/**<Notifies call state changes*/ LinphoneCallStateCb call_state_changed;/**<Notifies call state changes*/
NotifyPresenceReceivedCb notify_presence_recv; /**< Notify received presence events*/ NotifyPresenceReceivedCb notify_presence_recv; /**< Notify received presence events*/
...@@ -1048,7 +1053,7 @@ typedef enum _LinphoneWaitingState{ ...@@ -1048,7 +1053,7 @@ typedef enum _LinphoneWaitingState{
LinphoneWaitingProgress, LinphoneWaitingProgress,
LinphoneWaitingFinished LinphoneWaitingFinished
} LinphoneWaitingState; } LinphoneWaitingState;
typedef void * (*LinphoneWaitingCallback)(struct _LinphoneCore *lc, void *context, LinphoneWaitingState ws, const char *purpose, float progress); typedef void * (*LinphoneWaitingCallback)(LinphoneCore *lc, void *context, LinphoneWaitingState ws, const char *purpose, float progress);
/* THE main API */ /* THE main API */
......
This diff is collapsed.
...@@ -260,11 +260,11 @@ void linphone_proxy_config_edit(LinphoneProxyConfig *obj){ ...@@ -260,11 +260,11 @@ void linphone_proxy_config_edit(LinphoneProxyConfig *obj){
} }
} }
void linphone_proxy_config_apply(LinphoneProxyConfig *obj,LinphoneCore *lc) void linphone_proxy_config_apply(LinphoneProxyConfig *obj,LinphoneCore *lc){
{
obj->lc=lc; obj->lc=lc;
linphone_proxy_config_done(obj); linphone_proxy_config_done(obj);
} }
LinphoneAddress *guess_contact_for_register(LinphoneProxyConfig *obj){ LinphoneAddress *guess_contact_for_register(LinphoneProxyConfig *obj){
LinphoneAddress *ret=NULL; LinphoneAddress *ret=NULL;
LinphoneAddress *proxy=linphone_address_new(obj->reg_proxy); LinphoneAddress *proxy=linphone_address_new(obj->reg_proxy);
...@@ -312,38 +312,13 @@ LinphoneAddress *guess_contact_for_register(LinphoneProxyConfig *obj){ ...@@ -312,38 +312,13 @@ LinphoneAddress *guess_contact_for_register(LinphoneProxyConfig *obj){
} }
#endif //BUILD_UPNP #endif //BUILD_UPNP
#ifndef USE_BELLESIP
if(localip == NULL) {
char localip_tmp[LINPHONE_IPADDR_SIZE] = {'\0'};
localip = localip_tmp;
linphone_core_get_local_ip(obj->lc,host,localip_tmp);
}
if(localport == -1) {
localport = linphone_core_get_sip_port(obj->lc);
}
{
LCSipTransports tr;
linphone_core_get_sip_transports(obj->lc,&tr);
if (tr.udp_port <= 0) {
if (tr.tcp_port>0) {
sal_address_set_param(contact,"transport","tcp");
} else if (tr.tls_port>0) {
sal_address_set_param(contact,"transport","tls");
}
}
}
#endif
linphone_address_set_port(contact,localport); linphone_address_set_port(contact,localport);
linphone_address_set_domain(contact,localip); linphone_address_set_domain(contact,localip);
linphone_address_set_display_name(contact,NULL); linphone_address_set_display_name(contact,NULL);
#ifndef USE_BELLESIP
ret = linphone_address_as_string(contact);
linphone_address_destroy(contact);
#else
ret=contact; ret=contact;
#endif /*USE_BELLESIP*/
linphone_address_destroy (proxy); linphone_address_destroy (proxy);
ms_free(tmp); ms_free(tmp);
} }
......
mediastreamer2 @ dbe58747
Subproject commit 8097db23c50a476593cf912f0c554ca4e391c7e3 Subproject commit dbe58747533b5e2b3e3c25009f483158e2b0cde9
...@@ -28,6 +28,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -28,6 +28,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif #endif
string to_lower(const string &str){
string res=str;
for(string::iterator it=res.begin();it!=res.end();++it){
*it=tolower(*it);
}
return res;
}
CplusplusGenerator::CplusplusGenerator(){ CplusplusGenerator::CplusplusGenerator(){
} }
...@@ -42,17 +50,25 @@ void CplusplusGenerator::generate(Project *proj){ ...@@ -42,17 +50,25 @@ void CplusplusGenerator::generate(Project *proj){
for_each(classes.begin(),classes.end(),bind1st(mem_fun(&CplusplusGenerator::writeClass),this)); for_each(classes.begin(),classes.end(),bind1st(mem_fun(&CplusplusGenerator::writeClass),this));
} }
void CplusplusGenerator::writeEnumMember(ConstField *cf, bool isLast){
writeTabs(1);
mOutfile<<cf->getName();
if (!isLast) mOutfile<<",";
if (!cf->getHelp().empty()) mOutfile<<"\t/**< "<<cf->getHelp()<<" */";
mOutfile<<endl;
}
void CplusplusGenerator::writeClass(Class *klass){ void CplusplusGenerator::writeClass(Class *klass){
ostringstream filename; ostringstream filename;
if (klass->getType()!=Type::Class) return;
filename<<mCurProj->getName()<<"/"<<klass->getName()<<".hh"; filename<<mCurProj->getName()<<"/"<<klass->getName()<<".hh";
mOutfile.open(filename.str().c_str()); mOutfile.open(filename.str().c_str());
if (!mOutfile.is_open()){ if (!mOutfile.is_open()){
cerr<<"Could not write into "<<filename.str()<<endl; cerr<<"Could not write into "<<filename.str()<<endl;
return; return;
} }
const list<Method*> &methods=klass->getMethods(); list<Method*> methods=klass->getMethods();
list<ConstField*> constFields=klass->getConstFields();
mCurClass=klass; mCurClass=klass;
mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<<endl; mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<<endl;
mOutfile<<endl; mOutfile<<endl;
...@@ -60,10 +76,20 @@ void CplusplusGenerator::writeClass(Class *klass){ ...@@ -60,10 +76,20 @@ void CplusplusGenerator::writeClass(Class *klass){
mOutfile<<endl; mOutfile<<endl;
if (!mCurProj->getName().empty()) if (!mCurProj->getName().empty())
mOutfile<<"namespace "<<mCurProj->getName()<<"{"<<endl<<endl; mOutfile<<"namespace "<<mCurProj->getName()<<"{"<<endl<<endl;
mOutfile<<"class "<<klass->getName()<<"{"<<endl; if (klass->getType()==Type::Enum){
mOutfile<<"public:"<<endl; mOutfile<<"enum "<<klass->getName()<<"{"<<endl;
for_each(methods.begin(),methods.end(),bind1st(mem_fun(&CplusplusGenerator::writeMethod),this)); list<ConstField*>::iterator cfit,next;
mOutfile<<"}"<<endl<<endl; for (cfit=constFields.begin();cfit!=constFields.end();){
ConstField *cf=*cfit;
writeEnumMember(cf,++cfit==constFields.end());
}
}else{
mOutfile<<"class "<<klass->getName()<<"{"<<endl;
mOutfile<<"public:"<<endl;
for_each(methods.begin(),methods.end(),bind1st(mem_fun(&CplusplusGenerator::writeMethod),this));
}
mOutfile<<"};"<<endl<<endl;
if (!mCurProj->getName().empty()) if (!mCurProj->getName().empty())
mOutfile<<"} //end of namespace "<<mCurProj->getName()<<endl; mOutfile<<"} //end of namespace "<<mCurProj->getName()<<endl;
mOutfile<<endl; mOutfile<<endl;
...@@ -154,29 +180,102 @@ void JavascriptGenerator::generate(Project *proj){ ...@@ -154,29 +180,102 @@ void JavascriptGenerator::generate(Project *proj){
list<Class*> classes=proj->getClasses(); list<Class*> classes=proj->getClasses();
mCurProj=proj; mCurProj=proj;
#ifndef WIN32 #ifndef WIN32
unlink(proj->getName().c_str()); remove(to_lower(proj->getName()).c_str());
mkdir(proj->getName().c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH); mkdir(to_lower(proj->getName()).c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH);
#else #else
_mkdir(proj->getName().c_str()); _mkdir(to_lower(proj->getName()).c_str());
#endif #endif
ostringstream filename;
/*write a file for the namespace*/
filename<<to_lower(mCurProj->getName())<<"/"<<to_lower(mCurProj->getName())<<".js";
mOutfile.open(filename.str().c_str());
if (!mOutfile.is_open()){
cerr<<"Could not write into "<<filename.str()<<endl;
return;
}
mOutfile<<"/**"<<endl;
mOutfile<<" * Namespace for non-external variables and objects."<<endl;
mOutfile<<" * @namespace "<<mCurProj->getName()<<endl;
mOutfile<<"**/"<<endl;
mOutfile<<"var "<<proj->getName()<<" = {};"<<endl;
mOutfile.close();
for_each(classes.begin(),classes.end(),bind1st(mem_fun(&JavascriptGenerator::writeEnum),this));
for_each(classes.begin(),classes.end(),bind1st(mem_fun(&JavascriptGenerator::writeClass),this)); for_each(classes.begin(),classes.end(),bind1st(mem_fun(&JavascriptGenerator::writeClass),this));
} }
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();
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()){
cerr<<"Could not write into "<<filename.str()<<endl;
return;
}
mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<<endl<<endl;
mOutfile<<"var "<<mCurProj->getName()<<" = "<<mCurProj->getName()<<" || {};"<<endl;
mOutfile<<"/**"<<endl;
writeHelpComment(klass->getHelp(),0);
mOutfile<<endl;
mOutfile<<" * "<<"@readonly"<<endl;
mOutfile<<" * "<<"@enum {number}"<<endl;
mOutfile<<"**/"<<endl;
mOutfile<<mCurProj->getName()<<"."<<enum_name<<" = {"<<endl;
string prefix=ConstField::getCommonPrefix(members);
size_t prefix_size=prefix.size();
for(it=members.begin();it!=members.end();value++){
ConstField *cf=(*it);
if (!cf->getHelp().empty()){
writeTabs(1);
mOutfile<<"/**"<<endl;
writeHelpComment(cf->getHelp(),1);
mOutfile<<endl;
writeTabs(1);
mOutfile<<"*/"<<endl;
}
writeTabs(1);
mOutfile<<cf->getName().substr(prefix_size,string::npos)<<" : "<<value;
if (++it!=members.end()) mOutfile<<",";
mOutfile<<endl;
}
mOutfile<<"};"<<endl;
mOutfile.close();
}
void JavascriptGenerator::writeClass(Class *klass){ void JavascriptGenerator::writeClass(Class *klass){
ostringstream filename; ostringstream filename;
if (klass->getType()!=Type::Class) return; if (klass->getType()==Type::Enum) {
filename<<mCurProj->getName()<<"/"<<klass->getName()<<".js"; return;
}
filename<<to_lower(mCurProj->getName())<<"/"<<to_lower(klass->getName())<<".js";
mOutfile.open(filename.str().c_str()); mOutfile.open(filename.str().c_str());
if (!mOutfile.is_open()){ if (!mOutfile.is_open()){
cerr<<"Could not write into "<<filename.str()<<endl; cerr<<"Could not write into "<<filename.str()<<endl;
return; return;
} }
const list<Method*> &methods=klass->getMethods();
mCurClass=klass; mCurClass=klass;
mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<<endl; mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<<endl;
mOutfile<<endl; mOutfile<<endl;
const list<Method*> &methods=klass->getMethods();
//if (!mCurProj->getName().empty()) //if (!mCurProj->getName().empty())
// mOutfile<<"namespace "<<mCurProj->getName()<<"{"<<endl<<endl; // mOutfile<<"namespace "<<mCurProj->getName()<<"{"<<endl<<endl;
mOutfile<<"/**"<<endl; mOutfile<<"/**"<<endl;
...@@ -239,11 +338,12 @@ void JavascriptGenerator::writeTabs(int ntabs){ ...@@ -239,11 +338,12 @@ void JavascriptGenerator::writeTabs(int ntabs){
void JavascriptGenerator::writeHelpComment(const std::string &comment, int ntabs){ void JavascriptGenerator::writeHelpComment(const std::string &comment, int ntabs){
size_t i; size_t i;
int curindex=0; int curindex=0;
writeTabs(ntabs);
mOutfile<<" * "; mOutfile<<" * ";
for(i=0;i<comment.size();i++,curindex++){ for(i=0;i<comment.size();i++,curindex++){
if (comment[i]=='\n' || (curindex>100 && comment[i]==' ')){ if (comment[i]=='\n' || (curindex>100 && comment[i]==' ')){
mOutfile<<endl; mOutfile<<endl;
writeTabs(ntabs);
mOutfile<<" * "; mOutfile<<" * ";
curindex=0; curindex=0;
}else mOutfile<<comment[i]; }else mOutfile<<comment[i];
...@@ -251,6 +351,7 @@ void JavascriptGenerator::writeHelpComment(const std::string &comment, int ntabs ...@@ -251,6 +351,7 @@ void JavascriptGenerator::writeHelpComment(const std::string &comment, int ntabs
} }
void JavascriptGenerator::writeProperty(Property *prop){ void JavascriptGenerator::writeProperty(Property *prop){
if (prop->getName()=="userData" || prop->getName()=="userPointer") return;
mOutfile<<"/**"<<endl; mOutfile<<"/**"<<endl;
writeHelpComment(prop->getHelp(),0); writeHelpComment(prop->getHelp(),0);
mOutfile<<endl; mOutfile<<endl;
......
...@@ -40,6 +40,7 @@ private: ...@@ -40,6 +40,7 @@ private:
void writeTabs(int ntabs); void writeTabs(int ntabs);
void writeHelpComment(const std::string &comment, int ntabs); void writeHelpComment(const std::string &comment, int ntabs);
void writeMethod(Method *method); void writeMethod(Method *method);
void writeEnumMember(ConstField *cf, bool isLast);
ofstream mOutfile; ofstream mOutfile;
Project *mCurProj; Project *mCurProj;
Class *mCurClass; Class *mCurClass;
...@@ -51,6 +52,7 @@ public: ...@@ -51,6 +52,7 @@ public:
virtual void generate(Project *proj); virtual void generate(Project *proj);
private: private:
void writeClass(Class *klass); void writeClass(Class *klass);
void writeEnum(Class *klass);
void writeType(Type *type); void writeType(Type *type);
void writeArgument(Argument *arg, bool isReturn=false); void writeArgument(Argument *arg, bool isReturn=false);
void writeTabs(int ntabs); void writeTabs(int ntabs);
...@@ -62,5 +64,6 @@ private: ...@@ -62,5 +64,6 @@ private:
Class *mCurClass; Class *mCurClass;
}; };
string to_lower(const string &str);
#endif #endif
...@@ -250,6 +250,22 @@ static void parseFunction(Project *proj, xmlNode *node){ ...@@ -250,6 +250,22 @@ static void parseFunction(Project *proj, xmlNode *node){
} }
} }
static void parseEnum(Project *proj, XmlNode node){
string name=node.getChild("name").getText();
if (name[0]=='_') name.erase(0,1);
Class *klass=proj->getClass(name);
klass->setHelp(node.getChild("detaileddescription").getChild("para").getText());
list<XmlNode> enumValues=node.getChildren("enumvalue");
list<XmlNode>::iterator it;
for (it=enumValues.begin();it!=enumValues.end();++it){
ConstField *cf=new ConstField(Type::getType("int"),(*it).getChild("name").getText());
cf->setHelp((*it).getChild("detaileddescription").getChild("para").getText());
klass->addConstField(cf);
}
}
static void parseTypedef(Project *proj, xmlNode *node){ static void parseTypedef(Project *proj, xmlNode *node){
XmlNode tdef(node); XmlNode tdef(node);
string typecontent=tdef.getChild("type").getText(); string typecontent=tdef.getChild("type").getText();
...@@ -278,6 +294,8 @@ static void parseMemberDef(Project *proj, xmlNode *node){ ...@@ -278,6 +294,8 @@ static void parseMemberDef(Project *proj, xmlNode *node){
parseFunction(proj,node); parseFunction(proj,node);
}else if (kind=="typedef"){ }else if (kind=="typedef"){
parseTypedef(proj,node); parseTypedef(proj,node);
}else if (kind=="enum"){
parseEnum(proj,node);
} }
} }
...@@ -321,7 +339,7 @@ static int parse_file(Project *proj, const char *filename){ ...@@ -321,7 +339,7 @@ static int parse_file(Project *proj, const char *filename){
int main(int argc, char *argv[]){