mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-20 04:28:10 +00:00
Add forgotten daemon header
This commit is contained in:
parent
b429672bf8
commit
74fddfca2e
1 changed files with 140 additions and 0 deletions
140
daemon/daemon.h
Normal file
140
daemon/daemon.h
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#ifndef DAEMON_H_
|
||||
#define DAEMON_H_
|
||||
|
||||
#include <linphonecore.h>
|
||||
#include <mediastreamer2/mediastream.h>
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
|
||||
class Daemon;
|
||||
|
||||
class DaemonCommand {
|
||||
public:
|
||||
virtual ~DaemonCommand() {
|
||||
|
||||
};
|
||||
virtual void exec(Daemon *app, const char *args)=0;
|
||||
bool matches(const char *name) const;
|
||||
const std::string &getProto() const {
|
||||
return mProto;
|
||||
}
|
||||
const std::string &getHelp() const {
|
||||
return mHelp;
|
||||
}
|
||||
protected:
|
||||
DaemonCommand(const char *name, const char *proto, const char *help);
|
||||
const std::string mName;
|
||||
const std::string mProto;
|
||||
const std::string mHelp;
|
||||
};
|
||||
|
||||
class Response {
|
||||
public:
|
||||
enum Status {
|
||||
Ok, Error
|
||||
};
|
||||
virtual ~Response() {
|
||||
}
|
||||
Response() :
|
||||
mStatus(Ok) {
|
||||
}
|
||||
Response(const char *msg, Status status = Error) :
|
||||
mStatus(status) {
|
||||
if (status == Ok) {
|
||||
mBody = msg;
|
||||
} else {
|
||||
mReason = msg;
|
||||
}
|
||||
}
|
||||
void setStatus(Status st) {
|
||||
mStatus = st;
|
||||
}
|
||||
void setReason(const char *reason) {
|
||||
mReason = reason;
|
||||
}
|
||||
void setBody(const char *body) {
|
||||
mBody = body;
|
||||
}
|
||||
const std::string &getBody() const {
|
||||
return mBody;
|
||||
}
|
||||
virtual int toBuf(char *dst, int dstlen) const {
|
||||
int i = 0;
|
||||
i += snprintf(dst + i, dstlen - i, "Status: %s\n", mStatus == Ok ? "Ok" : "Error");
|
||||
if (mReason.size() > 0) {
|
||||
i += snprintf(dst + i, dstlen - i, "Reason: %s\n", mReason.c_str());
|
||||
}
|
||||
if (mBody.size() > 0) {
|
||||
i += snprintf(dst + i, dstlen - i, "\n%s\n", mBody.c_str());
|
||||
}
|
||||
return i;
|
||||
}
|
||||
private:
|
||||
Status mStatus;
|
||||
std::string mReason;
|
||||
std::string mBody;
|
||||
};
|
||||
|
||||
class EventResponse: public Response {
|
||||
public:
|
||||
EventResponse(LinphoneCall *call, LinphoneCallState state);
|
||||
private:
|
||||
};
|
||||
|
||||
class PayloadTypeResponse: public Response {
|
||||
public:
|
||||
PayloadTypeResponse(LinphoneCore *core, const PayloadType *payloadType, int index = -1, const std::string &prefix = std::string(), bool enabled_status = true);
|
||||
private:
|
||||
};
|
||||
|
||||
class Daemon {
|
||||
friend class DaemonCommand;
|
||||
public:
|
||||
typedef Response::Status Status;
|
||||
Daemon(const char *config_path, const char *factory_config_path, const char *log_file, const char *pipe_name, bool display_video, bool capture_video);
|
||||
~Daemon();
|
||||
int run();
|
||||
void quit();
|
||||
void sendResponse(const Response &resp);
|
||||
LinphoneCore *getCore();
|
||||
const std::list<DaemonCommand*> &getCommandList() const;
|
||||
LinphoneCall *findCall(int id);
|
||||
LinphoneProxyConfig *findProxy(int id);
|
||||
AudioStream *findAudioStream(int id);
|
||||
bool pullEvent();
|
||||
static int getCallId(LinphoneCall *call);
|
||||
int setCallId(LinphoneCall *call);
|
||||
static int getProxyId(LinphoneProxyConfig *proxy);
|
||||
int setProxyId(LinphoneProxyConfig *proxy);
|
||||
int setAudioStreamId(AudioStream *audio_stream);
|
||||
private:
|
||||
|
||||
static void callStateChanged(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState state, const char *msg);
|
||||
static int readlineHook();
|
||||
void callStateChanged(LinphoneCall *call, LinphoneCallState state, const char *msg);
|
||||
void execCommand(const char *cl);
|
||||
void initReadline();
|
||||
char *readPipe(char *buffer, int buflen);
|
||||
void iterate();
|
||||
void initCommands();
|
||||
void uninitCommands();
|
||||
LinphoneCore *mLc;
|
||||
std::list<DaemonCommand*> mCommands;
|
||||
std::queue<EventResponse*> mEventQueue;
|
||||
int mServerFd;
|
||||
int mChildFd;
|
||||
std::string mHistfile;
|
||||
bool mRunning;
|
||||
FILE *mLogFile;
|
||||
static Daemon *sZis;
|
||||
static int sCallIds;
|
||||
static int sProxyIds;
|
||||
static int sAudioStreamIds;
|
||||
static const int sLineSize = 512;
|
||||
std::map<int, AudioStream*> mAudioStreams;
|
||||
};
|
||||
|
||||
#endif //DAEMON_H_
|
||||
Loading…
Add table
Reference in a new issue