Пример #1
0
bool
Opal::Sip::EndPoint::populate_menu (const std::string& fullname,
				    const std::string& uri,
				    Ekiga::MenuBuilder& builder)
{
  if (0 == GetConnectionCount ())
    builder.add_action ("phone-pick-up", _("Call"),
			boost::bind (&Opal::Sip::EndPoint::on_dial, this, uri));
  else
    builder.add_action ("mail-forward", _("Transfer"),
			boost::bind (&Opal::Sip::EndPoint::on_transfer, this, uri));
  builder.add_action ("im-message-new", _("Message"),
		      boost::bind (&Opal::Sip::EndPoint::on_message, this, uri, fullname));

  return true;
}
Пример #2
0
int main() {
	WSAStartup(MAKEWORD(2, 2), &wsa);
	s = socket(AF_INET, SOCK_DGRAM, 0);

	server.sin_family = AF_INET;
	server.sin_addr.s_addr = INADDR_ANY;
	server.sin_port = htons(PORT);

	bind(s, (struct sockaddr *)&server, sizeof(server));

	GenerateMap();

	while (isRunning) {
		incrementIndex = -1;

		memset(buf, '\0', BUFLEN);
		recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *)&tempClient.address, &tempClient.addrLength);

		for (int x = 0; x < clientList.size(); x++) {
			if (tempClient.address.sin_port == clientList[x].address.sin_port) incrementIndex = x;
		}

		std::string tempMessage = "";

		switch (ProcessCommand(buf)) {
			case 0 :
				tempClient.uniqueID = incrementID;
				incrementID += 1;

				if (AddConnection(tempClient)) SendMessage("connect", tempClient);

				std::cout << GetConnectionCount() << "/" << maxConnections << std::endl;
				break;
			case 1:
				SendMap(clientList[incrementIndex]);
				break;
			case 2:
				InitializePlayer(clientList[incrementIndex]);

				tempMessage += "advert<position>" + std::to_string((int)clientList[incrementIndex].uniqueID) + ":";
				tempMessage += std::to_string((int)clientList[incrementIndex].player.position.x) + "," + std::to_string((int)clientList[incrementIndex].player.position.y);

				char tempMessageChar[BUFLEN];
				strcpy(tempMessageChar, tempMessage.c_str());
				SendMessage(tempMessageChar, clientList[incrementIndex], clientList);

				break;
			case 3:
				RequestPlayer(clientList[incrementIndex]);
				break;
			case 4:
				UpdatePosition(clientList[incrementIndex], buf);
				break;
		}

		std::cout << buf << std::endl;
	}

	closesocket(s);
	WSACleanup();

	return 0;
}
Пример #3
0
bool Opal::Sip::EndPoint::menu_builder_add_actions (const std::string& fullname,
                                                    const std::string& uri,
                                                    Ekiga::MenuBuilder & builder)
{
  bool populated = false;


  std::list<std::string> uris;
  std::list<std::string> accounts;

  if (!(uri.find ("sip:") == 0 || uri.find (":") == string::npos))
    return false;

  if (uri.find ("@") == string::npos) {

    Opal::Bank *bank = dynamic_cast<Opal::Bank*> (core.get ("opal-account-store"));

    if (bank) {

      for (Opal::Bank::iterator it = bank->begin ();
           it != bank->end ();
           it++) {

        if (it->get_protocol_name () == "SIP" && it->is_active ()) {

          std::stringstream uristr;
          std::string str = uri;

          for (unsigned i = 0 ; i < str.length() ; i++) {

            if (str [i] == ' ' || str [i] == '-') {
              str.erase (i,1);
              i--;
            }
          }

          if (str.find ("sip:") == string::npos)
            uristr << "sip:" << str;
          else
            uristr << str;

          uristr << "@" << it->get_host ();

          uris.push_back (uristr.str ());
          accounts.push_back (it->get_name ());
        }
      }
    }
  }
  else {
    uris.push_back (uri);
    accounts.push_back ("");
  }

  std::list<std::string>::iterator ita = accounts.begin ();
  for (std::list<std::string>::iterator it = uris.begin ();
       it != uris.end ();
       it++) {

    std::stringstream call_action;
    std::stringstream transfer_action;
    if (!(*ita).empty ()) {
      call_action << _("Call") << " [" << (*ita) << "]";
      transfer_action << _("Transfer") << " [" << (*ita) << "]";
    }
    else {
      call_action << _("Call");
      transfer_action << _("Transfer");
    }

    if (0 == GetConnectionCount ())
      builder.add_action ("call", call_action.str (),
                          sigc::bind (sigc::mem_fun (this, &Opal::Sip::EndPoint::on_dial), (*it)));
    else 
      builder.add_action ("transfer", transfer_action.str (),
                          sigc::bind (sigc::mem_fun (this, &Opal::Sip::EndPoint::on_transfer), (*it)));

    ita++;
  }

  ita = accounts.begin ();
  for (std::list<std::string>::iterator it = uris.begin ();
       it != uris.end ();
       it++) {

    std::stringstream msg_action;
    if (!(*ita).empty ()) 
      msg_action << _("Message") << " [" << (*ita) << "]";
    else
      msg_action << _("Message");

    builder.add_action ("message", msg_action.str (),
                        sigc::bind (sigc::mem_fun (this, &Opal::Sip::EndPoint::on_message), (*it), fullname));

    ita++;
  }

  populated = true;

  return populated;
}
Пример #4
0
bool BaseSignal::Empty() const
{
  return ( 0 == GetConnectionCount() );
}