Prefix LOG and CHECK with AOS_

This prepares us for introducing glog more widely and transitioning
things over where they make sense.

Change-Id: Ic6c208882407bc2153fe875ffc736d66f5c8ade5
diff --git a/aos/vision/blob/threshold.cc b/aos/vision/blob/threshold.cc
index 46221b5..047d8db 100644
--- a/aos/vision/blob/threshold.cc
+++ b/aos/vision/blob/threshold.cc
@@ -14,7 +14,7 @@
 // it operates in kChunkSize-pixel chunks.
 RangeImage FastYuyvYThreshold(ImageFormat fmt, const char *data,
                               uint8_t value) {
-  CHECK_EQ(0, fmt.w % kChunkSize);
+  AOS_CHECK_EQ(0, fmt.w % kChunkSize);
   std::vector<std::vector<ImageRange>> result;
   result.reserve(fmt.h);
 
@@ -107,7 +107,7 @@
     }
 
     ImageFormat shard_format = input_format_;
-    CHECK_EQ(shard_format.h % kThreads, 0);
+    AOS_CHECK_EQ(shard_format.h % kThreads, 0);
     shard_format.h /= kThreads;
 
     outputs_[i] = FastYuyvYThreshold(
diff --git a/aos/vision/events/epoll_events.cc b/aos/vision/events/epoll_events.cc
index f6cba76..651579a 100644
--- a/aos/vision/events/epoll_events.cc
+++ b/aos/vision/events/epoll_events.cc
@@ -14,29 +14,29 @@
 
 void EpollEvent::DirectEvent(uint32_t events) {
   if ((events & ~(EPOLLIN | EPOLLPRI | EPOLLERR)) != 0) {
-    LOG(FATAL, "unexpected epoll events set in %x on %d\n", events, fd());
+    AOS_LOG(FATAL, "unexpected epoll events set in %x on %d\n", events, fd());
   }
   ReadEvent();
 }
 
 void EpollEvent::SetEvents(uint32_t events) {
   events_ |= events;
-  CHECK(!loop_);
+  AOS_CHECK(!loop_);
 }
 
-EpollLoop::EpollLoop() : epoll_fd_(PCHECK(epoll_create1(0))) {}
+EpollLoop::EpollLoop() : epoll_fd_(AOS_PCHECK(epoll_create1(0))) {}
 
 void EpollLoop::Add(EpollEvent *event) {
   event->loop_ = this;
   struct epoll_event temp_event;
   temp_event.data.ptr = static_cast<void *>(event);
   temp_event.events = event->events();
-  PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_ADD, event->fd(), &temp_event));
+  AOS_PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_ADD, event->fd(), &temp_event));
 }
 
 void EpollLoop::Delete(EpollEvent *event) {
   event->loop_ = nullptr;
-  PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_DEL, event->fd(), NULL));
+  AOS_PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_DEL, event->fd(), NULL));
 }
 
 void EpollLoop::Run() {
@@ -45,7 +45,7 @@
     static constexpr size_t kNumberOfEvents = 64;
     epoll_event events[kNumberOfEvents];
     const int number_events =
-        PCHECK(epoll_wait(epoll_fd(), events, kNumberOfEvents, timeout));
+        AOS_PCHECK(epoll_wait(epoll_fd(), events, kNumberOfEvents, timeout));
 
     for (int i = 0; i < number_events; i++) {
       static_cast<EpollEvent *>(events[i].data.ptr)->DirectEvent(events[i].events);
diff --git a/aos/vision/events/gtk_event.cc b/aos/vision/events/gtk_event.cc
index 4ff9fde..d1f60a1 100644
--- a/aos/vision/events/gtk_event.cc
+++ b/aos/vision/events/gtk_event.cc
@@ -27,8 +27,8 @@
       for (int i = 0; i < number_events; i++) {
         EpollEvent *event = static_cast<EpollEvent *>(events[i].data.ptr);
         if ((events[i].events & ~(EPOLLIN | EPOLLPRI)) != 0) {
-          LOG(FATAL, "unexpected epoll events set in %x on %d\n",
-              events[i].events, event->fd());
+          AOS_LOG(FATAL, "unexpected epoll events set in %x on %d\n",
+                  events[i].events, event->fd());
         }
         event->ReadEvent();
       }
diff --git a/aos/vision/events/tcp_client.cc b/aos/vision/events/tcp_client.cc
index 8e197ec..94fa3d2 100644
--- a/aos/vision/events/tcp_client.cc
+++ b/aos/vision/events/tcp_client.cc
@@ -22,10 +22,10 @@
 int MakeSocketNonBlocking(int sfd) {
   int flags;
 
-  PCHECK(flags = fcntl(sfd, F_GETFL, 0));
+  AOS_PCHECK(flags = fcntl(sfd, F_GETFL, 0));
 
   flags |= O_NONBLOCK;
-  PCHECK(fcntl(sfd, F_SETFL, flags));
+  AOS_PCHECK(fcntl(sfd, F_SETFL, flags));
 
   return 0;
 }
@@ -35,7 +35,7 @@
   struct sockaddr_in serveraddr;
   struct hostent *server;
   /* socket: create the socket */
-  PCHECK(sockfd = socket(AF_INET, SOCK_STREAM, 0));
+  AOS_PCHECK(sockfd = socket(AF_INET, SOCK_STREAM, 0));
 
   /* gethostbyname: get the server's DNS entry */
   server = gethostbyname(hostname.c_str());
@@ -52,9 +52,9 @@
   serveraddr.sin_port = htons(portno);
 
   /* connect: create a connection with the server */
-  PCHECK(connect(sockfd, (const struct sockaddr *)&serveraddr,
-                 sizeof(serveraddr)));
-  PCHECK(MakeSocketNonBlocking(sockfd));
+  AOS_PCHECK(connect(sockfd, (const struct sockaddr *)&serveraddr,
+                     sizeof(serveraddr)));
+  AOS_PCHECK(MakeSocketNonBlocking(sockfd));
 
   return sockfd;
 }
diff --git a/aos/vision/events/tcp_server.cc b/aos/vision/events/tcp_server.cc
index 0fd7225..535c6b4 100644
--- a/aos/vision/events/tcp_server.cc
+++ b/aos/vision/events/tcp_server.cc
@@ -23,10 +23,10 @@
 int MakeSocketNonBlocking(int sfd) {
   int flags;
 
-  PCHECK(flags = fcntl(sfd, F_GETFL, 0));
+  AOS_PCHECK(flags = fcntl(sfd, F_GETFL, 0));
 
   flags |= O_NONBLOCK;
-  PCHECK(fcntl(sfd, F_SETFL, flags));
+  AOS_PCHECK(fcntl(sfd, F_SETFL, flags));
 
   return 0;
 }
@@ -41,7 +41,7 @@
   /*
    * socket: create the parent socket
    */
-  PCHECK(parentfd = socket(AF_INET, SOCK_STREAM, 0));
+  AOS_PCHECK(parentfd = socket(AF_INET, SOCK_STREAM, 0));
 
   /* setsockopt: Handy debugging trick that lets
    * us rerun the server immediately after we kill it;
@@ -49,8 +49,8 @@
    * Eliminates "ERROR on binding: Address already in use" error.
    */
   optval = 1;
-  PCHECK(setsockopt(parentfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval,
-                    sizeof(int)));
+  AOS_PCHECK(setsockopt(parentfd, SOL_SOCKET, SO_REUSEADDR,
+                        (const void *)&optval, sizeof(int)));
 
   /*
    * build the server's Internet address
@@ -69,11 +69,12 @@
   /*
    * bind: associate the parent socket with a port
    */
-  PCHECK(bind(parentfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)));
+  AOS_PCHECK(
+      bind(parentfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)));
 
