Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: webrtc/examples/peerconnection/client/linux/main_wnd.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 void OnRowActivatedCallback(GtkTreeView* tree_view, GtkTreePath* path, 54 void OnRowActivatedCallback(GtkTreeView* tree_view, GtkTreePath* path,
55 GtkTreeViewColumn* column, gpointer data) { 55 GtkTreeViewColumn* column, gpointer data) {
56 reinterpret_cast<GtkMainWnd*>(data)->OnRowActivated(tree_view, path, column); 56 reinterpret_cast<GtkMainWnd*>(data)->OnRowActivated(tree_view, path, column);
57 } 57 }
58 58
59 gboolean SimulateLastRowActivated(gpointer data) { 59 gboolean SimulateLastRowActivated(gpointer data) {
60 GtkTreeView* tree_view = reinterpret_cast<GtkTreeView*>(data); 60 GtkTreeView* tree_view = reinterpret_cast<GtkTreeView*>(data);
61 GtkTreeModel* model = gtk_tree_view_get_model(tree_view); 61 GtkTreeModel* model = gtk_tree_view_get_model(tree_view);
62 62
63 // "if iter is NULL, then the number of toplevel nodes is returned." 63 // "if iter is null, then the number of toplevel nodes is returned."
64 int rows = gtk_tree_model_iter_n_children(model, NULL); 64 int rows = gtk_tree_model_iter_n_children(model, nullptr);
65 GtkTreePath* lastpath = gtk_tree_path_new_from_indices(rows - 1, -1); 65 GtkTreePath* lastpath = gtk_tree_path_new_from_indices(rows - 1, -1);
66 66
67 // Select the last item in the list 67 // Select the last item in the list
68 GtkTreeSelection* selection = gtk_tree_view_get_selection(tree_view); 68 GtkTreeSelection* selection = gtk_tree_view_get_selection(tree_view);
69 gtk_tree_selection_select_path(selection, lastpath); 69 gtk_tree_selection_select_path(selection, lastpath);
70 70
71 // Our TreeView only has one column, so it is column 0. 71 // Our TreeView only has one column, so it is column 0.
72 GtkTreeViewColumn* column = gtk_tree_view_get_column(tree_view, 0); 72 GtkTreeViewColumn* column = gtk_tree_view_get_column(tree_view, 0);
73 73
74 gtk_tree_view_row_activated(tree_view, lastpath, column); 74 gtk_tree_view_row_activated(tree_view, lastpath, column);
75 75
76 gtk_tree_path_free(lastpath); 76 gtk_tree_path_free(lastpath);
77 return false; 77 return false;
78 } 78 }
79 79
80 // Creates a tree view, that we use to display the list of peers. 80 // Creates a tree view, that we use to display the list of peers.
81 void InitializeList(GtkWidget* list) { 81 void InitializeList(GtkWidget* list) {
82 GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); 82 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
83 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( 83 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
84 "List Items", renderer, "text", 0, NULL); 84 "List Items", renderer, "text", 0, nullptr);
85 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); 85 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
86 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); 86 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
87 gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store)); 87 gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store));
88 g_object_unref(store); 88 g_object_unref(store);
89 } 89 }
90 90
91 // Adds an entry to a tree view. 91 // Adds an entry to a tree view.
92 void AddToList(GtkWidget* list, const gchar* str, int value) { 92 void AddToList(GtkWidget* list, const gchar* str, int value) {
93 GtkListStore* store = GTK_LIST_STORE( 93 GtkListStore* store = GTK_LIST_STORE(
94 gtk_tree_view_get_model(GTK_TREE_VIEW(list))); 94 gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
(...skipping 29 matching lines...) Expand all
124 wnd->Draw(widget, cr); 124 wnd->Draw(widget, cr);
125 return false; 125 return false;
126 } 126 }
127 127
128 } // namespace 128 } // namespace
129 129
130 // 130 //
131 // GtkMainWnd implementation. 131 // GtkMainWnd implementation.
132 // 132 //
133 133
134 GtkMainWnd::GtkMainWnd(const char* server, int port, bool autoconnect, 134 GtkMainWnd::GtkMainWnd(const char* server,
135 int port,
136 bool autoconnect,
135 bool autocall) 137 bool autocall)
136 : window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL), 138 : window_(nullptr),
137 port_edit_(NULL), peer_list_(NULL), callback_(NULL), 139 draw_area_(nullptr),
138 server_(server), autoconnect_(autoconnect), autocall_(autocall) { 140 vbox_(nullptr),
141 server_edit_(nullptr),
142 port_edit_(nullptr),
143 peer_list_(nullptr),
144 callback_(nullptr),
145 server_(server),
146 autoconnect_(autoconnect),
147 autocall_(autocall) {
139 char buffer[10]; 148 char buffer[10];
140 sprintfn(buffer, sizeof(buffer), "%i", port); 149 sprintfn(buffer, sizeof(buffer), "%i", port);
141 port_ = buffer; 150 port_ = buffer;
142 } 151 }
143 152
144 GtkMainWnd::~GtkMainWnd() { 153 GtkMainWnd::~GtkMainWnd() {
145 RTC_DCHECK(!IsWindow()); 154 RTC_DCHECK(!IsWindow());
146 } 155 }
147 156
148 void GtkMainWnd::RegisterObserver(MainWndCallback* callback) { 157 void GtkMainWnd::RegisterObserver(MainWndCallback* callback) {
149 callback_ = callback; 158 callback_ = callback;
150 } 159 }
151 160
152 bool GtkMainWnd::IsWindow() { 161 bool GtkMainWnd::IsWindow() {
153 return window_ != NULL && GTK_IS_WINDOW(window_); 162 return window_ != nullptr && GTK_IS_WINDOW(window_);
154 } 163 }
155 164
156 void GtkMainWnd::MessageBox(const char* caption, const char* text, 165 void GtkMainWnd::MessageBox(const char* caption, const char* text,
157 bool is_error) { 166 bool is_error) {
158 GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(window_), 167 GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(window_),
159 GTK_DIALOG_DESTROY_WITH_PARENT, 168 GTK_DIALOG_DESTROY_WITH_PARENT,
160 is_error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, 169 is_error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO,
161 GTK_BUTTONS_CLOSE, "%s", text); 170 GTK_BUTTONS_CLOSE, "%s", text);
162 gtk_window_set_title(GTK_WINDOW(dialog), caption); 171 gtk_window_set_title(GTK_WINDOW(dialog), caption);
163 gtk_dialog_run(GTK_DIALOG(dialog)); 172 gtk_dialog_run(GTK_DIALOG(dialog));
(...skipping 27 matching lines...) Expand all
191 void GtkMainWnd::StopRemoteRenderer() { 200 void GtkMainWnd::StopRemoteRenderer() {
192 remote_renderer_.reset(); 201 remote_renderer_.reset();
193 } 202 }
194 203
195 void GtkMainWnd::QueueUIThreadCallback(int msg_id, void* data) { 204 void GtkMainWnd::QueueUIThreadCallback(int msg_id, void* data) {
196 g_idle_add(HandleUIThreadCallback, 205 g_idle_add(HandleUIThreadCallback,
197 new UIThreadCallbackData(callback_, msg_id, data)); 206 new UIThreadCallbackData(callback_, msg_id, data));
198 } 207 }
199 208
200 bool GtkMainWnd::Create() { 209 bool GtkMainWnd::Create() {
201 RTC_DCHECK(window_ == NULL); 210 RTC_DCHECK(window_ == nullptr);
202 211
203 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); 212 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
204 if (window_) { 213 if (window_) {
205 gtk_window_set_position(GTK_WINDOW(window_), GTK_WIN_POS_CENTER); 214 gtk_window_set_position(GTK_WINDOW(window_), GTK_WIN_POS_CENTER);
206 gtk_window_set_default_size(GTK_WINDOW(window_), 640, 480); 215 gtk_window_set_default_size(GTK_WINDOW(window_), 640, 480);
207 gtk_window_set_title(GTK_WINDOW(window_), "PeerConnection client"); 216 gtk_window_set_title(GTK_WINDOW(window_), "PeerConnection client");
208 g_signal_connect(G_OBJECT(window_), "delete-event", 217 g_signal_connect(G_OBJECT(window_), "delete-event",
209 G_CALLBACK(&OnDestroyedCallback), this); 218 G_CALLBACK(&OnDestroyedCallback), this);
210 g_signal_connect(window_, "key-press-event", G_CALLBACK(OnKeyPressCallback), 219 g_signal_connect(window_, "key-press-event", G_CALLBACK(OnKeyPressCallback),
211 this); 220 this);
212 221
213 SwitchToConnectUI(); 222 SwitchToConnectUI();
214 } 223 }
215 224
216 return window_ != NULL; 225 return window_ != nullptr;
217 } 226 }
218 227
219 bool GtkMainWnd::Destroy() { 228 bool GtkMainWnd::Destroy() {
220 if (!IsWindow()) 229 if (!IsWindow())
221 return false; 230 return false;
222 231
223 gtk_widget_destroy(window_); 232 gtk_widget_destroy(window_);
224 window_ = NULL; 233 window_ = nullptr;
225 234
226 return true; 235 return true;
227 } 236 }
228 237
229 void GtkMainWnd::SwitchToConnectUI() { 238 void GtkMainWnd::SwitchToConnectUI() {
230 LOG(INFO) << __FUNCTION__; 239 LOG(INFO) << __FUNCTION__;
231 240
232 RTC_DCHECK(IsWindow()); 241 RTC_DCHECK(IsWindow());
233 RTC_DCHECK(vbox_ == NULL); 242 RTC_DCHECK(vbox_ == nullptr);
234 243
235 gtk_container_set_border_width(GTK_CONTAINER(window_), 10); 244 gtk_container_set_border_width(GTK_CONTAINER(window_), 10);
236 245
237 if (peer_list_) { 246 if (peer_list_) {
238 gtk_widget_destroy(peer_list_); 247 gtk_widget_destroy(peer_list_);
239 peer_list_ = NULL; 248 peer_list_ = nullptr;
240 } 249 }
241 250
242 #if GTK_MAJOR_VERSION == 2 251 #if GTK_MAJOR_VERSION == 2
243 vbox_ = gtk_vbox_new(FALSE, 5); 252 vbox_ = gtk_vbox_new(FALSE, 5);
244 #else 253 #else
245 vbox_ = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 254 vbox_ = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
246 #endif 255 #endif
247 GtkWidget* valign = gtk_alignment_new(0, 1, 0, 0); 256 GtkWidget* valign = gtk_alignment_new(0, 1, 0, 0);
248 gtk_container_add(GTK_CONTAINER(vbox_), valign); 257 gtk_container_add(GTK_CONTAINER(vbox_), valign);
249 gtk_container_add(GTK_CONTAINER(window_), vbox_); 258 gtk_container_add(GTK_CONTAINER(window_), vbox_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 g_idle_add(SimulateButtonClick, button); 291 g_idle_add(SimulateButtonClick, button);
283 } 292 }
284 293
285 void GtkMainWnd::SwitchToPeerList(const Peers& peers) { 294 void GtkMainWnd::SwitchToPeerList(const Peers& peers) {
286 LOG(INFO) << __FUNCTION__; 295 LOG(INFO) << __FUNCTION__;
287 296
288 if (!peer_list_) { 297 if (!peer_list_) {
289 gtk_container_set_border_width(GTK_CONTAINER(window_), 0); 298 gtk_container_set_border_width(GTK_CONTAINER(window_), 0);
290 if (vbox_) { 299 if (vbox_) {
291 gtk_widget_destroy(vbox_); 300 gtk_widget_destroy(vbox_);
292 vbox_ = NULL; 301 vbox_ = nullptr;
293 server_edit_ = NULL; 302 server_edit_ = nullptr;
294 port_edit_ = NULL; 303 port_edit_ = nullptr;
295 } else if (draw_area_) { 304 } else if (draw_area_) {
296 gtk_widget_destroy(draw_area_); 305 gtk_widget_destroy(draw_area_);
297 draw_area_ = NULL; 306 draw_area_ = nullptr;
298 draw_buffer_.reset(); 307 draw_buffer_.reset();
299 } 308 }
300 309
301 peer_list_ = gtk_tree_view_new(); 310 peer_list_ = gtk_tree_view_new();
302 g_signal_connect(peer_list_, "row-activated", 311 g_signal_connect(peer_list_, "row-activated",
303 G_CALLBACK(OnRowActivatedCallback), this); 312 G_CALLBACK(OnRowActivatedCallback), this);
304 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(peer_list_), FALSE); 313 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(peer_list_), FALSE);
305 InitializeList(peer_list_); 314 InitializeList(peer_list_);
306 gtk_container_add(GTK_CONTAINER(window_), peer_list_); 315 gtk_container_add(GTK_CONTAINER(window_), peer_list_);
307 gtk_widget_show_all(window_); 316 gtk_widget_show_all(window_);
308 } else { 317 } else {
309 GtkListStore* store = 318 GtkListStore* store =
310 GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(peer_list_))); 319 GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(peer_list_)));
311 gtk_list_store_clear(store); 320 gtk_list_store_clear(store);
312 } 321 }
313 322
314 AddToList(peer_list_, "List of currently connected peers:", -1); 323 AddToList(peer_list_, "List of currently connected peers:", -1);
315 for (Peers::const_iterator i = peers.begin(); i != peers.end(); ++i) 324 for (Peers::const_iterator i = peers.begin(); i != peers.end(); ++i)
316 AddToList(peer_list_, i->second.c_str(), i->first); 325 AddToList(peer_list_, i->second.c_str(), i->first);
317 326
318 if (autocall_ && peers.begin() != peers.end()) 327 if (autocall_ && peers.begin() != peers.end())
319 g_idle_add(SimulateLastRowActivated, peer_list_); 328 g_idle_add(SimulateLastRowActivated, peer_list_);
320 } 329 }
321 330
322 void GtkMainWnd::SwitchToStreamingUI() { 331 void GtkMainWnd::SwitchToStreamingUI() {
323 LOG(INFO) << __FUNCTION__; 332 LOG(INFO) << __FUNCTION__;
324 333
325 RTC_DCHECK(draw_area_ == NULL); 334 RTC_DCHECK(draw_area_ == nullptr);
326 335
327 gtk_container_set_border_width(GTK_CONTAINER(window_), 0); 336 gtk_container_set_border_width(GTK_CONTAINER(window_), 0);
328 if (peer_list_) { 337 if (peer_list_) {
329 gtk_widget_destroy(peer_list_); 338 gtk_widget_destroy(peer_list_);
330 peer_list_ = NULL; 339 peer_list_ = nullptr;
331 } 340 }
332 341
333 draw_area_ = gtk_drawing_area_new(); 342 draw_area_ = gtk_drawing_area_new();
334 gtk_container_add(GTK_CONTAINER(window_), draw_area_); 343 gtk_container_add(GTK_CONTAINER(window_), draw_area_);
335 g_signal_connect(G_OBJECT(draw_area_), "draw", G_CALLBACK(&::Draw), this); 344 g_signal_connect(G_OBJECT(draw_area_), "draw", G_CALLBACK(&::Draw), this);
336 345
337 gtk_widget_show_all(window_); 346 gtk_widget_show_all(window_);
338 } 347 }
339 348
340 void GtkMainWnd::OnDestroyed(GtkWidget* widget, GdkEvent* event) { 349 void GtkMainWnd::OnDestroyed(GtkWidget* widget, GdkEvent* event) {
341 callback_->Close(); 350 callback_->Close();
342 window_ = NULL; 351 window_ = nullptr;
343 draw_area_ = NULL; 352 draw_area_ = nullptr;
344 vbox_ = NULL; 353 vbox_ = nullptr;
345 server_edit_ = NULL; 354 server_edit_ = nullptr;
346 port_edit_ = NULL; 355 port_edit_ = nullptr;
347 peer_list_ = NULL; 356 peer_list_ = nullptr;
348 } 357 }
349 358
350 void GtkMainWnd::OnClicked(GtkWidget* widget) { 359 void GtkMainWnd::OnClicked(GtkWidget* widget) {
351 // Make the connect button insensitive, so that it cannot be clicked more than 360 // Make the connect button insensitive, so that it cannot be clicked more than
352 // once. Now that the connection includes auto-retry, it should not be 361 // once. Now that the connection includes auto-retry, it should not be
353 // necessary to click it more than once. 362 // necessary to click it more than once.
354 gtk_widget_set_sensitive(widget, false); 363 gtk_widget_set_sensitive(widget, false);
355 server_ = gtk_entry_get_text(GTK_ENTRY(server_edit_)); 364 server_ = gtk_entry_get_text(GTK_ENTRY(server_edit_));
356 port_ = gtk_entry_get_text(GTK_ENTRY(port_edit_)); 365 port_ = gtk_entry_get_text(GTK_ENTRY(port_edit_));
357 int port = port_.length() ? atoi(port_.c_str()) : 0; 366 int port = port_.length() ? atoi(port_.c_str()) : 0;
(...skipping 16 matching lines...) Expand all
374 break; 383 break;
375 384
376 #if GTK_MAJOR_VERSION == 2 385 #if GTK_MAJOR_VERSION == 2
377 case GDK_KP_Enter: 386 case GDK_KP_Enter:
378 case GDK_Return: 387 case GDK_Return:
379 #else 388 #else
380 case GDK_KEY_KP_Enter: 389 case GDK_KEY_KP_Enter:
381 case GDK_KEY_Return: 390 case GDK_KEY_Return:
382 #endif 391 #endif
383 if (vbox_) { 392 if (vbox_) {
384 OnClicked(NULL); 393 OnClicked(nullptr);
385 } else if (peer_list_) { 394 } else if (peer_list_) {
386 // OnRowActivated will be called automatically when the user 395 // OnRowActivated will be called automatically when the user
387 // presses enter. 396 // presses enter.
388 } 397 }
389 break; 398 break;
390 399
391 default: 400 default:
392 break; 401 break;
393 } 402 }
394 } 403 }
395 } 404 }
396 405
397 void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, 406 void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
398 GtkTreeViewColumn* column) { 407 GtkTreeViewColumn* column) {
399 RTC_DCHECK(peer_list_ != NULL); 408 RTC_DCHECK(peer_list_ != nullptr);
400 GtkTreeIter iter; 409 GtkTreeIter iter;
401 GtkTreeModel* model; 410 GtkTreeModel* model;
402 GtkTreeSelection* selection = 411 GtkTreeSelection* selection =
403 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); 412 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
404 if (gtk_tree_selection_get_selected(selection, &model, &iter)) { 413 if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
405 char* text; 414 char* text;
406 int id = -1; 415 int id = -1;
407 gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1); 416 gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1);
408 if (id != -1) 417 if (id != -1)
409 callback_->ConnectToPeer(id); 418 callback_->ConnectToPeer(id);
410 g_free(text); 419 g_free(text);
411 } 420 }
412 } 421 }
413 422
414 void GtkMainWnd::OnRedraw() { 423 void GtkMainWnd::OnRedraw() {
415 gdk_threads_enter(); 424 gdk_threads_enter();
416 425
417 VideoRenderer* remote_renderer = remote_renderer_.get(); 426 VideoRenderer* remote_renderer = remote_renderer_.get();
418 if (remote_renderer && remote_renderer->image() != NULL && 427 if (remote_renderer && remote_renderer->image() != nullptr &&
419 draw_area_ != NULL) { 428 draw_area_ != nullptr) {
420 width_ = remote_renderer->width(); 429 width_ = remote_renderer->width();
421 height_ = remote_renderer->height(); 430 height_ = remote_renderer->height();
422 431
423 if (!draw_buffer_.get()) { 432 if (!draw_buffer_.get()) {
424 draw_buffer_size_ = (width_ * height_ * 4) * 4; 433 draw_buffer_size_ = (width_ * height_ * 4) * 4;
425 draw_buffer_.reset(new uint8_t[draw_buffer_size_]); 434 draw_buffer_.reset(new uint8_t[draw_buffer_size_]);
426 gtk_widget_set_size_request(draw_area_, width_ * 2, height_ * 2); 435 gtk_widget_set_size_request(draw_area_, width_ * 2, height_ * 2);
427 } 436 }
428 437
429 const uint32_t* image = 438 const uint32_t* image =
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 libyuv::I420ToABGR(buffer->DataY(), buffer->StrideY(), 548 libyuv::I420ToABGR(buffer->DataY(), buffer->StrideY(),
540 buffer->DataU(), buffer->StrideU(), 549 buffer->DataU(), buffer->StrideU(),
541 buffer->DataV(), buffer->StrideV(), 550 buffer->DataV(), buffer->StrideV(),
542 image_.get(), width_ * 4, 551 image_.get(), width_ * 4,
543 buffer->width(), buffer->height()); 552 buffer->width(), buffer->height());
544 553
545 gdk_threads_leave(); 554 gdk_threads_leave();
546 555
547 g_idle_add(Redraw, main_wnd_); 556 g_idle_add(Redraw, main_wnd_);
548 } 557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698