Context: Refine API

pull/1969/head
winlin 4 years ago
parent cf428b8db4
commit 311cb77b36

@ -340,7 +340,7 @@ srs_error_t SrsPublishRecvThread::error_code()
return srs_error_copy(recv_error); return srs_error_copy(recv_error);
} }
void SrsPublishRecvThread::set_cid(std::string v) void SrsPublishRecvThread::set_cid(SrsContextId v)
{ {
ncid = v; ncid = v;
} }

@ -180,7 +180,7 @@ public:
virtual int64_t nb_msgs(); virtual int64_t nb_msgs();
virtual uint64_t nb_video_frames(); virtual uint64_t nb_video_frames();
virtual srs_error_t error_code(); virtual srs_error_t error_code();
virtual void set_cid(std::string v); virtual void set_cid(SrsContextId v);
virtual SrsContextId get_cid(); virtual SrsContextId get_cid();
public: public:
virtual srs_error_t start(); virtual srs_error_t start();

@ -27,11 +27,6 @@ _SrsContextId::_SrsContextId()
{ {
} }
_SrsContextId::_SrsContextId(std::string v)
{
v_ = v;
}
_SrsContextId::_SrsContextId(const _SrsContextId& cp) _SrsContextId::_SrsContextId(const _SrsContextId& cp)
{ {
v_ = cp.v_; v_ = cp.v_;
@ -57,6 +52,12 @@ bool _SrsContextId::empty() const
return v_.empty(); return v_.empty();
} }
_SrsContextId& _SrsContextId::set_value(const std::string& v)
{
v_ = v;
return *this;
}
int _SrsContextId::compare(const _SrsContextId& to) const int _SrsContextId::compare(const _SrsContextId& to) const
{ {
return v_.compare(to.v_); return v_.compare(to.v_);

@ -124,13 +124,14 @@ private:
std::string v_; std::string v_;
public: public:
_SrsContextId(); _SrsContextId();
_SrsContextId(std::string v);
_SrsContextId(const _SrsContextId& cp); _SrsContextId(const _SrsContextId& cp);
_SrsContextId& operator=(const _SrsContextId& cp); _SrsContextId& operator=(const _SrsContextId& cp);
virtual ~_SrsContextId(); virtual ~_SrsContextId();
public: public:
const char* c_str() const; const char* c_str() const;
bool empty() const; bool empty() const;
// Set the value of context id.
_SrsContextId& set_value(const std::string& v);
// Compare the two context id. @see http://www.cplusplus.com/reference/string/string/compare/ // Compare the two context id. @see http://www.cplusplus.com/reference/string/string/compare/
// 0 They compare equal // 0 They compare equal
// <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter. // <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.

@ -45,8 +45,8 @@ SrsThreadContext::~SrsThreadContext()
SrsContextId SrsThreadContext::generate_id() SrsContextId SrsThreadContext::generate_id()
{ {
SrsContextId cid = SrsContextId(srs_random_str(8)); SrsContextId cid = SrsContextId();
return cid; return cid.set_value(srs_random_str(8));
} }
const SrsContextId& SrsThreadContext::get_id() const SrsContextId& SrsThreadContext::get_id()

Loading…
Cancel
Save