-  PCHECK(listen(parentfd, SOMAXCONN));
+  AOS_PCHECK(listen(parentfd, SOMAXCONN));
 
-  LOG(INFO, "connected to port: %d on fd: %d\n", portno, parentfd);
+  AOS_LOG(INFO, "connected to port: %d on fd: %d\n", portno, parentfd);
   return parentfd;
 }
 
@@ -94,14 +95,14 @@
          connections. */
       return;
     } else {
-      PLOG(WARNING, "accept");
+      AOS_PLOG(WARNING, "accept");
       return;
     }
   }
 
   /* Make the incoming socket non-blocking and add it to the
      list of fds to monitor. */
-  PCHECK(MakeSocketNonBlocking(infd));
+  AOS_PCHECK(MakeSocketNonBlocking(infd));
 
   loop()->Add(Construct(infd));
 }
diff --git a/aos/vision/events/udp.cc b/aos/vision/events/udp.cc
index ed39db9..8734443 100644
--- a/aos/vision/events/udp.cc
+++ b/aos/vision/events/udp.cc
@@ -8,17 +8,17 @@
 namespace events {
 
 TXUdpSocket::TXUdpSocket(const std::string &ip_addr, int port)
-    : fd_(PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))) {
+    : fd_(AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))) {
   sockaddr_in destination_in;
   memset(&destination_in, 0, sizeof(destination_in));
   destination_in.sin_family = AF_INET;
   destination_in.sin_port = htons(port);
   if (inet_aton(ip_addr.c_str(), &destination_in.sin_addr) == 0) {
-    LOG(FATAL, "invalid IP address %s\n", ip_addr.c_str());
+    AOS_LOG(FATAL, "invalid IP address %s\n", ip_addr.c_str());
   }
 
-  PCHECK(connect(fd_.get(), reinterpret_cast<sockaddr *>(&destination_in),
-                 sizeof(destination_in)));
+  AOS_PCHECK(connect(fd_.get(), reinterpret_cast<sockaddr *>(&destination_in),
+                     sizeof(destination_in)));
 }
 
 int TXUdpSocket::Send(const char *data, int size) {
@@ -27,7 +27,7 @@
 }
 
 int RXUdpSocket::SocketBindListenOnPort(int port) {
-  int fd = PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP));
+  int fd = AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP));
   sockaddr_in bind_address;
   memset(&bind_address, 0, sizeof(bind_address));
 
