Merge "conman:  More debug logging, persist 'wifi setclient' options."
diff --git a/base/bruno/asyncsocket.h b/base/bruno/asyncsocket.h
index ce06cdf..0e96979 100644
--- a/base/bruno/asyncsocket.h
+++ b/base/bruno/asyncsocket.h
@@ -113,15 +113,19 @@
 
  protected:
   virtual void OnConnectEvent(AsyncSocket* socket) {
+    (void)socket;
     SignalConnectEvent(this);
   }
   virtual void OnReadEvent(AsyncSocket* socket) {
+    (void)socket;
     SignalReadEvent(this);
   }
   virtual void OnWriteEvent(AsyncSocket* socket) {
+    (void)socket;
     SignalWriteEvent(this);
   }
   virtual void OnCloseEvent(AsyncSocket* socket, int err) {
+    (void)socket;
     SignalCloseEvent(this, err);
   }
 
diff --git a/base/bruno/scoped_ptr.h b/base/bruno/scoped_ptr.h
index 9e8a06d..0fa5b36 100644
--- a/base/bruno/scoped_ptr.h
+++ b/base/bruno/scoped_ptr.h
@@ -60,6 +60,8 @@
 
   void reset(T* p = NULL) {
     typedef char type_must_be_complete[sizeof(T)];
+    type_must_be_complete *x;
+    (void)x;
 
     if (ptr != p) {
       T* obj = ptr;
@@ -137,11 +139,15 @@
 
   ~scoped_array() {
     typedef char type_must_be_complete[sizeof(T)];
+    type_must_be_complete *x;
+    (void)x;
     delete[] ptr;
   }
 
   void reset(T* p = NULL) {
     typedef char type_must_be_complete[sizeof(T)];
+    type_must_be_complete *x;
+    (void)x;
 
     if (ptr != p) {
       T* arr = ptr;
diff --git a/base/bruno/socketserver.h b/base/bruno/socketserver.h
index bdeef5b..12e8acc 100644
--- a/base/bruno/socketserver.h
+++ b/base/bruno/socketserver.h
@@ -44,7 +44,7 @@
   // When the socket server is installed into a Thread, this function is
   // called to allow the socket server to use the thread's message queue for
   // any messaging that it might need to perform.
-  virtual void SetMessageQueue(MessageQueue* queue) {}
+  virtual void SetMessageQueue(MessageQueue* queue) { (void)queue; }
 
   // Sleeps until:
   //  1) cms milliseconds have elapsed (unless cms == kForever)
diff --git a/sysmgr/Makefile b/sysmgr/Makefile
index 18a47ef..19e85b7 100644
--- a/sysmgr/Makefile
+++ b/sysmgr/Makefile
@@ -10,14 +10,13 @@
 BINDIR=$(PREFIX)/bin
 LIBDIR=$(PREFIX)/lib
 INCLUDEDIR=$(PREFIX)/include
-PKG_CONFIG?=pkg-config
 
 CC=$(CROSS_COMPILE)gcc
 CXX=$(CROSS_COMPILE)g++
 RM=rm -f
 INCS=-Iperipheral -I../base -I../libstacktrace
 CFLAGS=-Wall -Wimplicit -Wno-unknown-pragmas -W
-CPPFLAGS=$(subst -Wstrict-prototypes,,$(subst -std=c99,,$(shell $(PKG_CONFIG) --cflags brunobase)))
+CXXFLAGS=
 
 all: $(TARGETS)
 
@@ -41,7 +40,6 @@
 install-libs: all
 	mkdir -p $(INCLUDEDIR)/sysmgr $(LIBDIR)/pkgconfig
 	$(INSTALL) -m 0644 platform_peripheral_api.h $(INCLUDEDIR)/sysmgr/
-	$(INSTALL) -m 0644 brunoperipheral.pc $(LIBDIR)/pkgconfig/
 	$(INSTALL) -m 0755 peripheral/libbrunoperipheral.so $(LIBDIR)/
 
 peripheral/libbrunoperipheral.so: peripheral/all
@@ -51,16 +49,12 @@
 
 %: %.o
 	@echo "LINK $@"
-	$(Q)$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(INCS) \
+	$(Q)$(CXX) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) $(INCS) \
 		-o $@ $^ -lpthread
 
 %.o: %.cc
 	@echo " CXX $@"
-	$(Q)$(CXX) $(CFLAGS) $(CPPFLAGS) $(INCS) -o $@ -c $<
-
-%.o: %.c
-	@echo " CC  $@"
-	$(Q)$(CC) -std=c99 $(CFLAGS) $(CPPFLAGS) $(INCS) -o $@ -c $<
+	$(Q)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCS) -o $@ -c $<
 
 %/all:
 	$(MAKE) -C $* all
diff --git a/sysmgr/brunoperipheral.pc b/sysmgr/brunoperipheral.pc
deleted file mode 100644
index 51c7a81..0000000
--- a/sysmgr/brunoperipheral.pc
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=/usr
-exec_prefix=/usr
-libdir=${exec_prefix}/lib
-includedir=${prefix}/include
-
-Name: Bruno Peripheral
-Description: Bruno Peripheral Library
-Version: 1.0.0
-Libs: -L${libdir} -lbrunoperipheral
-Libs.private:
-Cflags:
diff --git a/sysmgr/peripheral/common.cc b/sysmgr/peripheral/common.cc
index f1094b2..9517926 100644
--- a/sysmgr/peripheral/common.cc
+++ b/sysmgr/peripheral/common.cc
@@ -11,130 +11,32 @@
 
 namespace bruno_platform_peripheral {
 
-const std::string Common::kErrorString = "ERROR";
-
-
-std::string Common::ExecCmd(std::string& cmd, std::string *pattern,
-                           enum ExecCmdCompareTypes action) {
-  char buffer[256];
-  std::string result = "";
-  FILE* pipe = popen(cmd.c_str(), "r");
-
-  LOG(LS_INFO) << "ExecCmd: cmd= " << cmd << " action= " << action << std::endl
-               << "pattern= " << ((pattern == NULL)? "NULL": *pattern) << std::endl;
-  if (!pipe) {
-    LOG(LS_ERROR) << "ExecCmd(): ERROR" << std::endl;
-    return kErrorString;
-  }
-  int is_continue = true;
-  size_t found;
-
-  while((!feof(pipe)) && (is_continue)) {
-    if(fgets(buffer, sizeof(buffer), pipe) != NULL) {
-      /* pattern == NULL, read and return all of lines
-       * pattern != NULL, return the line if found the pattern in the line
-       */
-      if (pattern != NULL) {
-        result = std::string(buffer);
-      }
-      switch (action) {
-        case STRING_COMPARE:
-          /* Compare strings when the pattern is in beginning of the
-           * compared string.
-           */
-          if (result.compare(0, pattern->size(), *pattern) == 0) {
-            is_continue = false;  /* Found the pattern. Exit. */
-            break;
-          }
-          result.clear();
-          break;
-        case STRING_FIND:
-          /* Find in the compared string if the starting position is unknown.
-           * More time consuming.
-           */
-          found = result.find(*pattern);
-          if (found != std::string::npos) {
-            LOG(LS_VERBOSE) << "ExecCmd: FOUND **result= " << result << std::endl;
-            is_continue = false;  /* Found the pattern. Exit. */
-            break;
-          }
-          result.clear();
-          break;
-        case STRING_RETRUN_ALL_MSGS:
-          result += buffer;
-          break;
-      }
-    }
-  }
-
-  pclose(pipe);
-  return result;
-}
-
-void Common::Split(const std::string& str,
-            const std::string& delimiters, std::vector<std::string>& tokens) {
-  /* Skip delimiters at beginning. */
-  LOG(LS_VERBOSE) << "Split: str= " << str
-                  << "delimiters= " << delimiters << std::endl;
-  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
-  /* Find first "non-delimiter". */
-  std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
-
-  while (std::string::npos != pos || std::string::npos != lastPos) {
-      // Found a token, add it to the vector.
-      tokens.push_back(str.substr(lastPos, pos - lastPos));
-      // Skip delimiters.
-      lastPos = str.find_first_not_of(delimiters, pos);
-      // Find next "non-delimiter"
-      pos = str.find_first_of(delimiters, lastPos);
-  }
-
-  /* Debug print only. Remove later. */
-  for (size_t i = 0; i < tokens.size(); i++) {
-    LOG(LS_VERBOSE) << "idx= " << i << " token= " << tokens[i] << std::endl;
-  }
-
-  LOG(LS_VERBOSE) << "Split: exit." << std::endl;
-}
-
-
-bool Common::Reboot() {
-  bool  is_ok = true;
-
+bool Reboot() {
   sync();
   int ret = reboot(LINUX_REBOOT_CMD_RESTART);
   if (ret < 0) {
     LOG(LS_ERROR) << "Reboot: failed (ret=" << ret << ")" << std::endl;
-    is_ok = false;
+    return false;
   }
-  return(is_ok);
+  return true;
 }
 
 
-bool Common::Poweroff() {
-  bool  is_ok = true;
-
+bool Poweroff() {
   sync();
   int ret = system("poweroff-with-message 'poweroff requested by sysmgr'");
   if (ret != 0) {
     LOG(LS_ERROR) << "Poweroff: failed (ret=" << ret << ")" << std::endl;
-    is_ok = false;
+    return false;
   }
-  return(is_ok);
+  return true;
 }
 
 
-void Common::SetLED(LedControl led, const std::string message) {
+void SetLEDOverheat(const std::string& message) {
   std::ofstream file;
-  const char *filename = "/dev/null";
-  const char *led_pattern = "0";
-
-  switch(led) {
-    case OVERHEATING:
-      filename = OVERHEATING_LED_FILE;
-      led_pattern = OVERHEATING_LED_ON;
-      break;
-  }
+  const char *filename = OVERHEATING_LED_FILE;
+  const char *led_pattern = OVERHEATING_LED_ON;
 
   /* Set LED by sending string to GPIO mailbox */
   file.open(filename);
@@ -149,14 +51,8 @@
   }
 }
 
-void Common::ClrLED(LedControl led, const std::string message) {
-  std::string filename = "/dev/null";
-
-  switch(led) {
-    case OVERHEATING:
-      filename = OVERHEATING_LED_FILE;
-      break;
-  }
+void ClrLEDOverheat(const std::string& message) {
+  std::string filename = OVERHEATING_LED_FILE;
 
   unlink(filename.c_str());
 
@@ -170,34 +66,31 @@
 }
 
 /* Convert from string to floating point number */
-bool Common::ConvertStringToFloat(const std::string& value_str, float *value) {
-  bool  rtn = true;
+bool ConvertStringToFloat(const std::string& value_str, float *value) {
   std::stringstream ss(value_str);
 
   if((ss >> *value).fail()) {
     *value = 0.0;
-    rtn = false;
     LOG(LS_ERROR) << "ConvertStringToFloat: Failed to convert" << std::endl;
+    return false;
   }
-  return rtn;
+  return true;
 }
 
 /* Convert from string to integer */
-bool Common::ConvertStringToUint16(const std::string& value_str, uint16_t *value) {
-  bool  rtn = true;
+bool ConvertStringToUint16(const std::string& value_str, uint16_t *value) {
   std::stringstream ss(value_str);
 
   if((ss >> *value).fail()) {
     *value = 0;
-    rtn = false;
     LOG(LS_ERROR) << "ConvertStringToInt: Failed to convert" << std::endl;
+    return false;
   }
-  return rtn;
+  return true;
 }
 
-
 /* Convert from integer to string */
-void Common::ConvertUint16ToString(const uint16_t& value, std::string *value_str) {
+void ConvertUint16ToString(const uint16_t& value, std::string *value_str) {
   std::stringstream ss;
   ss << value;
   *value_str = ss.str();
diff --git a/sysmgr/peripheral/common.h b/sysmgr/peripheral/common.h
index df72ac6..9b21e16 100644
--- a/sysmgr/peripheral/common.h
+++ b/sysmgr/peripheral/common.h
@@ -23,34 +23,13 @@
 
 namespace bruno_platform_peripheral {
 
-class Common {
- public:
-  enum ExecCmdCompareTypes {
-    STRING_COMPARE,
-    STRING_FIND,
-    STRING_RETRUN_ALL_MSGS
-  };
-
-  enum LedControl {
-    OVERHEATING
-  };
-
-  static const std::string kErrorString;
-
-  static std::string ExecCmd(std::string& cmd, std::string *pattern,
-                             enum ExecCmdCompareTypes action);
-  static void Split(const std::string& str,
-              const std::string& delimiters, std::vector<std::string>& tokens);
-  static bool Reboot();
-  static bool Poweroff();
-  static void SetLED(LedControl led, const std::string message);
-  static void ClrLED(LedControl led, const std::string message);
-  static bool ConvertStringToFloat(const std::string& value_str, float *value);
-  static bool ConvertStringToUint16(const std::string& value_str, uint16_t *value);
-  static void ConvertUint16ToString(const uint16_t& value, std::string *value_str);
-
-  DISALLOW_COPY_AND_ASSIGN(Common);
-};
+bool Reboot();
+bool Poweroff();
+void SetLEDOverheat(const std::string& message);
+void ClrLEDOverheat(const std::string& message);
+bool ConvertStringToFloat(const std::string& value_str, float *value);
+bool ConvertStringToUint16(const std::string& value_str, uint16_t *value);
+void ConvertUint16ToString(const uint16_t& value, std::string *value_str);
 
 }  // namespace bruno_platform_peripheral
 
diff --git a/sysmgr/peripheral/fancontrol.h b/sysmgr/peripheral/fancontrol.h
index 4e379ad..ab2eecd 100644
--- a/sysmgr/peripheral/fancontrol.h
+++ b/sysmgr/peripheral/fancontrol.h
@@ -39,7 +39,7 @@
 }FanControlParams;
 
 
-class FanControl: public Mailbox {
+class FanControl : public Mailbox {
  public:
   enum StateType {
     OFF,
diff --git a/sysmgr/peripheral/mailbox.cc b/sysmgr/peripheral/mailbox.cc
index 8bda816..2af9e2e 100644
--- a/sysmgr/peripheral/mailbox.cc
+++ b/sysmgr/peripheral/mailbox.cc
@@ -27,7 +27,7 @@
   *fan_speed = 0;
   rtn = ReadValueString(kMailboxFanSpeedFile, &value_str);
   if (rtn == true) {
-    rtn = Common::ConvertStringToUint16(value_str, fan_speed);
+    rtn = ConvertStringToUint16(value_str, fan_speed);
   }
   return rtn;
 }
@@ -44,7 +44,7 @@
   *soc_temperature = 0.0;
   rtn = ReadValueString(kMailboxCpuTemperatureFile, &value_str);
   if (rtn == true) {
-    rtn = Common::ConvertStringToFloat(value_str, soc_temperature);
+    rtn = ConvertStringToFloat(value_str, soc_temperature);
   }
   return rtn;
 }
@@ -70,7 +70,7 @@
 bool Mailbox::WriteFanDutyCycle(uint16_t duty_cycle) {
   std::string value_str;
 
-  Common::ConvertUint16ToString(duty_cycle, &value_str);
+  ConvertUint16ToString(duty_cycle, &value_str);
   return WriteValueString(kMailboxFanPercentFile, value_str);
 }
 
@@ -87,7 +87,7 @@
 
   rtn = ReadValueString(kMailboxFanPercentFile, &value_str);
   if (rtn == true) {
-    rtn = Common::ConvertStringToUint16(value_str, duty_cycle);
+    rtn = ConvertStringToUint16(value_str, duty_cycle);
   }
   return rtn;
 }
@@ -128,22 +128,16 @@
 
 /* Read value string from the text file */
 bool Mailbox::ReadValueString(const std::string& in_file, std::string *value_str) {
-  bool  rtn = false;
-
   std::ifstream file;
-
   file.open(in_file.c_str(), std::ios::in);
   if (file.is_open()) {
     std::getline(file, *value_str);
     file.close();
-    rtn = true;
-  } else {
-    *value_str = Common::kErrorString;         /* Retrun a default error string */
-    LOG(LS_ERROR) << "ReadValueString: Failed to open: " << in_file;
+    return true;
   }
-
-  LOG(LS_VERBOSE) << "rtn=" << rtn;
-  return rtn;
+  *value_str = "ERROR";
+  LOG(LS_ERROR) << "ReadValueString: Failed to open: " << in_file;
+  return false;
 }
 
 } // ce bruno_platform_peripheral
diff --git a/sysmgr/peripheral/peripheralmon.cc b/sysmgr/peripheral/peripheralmon.cc
index 4e7b123..dbd6f49 100644
--- a/sysmgr/peripheral/peripheralmon.cc
+++ b/sysmgr/peripheral/peripheralmon.cc
@@ -76,7 +76,7 @@
 
   if (soc_temperature < overheat_value) {
     overheating_ = 0;
-    Common::ClrLED(Common::OVERHEATING, "");
+    ClrLEDOverheat("");
   }
   else {
     overheating_ ++;
@@ -84,15 +84,15 @@
     if (overheating_ >= OVERHEATING_COUNT) {
       message << "System power off: SOC overheating " << overheating_;
       LOG(LS_ERROR) << message.str();
-      Common::ClrLED(Common::OVERHEATING, "");
+      ClrLEDOverheat("");
 
       overheating_ = 0;
-      Common::Poweroff();
+      Poweroff();
     }
     else {
       message << "SOC overheating detected " << overheating_;
       LOG(LS_ERROR) << message.str();
-      Common::SetLED(Common::OVERHEATING, message.str());
+      SetLEDOverheat(message.str());
     }
   }
 }