Exemple #1
0
RestHTTPCode AudioActionHandler::DoAction(BaseProtocol *pFrom,
                                          bool isRO,
                                          vector<string> &resource,
                                          Variant &payload,
                                          Variant &message) {
  string collection = resource[3];
  string id = resource[4];

  if(!MAP_HAS1(_actionMaps, collection)) {
    return SendFailure(HC_400_BAD_REQUEST, EC_106_COLLECTION_NOT_FOUND,
        "Unable to find collection: " + collection, message);
  }
  if(!MAP_HAS1(*_actionMaps[collection], isRO)){
    return SendFailure(HC_400_BAD_REQUEST, EC_103_METHOD_NOT_ALLOWED,
        "Invalid method: " + isRO, message);
  }
  if(!MAP_HAS1(*(*_actionMaps[collection])[isRO], id)){
    return SendFailure(HC_400_BAD_REQUEST, EC_107_RESOURCE_ID_NOT_FOUND,
        "Unable to find resource id: " + id, message);
  }

  if (payload.HasKey(REST_URI_STR)) {
    _uri=(string)payload[REST_URI_STR];
  }
  if (payload.HasKey(REST_TID_STR)) {
    _tid=(string)payload[REST_TID_STR];
  }
  Action pAction = (*(*_actionMaps[collection])[isRO])[id];
  return ((this->*pAction)(payload[REST_PARAM_STR], message));
}
Exemple #2
0
RestHTTPCode AudioActionHandler::PostMicStream(Variant &params, Variant &message) {
  if (!params.HasKey("enabled")) {
    return SendFailure(HC_400_BAD_REQUEST,
                       EC_109_MISSING_MANDATORY_PARAMETERS,
                       "Missing parameter: enabled", message);
  }
  if (params["enabled"]!=V_BOOL) {
    return SendFailure(HC_400_BAD_REQUEST,
                       EC_109_MISSING_MANDATORY_PARAMETERS,
                       "Invalid parameter type: enabled", message);
  }

  bool enabled=((bool)params["enabled"]);
  if (!_pMICInstance) {
    return SendFailure( HC_503_SERVICE_UNAVAILABLE,
                        EC_401_MIC_DEVICE_NOT_FOUND,
                        "Microphone device not found", message);
  }
  if (enabled) {
    _pMICInstance->Start();
  }
  else {
    _pMICInstance->Stop();
  }

  return HC_202_ACCEPTED;
}
Exemple #3
0
void ServiceTimer::OnCmdFinished(uint32_t msgId, uint8_t* pData,
                                 uint32_t dataLength) {
#define CAM_AGENT "camAgent"
  string result((char*)pData, dataLength);
  Variant data;
  uint32_t start=0;
  _msgId=0;

  if (!Variant::DeserializeFromJSON(result, data, start)) {
    WARN ("invalid service json");
    return;
  }
  if (data!=V_MAP) {
    WARN ("invalid service addr");
    return;
  }

  if (data.HasKey(CAM_AGENT) && data[CAM_AGENT]==V_STRING) {
    string addr=(string)data[CAM_AGENT];
    _wsParams.uri= addr+"/?cuid="+SystemManager::GetCUID()+"&hv="+ _token;
  }
  else {
    WARN ("invalid service addr");
  }
}
//private
bool QICStreamerApplication::InitCloudService() {

    return true;
  if (SystemManager::IsFactoryMode()) {
    return true;
  }

  uint32_t timeout=stringToNum<uint32_t>(SystemManager::GetNVRam(NVRAM_NETWORK_WS_TIMEOUT));
  bool cloudEnabled=stringToNum<bool>(SystemManager::GetNVRam(NVRAM_NETWORK_CLOUD_ENABLED));
  bool isSSL=true;
  string serverAgent=SystemManager::GetNVRam(NVRAM_NETWORK_CLOUD_SERVERAGENT);
  string regAgent=SystemManager::GetNVRam(NVRAM_NETWORK_CLOUD_REGAGENT);
  string defaultServer;

  if (!_pWSOutHandler)
    return false;
  if (!_configuration.HasKey("defaultConfig"))
    return false;

  Variant defaultConfig = _configuration["defaultConfig"];

  if (defaultConfig.HasKey("cloud", false)) {
    Variant cloudConfig = defaultConfig["cloud"];
    FOR_MAP (cloudConfig, string, Variant, i) {
        BaseServiceTimer* pServiceTimer=NULL;
        ws_param_t wsParam=
          {cloudEnabled, false, isSSL, 0, 0, timeout, defaultServer, ""};

        Variant temp = MAP_VAL(i);
        if (temp.HasKey(CONF_CLOUD_CONNECTNAME)) {
          wsParam.name = (string)temp[CONF_CLOUD_CONNECTNAME];
        }

        if (temp.HasKey(CONF_CLOUD_ISREG)) {
          wsParam.isReg= true;
          wsParam.enabled=true;
          if (!SystemManager::GetCUID().empty() && !SystemManager::GetPrivateKey().empty())
            continue;
          pServiceTimer = new RegServiceTimer (this, wsParam, regAgent);
        }
        else {
          pServiceTimer = new ServiceTimer (this, wsParam, serverAgent);
        }

        pServiceTimer->EnqueueForTimeEvent(1);
        _pWSOutHandler->RegisterServiceTimer(wsParam.name, pServiceTimer);
    } //for map
Exemple #5
0
RestHTTPCode AudioActionHandler::PostSpeakerVolume(Variant &params, Variant &message) {
  if (!_pSpeakerInstance) {
    return SendFailure( HC_503_SERVICE_UNAVAILABLE,
                        EC_402_SPEAKER_DEVICE_NOT_FOUND,
                        "Speaker device not found", message);
  }
  if (params.HasKey("volume")) {
    uint32_t volume = (uint32_t) atoi(STR(params["volume"]));
    _pSpeakerInstance->SetVolume(volume);
  }
  return HC_202_ACCEPTED;
}
bool QICStreamerApplication::PushLocalStream(Variant streamConfig) {
  // check streamName
  if(!streamConfig.HasKey("targetStreamName")){
    INFO("Unable to find targetStreamName");
    return false;
  }
  //3. do handshake for live avc stream
  _liveAVCStream.status = LSS_HANDSHAKE;
  _liveAVCStream.streamName = (string) streamConfig["targetStreamName"];

  return BaseClientApplication::PushLocalStream(streamConfig);
}
bool UDSCommandAppProtocolHandler::OnMessage(BaseUDSMessageProtocol *pProtocol, Variant &message)
{
  if(!message.HasKey("type") && !message.HasKey("id")) {
    FATAL("Unable to get message type or thread id\n%s", STR(message.ToString()));
    return false;
  }
  if(((uint8_t)message["type"]) == UDSCommandThread::MM_THREAD_CREATED) {
    uint32_t threadId = (uint32_t) message["id"];
    UDSCommandThread *pThread = (UDSCommandThread*)ThreadManager::FindThreadById(threadId);
    if(pThread == NULL) {
      FATAL("Unable to find thread by id(%d)", threadId);
      return false;
    }
    pThread->SetUDSMessageProtocol(pProtocol);
    ThreadManager::EnqueueThread(pThread->GetType(), pThread);
    //INFO("set protocol");
    //pThread->SetUDSMessageProtocol(pProtocol);
  }else{
    FATAL("Unable to handle this message type");
    return false;
  }
  return true;
}
Exemple #8
0
RestHTTPCode AudioActionHandler::PostSpeakerDevice(Variant &params, Variant &message) {
  if (!_pSpeakerInstance) {
    return SendFailure( HC_503_SERVICE_UNAVAILABLE,
                        EC_402_SPEAKER_DEVICE_NOT_FOUND,
                        "Speaker device not found", message);
  }
  if (params.HasKey("enabled")) {
    bool enabled=(string)params["enabled"]=="true";
    if (enabled) {
      _pSpeakerInstance->Open();
    }
    else {
      _pSpeakerInstance->Close();
    }
  }
  return HC_202_ACCEPTED;
}
Exemple #9
0
RestHTTPCode AudioActionHandler::PostSpeakerStream(Variant &params, Variant &message) {
  if (!params.HasKey("enabled")) {
    return SendFailure(HC_400_BAD_REQUEST,
                       EC_109_MISSING_MANDATORY_PARAMETERS,
                       "Missing parameter: enabled", message);
  }

  bool enabled=((string)params["enabled"])=="true";
  if (!_pSpeakerInstance) {
    return SendFailure( HC_503_SERVICE_UNAVAILABLE,
                        EC_402_SPEAKER_DEVICE_NOT_FOUND,
                        "Speaker device not found", message);
  }
  if (enabled) {
    _pSpeakerInstance->Start();
  }
  else {
    _pSpeakerInstance->Stop();
  }

  return HC_202_ACCEPTED;
}
Exemple #10
0
RestHTTPCode AudioActionHandler::PlayFile(Variant &parameters, Variant &message) {

  if (!_pSpeakerInstance) {
    return SendFailure( HC_503_SERVICE_UNAVAILABLE,
                        EC_402_SPEAKER_DEVICE_NOT_FOUND,
                        "Speaker device not found", message);
  }
  if (!parameters.HasKey("filename")) {
    return SendFailure(HC_400_BAD_REQUEST,
        (RestErrorCode)(EC_109_MISSING_MANDATORY_PARAMETERS),
        "Missing parameter: filename", message);
  }

  string filename = (string)parameters["filename"];
  string fullpath=_filePath+"/"+filename;
  DEBUG ("filepath:%s", STR(fullpath));
  if (!fileExists(fullpath)) {
    return SendFailure(HC_400_BAD_REQUEST, EC_404_SPEAKER_FILE_NOT_FOUND,
        "File not exists", message);
  }

  if (_pSpeakerInstance->IsStart()) {
    return SendFailure(HC_400_BAD_REQUEST, EC_403_SPEAKER_PLAYING,
                       "Speaker is playing...", message);
  }

  if (!_pSpeakerInstance->LinkFileStream(fullpath)) {
    return SendFailure(HC_400_BAD_REQUEST, EC_406_SPEAKER_LINK_STREAM,
                       "Unable to link audio data", message);
  }

  if (!_pSpeakerInstance->Play()) {
    return SendFailure(HC_400_BAD_REQUEST, EC_405_SPEAKER_DEVICE_PLAY,
                       "Unable to play audio", message);
  }
  return HC_200_OK;
}
Exemple #11
0
bool AMF0Serializer::WriteObject(IOBuffer &buffer, Variant &variant,
		bool writeType) {

	if (writeType)
		buffer.ReadFromRepeat(AMF0_OBJECT, 1);

	Variant temp = variant;

	FOR_VECTOR_ITERATOR(string, _keysOrder, i) {
		if (temp.HasKey(VECTOR_VAL(i))) {
			if (!WriteShortString(buffer, VECTOR_VAL(i), false)) {
				FATAL("Unable to serialize key");
				return false;
			}
			if (!Write(buffer, temp[VECTOR_VAL(i)])) {
				FATAL("Unable to serialize value");
				return false;
			}
			temp.RemoveKey(VECTOR_VAL(i));
		}
	}

	FOR_MAP(temp, string, Variant, i) {
		string key = MAP_KEY(i);
		if (key.find(VAR_INDEX_VALUE) == 0) {
			key = key.substr(VAR_INDEX_VALUE_LEN);
		}
		if (!WriteShortString(buffer, key, false)) {
			FATAL("Unable to serialize key");
			return false;
		}
		if (!Write(buffer, MAP_VAL(i))) {
			FATAL("Unable to serialize value");
			return false;
		}
	}
Exemple #12
0
bool AMF0Serializer::WriteObject(IOBuffer &buffer, Variant &variant,
		bool writeType) {

	if (writeType)
		buffer.ReadFromRepeat(AMF0_OBJECT, 1);

	Variant temp = variant;

	FOR_VECTOR_ITERATOR(string, _keysOrder, i) {
		if (temp.HasKey(VECTOR_VAL(i))) {
			if (!WriteShortString(buffer, VECTOR_VAL(i), false)) {
				FATAL("Unable to serialize key");
				return false;
			}
			if (!Write(buffer, temp[VECTOR_VAL(i)])) {
				FATAL("Unable to serialize value");
				return false;
			}
			temp.RemoveKey(VECTOR_VAL(i));
		}
	}

	FOR_MAP(temp, string, Variant, i) {
		string key = MAP_KEY(i);
		if ((key.length() == 10) && (key[0] == '0') && (key[1] == 'x')) {
			key = format("%"PRIu32, (uint32_t) strtol(key.c_str(), NULL, 16));
		}
		if (!WriteShortString(buffer, key, false)) {
			FATAL("Unable to serialize key");
			return false;
		}
		if (!Write(buffer, MAP_VAL(i))) {
			FATAL("Unable to serialize value");
			return false;
		}
	}
Exemple #13
0
bool SDP::ParseTransportLinePart(string raw, Variant &result) {
	result.Reset();
	result["original"] = raw;

	//1. split after ';'
	vector<string> parts;
	split(raw, ";", parts);

	//2. Construct the result
	for (uint32_t i = 0; i < parts.size(); i++) {
		string part = parts[i];
		trim(part);
		if (part == "")
			continue;
		string::size_type pos = part.find('=');
		if (pos == string::npos) {
			result[lowerCase(part)] = (bool)true;
			continue;
		}
		result[lowerCase(part.substr(0, pos))] = part.substr(pos + 1);
	}

	vector<string> keys;
	ADD_VECTOR_END(keys, "client_port");
	ADD_VECTOR_END(keys, "server_port");
	ADD_VECTOR_END(keys, "interleaved");

	for (uint32_t i = 0; i < keys.size(); i++) {
		string key = keys[i];
		if (!result.HasKey(key))
			continue;
		parts.clear();
		raw = (string) result[key];
		split(raw, "-", parts);
		if ((parts.size() != 2) && (parts.size() != 1)) {
			FATAL("Invalid transport line: %s", STR(raw));
			return false;
		}
		string all = "";
		uint16_t data = 0;
		uint16_t rtcp = 0;
		if (parts.size() == 2) {
			data = (uint16_t) atoi(STR(parts[0]));
			rtcp = (uint16_t) atoi(STR(parts[1]));
			if (((data % 2) != 0) || ((data + 1) != rtcp)) {
				FATAL("Invalid transport line: %s", STR(raw));
				return false;
			}
			all = format("%"PRIu16"-%"PRIu16, data, rtcp);
		} else {
			data = (uint16_t) atoi(STR(parts[0]));
			all = format("%"PRIu16, data);
			rtcp = 0;
		}
		if (all != raw) {
			FATAL("Invalid transport line: %s", STR(raw));
			return false;
		}
		result.RemoveKey(key);
		result[key]["data"] = (uint16_t) data;
		result[key]["rtcp"] = (uint16_t) rtcp;
		result[key]["all"] = all;
	}

	return true;
}
Exemple #14
0
bool PopVariant(lua_State *pLuaState, Variant &variant, int32_t idx, bool pop) {
	variant.Reset();
	int32_t type = lua_type(pLuaState, idx);
	switch (type) {
		case LUA_TNIL:
		{
			variant.Reset();
			if (pop)
				lua_remove(pLuaState, idx);
			break;
		}
		case LUA_TBOOLEAN:
		{
			variant = (bool)(lua_toboolean(pLuaState, idx) != 0);
			if (pop)
				lua_remove(pLuaState, idx);
			break;
		}
		case LUA_TNUMBER:
		{
			lua_Number luaNumber = lua_tonumber(pLuaState, idx);
			if (pop)
				lua_remove(pLuaState, idx);
			variant = (double) luaNumber;
			variant.Compact();

			break;
		}
		case LUA_TSTRING:
		{
			string nullable = lua_tostring(pLuaState, idx);
			if (pop)
				lua_remove(pLuaState, idx);
			if (nullable == VAR_NULL_VALUE)
				variant = Variant();
			else
				variant = nullable;
			break;
		}
		case LUA_TTABLE:
		{
			bool isArray = true;
			lua_pushnil(pLuaState);
			while (lua_next(pLuaState, idx) != 0) {
				Variant value;
				if (!PopVariant(pLuaState, value, lua_gettop(pLuaState)))
					return false;

				Variant key;
				if (!PopVariant(pLuaState, key, lua_gettop(pLuaState), false))
					return false;

				variant[key] = value;
				isArray &= (key == _V_NUMERIC);
			}

			variant.IsArray(isArray);

			if (variant.HasKey(VAR_MAP_NAME)) {
				variant.SetTypeName(variant[VAR_MAP_NAME]);
				variant.RemoveKey(VAR_MAP_NAME);
			} else {
				variant.ConvertToTimestamp();
			}
			if (pop)
				lua_remove(pLuaState, idx);
			break;
		}
		default:
		{
			WARN("Element type not supported: %d (0x%x)", type, type);
			return false;
			break;
		}
	}
	return true;
}