@@ -35,15 +35,15 @@
   bind_address.sin_port = htons(port);
   bind_address.sin_addr.s_addr = htonl(INADDR_ANY);
 
-  PCHECK(bind(fd, reinterpret_cast<sockaddr *>(&bind_address),
-              sizeof(bind_address)));
+  AOS_PCHECK(bind(fd, reinterpret_cast<sockaddr *>(&bind_address),
+                  sizeof(bind_address)));
   return fd;
 }
 
 RXUdpSocket::RXUdpSocket(int port) : fd_(SocketBindListenOnPort(port)) {}
 
 int RXUdpSocket::Recv(void *data, int size) {
-  return PCHECK(recv(fd_.get(), static_cast<char *>(data), size, 0));
+  return AOS_PCHECK(recv(fd_.get(), static_cast<char *>(data), size, 0));
 }
 
 }  // namespace events
diff --git a/aos/vision/image/image_stream.cc b/aos/vision/image/image_stream.cc
index 1dba674..62f5e81 100644
--- a/aos/vision/image/image_stream.cc
+++ b/aos/vision/image/image_stream.cc
@@ -8,7 +8,7 @@
 void ImageStreamEvent::ProcessHelper(
     DataRef data, aos::monotonic_clock::time_point timestamp) {
   if (data.size() < 300) {
-    LOG(INFO, "got bad img of size(%d)\n", static_cast<int>(data.size()));
+    AOS_LOG(INFO, "got bad img of size(%d)\n", static_cast<int>(data.size()));
     return;
   }
   ProcessImage(data, timestamp);
diff --git a/aos/vision/image/jpeg_routines.cc b/aos/vision/image/jpeg_routines.cc
index 237daff..507fb3b 100644
--- a/aos/vision/image/jpeg_routines.cc
+++ b/aos/vision/image/jpeg_routines.cc
@@ -66,7 +66,7 @@
   int nsymbols = 0;
   for (int len = 1; len <= 16; len++) nsymbols += bits[len];
   if (nsymbols < 1 || nsymbols > 256) {
-    LOG(FATAL, "%s:%d: Error, bad huffman table", __FILE__, __LINE__);
+    AOS_LOG(FATAL, "%s:%d: Error, bad huffman table", __FILE__, __LINE__);
   }
 
   memcpy((*htblptr)->huffval, val, nsymbols * sizeof(uint8_t));
diff --git a/aos/vision/image/reader.cc b/aos/vision/image/reader.cc
index 991339b..7584369 100644
--- a/aos/vision/image/reader.cc
+++ b/aos/vision/image/reader.cc
@@ -42,15 +42,15 @@
     : dev_name_(dev_name), process_(std::move(process)), params_(params) {
   struct stat st;
   if (stat(dev_name.c_str(), &st) == -1) {
-    PLOG(FATAL, "Cannot identify '%s'", dev_name.c_str());
+    AOS_PLOG(FATAL, "Cannot identify '%s'", dev_name.c_str());
   }
   if (!S_ISCHR(st.st_mode)) {
-    PLOG(FATAL, "%s is no device\n", dev_name.c_str());
+    AOS_PLOG(FATAL, "%s is no device\n", dev_name.c_str());
   }
 
   fd_ = open(dev_name.c_str(), O_RDWR /* required */ | O_NONBLOCK, 0);
   if (fd_ == -1) {
-    PLOG(FATAL, "Cannot open '%s'", dev_name.c_str());
+    AOS_PLOG(FATAL, "Cannot open '%s'", dev_name.c_str());
   }
 
   Init();
@@ -58,17 +58,18 @@
   InitMMap();
 
   SetExposure(params.exposure());
-  LOG(INFO, "Bat Vision Successfully Initialized.\n");
+  AOS_LOG(INFO, "Bat Vision Successfully Initialized.\n");
 }
 
 void Reader::QueueBuffer(v4l2_buffer *buf) {
   if (xioctl(fd_, VIDIOC_QBUF, buf) == -1) {
-    PLOG(WARNING,
-         "ioctl VIDIOC_QBUF(%d, %p)."
-         " losing buf #%" PRIu32 "\n",
-         fd_, &buf, buf->index);
+    AOS_PLOG(WARNING,
+             "ioctl VIDIOC_QBUF(%d, %p)."
+             " losing buf #%" PRIu32 "\n",
+             fd_, &buf, buf->index);
   } else {
-    //    LOG(DEBUG, "put buf #%" PRIu32 " into driver's queue\n", buf->index);
+    //    AOS_LOG(DEBUG, "put buf #%" PRIu32 " into driver's queue\n",
+    //    buf->index);
     ++queued_;
   }
 }
@@ -81,7 +82,7 @@
 
   if (xioctl(fd_, VIDIOC_DQBUF, &buf) == -1) {
     if (errno != EAGAIN) {
-      PLOG(ERROR, "ioctl VIDIOC_DQBUF(%d, %p)", fd_, &buf);
+      AOS_PLOG(ERROR, "ioctl VIDIOC_DQBUF(%d, %p)", fd_, &buf);
     }
     return;
   }
@@ -110,15 +111,15 @@
     buf.memory = V4L2_MEMORY_MMAP;
     buf.index = n;
     if (xioctl(fd_, VIDIOC_QUERYBUF, &buf) == -1) {
-      PLOG(FATAL, "ioctl VIDIOC_QUERYBUF(%d, %p)", fd_, &buf);
+      AOS_PLOG(FATAL, "ioctl VIDIOC_QUERYBUF(%d, %p)", fd_, &buf);
     }
     buffers_[n].length = buf.length;
     buffers_[n].start = mmap(NULL, buf.length, PROT_READ | PROT_WRITE,
                              MAP_SHARED, fd_, buf.m.offset);
     if (buffers_[n].start == MAP_FAILED) {
-      PLOG(FATAL,
-           "mmap(NULL, %zd, PROT_READ | PROT_WRITE, MAP_SHARED, %d, %jd)",
-           (size_t)buf.length, fd_, static_cast<intmax_t>(buf.m.offset));
+      AOS_PLOG(FATAL,
+               "mmap(NULL, %zd, PROT_READ | PROT_WRITE, MAP_SHARED, %d, %jd)",
+               (size_t)buf.length, fd_, static_cast<intmax_t>(buf.m.offset));
     }
   }
 }
