Commit e3351c74 authored by jacobgladish's avatar jacobgladish

More code cleanup.

* Added IAdapter::GetStatusText
* Removed some warning ignores in Makefiles and now use pragmas.
parent e27b9c37
......@@ -4,8 +4,9 @@
#include "MockAdapterDevice.h"
#include "Common/Log.h"
#include <vector>
#include <algorithm>
#include <sstream>
#include <vector>
namespace
{
......@@ -315,3 +316,15 @@ adapters::mock::MockAdapter::NotifySignalListeners(std::shared_ptr<MockAdapterSi
return st;
}
std::string
adapters::mock::MockAdapter::GetStatusText(bridge::AdapterStatus st)
{
if (st == 0)
return std::string("ok");
std::stringstream buff;
buff << "MockError:";
buff << static_cast<uint32_t>(st);
return buff.str();
}
......@@ -26,6 +26,8 @@ namespace mock
virtual common::Guid GetExposedApplicationGuid();
virtual bridge::AdapterSignalVector GetSignals();
virtual std::string GetStatusText(bridge::AdapterStatus st);
virtual bridge::AdapterStatus Initialize(std::shared_ptr<bridge::IAdapterLog> const& log);
virtual bridge::AdapterStatus Shutdown();
......
#include "Adapters/MockAdapter/MockDevices.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
namespace
{
using namespace adapters::mock;
......@@ -275,4 +278,4 @@ adapters::mock::PropertyAttributeIdToString(MockPropertyAttributeId attrId)
return s;
}
#pragma GCC diagnostic pop
......@@ -3,7 +3,17 @@
#include <stdint.h>
#include <string>
#include <vector>
//
// TODO
// Adapters should be able to be built without alljoyn?
// This is mock, but let's remove alljoyn deps to use
// the MockAdapter as a confirmation that it's possible
//
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#include <alljoyn/Message.h>
#pragma GCC diagnostic pop
namespace adapters
{
......
#pragma once
#include "Common/Guid.h"
#include <alljoyn/AboutData.h>
#include <alljoyn/AboutObj.h>
#include <alljoyn/BusAttachment.h>
#include <alljoyn/InterfaceDescription.h>
#include <alljoyn/Status.h>
#include "Bridge/AllJoynHeaders.h"
#include <memory>
......
#pragma once
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#include <alljoyn/AboutData.h>
#include <alljoyn/AboutObj.h>
#include <alljoyn/BusAttachment.h>
#include <alljoyn/BusListener.h>
#include <alljoyn/BusObject.h>
#include <alljoyn/InterfaceDescription.h>
#include <alljoyn/Message.h>
#include <alljoyn/MsgArg.h>
#include <alljoyn/Status.h>
#include <alljoyn/SessionListener.h>
#include <alljoyn/SessionPortListener.h>
#pragma GCC diagnostic pop
......@@ -208,6 +208,8 @@ bridge::DeviceSystemBridge::InitializeAdapter()
QStatus
bridge::DeviceSystemBridge::InitializeDevices(bool update)
{
QStatus st = ER_OK;
AdapterDeviceVector deviceList;
std::shared_ptr<IAdapterIoRequest> request;
......@@ -215,16 +217,24 @@ bridge::DeviceSystemBridge::InitializeDevices(bool update)
if (update)
opts = EnumDeviceOptions::ForceRefresh;
int ret = m_adapter->EnumDevices(opts, deviceList, &request);
AdapterStatus adapterStatus = m_adapter->EnumDevices(opts, deviceList, &request);
if (!IsOk(adapterStatus))
{
DSBLOG_WARN("failed to enumerate devices: %d", m_adapter->GetStatusText(adapterStatus).c_str());
if (ret != 0)
// TODO: we need some translation from AdapterStatus to QStatus
st = ER_FAIL;
goto Leave;
}
if (request)
{
ret = request->Wait(kWaitTimeoutForAdapterOperation);
if (ret != 0)
adapterStatus = request->Wait(kWaitTimeoutForAdapterOperation);
if (!IsOk(adapterStatus))
{
DSBLOG_WARN("failed to wait for async i/o request: %s", m_adapter->GetStatusText(adapterStatus).c_str());
st = ER_FAIL;
goto Leave;
}
}
......@@ -234,18 +244,18 @@ bridge::DeviceSystemBridge::InitializeDevices(bool update)
{
// TODO: get configuration for device, only expose visible devices
if (update)
ret = UpdateDevice(*begin, true);
st = UpdateDevice(*begin, true);
else
ret = CreateDevice(*begin);
st = CreateDevice(*begin);
if (ret != 0)
DSBLOG_WARN("Failed to %s device: %d", update ? "update" : "create", ret);
if (st != ER_OK)
DSBLOG_WARN("Failed to %s device: %s", update ? "update" : "create", QCC_StatusText(st));
}
// TODO: Save bridge configuration to XML
Leave:
return ret == 0 ? ER_OK : ER_FAIL;
return st;
}
void
......
#pragma once
#include "Bridge/BridgeConfig.h"
#include <alljoyn/BusAttachment.h>
#include <alljoyn/BusListener.h>
#include <alljoyn/SessionListener.h>
#include <alljoyn/SessionPortListener.h>
#include "Bridge/AllJoynHeaders.h"
#include <memory>
......
#ifndef __DEVICE_MAIN_H__
#define __DEVICE_MAIN_H__
#include <map>
#include <alljoyn/BusObject.h>
#include <alljoyn/InterfaceDescription.h>
#include "Bridge/AllJoynHeaders.h"
#include "Bridge/IAdapter.h"
#include "IAdapter.h"
#include <map>
namespace bridge
{
......
#ifndef __DEVICE_METHOD_H__
#define __DEVICE_METHOD_H__
#include "IAdapter.h"
#include "Bridge/IAdapter.h"
#include "Bridge/AllJoynHeaders.h"
#include <alljoyn/Message.h>
#include <alljoyn/MsgArg.h>
#include <alljoyn/Status.h>
namespace bridge
{
......
......@@ -164,9 +164,10 @@ namespace bridge
{
public:
virtual ~IAdapterIoRequest() { }
virtual int32_t GetStatus() = 0;;
virtual int32_t Wait(uint32_t timeoutMillis = std::numeric_limits<uint32_t>::max()) = 0;
virtual int32_t Cancel() = 0;
virtual AdapterStatus GetStatus() = 0;;
virtual AdapterStatus Wait(uint32_t timeoutMillis = std::numeric_limits<uint32_t>::max()) = 0;
virtual AdapterStatus Cancel() = 0;
};
enum class EnumDeviceOptions
......@@ -192,6 +193,8 @@ namespace bridge
virtual common::Guid GetExposedApplicationGuid() = 0;
virtual AdapterSignalVector GetSignals() = 0;
virtual std::string GetStatusText(AdapterStatus st) = 0;
virtual AdapterStatus SetConfiguration(std::vector<uint8_t> const& configData) = 0;
virtual AdapterStatus GetConfiguration(std::vector<uint8_t>* configData) = 0;
......@@ -306,10 +309,10 @@ namespace bridge
{
}
virtual int32_t GetStatus()
virtual AdapterStatus GetStatus()
{ return m_status; }
virtual int32_t Wait(uint32_t millis = std::numeric_limits<uint32_t>::max())
virtual AdapterStatus Wait(uint32_t millis = std::numeric_limits<uint32_t>::max())
{
if (millis != std::numeric_limits<uint32_t>::max())
{
......@@ -330,7 +333,7 @@ namespace bridge
return 0;
}
virtual int32_t Cancel()
virtual AdapterStatus Cancel()
{
std::unique_lock<std::mutex> lk(m_mutex);
m_canceled = true;
......@@ -341,7 +344,7 @@ namespace bridge
return 0;
}
void SetComplete(int32_t status)
void SetComplete(AdapterStatus status)
{
std::unique_lock<std::mutex> lk(m_mutex);
m_status = status;
......@@ -352,7 +355,7 @@ namespace bridge
}
private:
int32_t m_status;
AdapterStatus m_status;
bool m_canceled;
bool m_completed;
std::mutex m_mutex;
......
......@@ -2,7 +2,10 @@
#include "DeviceProviders/AllJoynStatus.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#include <alljoyn/AboutListener.h>
#pragma GCC diagnostic pop
#include <map>
#include <memory>
......
#pragma once
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#include <alljoyn/BusAttachment.h>
#include <alljoyn/ProxyBusObject.h>
#include <alljoyn/SessionListener.h>
#pragma GCC diagnostic pop
#include <map>
#include <memory>
......
......@@ -28,11 +28,11 @@ LIBXML_INC?=/usr/include/libxml2
ALLJOYN_INSTALL_DIR?=/Users/jgladi200/Work/alljoyn/alljoyn-15.09.00a-src/build/darwin/x86/debug/dist/cpp
CXXFLAGS=-D QCC_OS_GROUP_POSIX -Wall -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -Wno-ignored-qualifiers -std=c++11 -I. -I$(ALLJOYN_INSTALL_DIR)/inc -I$(LIBXML_INC)
LDFLAGS=-L $(ALLJOYN_INSTALL_DIR)/lib -lalljoyn -lcrypto -lxml2
DEV_PROVIDER_OBJS=$(patsubst %.cpp, %.o, $(SRCS))
OBJS=$(DEV_PROVIDER_OBJS)
DEPS = $(OBJS:%.o=%.d) $(TEST_OBJS:%.o=%.d)
CXXFLAGS = -Wall -Wextra -std=c++11 -I. -I$(ALLJOYN_INSTALL_DIR)/inc -I$(LIBXML_INC)
LDFLAGS = -L $(ALLJOYN_INSTALL_DIR)/lib -lalljoyn -lcrypto -lxml2
DEV_PROVIDER_OBJS = $(patsubst %.cpp, %.o, $(SRCS))
OBJS = $(DEV_PROVIDER_OBJS)
DEPS = $(OBJS:%.o=%.d) $(TEST_OBJS:%.o=%.d)
GTEST_DIR?=/usr/src/gtest
ifneq ("$(wildcard $(GTEST_DIR)/libgtest.a)","")
......@@ -45,20 +45,21 @@ endif
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDFLAGS += -pthread -luuid
CXXFLAGS += -DQCC_OS_GROUP_POSIX
endif
ifeq ($(DEBUG), 1)
CXXFLAGS += -g
CXXFLAGS += -g
else
CXXFLAGS += -O2
CXXFLAGS += -O2
endif
ifeq ($V, 1)
CXX_PRETTY = $(CXX)
LD_PRETTY = $(CXX)
CXX_PRETTY = $(CXX)
LD_PRETTY = $(CXX)
else
CXX_PRETTY = @echo " [CXX] $<" ; $(CXX)
LD_PRETTY = @echo "[LINK] $@" ; $(CXX)
CXX_PRETTY = @echo " [CXX] $<" ; $(CXX)
LD_PRETTY = @echo "[LINK] $@" ; $(CXX)
endif
all: moc-adapter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment