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

Unified Diff: cloud_print/gcp20/prototype/conio_posix.cc

Issue 19468002: Added confirmation for printer registration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-api-availability-check
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: cloud_print/gcp20/prototype/conio_posix.cc
diff --git a/cloud_print/gcp20/prototype/conio_posix.cc b/cloud_print/gcp20/prototype/conio_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..de5d99fe2a1b7d3301aa8145287186c06939af14
--- /dev/null
+++ b/cloud_print/gcp20/prototype/conio_posix.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cloud_print/gcp20/prototype/conio_posix.h"
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <termios.h>
+#include <unistd.h>
+
+void SetTemporaryTermiosSettings(bool temporary) {
+ static termios oldt, newt;
+
+ if (temporary) {
+ tcgetattr(STDIN_FILENO, &oldt);
+ newt = oldt;
+ newt.c_lflag &= ~ICANON; // Disable buffered IO.
+ tcsetattr(STDIN_FILENO, TCSANOW, &newt);
+ } else {
+ tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // Restore default settings.
+ }
+}
+
+int kbhit() {
+ SetTemporaryTermiosSettings(true);
+
+ timeval tv;
+ fd_set rdfs;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&rdfs);
+ FD_SET(STDIN_FILENO, &rdfs);
+ select(STDIN_FILENO + 1, &rdfs, NULL, NULL, &tv);
+ SetTemporaryTermiosSettings(false);
+
+ return FD_ISSET(STDIN_FILENO, &rdfs);
+}
+
+int getche() {
+ SetTemporaryTermiosSettings(true);
+ int c = getchar();
+ SetTemporaryTermiosSettings(false);
+ return c;
+}
+

Powered by Google App Engine
This is Rietveld 408576698