@@ -131,14 +132,14 @@
   req.memory = V4L2_MEMORY_MMAP;
   if (xioctl(fd_, VIDIOC_REQBUFS, &req) == -1) {
     if (EINVAL == errno) {
-      LOG(FATAL, "%s does not support memory mapping\n", dev_name_.c_str());
+      AOS_LOG(FATAL, "%s does not support memory mapping\n", dev_name_.c_str());
     } else {
-      PLOG(FATAL, "ioctl VIDIOC_REQBUFS(%d, %p)\n", fd_, &req);
+      AOS_PLOG(FATAL, "ioctl VIDIOC_REQBUFS(%d, %p)\n", fd_, &req);
     }
   }
   queued_ = kNumBuffers;
   if (req.count != kNumBuffers) {
-    LOG(FATAL, "Insufficient buffer memory on %s\n", dev_name_.c_str());
+    AOS_LOG(FATAL, "Insufficient buffer memory on %s\n", dev_name_.c_str());
   }
 }
 
@@ -150,11 +151,11 @@
   int r = xioctl(fd_, VIDIOC_G_CTRL, &getArg);
   if (r == 0) {
     if (getArg.value == value) {
-      LOG(DEBUG, "Camera control %s was already %d\n", name, getArg.value);
+      AOS_LOG(DEBUG, "Camera control %s was already %d\n", name, getArg.value);
       return true;
     }
   } else if (errno == EINVAL) {
-    LOG(DEBUG, "Camera control %s is invalid\n", name);
+    AOS_LOG(DEBUG, "Camera control %s is invalid\n", name);
     errno = 0;
     return false;
   }
