Reformat the WebRTC code base

Running clang-format with chromium's style guide.

The goal is n-fold:
 * providing consistency and readability (that's what code guidelines are for)
 * preventing noise with presubmit checks and git cl format
 * building on the previous point: making it easier to automatically fix format issues
 * you name it

Please consider using git-hyper-blame to ignore this commit.

Bug: webrtc:9340
Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87
Reviewed-on: https://webrtc-review.googlesource.com/81185
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23660}
This commit is contained in:
Yves Gerey
2018-06-19 15:03:05 +02:00
parent b602123a5a
commit 665174fdbb
1569 changed files with 30495 additions and 30309 deletions

View File

@ -41,8 +41,7 @@ class DummySetSessionDescriptionObserver
: public webrtc::SetSessionDescriptionObserver {
public:
static DummySetSessionDescriptionObserver* Create() {
return
new rtc::RefCountedObject<DummySetSessionDescriptionObserver>();
return new rtc::RefCountedObject<DummySetSessionDescriptionObserver>();
}
virtual void OnSuccess() { RTC_LOG(INFO) << __FUNCTION__; }
virtual void OnFailure(webrtc::RTCError error) {
@ -52,10 +51,7 @@ class DummySetSessionDescriptionObserver
};
Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd)
: peer_id_(-1),
loopback_(false),
client_(client),
main_wnd_(main_wnd) {
: peer_id_(-1), loopback_(false), client_(client), main_wnd_(main_wnd) {
client_->RegisterObserver(this);
main_wnd->RegisterObserver(this);
}
@ -87,15 +83,14 @@ bool Conductor::InitializePeerConnection() {
nullptr /* audio_processing */);
if (!peer_connection_factory_) {
main_wnd_->MessageBox("Error",
"Failed to initialize PeerConnectionFactory", true);
main_wnd_->MessageBox("Error", "Failed to initialize PeerConnectionFactory",
true);
DeletePeerConnection();
return false;
}
if (!CreatePeerConnection(/*dtls=*/true)) {
main_wnd_->MessageBox("Error",
"CreatePeerConnection failed", true);
main_wnd_->MessageBox("Error", "CreatePeerConnection failed", true);
DeletePeerConnection();
}
@ -363,8 +358,8 @@ void Conductor::ConnectToPeer(int peer_id) {
RTC_DCHECK(peer_id != -1);
if (peer_connection_.get()) {
main_wnd_->MessageBox("Error",
"We only support connecting to one peer at a time", true);
main_wnd_->MessageBox(
"Error", "We only support connecting to one peer at a time", true);
return;
}

View File

@ -30,11 +30,10 @@ namespace cricket {
class VideoRenderer;
} // namespace cricket
class Conductor
: public webrtc::PeerConnectionObserver,
public webrtc::CreateSessionDescriptionObserver,
public PeerConnectionClientObserver,
public MainWndCallback {
class Conductor : public webrtc::PeerConnectionObserver,
public webrtc::CreateSessionDescriptionObserver,
public PeerConnectionClientObserver,
public MainWndCallback {
public:
enum CallbackID {
MEDIA_CHANNELS_INITIALIZED = 1,

View File

@ -20,13 +20,19 @@ extern const uint16_t kDefaultServerPort; // From defaults.[h|cc]
// for each platform.
DEFINE_bool(help, false, "Prints this message");
DEFINE_bool(autoconnect, false, "Connect to the server without user "
"intervention.");
DEFINE_bool(autoconnect,
false,
"Connect to the server without user "
"intervention.");
DEFINE_string(server, "localhost", "The server to connect to.");
DEFINE_int(port, kDefaultServerPort,
DEFINE_int(port,
kDefaultServerPort,
"The port on which the server is listening.");
DEFINE_bool(autocall, false, "Call the first available other client on "
"the server without user intervention. Note: this flag should only be set "
"to true on one of the two clients.");
DEFINE_bool(
autocall,
false,
"Call the first available other client on "
"the server without user intervention. Note: this flag should only be set "
"to true on one of the two clients.");
#endif // EXAMPLES_PEERCONNECTION_CLIENT_FLAGDEFS_H_

View File

@ -38,15 +38,15 @@ class CustomSocketServer : public rtc::PhysicalSocketServer {
// different thread. Alternatively we could look at merging the two loops
// by implementing a dispatcher for the socket server and/or use
// g_main_context_set_poll_func.
while (gtk_events_pending())
gtk_main_iteration();
while (gtk_events_pending())
gtk_main_iteration();
if (!wnd_->IsWindow() && !conductor_->connection_active() &&
client_ != NULL && !client_->is_connected()) {
message_queue_->Quit();
}
return rtc::PhysicalSocketServer::Wait(0/*cms == -1 ? 1 : cms*/,
process_io);
return rtc::PhysicalSocketServer::Wait(0 /*cms == -1 ? 1 : cms*/,
process_io);
}
protected:
@ -58,15 +58,15 @@ class CustomSocketServer : public rtc::PhysicalSocketServer {
int main(int argc, char* argv[]) {
gtk_init(&argc, &argv);
// g_type_init API is deprecated (and does nothing) since glib 2.35.0, see:
// https://mail.gnome.org/archives/commits-list/2012-November/msg07809.html
// g_type_init API is deprecated (and does nothing) since glib 2.35.0, see:
// https://mail.gnome.org/archives/commits-list/2012-November/msg07809.html
#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init();
g_type_init();
#endif
// g_thread_init API is deprecated since glib 2.31.0, see release note:
// http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.html
// g_thread_init API is deprecated since glib 2.31.0, see release note:
// http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.html
#if !GLIB_CHECK_VERSION(2, 31, 0)
g_thread_init(NULL);
g_thread_init(NULL);
#endif
rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);

View File

@ -30,7 +30,8 @@ namespace {
// GtkMainWnd instance.
//
gboolean OnDestroyedCallback(GtkWidget* widget, GdkEvent* event,
gboolean OnDestroyedCallback(GtkWidget* widget,
GdkEvent* event,
gpointer data) {
reinterpret_cast<GtkMainWnd*>(data)->OnDestroyed(widget, event);
return FALSE;
@ -45,14 +46,17 @@ gboolean SimulateButtonClick(gpointer button) {
return false;
}
gboolean OnKeyPressCallback(GtkWidget* widget, GdkEventKey* key,
gboolean OnKeyPressCallback(GtkWidget* widget,
GdkEventKey* key,
gpointer data) {
reinterpret_cast<GtkMainWnd*>(data)->OnKeyPress(widget, key);
return false;
}
void OnRowActivatedCallback(GtkTreeView* tree_view, GtkTreePath* path,
GtkTreeViewColumn* column, gpointer data) {
void OnRowActivatedCallback(GtkTreeView* tree_view,
GtkTreePath* path,
GtkTreeViewColumn* column,
gpointer data) {
reinterpret_cast<GtkMainWnd*>(data)->OnRowActivated(tree_view, path, column);
}
@ -90,8 +94,8 @@ void InitializeList(GtkWidget* list) {
// Adds an entry to a tree view.
void AddToList(GtkWidget* list, const gchar* str, int value) {
GtkListStore* store = GTK_LIST_STORE(
gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
GtkListStore* store =
GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
GtkTreeIter iter;
gtk_list_store_append(store, &iter);
@ -131,11 +135,20 @@ gboolean Draw(GtkWidget* widget, cairo_t* cr, gpointer data) {
// GtkMainWnd implementation.
//
GtkMainWnd::GtkMainWnd(const char* server, int port, bool autoconnect,
GtkMainWnd::GtkMainWnd(const char* server,
int port,
bool autoconnect,
bool autocall)
: window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL),
port_edit_(NULL), peer_list_(NULL), callback_(NULL),
server_(server), autoconnect_(autoconnect), autocall_(autocall) {
: window_(NULL),
draw_area_(NULL),
vbox_(NULL),
server_edit_(NULL),
port_edit_(NULL),
peer_list_(NULL),
callback_(NULL),
server_(server),
autoconnect_(autoconnect),
autocall_(autocall) {
char buffer[10];
sprintfn(buffer, sizeof(buffer), "%i", port);
port_ = buffer;
@ -153,12 +166,13 @@ bool GtkMainWnd::IsWindow() {
return window_ != NULL && GTK_IS_WINDOW(window_);
}
void GtkMainWnd::MessageBox(const char* caption, const char* text,
void GtkMainWnd::MessageBox(const char* caption,
const char* text,
bool is_error) {
GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(window_),
GTK_DIALOG_DESTROY_WITH_PARENT,
is_error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE, "%s", text);
GtkWidget* dialog = gtk_message_dialog_new(
GTK_WINDOW(window_), GTK_DIALOG_DESTROY_WITH_PARENT,
is_error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s",
text);
gtk_window_set_title(GTK_WINDOW(dialog), caption);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
@ -174,7 +188,6 @@ MainWindow::UI GtkMainWnd::current_ui() {
return STREAMING;
}
void GtkMainWnd::StartLocalRenderer(webrtc::VideoTrackInterface* local_video) {
local_renderer_.reset(new VideoRenderer(this, local_video));
}
@ -394,7 +407,8 @@ void GtkMainWnd::OnKeyPress(GtkWidget* widget, GdkEventKey* key) {
}
}
void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view,
GtkTreePath* path,
GtkTreeViewColumn* column) {
RTC_DCHECK(peer_list_ != NULL);
GtkTreeIter iter;
@ -402,12 +416,12 @@ void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
GtkTreeSelection* selection =
gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
char* text;
int id = -1;
gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1);
if (id != -1)
callback_->ConnectToPeer(id);
g_free(text);
char* text;
int id = -1;
gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1);
if (id != -1)
callback_->ConnectToPeer(id);
g_free(text);
}
}
@ -519,8 +533,7 @@ void GtkMainWnd::VideoRenderer::SetSize(int width, int height) {
gdk_threads_leave();
}
void GtkMainWnd::VideoRenderer::OnFrame(
const webrtc::VideoFrame& video_frame) {
void GtkMainWnd::VideoRenderer::OnFrame(const webrtc::VideoFrame& video_frame) {
gdk_threads_enter();
rtc::scoped_refptr<webrtc::I420BufferInterface> buffer(
@ -536,11 +549,10 @@ void GtkMainWnd::VideoRenderer::OnFrame(
// This was supposed to be a call to libyuv::I420ToRGBA but it was resulting
// in a reddish video output (see https://bugs.webrtc.org/6857) because it
// was producing an unexpected byte order (ABGR, byte swapped).
libyuv::I420ToABGR(buffer->DataY(), buffer->StrideY(),
buffer->DataU(), buffer->StrideU(),
buffer->DataV(), buffer->StrideV(),
image_.get(), width_ * 4,
buffer->width(), buffer->height());
libyuv::I420ToABGR(buffer->DataY(), buffer->StrideY(), buffer->DataU(),
buffer->StrideU(), buffer->DataV(), buffer->StrideV(),
image_.get(), width_ * 4, buffer->width(),
buffer->height());
gdk_threads_leave();

View File

@ -39,8 +39,7 @@ class GtkMainWnd : public MainWindow {
virtual void SwitchToConnectUI();
virtual void SwitchToPeerList(const Peers& peers);
virtual void SwitchToStreamingUI();
virtual void MessageBox(const char* caption, const char* text,
bool is_error);
virtual void MessageBox(const char* caption, const char* text, bool is_error);
virtual MainWindow::UI current_ui();
virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
virtual void StopLocalRenderer();
@ -67,7 +66,8 @@ class GtkMainWnd : public MainWindow {
// Callback when the user double clicks a peer in order to initiate a
// connection.
void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
void OnRowActivated(GtkTreeView* tree_view,
GtkTreePath* path,
GtkTreeViewColumn* column);
void OnRedraw();
@ -86,13 +86,9 @@ class GtkMainWnd : public MainWindow {
const uint8_t* image() const { return image_.get(); }
int width() const {
return width_;
}
int width() const { return width_; }
int height() const {
return height_;
}
int height() const { return height_; }
protected:
void SetSize(int width, int height);
@ -104,9 +100,9 @@ class GtkMainWnd : public MainWindow {
};
protected:
GtkWidget* window_; // Our main window.
GtkWidget* window_; // Our main window.
GtkWidget* draw_area_; // The drawing surface for rendering video streams.
GtkWidget* vbox_; // Container for the Connect UI.
GtkWidget* vbox_; // Container for the Connect UI.
GtkWidget* server_edit_;
GtkWidget* port_edit_;
GtkWidget* peer_list_; // The list of peers.

View File

@ -17,8 +17,10 @@
#include "rtc_base/win32socketinit.h"
#include "rtc_base/win32socketserver.h"
int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
wchar_t* cmd_line, int cmd_show) {
int PASCAL wWinMain(HINSTANCE instance,
HINSTANCE prev_instance,
wchar_t* cmd_line,
int cmd_show) {
rtc::EnsureWinsockInit();
rtc::Win32SocketServer w32_ss;
rtc::Win32Thread w32_thread(&w32_ss);
@ -26,7 +28,7 @@ int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
rtc::WindowsCommandLineArguments win_args;
int argc = win_args.argc();
char **argv = win_args.argv();
char** argv = win_args.argv();
rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (FLAG_help) {
@ -50,7 +52,7 @@ int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
rtc::InitializeSSL();
PeerConnectionClient client;
rtc::scoped_refptr<Conductor> conductor(
new rtc::RefCountedObject<Conductor>(&client, &wnd));
new rtc::RefCountedObject<Conductor>(&client, &wnd));
// Main loop.
MSG msg;

View File

@ -31,8 +31,10 @@ const char kConnecting[] = "Connecting... ";
const char kNoVideoStreams[] = "(no video streams either way)";
const char kNoIncomingStream[] = "(no incoming video)";
void CalculateWindowSizeForText(HWND wnd, const wchar_t* text,
size_t* width, size_t* height) {
void CalculateWindowSizeForText(HWND wnd,
const wchar_t* text,
size_t* width,
size_t* height) {
HDC dc = ::GetDC(wnd);
RECT text_rc = {0};
::DrawText(dc, text, -1, &text_rc, DT_CALCRECT | DT_SINGLELINE);
@ -42,11 +44,9 @@ void CalculateWindowSizeForText(HWND wnd, const wchar_t* text,
::GetWindowRect(wnd, &window);
*width = text_rc.right - text_rc.left;
*width += (window.right - window.left) -
(client.right - client.left);
*width += (window.right - window.left) - (client.right - client.left);
*height = text_rc.bottom - text_rc.top;
*height += (window.bottom - window.top) -
(client.bottom - client.top);
*height += (window.bottom - window.top) - (client.bottom - client.top);
}
HFONT GetDefaultFont() {
@ -62,18 +62,30 @@ std::string GetWindowText(HWND wnd) {
void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) {
LRESULT index = ::SendMessageA(listbox, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(str.c_str()));
reinterpret_cast<LPARAM>(str.c_str()));
::SendMessageA(listbox, LB_SETITEMDATA, index, item_data);
}
} // namespace
MainWnd::MainWnd(const char* server, int port, bool auto_connect,
MainWnd::MainWnd(const char* server,
int port,
bool auto_connect,
bool auto_call)
: ui_(CONNECT_TO_SERVER), wnd_(NULL), edit1_(NULL), edit2_(NULL),
label1_(NULL), label2_(NULL), button_(NULL), listbox_(NULL),
destroyed_(false), callback_(NULL), nested_msg_(NULL),
server_(server), auto_connect_(auto_connect), auto_call_(auto_call) {
: ui_(CONNECT_TO_SERVER),
wnd_(NULL),
edit1_(NULL),
edit2_(NULL),
label1_(NULL),
label2_(NULL),
button_(NULL),
listbox_(NULL),
destroyed_(false),
callback_(NULL),
nested_msg_(NULL),
server_(server),
auto_connect_(auto_connect),
auto_call_(auto_call) {
char buffer[10] = {0};
sprintfn(buffer, sizeof(buffer), "%i", port);
port_ = buffer;
@ -89,10 +101,11 @@ bool MainWnd::Create() {
return false;
ui_thread_id_ = ::GetCurrentThreadId();
wnd_ = ::CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, kClassName, L"WebRTC",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, GetModuleHandle(NULL), this);
wnd_ =
::CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, kClassName, L"WebRTC",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), this);
::SendMessage(wnd_, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()),
TRUE);
@ -176,10 +189,10 @@ void MainWnd::SwitchToPeerList(const Peers& peers) {
LRESULT count = ::SendMessage(listbox_, LB_GETCOUNT, 0, 0);
if (count != LB_ERR) {
// Select the last item in the list
LRESULT selection = ::SendMessage(listbox_, LB_SETCURSEL , count - 1, 0);
LRESULT selection = ::SendMessage(listbox_, LB_SETCURSEL, count - 1, 0);
if (selection != LB_ERR)
::PostMessage(wnd_, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(listbox_),
LBN_DBLCLK),
::PostMessage(wnd_, WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(listbox_), LBN_DBLCLK),
reinterpret_cast<LPARAM>(listbox_));
}
}
@ -199,7 +212,6 @@ void MainWnd::MessageBox(const char* caption, const char* text, bool is_error) {
::MessageBoxA(handle(), text, caption, flags);
}
void MainWnd::StartLocalRenderer(webrtc::VideoTrackInterface* local_video) {
local_renderer_.reset(new VideoRenderer(handle(), 1, 1, local_video));
}
@ -218,7 +230,8 @@ void MainWnd::StopRemoteRenderer() {
void MainWnd::QueueUIThreadCallback(int msg_id, void* data) {
::PostThreadMessage(ui_thread_id_, UI_THREAD_CALLBACK,
static_cast<WPARAM>(msg_id), reinterpret_cast<LPARAM>(data));
static_cast<WPARAM>(msg_id),
reinterpret_cast<LPARAM>(data));
}
void MainWnd::OnPaint() {
@ -244,7 +257,7 @@ void MainWnd::OnPaint() {
::SetStretchBltMode(dc_mem, HALFTONE);
// Set the map mode so that the ratio will be maintained for us.
HDC all_dc[] = { ps.hdc, dc_mem };
HDC all_dc[] = {ps.hdc, dc_mem};
for (int i = 0; i < arraysize(all_dc); ++i) {
SetMapMode(all_dc[i], MM_ISOTROPIC);
SetWindowExtEx(all_dc[i], width, height, NULL);
@ -254,35 +267,34 @@ void MainWnd::OnPaint() {
HBITMAP bmp_mem = ::CreateCompatibleBitmap(ps.hdc, rc.right, rc.bottom);
HGDIOBJ bmp_old = ::SelectObject(dc_mem, bmp_mem);
POINT logical_area = { rc.right, rc.bottom };
POINT logical_area = {rc.right, rc.bottom};
DPtoLP(ps.hdc, &logical_area, 1);
HBRUSH brush = ::CreateSolidBrush(RGB(0, 0, 0));
RECT logical_rect = {0, 0, logical_area.x, logical_area.y };
RECT logical_rect = {0, 0, logical_area.x, logical_area.y};
::FillRect(dc_mem, &logical_rect, brush);
::DeleteObject(brush);
int x = (logical_area.x / 2) - (width / 2);
int y = (logical_area.y / 2) - (height / 2);
StretchDIBits(dc_mem, x, y, width, height,
0, 0, width, height, image, &bmi, DIB_RGB_COLORS, SRCCOPY);
StretchDIBits(dc_mem, x, y, width, height, 0, 0, width, height, image,
&bmi, DIB_RGB_COLORS, SRCCOPY);
if ((rc.right - rc.left) > 200 && (rc.bottom - rc.top) > 200) {
const BITMAPINFO& bmi = local_renderer->bmi();
image = local_renderer->image();
int thumb_width = bmi.bmiHeader.biWidth / 4;
int thumb_height = abs(bmi.bmiHeader.biHeight) / 4;
StretchDIBits(dc_mem,
logical_area.x - thumb_width - 10,
logical_area.y - thumb_height - 10,
thumb_width, thumb_height,
0, 0, bmi.bmiHeader.biWidth, -bmi.bmiHeader.biHeight,
image, &bmi, DIB_RGB_COLORS, SRCCOPY);
StretchDIBits(dc_mem, logical_area.x - thumb_width - 10,
logical_area.y - thumb_height - 10, thumb_width,
thumb_height, 0, 0, bmi.bmiHeader.biWidth,
-bmi.bmiHeader.biHeight, image, &bmi, DIB_RGB_COLORS,
SRCCOPY);
}
BitBlt(ps.hdc, 0, 0, logical_area.x, logical_area.y,
dc_mem, 0, 0, SRCCOPY);
BitBlt(ps.hdc, 0, 0, logical_area.x, logical_area.y, dc_mem, 0, 0,
SRCCOPY);
// Cleanup.
::SelectObject(dc_mem, bmp_old);
@ -305,7 +317,7 @@ void MainWnd::OnPaint() {
text += kNoIncomingStream;
}
::DrawTextA(ps.hdc, text.c_str(), -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
::SelectObject(ps.hdc, old_font);
}
} else {
@ -393,8 +405,8 @@ bool MainWnd::OnMessage(UINT msg, WPARAM wp, LPARAM lp, LRESULT* result) {
// static
LRESULT CALLBACK MainWnd::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
MainWnd* me = reinterpret_cast<MainWnd*>(
::GetWindowLongPtr(hwnd, GWLP_USERDATA));
MainWnd* me =
reinterpret_cast<MainWnd*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (!me && WM_CREATE == msg) {
CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lp);
me = reinterpret_cast<MainWnd*>(cs->lpCreateParams);
@ -433,7 +445,7 @@ bool MainWnd::RegisterWindowClass() {
if (wnd_class_)
return true;
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
WNDCLASSEX wcex = {sizeof(WNDCLASSEX)};
wcex.style = CS_DBLCLKS;
wcex.hInstance = GetModuleHandle(NULL);
wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
@ -445,17 +457,18 @@ bool MainWnd::RegisterWindowClass() {
return wnd_class_ != 0;
}
void MainWnd::CreateChildWindow(HWND* wnd, MainWnd::ChildWindowID id,
const wchar_t* class_name, DWORD control_style,
void MainWnd::CreateChildWindow(HWND* wnd,
MainWnd::ChildWindowID id,
const wchar_t* class_name,
DWORD control_style,
DWORD ex_style) {
if (::IsWindow(*wnd))
return;
// Child windows are invisible at first, and shown after being resized.
DWORD style = WS_CHILD | control_style;
*wnd = ::CreateWindowEx(ex_style, class_name, L"", style,
100, 100, 100, 100, wnd_,
reinterpret_cast<HMENU>(id),
*wnd = ::CreateWindowEx(ex_style, class_name, L"", style, 100, 100, 100, 100,
wnd_, reinterpret_cast<HMENU>(id),
GetModuleHandle(NULL), NULL);
RTC_DCHECK(::IsWindow(*wnd) != FALSE);
::SendMessage(*wnd, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()),
@ -486,11 +499,9 @@ void MainWnd::LayoutConnectUI(bool show) {
size_t width;
size_t height;
} windows[] = {
{ label1_, L"Server" },
{ edit1_, L"XXXyyyYYYgggXXXyyyYYYggg" },
{ label2_, L":" },
{ edit2_, L"XyXyX" },
{ button_, L"Connect" },
{label1_, L"Server"}, {edit1_, L"XXXyyyYYYgggXXXyyyYYYggg"},
{label2_, L":"}, {edit2_, L"XyXyX"},
{button_, L"Connect"},
};
if (show) {
@ -511,8 +522,7 @@ void MainWnd::LayoutConnectUI(bool show) {
size_t top = y - (windows[i].height / 2);
::MoveWindow(windows[i].wnd, static_cast<int>(x), static_cast<int>(top),
static_cast<int>(windows[i].width),
static_cast<int>(windows[i].height),
TRUE);
static_cast<int>(windows[i].height), TRUE);
x += kSeparator + windows[i].width;
if (windows[i].text[0] != 'X')
::SetWindowText(windows[i].wnd, windows[i].text);
@ -566,7 +576,9 @@ void MainWnd::HandleTabbing() {
//
MainWnd::VideoRenderer::VideoRenderer(
HWND wnd, int width, int height,
HWND wnd,
int width,
int height,
webrtc::VideoTrackInterface* track_to_render)
: wnd_(wnd), rendered_track_(track_to_render) {
::InitializeCriticalSection(&buffer_lock_);
@ -577,8 +589,8 @@ MainWnd::VideoRenderer::VideoRenderer(
bmi_.bmiHeader.biCompression = BI_RGB;
bmi_.bmiHeader.biWidth = width;
bmi_.bmiHeader.biHeight = -height;
bmi_.bmiHeader.biSizeImage = width * height *
(bmi_.bmiHeader.biBitCount >> 3);
bmi_.bmiHeader.biSizeImage =
width * height * (bmi_.bmiHeader.biBitCount >> 3);
rendered_track_->AddOrUpdateSink(this, rtc::VideoSinkWants());
}
@ -596,14 +608,12 @@ void MainWnd::VideoRenderer::SetSize(int width, int height) {
bmi_.bmiHeader.biWidth = width;
bmi_.bmiHeader.biHeight = -height;
bmi_.bmiHeader.biSizeImage = width * height *
(bmi_.bmiHeader.biBitCount >> 3);
bmi_.bmiHeader.biSizeImage =
width * height * (bmi_.bmiHeader.biBitCount >> 3);
image_.reset(new uint8_t[bmi_.bmiHeader.biSizeImage]);
}
void MainWnd::VideoRenderer::OnFrame(
const webrtc::VideoFrame& video_frame) {
void MainWnd::VideoRenderer::OnFrame(const webrtc::VideoFrame& video_frame) {
{
AutoLock<VideoRenderer> lock(this);
@ -616,12 +626,10 @@ void MainWnd::VideoRenderer::OnFrame(
SetSize(buffer->width(), buffer->height());
RTC_DCHECK(image_.get() != NULL);
libyuv::I420ToARGB(buffer->DataY(), buffer->StrideY(),
buffer->DataU(), buffer->StrideU(),
buffer->DataV(), buffer->StrideV(),
libyuv::I420ToARGB(buffer->DataY(), buffer->StrideY(), buffer->DataU(),
buffer->StrideU(), buffer->DataV(), buffer->StrideV(),
image_.get(),
bmi_.bmiHeader.biWidth *
bmi_.bmiHeader.biBitCount / 8,
bmi_.bmiHeader.biWidth * bmi_.bmiHeader.biBitCount / 8,
buffer->width(), buffer->height());
}
InvalidateRect(wnd_, NULL, TRUE);

View File

@ -32,6 +32,7 @@ class MainWndCallback {
virtual void DisconnectFromCurrentPeer() = 0;
virtual void UIThreadCallback(int msg_id, void* data) = 0;
virtual void Close() = 0;
protected:
virtual ~MainWndCallback() {}
};
@ -50,7 +51,8 @@ class MainWindow {
virtual void RegisterObserver(MainWndCallback* callback) = 0;
virtual bool IsWindow() = 0;
virtual void MessageBox(const char* caption, const char* text,
virtual void MessageBox(const char* caption,
const char* text,
bool is_error) = 0;
virtual UI current_ui() = 0;
@ -90,8 +92,7 @@ class MainWnd : public MainWindow {
virtual void SwitchToConnectUI();
virtual void SwitchToPeerList(const Peers& peers);
virtual void SwitchToStreamingUI();
virtual void MessageBox(const char* caption, const char* text,
bool is_error);
virtual void MessageBox(const char* caption, const char* text, bool is_error);
virtual UI current_ui() { return ui_; }
virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
@ -105,17 +106,15 @@ class MainWnd : public MainWindow {
class VideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
public:
VideoRenderer(HWND wnd, int width, int height,
VideoRenderer(HWND wnd,
int width,
int height,
webrtc::VideoTrackInterface* track_to_render);
virtual ~VideoRenderer();
void Lock() {
::EnterCriticalSection(&buffer_lock_);
}
void Lock() { ::EnterCriticalSection(&buffer_lock_); }
void Unlock() {
::LeaveCriticalSection(&buffer_lock_);
}
void Unlock() { ::LeaveCriticalSection(&buffer_lock_); }
// VideoSinkInterface implementation
void OnFrame(const webrtc::VideoFrame& frame) override;
@ -145,6 +144,7 @@ class MainWnd : public MainWindow {
public:
explicit AutoLock(T* obj) : obj_(obj) { obj_->Lock(); }
~AutoLock() { obj_->Unlock(); }
protected:
T* obj_;
};
@ -168,8 +168,11 @@ class MainWnd : public MainWindow {
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
static bool RegisterWindowClass();
void CreateChildWindow(HWND* wnd, ChildWindowID id, const wchar_t* class_name,
DWORD control_style, DWORD ex_style);
void CreateChildWindow(HWND* wnd,
ChildWindowID id,
const wchar_t* class_name,
DWORD control_style,
DWORD ex_style);
void CreateChildWindows();
void LayoutConnectUI(bool show);

View File

@ -46,30 +46,23 @@ rtc::AsyncSocket* CreateClientSocket(int family) {
} // namespace
PeerConnectionClient::PeerConnectionClient()
: callback_(NULL),
resolver_(NULL),
state_(NOT_CONNECTED),
my_id_(-1) {
}
: callback_(NULL), resolver_(NULL), state_(NOT_CONNECTED), my_id_(-1) {}
PeerConnectionClient::~PeerConnectionClient() {
}
PeerConnectionClient::~PeerConnectionClient() {}
void PeerConnectionClient::InitSocketSignals() {
RTC_DCHECK(control_socket_.get() != NULL);
RTC_DCHECK(hanging_get_.get() != NULL);
control_socket_->SignalCloseEvent.connect(this,
&PeerConnectionClient::OnClose);
hanging_get_->SignalCloseEvent.connect(this,
&PeerConnectionClient::OnClose);
&PeerConnectionClient::OnClose);
hanging_get_->SignalCloseEvent.connect(this, &PeerConnectionClient::OnClose);
control_socket_->SignalConnectEvent.connect(this,
&PeerConnectionClient::OnConnect);
hanging_get_->SignalConnectEvent.connect(this,
&PeerConnectionClient::OnHangingGetConnect);
control_socket_->SignalReadEvent.connect(this,
&PeerConnectionClient::OnRead);
hanging_get_->SignalReadEvent.connect(this,
&PeerConnectionClient::OnHangingGetRead);
&PeerConnectionClient::OnConnect);
hanging_get_->SignalConnectEvent.connect(
this, &PeerConnectionClient::OnHangingGetConnect);
control_socket_->SignalReadEvent.connect(this, &PeerConnectionClient::OnRead);
hanging_get_->SignalReadEvent.connect(
this, &PeerConnectionClient::OnHangingGetRead);
}
int PeerConnectionClient::id() const {
@ -90,7 +83,8 @@ void PeerConnectionClient::RegisterObserver(
callback_ = callback;
}
void PeerConnectionClient::Connect(const std::string& server, int port,
void PeerConnectionClient::Connect(const std::string& server,
int port,
const std::string& client_name) {
RTC_DCHECK(!server.empty());
RTC_DCHECK(!client_name.empty());
@ -142,8 +136,8 @@ void PeerConnectionClient::DoConnect() {
hanging_get_.reset(CreateClientSocket(server_address_.ipaddr().family()));
InitSocketSignals();
char buffer[1024];
sprintfn(buffer, sizeof(buffer),
"GET /sign_in?%s HTTP/1.0\r\n\r\n", client_name_.c_str());
sprintfn(buffer, sizeof(buffer), "GET /sign_in?%s HTTP/1.0\r\n\r\n",
client_name_.c_str());
onconnect_data_ = buffer;
bool ret = ConnectControlSocket();
@ -165,11 +159,11 @@ bool PeerConnectionClient::SendToPeer(int peer_id, const std::string& message) {
char headers[1024];
sprintfn(headers, sizeof(headers),
"POST /message?peer_id=%i&to=%i HTTP/1.0\r\n"
"Content-Length: %i\r\n"
"Content-Type: text/plain\r\n"
"\r\n",
my_id_, peer_id, message.length());
"POST /message?peer_id=%i&to=%i HTTP/1.0\r\n"
"Content-Length: %i\r\n"
"Content-Type: text/plain\r\n"
"\r\n",
my_id_, peer_id, message.length());
onconnect_data_ = headers;
onconnect_data_ += message;
return ConnectControlSocket();
@ -197,7 +191,7 @@ bool PeerConnectionClient::SignOut() {
if (my_id_ != -1) {
char buffer[1024];
sprintfn(buffer, sizeof(buffer),
"GET /sign_out?peer_id=%i HTTP/1.0\r\n\r\n", my_id_);
"GET /sign_out?peer_id=%i HTTP/1.0\r\n\r\n", my_id_);
onconnect_data_ = buffer;
return ConnectControlSocket();
} else {
@ -243,8 +237,8 @@ void PeerConnectionClient::OnConnect(rtc::AsyncSocket* socket) {
void PeerConnectionClient::OnHangingGetConnect(rtc::AsyncSocket* socket) {
char buffer[1024];
sprintfn(buffer, sizeof(buffer),
"GET /wait?peer_id=%i HTTP/1.0\r\n\r\n", my_id_);
sprintfn(buffer, sizeof(buffer), "GET /wait?peer_id=%i HTTP/1.0\r\n\r\n",
my_id_);
int len = static_cast<int>(strlen(buffer));
int sent = socket->Send(buffer, len);
RTC_DCHECK(sent == len);
@ -273,7 +267,8 @@ bool PeerConnectionClient::GetHeaderValue(const std::string& data,
return false;
}
bool PeerConnectionClient::GetHeaderValue(const std::string& data, size_t eoh,
bool PeerConnectionClient::GetHeaderValue(const std::string& data,
size_t eoh,
const char* header_pattern,
std::string* value) {
RTC_DCHECK(value != NULL);
@ -331,8 +326,8 @@ void PeerConnectionClient::OnRead(rtc::AsyncSocket* socket) {
size_t content_length = 0;
if (ReadIntoBuffer(socket, &control_data_, &content_length)) {
size_t peer_id = 0, eoh = 0;
bool ok = ParseServerResponse(control_data_, content_length, &peer_id,
&eoh);
bool ok =
ParseServerResponse(control_data_, content_length, &peer_id, &eoh);
if (ok) {
if (my_id_ == -1) {
// First response. Let's store our server assigned ID.
@ -351,7 +346,8 @@ void PeerConnectionClient::OnRead(rtc::AsyncSocket* socket) {
std::string name;
bool connected;
if (ParseEntry(control_data_.substr(pos, eol - pos), &name, &id,
&connected) && id != my_id_) {
&connected) &&
id != my_id_) {
peers_[id] = name;
callback_->OnPeerConnected(id, name);
}
@ -383,8 +379,8 @@ void PeerConnectionClient::OnHangingGetRead(rtc::AsyncSocket* socket) {
size_t content_length = 0;
if (ReadIntoBuffer(socket, &notification_data_, &content_length)) {
size_t peer_id = 0, eoh = 0;
bool ok = ParseServerResponse(notification_data_, content_length,
&peer_id, &eoh);
bool ok =
ParseServerResponse(notification_data_, content_length, &peer_id, &eoh);
if (ok) {
// Store the position where the body begins.

View File

@ -56,7 +56,8 @@ class PeerConnectionClient : public sigslot::has_slots<>,
void RegisterObserver(PeerConnectionClientObserver* callback);
void Connect(const std::string& server, int port,
void Connect(const std::string& server,
int port,
const std::string& client_name);
bool SendToPeer(int peer_id, const std::string& message);
@ -78,14 +79,19 @@ class PeerConnectionClient : public sigslot::has_slots<>,
void OnMessageFromPeer(int peer_id, const std::string& message);
// Quick and dirty support for parsing HTTP header values.
bool GetHeaderValue(const std::string& data, size_t eoh,
const char* header_pattern, size_t* value);
bool GetHeaderValue(const std::string& data,
size_t eoh,
const char* header_pattern,
size_t* value);
bool GetHeaderValue(const std::string& data, size_t eoh,
const char* header_pattern, std::string* value);
bool GetHeaderValue(const std::string& data,
size_t eoh,
const char* header_pattern,
std::string* value);
// Returns true if the whole response has been read.
bool ReadIntoBuffer(rtc::AsyncSocket* socket, std::string* data,
bool ReadIntoBuffer(rtc::AsyncSocket* socket,
std::string* data,
size_t* content_length);
void OnRead(rtc::AsyncSocket* socket);
@ -93,13 +99,17 @@ class PeerConnectionClient : public sigslot::has_slots<>,
void OnHangingGetRead(rtc::AsyncSocket* socket);
// Parses a single line entry in the form "<name>,<id>,<connected>"
bool ParseEntry(const std::string& entry, std::string* name, int* id,
bool ParseEntry(const std::string& entry,
std::string* name,
int* id,
bool* connected);
int GetResponseStatus(const std::string& response);
bool ParseServerResponse(const std::string& response, size_t content_length,
size_t* peer_id, size_t* eoh);
bool ParseServerResponse(const std::string& response,
size_t content_length,
size_t* peer_id,
size_t* eoh);
void OnClose(rtc::AsyncSocket* socket, int err);

View File

@ -29,7 +29,7 @@ const char DataSocket::kCrossOriginAllowHeaders[] =
"Access-Control-Allow-Credentials: true\r\n"
"Access-Control-Allow-Methods: POST, GET, OPTIONS\r\n"
"Access-Control-Allow-Headers: Content-Type, "
"Content-Length, Connection, Cache-Control\r\n"
"Content-Length, Connection, Cache-Control\r\n"
"Access-Control-Expose-Headers: Content-Length, X-Peer-Id\r\n";
#if defined(WIN32)
@ -116,10 +116,11 @@ bool DataSocket::OnDataAvailable(bool* close_socket) {
bool DataSocket::Send(const std::string& data) const {
return send(socket_, data.data(), static_cast<int>(data.length()), 0) !=
SOCKET_ERROR;
SOCKET_ERROR;
}
bool DataSocket::Send(const std::string& status, bool connection_close,
bool DataSocket::Send(const std::string& status,
bool connection_close,
const std::string& content_type,
const std::string& extra_headers,
const std::string& data) const {
@ -127,8 +128,9 @@ bool DataSocket::Send(const std::string& status, bool connection_close,
assert(!status.empty());
std::string buffer("HTTP/1.1 " + status + "\r\n");
buffer += "Server: PeerConnectionTestServer/0.1\r\n"
"Cache-Control: no-cache\r\n";
buffer +=
"Server: PeerConnectionTestServer/0.1\r\n"
"Cache-Control: no-cache\r\n";
if (connection_close)
buffer += "Connection: close\r\n";
@ -136,8 +138,8 @@ bool DataSocket::Send(const std::string& status, bool connection_close,
if (!content_type.empty())
buffer += "Content-Type: " + content_type + "\r\n";
buffer += "Content-Length: " + int2str(static_cast<int>(data.size())) +
"\r\n";
buffer +=
"Content-Length: " + int2str(static_cast<int>(data.size())) + "\r\n";
if (!extra_headers.empty()) {
buffer += extra_headers;
@ -190,9 +192,7 @@ bool DataSocket::ParseMethodAndPath(const char* begin, size_t len) {
size_t method_name_len;
RequestMethod id;
} supported_methods[] = {
{ "GET", 3, GET },
{ "POST", 4, POST },
{ "OPTIONS", 7, OPTIONS },
{"GET", 3, GET}, {"POST", 4, POST}, {"OPTIONS", 7, OPTIONS},
};
const char* path = NULL;
@ -231,15 +231,15 @@ bool DataSocket::ParseContentLengthAndType(const char* headers, size_t length) {
static const char kContentLength[] = "Content-Length:";
static const char kContentType[] = "Content-Type:";
if ((headers + ARRAYSIZE(kContentLength)) < end &&
strncmp(headers, kContentLength,
ARRAYSIZE(kContentLength) - 1) == 0) {
strncmp(headers, kContentLength, ARRAYSIZE(kContentLength) - 1) ==
0) {
headers += ARRAYSIZE(kContentLength) - 1;
while (headers[0] == ' ')
++headers;
content_length_ = atoi(headers);
} else if ((headers + ARRAYSIZE(kContentType)) < end &&
strncmp(headers, kContentType,
ARRAYSIZE(kContentType) - 1) == 0) {
strncmp(headers, kContentType, ARRAYSIZE(kContentType) - 1) ==
0) {
headers += ARRAYSIZE(kContentType) - 1;
while (headers[0] == ' ')
++headers;
@ -267,13 +267,13 @@ bool ListeningSocket::Listen(unsigned short port) {
assert(valid());
int enabled = 1;
setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*>(&enabled), sizeof(enabled));
reinterpret_cast<const char*>(&enabled), sizeof(enabled));
struct sockaddr_in addr = {0};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(port);
if (bind(socket_, reinterpret_cast<const sockaddr*>(&addr),
sizeof(addr)) == SOCKET_ERROR) {
if (bind(socket_, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) ==
SOCKET_ERROR) {
printf("bind failed\n");
return false;
}

View File

@ -27,7 +27,7 @@ typedef int NativeSocket;
#endif
#ifndef INVALID_SOCKET
#define INVALID_SOCKET static_cast<NativeSocket>(-1)
#define INVALID_SOCKET static_cast<NativeSocket>(-1)
#endif
#endif
@ -35,8 +35,8 @@ typedef int NativeSocket;
class SocketBase {
public:
SocketBase() : socket_(INVALID_SOCKET) { }
explicit SocketBase(NativeSocket socket) : socket_(socket) { }
SocketBase() : socket_(INVALID_SOCKET) {}
explicit SocketBase(NativeSocket socket) : socket_(socket) {}
~SocketBase() { Close(); }
NativeSocket socket() const { return socket_; }
@ -60,13 +60,9 @@ class DataSocket : public SocketBase {
};
explicit DataSocket(NativeSocket socket)
: SocketBase(socket),
method_(INVALID),
content_length_(0) {
}
: SocketBase(socket), method_(INVALID), content_length_(0) {}
~DataSocket() {
}
~DataSocket() {}
static const char kCrossOriginAllowHeaders[];
@ -110,9 +106,11 @@ class DataSocket : public SocketBase {
// header terminates with "\r\n".
// |data| is the body of the message. It's length will be specified via
// a "Content-Length" header.
bool Send(const std::string& status, bool connection_close,
bool Send(const std::string& status,
bool connection_close,
const std::string& content_type,
const std::string& extra_headers, const std::string& data) const;
const std::string& extra_headers,
const std::string& data) const;
// Clears all held state and prepares the socket for receiving a new request.
void Clear();

View File

@ -94,7 +94,7 @@ int main(int argc, char* argv[]) {
for (SocketArray::iterator i = sockets.begin(); i != sockets.end(); ++i)
FD_SET((*i)->socket(), &socket_set);
struct timeval timeout = { 10, 0 };
struct timeval timeout = {10, 0};
if (select(FD_SETSIZE, &socket_set, NULL, NULL, &timeout) == SOCKET_ERROR) {
printf("select failed\n");
break;
@ -111,8 +111,7 @@ int main(int argc, char* argv[]) {
if (s->PathEquals("/sign_in")) {
clients.AddMember(s);
} else {
printf("No member found for: %s\n",
s->request_path().c_str());
printf("No member found for: %s\n", s->request_path().c_str());
s->Send("500 Error", true, "text/plain", "",
"Peer most likely gone.");
}
@ -127,7 +126,7 @@ int main(int argc, char* argv[]) {
s->Send("200 OK", true, "text/plain", "", "");
} else {
printf("Couldn't find target for request: %s\n",
s->request_path().c_str());
s->request_path().c_str());
s->Send("500 Error", true, "text/plain", "",
"Peer most likely gone.");
}

View File

@ -37,7 +37,7 @@ using rtc::sprintfn;
static const char kPeerIdHeader[] = "Pragma: ";
static const char* kRequestPaths[] = {
"/wait", "/sign_out", "/message",
"/wait", "/sign_out", "/message",
};
enum RequestPathIndex {
@ -55,8 +55,10 @@ const size_t kMaxNameLength = 512;
int ChannelMember::s_member_id_ = 0;
ChannelMember::ChannelMember(DataSocket* socket)
: waiting_socket_(NULL), id_(++s_member_id_),
connected_(true), timestamp_(time(NULL)) {
: waiting_socket_(NULL),
id_(++s_member_id_),
connected_(true),
timestamp_(time(NULL)) {
assert(socket);
assert(socket->method() == DataSocket::GET);
assert(socket->PathEquals("/sign_in"));
@ -69,8 +71,7 @@ ChannelMember::ChannelMember(DataSocket* socket)
std::replace(name_.begin(), name_.end(), ',', '_');
}
ChannelMember::~ChannelMember() {
}
ChannelMember::~ChannelMember() {}
bool ChannelMember::is_wait_request(DataSocket* ds) const {
return ds && ds->PathEquals(kRequestPaths[kWait]);
@ -87,8 +88,7 @@ std::string ChannelMember::GetPeerIdHeader() const {
bool ChannelMember::NotifyOfOtherMember(const ChannelMember& other) {
assert(&other != this);
QueueResponse("200 OK", "text/plain", GetPeerIdHeader(),
other.GetEntry());
QueueResponse("200 OK", "text/plain", GetPeerIdHeader(), other.GetEntry());
return true;
}
@ -110,11 +110,9 @@ void ChannelMember::ForwardRequestToPeer(DataSocket* ds, ChannelMember* peer) {
std::string extra_headers(GetPeerIdHeader());
if (peer == this) {
ds->Send("200 OK", true, ds->content_type(), extra_headers,
ds->data());
ds->Send("200 OK", true, ds->content_type(), extra_headers, ds->data());
} else {
printf("Client %s sending to %s\n",
name_.c_str(), peer->name().c_str());
printf("Client %s sending to %s\n", name_.c_str(), peer->name().c_str());
peer->QueueResponse("200 OK", ds->content_type(), extra_headers,
ds->data());
ds->Send("200 OK", true, "text/plain", "", "");
@ -135,8 +133,8 @@ void ChannelMember::QueueResponse(const std::string& status,
if (waiting_socket_) {
assert(queue_.size() == 0);
assert(waiting_socket_->method() == DataSocket::GET);
bool ok = waiting_socket_->Send(status, true, content_type, extra_headers,
data);
bool ok =
waiting_socket_->Send(status, true, content_type, extra_headers, data);
if (!ok) {
printf("Failed to deliver data to waiting socket\n");
}
@ -251,7 +249,7 @@ bool PeerChannel::AddMember(DataSocket* ds) {
members_.push_back(new_guy);
printf("New member added (total=%s): %s\n",
size_t2str(members_.size()).c_str(), new_guy->name().c_str());
size_t2str(members_.size()).c_str(), new_guy->name().c_str());
// Let the newly connected peer know about other members of the channel.
std::string content_type;

View File

@ -44,8 +44,10 @@ class ChannelMember {
void OnClosing(DataSocket* ds);
void QueueResponse(const std::string& status, const std::string& content_type,
const std::string& extra_headers, const std::string& data);
void QueueResponse(const std::string& status,
const std::string& content_type,
const std::string& extra_headers,
const std::string& data);
void SetWaitingSocket(DataSocket* ds);
@ -68,12 +70,9 @@ class PeerChannel {
public:
typedef std::vector<ChannelMember*> Members;
PeerChannel() {
}
PeerChannel() {}
~PeerChannel() {
DeleteAll();
}
~PeerChannel() { DeleteAll(); }
const Members& members() const { return members_; }