Commit 77d61696 authored by Simon Morlat's avatar Simon Morlat

improve documentation, rationalize some callbacks name.

lp-gen-wrapper functional.
parent 122c5bbc
......@@ -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";
}
......
......@@ -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.
......
......@@ -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;
}
......
This diff is collapsed.
......@@ -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;
......
......@@ -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;
}
......@@ -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;
......
......@@ -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"){
......
......@@ -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"
};
......@@ -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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment