int cConnectionManager::GetCurrentConnectionInfo(Upnp_Action_Request* request){

  long id;
  if(ParseIntegerValue(request->ActionRequest, "ConnectionID", id) != UPNP_E_SUCCESS){
    esyslog("UPnP\tInvalid arguments. ConnectionID missing or wrong");
    SetError(request, UPNP_SOAP_E_INVALID_ARGS);
    return request->ErrCode;
  }
  int32_t connectionID = id;

  cVirtualConnection* connection = mVirtualConnections[connectionID];

  if(connection == NULL){
    esyslog("UPnP\tNo valid connection found with given ID=%d!", connectionID);
    SetError(request, UPNP_CMS_E_INVALID_CONNECTION_REFERENCE);
    return request->ErrCode;
  }

  std::stringstream ss;
  ss << "<u:" << request->ActionName << "Response xmlns:u=\"" << GetServiceDescription().serviceType << "\">"
     << "  <ProtocolInfo>" << connection->GetRemoteProtocolInfo() << "</ProtocolInfo>"
     << "  <PeerConnectionManager>" << connection->GetPeerConnectionManager() << "</PeerConnectionManager>"
     << "  <PeerConnectionID>" << connection->GetPeerConnectionID() << "</PeerConnectionID>"
     << "  <Direction>" << connection->GetDirectionString() << "</Direction>"
     << "  <RcsID>" << connection->GetRcsID() << "</RcsID>"
     << "  <AVTransportID>" << connection->GetAVTransportID() << "</AVTransportID>"
     << "  <Status>" << connection->GetStatusString() << "</Status>"
     << "</u:" << request->ActionName << "Response>";

  request->ActionResult = ixmlParseBuffer(ss.str().c_str());
  request->ErrCode = UPNP_E_SUCCESS;
  return request->ErrCode;
}
void my_solarWrapper::Invoke(staff::Operation& rOperation, const std::string& sSessionId, const std::string& sInstanceId)
{
  const staff::DataObject& rRequest = rOperation.Request();
  const std::string& sOperationName = rOperation.GetName();

  if (sOperationName == "GetServiceDescription")
  {
    rOperation.SetResponse(GetServiceDescription());
  }
  else
  if (sOperationName == "CreateInstance")
  {
    staff::ServiceInstanceManager::Inst().CreateServiceInstance(sSessionId, m_sName,
                                                                rRequest.GetChildTextByLocalName("sInstanceId"));
  }
  else
  if (sOperationName == "FreeInstance")
  {
    staff::ServiceInstanceManager::Inst().FreeServiceInstance(sSessionId, m_sName,
                                                              rRequest.GetChildTextByLocalName("sInstanceId"));
  }
  else
  {
    staff::SharedPtr<my_solarImpl> tpServiceImpl = GetImpl(sSessionId, sInstanceId);
    if (sOperationName == "solarcreate")
    {
      rOperation.Result().SetValue(tpServiceImpl->solarcreate());
    }
    else
    if (sOperationName == "solarinit")
    {
      int gen_mode_v = 0;
      int gen_status_v = 0;
      int panel_type_v = 0;
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("gen_mode_v", gen_mode_v), "Invalid value for element gen_mode_v");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("gen_status_v", gen_status_v), "Invalid value for element gen_status_v");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("panel_type_v", panel_type_v), "Invalid value for element panel_type_v");
      rOperation.Result().SetValue(tpServiceImpl->solarinit(gen_mode_v, gen_status_v, panel_type_v));
    }
    else
    if (sOperationName == "solarsync")
    {
      int t0 = 0;
      int t1 = 0;
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("t0", t0), "Invalid value for element t0");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("t1", t1), "Invalid value for element t1");
      rOperation.Result().SetValue(tpServiceImpl->solarsync(t0, t1));
    }
    else
    {
      STAFF_THROW(staff::RemoteException, "Unknown Operation: " + rOperation.GetName());
    }

    rOperation.GetResponse().SetNamespaceUriGenPrefix("http://tempui.org/my_solar");
  }
}
int cConnectionManager::GetProtocolInfo(Upnp_Action_Request* request){
  std::stringstream ss;

  std::string protocolInfo = tools::StringListToCSV(mMediaServer->GetManager().GetSupportedProtocolInfos());

  ss << "<u:" << request->ActionName << "Response xmlns:u=\"" << GetServiceDescription().serviceType << "\">"
     << "  <Source>" << protocolInfo.c_str() << "</Source>"
     << "  <Sink></Sink>"
     << "</u:" << request->ActionName << "Response>";

  request->ActionResult = ixmlParseBuffer(ss.str().c_str());
  request->ErrCode = UPNP_E_SUCCESS;
  return request->ErrCode;
}
int cConnectionManager::GetCurrentConnectionIDs(Upnp_Action_Request* request){
  std::string IDs = this->GetConnectionIDsCVS();
  if(IDs.empty()){
    SetError(request, UPNP_E_INTERNAL_ERROR);
    return request->ErrCode;
  }

  std::stringstream ss;

  ss << "<u:" << request->ActionName << "Response xmlns:u=\"" << GetServiceDescription().serviceType << "\">"
     << "  <ConnectionIDs>" << IDs << "</ConnectionIDs>"
     << "</u:" << request->ActionName << "Response>";

  request->ActionResult = ixmlParseBuffer(ss.str().c_str());
  request->ErrCode = UPNP_E_SUCCESS;
  return request->ErrCode;
}
void my_controllerWrapper::Invoke(staff::Operation& rOperation, const std::string& sSessionId, const std::string& sInstanceId)
{
  const staff::DataObject& rRequest = rOperation.Request();
  const std::string& sOperationName = rOperation.GetName();

  if (sOperationName == "GetServiceDescription")
  {
    rOperation.SetResponse(GetServiceDescription());
  }
  else
  if (sOperationName == "CreateInstance")
  {
    staff::ServiceInstanceManager::Inst().CreateServiceInstance(sSessionId, m_sName,
                                                                rRequest.GetChildTextByLocalName("sInstanceId"));
  }
  else
  if (sOperationName == "FreeInstance")
  {
    staff::ServiceInstanceManager::Inst().FreeServiceInstance(sSessionId, m_sName,
                                                              rRequest.GetChildTextByLocalName("sInstanceId"));
  }
  else
  {
    staff::SharedPtr<my_controllerImpl> tpServiceImpl = GetImpl(sSessionId, sInstanceId);
    if (sOperationName == "COinit")
    {
      double market_init_price = 0;
      int pstate = 0;
      int market_period = 0;
      int control_mode = 0;
      double psetpoint = 0;
      double base_setpoint = 0;
      double heating_base_setpoint = 0;
      double cooling_base_setpoint = 0;
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("market_init_price", market_init_price), "Invalid value for element market_init_price");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("pstate", pstate), "Invalid value for element pstate");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("market_period", market_period), "Invalid value for element market_period");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("control_mode", control_mode), "Invalid value for element control_mode");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("psetpoint", psetpoint), "Invalid value for element psetpoint");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("base_setpoint", base_setpoint), "Invalid value for element base_setpoint");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("heating_base_setpoint", heating_base_setpoint), "Invalid value for element heating_base_setpoint");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("cooling_base_setpoint", cooling_base_setpoint), "Invalid value for element cooling_base_setpoint");
      rOperation.Result().SetValue(tpServiceImpl->COinit(market_init_price, pstate, market_period, control_mode, psetpoint, base_setpoint, heating_base_setpoint, cooling_base_setpoint));
    }
    else
    if (sOperationName == "COpresync")
    {
      double base_setpoint = 0;
      double psetpoint = 0;
      int control_mode = 0;
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("base_setpoint", base_setpoint), "Invalid value for element base_setpoint");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("psetpoint", psetpoint), "Invalid value for element psetpoint");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("control_mode", control_mode), "Invalid value for element control_mode");
      rOperation.Result().SetValue(tpServiceImpl->COpresync(base_setpoint, psetpoint, control_mode));
    }
    else
    if (sOperationName == "COsync")
    {
      double load = 0;
      double demand = 0;
      int pstate = 0;
      double total = 0;
      double target = 0;
      double pAvg = 0;
      double pStd = 0;
      double base_setpoint = 0;
      int control_mode = 0;
      double market_current_frameclearing_price = 0;
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("load", load), "Invalid value for element load");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("demand", demand), "Invalid value for element demand");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("pstate", pstate), "Invalid value for element pstate");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("total", total), "Invalid value for element total");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("target", target), "Invalid value for element target");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("pAvg", pAvg), "Invalid value for element pAvg");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("pStd", pStd), "Invalid value for element pStd");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("base_setpoint", base_setpoint), "Invalid value for element base_setpoint");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("control_mode", control_mode), "Invalid value for element control_mode");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("market_current_frameclearing_price", market_current_frameclearing_price), "Invalid value for element market_current_frameclearing_price");
      rOperation.Result().SetValue(tpServiceImpl->COsync(load, demand, pstate, total, target, pAvg, pStd, base_setpoint, control_mode, market_current_frameclearing_price));
    }
    else
    if (sOperationName == "COpostsync")
    {
      int control_mode = 0;
      double base_setpoint = 0;
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("control_mode", control_mode), "Invalid value for element control_mode");
      STAFF_ASSERT(rRequest.GetChildValueByLocalName("base_setpoint", base_setpoint), "Invalid value for element base_setpoint");
      rOperation.Result().SetValue(tpServiceImpl->COpostsync(control_mode, base_setpoint));
    }
    else
    {
      STAFF_THROW(staff::RemoteException, "Unknown Operation: " + rOperation.GetName());
    }

    rOperation.GetResponse().SetNamespaceUriGenPrefix("http://tempui.org/my_controller");
  }
}
Esempio n. 6
0
INT_PTR CALLBACK
DeleteDialogProc(HWND hDlg,
                 UINT message,
                 WPARAM wParam,
                 LPARAM lParam)
{
    PMAIN_WND_INFO Info = NULL;
    HICON hIcon = NULL;

    /* Get the window context */
    Info = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
                                            GWLP_USERDATA);
    if (Info == NULL && message != WM_INITDIALOG)
    {
        return FALSE;
    }

    switch (message)
    {
        case WM_INITDIALOG:
        {
            LPWSTR lpDescription;

            Info = (PMAIN_WND_INFO)lParam;
            if (Info != NULL)
            {
                SetWindowLongPtrW(hDlg,
                                  GWLP_USERDATA,
                                  (LONG_PTR)Info);

                hIcon = (HICON)LoadImageW(hInstance,
                                          MAKEINTRESOURCE(IDI_SM_ICON),
                                          IMAGE_ICON,
                                          16,
                                          16,
                                          0);
                if (hIcon)
                {
                    SendMessageW(hDlg,
                                 WM_SETICON,
                                 ICON_SMALL,
                                 (LPARAM)hIcon);
                    DestroyIcon(hIcon);
                }

                SendDlgItemMessageW(hDlg,
                                    IDC_DEL_NAME,
                                    WM_SETTEXT,
                                    0,
                                    (LPARAM)Info->pCurrentService->lpDisplayName);

                lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
                if (lpDescription)
                {
                    SendDlgItemMessageW(hDlg,
                                        IDC_DEL_DESC,
                                        WM_SETTEXT,
                                        0,
                                        (LPARAM)lpDescription);
                    HeapFree(ProcessHeap,
                             0,
                             lpDescription);
                }

                return TRUE;
            }

            return FALSE;
        }

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDOK:
                {
                    if (DoDeleteService(Info, hDlg))
                    {
                        (void)ListView_DeleteItem(Info->hListView,
                                                  Info->SelectedItem);
                        UpdateServiceCount(Info);
                    }
                    EndDialog(hDlg,
                              LOWORD(wParam));
                    return TRUE;
                }

                case IDCANCEL:
                {
                    EndDialog(hDlg,
                              LOWORD(wParam));
                    return TRUE;
                }
            }
        }
    }

    return FALSE;
}