@@ -165,7 +166,7 @@
     return true;
   }
 
-  LOG(DEBUG, "Couldn't set camera control %s to %d", name, value);
+  AOS_LOG(DEBUG, "Couldn't set camera control %s to %d", name, value);
   errno = 0;
   return false;
 }
@@ -179,16 +180,16 @@
   v4l2_capability cap;
   if (xioctl(fd_, VIDIOC_QUERYCAP, &cap) == -1) {
     if (EINVAL == errno) {
-      LOG(FATAL, "%s is no V4L2 device\n", dev_name_.c_str());
+      AOS_LOG(FATAL, "%s is no V4L2 device\n", dev_name_.c_str());
     } else {
-      PLOG(FATAL, "ioctl VIDIOC_QUERYCAP(%d, %p)", fd_, &cap);
+      AOS_PLOG(FATAL, "ioctl VIDIOC_QUERYCAP(%d, %p)", fd_, &cap);
     }
   }
   if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
-    LOG(FATAL, "%s is no video capture device\n", dev_name_.c_str());
+    AOS_LOG(FATAL, "%s is no video capture device\n", dev_name_.c_str());
   }
   if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
-    LOG(FATAL, "%s does not support streaming i/o\n", dev_name_.c_str());
+    AOS_LOG(FATAL, "%s does not support streaming i/o\n", dev_name_.c_str());
   }
 
   /* Select video input, video standard and tune here. */
@@ -208,12 +209,12 @@
           break;
         default:
           /* Errors ignored. */
-          PLOG(WARNING, "xioctl VIDIOC_S_CROP");
+          AOS_PLOG(WARNING, "xioctl VIDIOC_S_CROP");
           break;
       }
     }
   } else {
-    PLOG(WARNING, "xioctl VIDIOC_CROPCAP");
+    AOS_PLOG(WARNING, "xioctl VIDIOC_CROPCAP");
   }
 
   v4l2_format fmt;
@@ -226,8 +227,8 @@
   // fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
   // fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
   if (xioctl(fd_, VIDIOC_S_FMT, &fmt) == -1) {
-    LOG(FATAL, "ioctl VIDIC_S_FMT(%d, %p) failed with %d: %s\n", fd_, &fmt,
-        errno, strerror(errno));
+    AOS_LOG(FATAL, "ioctl VIDIC_S_FMT(%d, %p) failed with %d: %s\n", fd_, &fmt,
+            errno, strerror(errno));
   }
   /* Note VIDIOC_S_FMT may change width and height. */
 
@@ -239,21 +240,21 @@
 
   if (!SetCameraControl(V4L2_CID_EXPOSURE_AUTO, "V4L2_CID_EXPOSURE_AUTO",
                         V4L2_EXPOSURE_MANUAL)) {
-    LOG(FATAL, "Failed to set exposure\n");
+    AOS_LOG(FATAL, "Failed to set exposure\n");
   }
 
   if (!SetCameraControl(V4L2_CID_EXPOSURE_ABSOLUTE,
                         "V4L2_CID_EXPOSURE_ABSOLUTE", params_.exposure())) {
-    LOG(FATAL, "Failed to set exposure\n");
+    AOS_LOG(FATAL, "Failed to set exposure\n");
   }
 
   if (!SetCameraControl(V4L2_CID_BRIGHTNESS, "V4L2_CID_BRIGHTNESS",
                         params_.brightness())) {
-    LOG(FATAL, "Failed to set up camera\n");
+    AOS_LOG(FATAL, "Failed to set up camera\n");
   }
 
   if (!SetCameraControl(V4L2_CID_GAIN, "V4L2_CID_GAIN", params_.gain())) {
-    LOG(FATAL, "Failed to set up camera\n");
+    AOS_LOG(FATAL, "Failed to set up camera\n");
   }
 
   // set framerate
@@ -264,18 +265,18 @@
   setfps->parm.capture.timeperframe.numerator = 1;
   setfps->parm.capture.timeperframe.denominator = params_.fps();
   if (xioctl(fd_, VIDIOC_S_PARM, setfps) == -1) {
-    PLOG(FATAL, "ioctl VIDIOC_S_PARM(%d, %p)\n", fd_, setfps);
+    AOS_PLOG(FATAL, "ioctl VIDIOC_S_PARM(%d, %p)\n", fd_, setfps);
   }
-  LOG(INFO, "framerate ended up at %d/%d\n",
-      setfps->parm.capture.timeperframe.numerator,
-      setfps->parm.capture.timeperframe.denominator);
+  AOS_LOG(INFO, "framerate ended up at %d/%d\n",
+          setfps->parm.capture.timeperframe.numerator,
+          setfps->parm.capture.timeperframe.denominator);
 }
 
 aos::vision::ImageFormat Reader::get_format() {
   struct v4l2_format fmt;
   fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   if (xioctl(fd_, VIDIOC_G_FMT, &fmt) == -1) {
-    PLOG(FATAL, "ioctl VIDIC_G_FMT(%d, %p)\n", fd_, &fmt);
+    AOS_PLOG(FATAL, "ioctl VIDIC_G_FMT(%d, %p)\n", fd_, &fmt);
   }
 
   return aos::vision::ImageFormat{(int)fmt.fmt.pix.width,
@@ -283,7 +284,7 @@
 }
 
 void Reader::Start() {
-  LOG(DEBUG, "queueing buffers for the first time\n");
+  AOS_LOG(DEBUG, "queueing buffers for the first time\n");
   v4l2_buffer buf;
   for (unsigned int i = 0; i < kNumBuffers; ++i) {
     CLEAR(buf);
@@ -292,11 +293,11 @@
     buf.index = i;
     QueueBuffer(&buf);
   }
-  LOG(DEBUG, "done with first queue\n");
+  AOS_LOG(DEBUG, "done with first queue\n");
 
   v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   if (xioctl(fd_, VIDIOC_STREAMON, &type) == -1) {
-    PLOG(FATAL, "ioctl VIDIOC_STREAMON(%d, %p)\n", fd_, &type);
+    AOS_PLOG(FATAL, "ioctl VIDIOC_STREAMON(%d, %p)\n", fd_, &type);
   }
 }