コード例 #1
0
ファイル: Parser.cpp プロジェクト: BlackHoleJet/freeze
void
Parser::write(std::list<string>& args)
{
    DirectoryPrx dir = _dirs.front();
    string name = args.front();
    args.pop_front();
    NodeDesc d;
    try
    {
        d = dir->find(name);
    }
    catch(const NoSuchName&)
    {
        cout << "`" << name << "': no such file" << endl;
        return;
    }
    if(d.type == DirType)
    {
        cout << "`" << name << "': not a file" << endl;
        return;
    }
    FilePrx f = FilePrx::uncheckedCast(d.proxy);

    Lines l;
    for(std::list<string>::const_iterator i = args.begin(); i != args.end(); ++i)
    {
        l.push_back(*i);
    }
    f->write(l);
}
コード例 #2
0
ファイル: Parser.cpp プロジェクト: BlackHoleJet/freeze
void
Parser::cat(const string& name)
{
    DirectoryPrx dir = _dirs.front();
    NodeDesc d;
    try
    {
        d = dir->find(name);
    }
    catch(const NoSuchName&)
    {
        cout << "`" << name << "': no such file" << endl;
        return;
    }
    if(d.type == DirType)
    {
        cout << "`" << name << "': not a file" << endl;
        return;
    }
    FilePrx f = FilePrx::uncheckedCast(d.proxy);
    Lines l = f->read();
    for(Lines::const_iterator i = l.begin(); i != l.end(); ++i)
    {
        cout << *i << endl;
    }
}
コード例 #3
0
ファイル: Client.cpp プロジェクト: 2008hatake/zeroc-ice
static void
listRecursive(const DirectoryPrx& dir, int depth = 0)
{
    string indent(++depth, '\t');

    NodeSeq contents = dir->list();

    for(NodeSeq::const_iterator i = contents.begin(); i != contents.end(); ++i)
    {
        DirectoryPrx dir = DirectoryPrx::checkedCast(*i);
        FilePrx file = FilePrx::uncheckedCast(*i);
        cout << indent << (*i)->name() << (dir ? " (directory):" : " (file):") << endl;
        if(dir)
        {
            listRecursive(dir, depth);
        }
        else
        {
            Lines text = file->read();
            for(Lines::const_iterator j = text.begin(); j != text.end(); ++j)
            {
                cout << indent << "\t" << *j << endl;
            }
        }
    }
}
コード例 #4
0
ファイル: Parser.cpp プロジェクト: BlackHoleJet/freeze
void
Parser::destroy(const std::list<string>& names)
{
    DirectoryPrx dir = _dirs.front();

    for(std::list<string>::const_iterator i = names.begin(); i != names.end(); ++i)
    {
        if(*i == "*")
        {
            NodeDescSeq nodes = dir->list();
            for(NodeDescSeq::iterator j = nodes.begin(); j != nodes.end(); ++j)
            {
                try
                {
                    j->proxy->destroy();
                }
                catch(const PermissionDenied& ex)
                {
                    cout << "cannot remove `" << j->name << "': " << ex.reason << endl;
                }
            }
            return;
        }
        else
        {
            NodeDesc d;
            try
            {
                d = dir->find(*i);
            }
            catch(const NoSuchName&)
            {
                cout << "`" << *i << "': no such file or directory" << endl;
                return;
            }
            try
            {
                d.proxy->destroy();
            }
            catch(const PermissionDenied& ex)
            {
                cout << "cannot remove `" << *i << "': " << ex.reason << endl;
            }
        }
    }
}
コード例 #5
0
ファイル: Parser.cpp プロジェクト: BlackHoleJet/freeze
void
Parser::cd(const string& name)
{
    if(name == "/")
    {
       while(_dirs.size() > 1)
       {
           _dirs.pop_front();
       }
       return;
    }

    if(name == "..")
    {
       if(_dirs.size() > 1)
       {
           _dirs.pop_front();
       }
       return;
    }

    DirectoryPrx dir = _dirs.front();
    NodeDesc d;
    try
    {
        d = dir->find(name);
    }
    catch(const NoSuchName&)
    {
        cout << "`" << name << "': no such directory" << endl;
        return;
    }
    if(d.type == FileType)
    {
        cout << "`" << name << "': not a directory" << endl;
        return;
    }
    _dirs.push_front(DirectoryPrx::uncheckedCast(d.proxy));
}
コード例 #6
0
ファイル: Parser.cpp プロジェクト: BlackHoleJet/freeze
void
Parser::createFile(const std::list<string>& names)
{
    DirectoryPrx dir = _dirs.front();

    for(std::list<string>::const_iterator i = names.begin(); i != names.end(); ++i)
    {
        if(*i == "..")
        {
            cout << "Cannot create a file named `..'" << endl;
            continue;
        }

        try
        {
            dir->createFile(*i);
        }
        catch(const NameInUse&)
        {
            cout << "`" << *i << "' exists already" << endl;
        }
    }
}
コード例 #7
0
ファイル: Parser.cpp プロジェクト: BlackHoleJet/freeze
void
Parser::list(const DirectoryPrx& dir, bool recursive, int depth)
{
    string indent(depth++, '\t');

    NodeDescSeq contents = dir->list();

    for(NodeDescSeq::const_iterator i = contents.begin(); i != contents.end(); ++i)
    {
        DirectoryPrx d = i->type == DirType ? DirectoryPrx::uncheckedCast(i->proxy) : (DirectoryPrx)0;
        cout << indent << i->name << (d ? " (directory)" : " (file)");
        if(d && recursive)
        {
            cout << ":" << endl;
            list(d, true, depth);
        }
        else
        {
            cout << endl;
        }
    }
}
コード例 #8
0
ファイル: aghphonedialog.cpp プロジェクト: fffaraz/Multimedia
void AghPhoneDialog::menuTriggered(QAction *action) {
	cout << action->text().toLocal8Bit().data() << endl;
	QString operation = action->text();

	if (operation == "Preferences") {
		prefDialog->exec();
		prefDialog->updateConfiguration();
		configuration->saveConf();
	} else if (operation == "Close") {
		terminateApplication();
	} else if (operation == "Search in directory") {
		searchDir->exec();
		TerminalAddress *foundTerminal = searchDir->getSelectedTerminal();

		// check whether terminal was selected
		if (foundTerminal == NULL) {
			return;
		}

		QString foundTermName = foundTerminal->name.c_str();
		foundTermName += ":";
		foundTermName += foundTerminal->port.c_str();
		if (foundTerminal != 0) {
			this->putTerminalIntoList(foundTerminal, foundTermName);
		}
	} else if (operation == "Log in") {
		registeredAddress = new TerminalAddress;

		if (isRegistered) {
			QMessageBox::critical( this, this->windowTitle(),
					"User already registered");
			return;
		}

		if (this->configuration->directoryAlias->size() <= 0) {
			QMessageBox::critical( this, this->windowTitle(),
					"User alias not specified! Check your configuration.");
			return;
		}

		if (this->configuration->localPort->size() <= 0) {
			QMessageBox::critical( this, this->windowTitle(),
					"Local port not specified! Check your configuration.");
			return;
		}

		registeredAddress->name = *(this->configuration->directoryAlias);
		registeredAddress->port = *(this->configuration->localPort);

		// Get directory reference
		QString errorMessage = this->configuration->validateDirectory().c_str();

		if (errorMessage.count() > 0) {
			QMessageBox::critical( this, this->windowTitle(),
					errorMessage);

		} else {
			// search for directory
			try {
				Ice::CommunicatorPtr ic = Ice::initialize();
				stringstream a;
				a << *(configuration->directoryName)
				<< ":default -h " << *(configuration->directoryAddress)
				<< " -p " << *(configuration->directoryPort);
				Ice::ObjectPrx base = ic->stringToProxy ( a.str() );
				DirectoryPrx directory = DirectoryPrx::checkedCast ( base );

				if ( !directory ) {
					QMessageBox::critical( this, this->windowTitle(),
							"Connection to directory failed, please check your configuration!");
				} else {
					directory->registerTerminal(*registeredAddress);
					isRegistered = true;


					QString message("Terminal ");
					message += registeredAddress->name.c_str();
					message += " successfully registered.";
					statusbar->showMessage(message, 5000);
				}

				ic->destroy();

			} catch (TerminalExistsException ex) {
				QMessageBox::critical( this, this->windowTitle(),
						"User already registered, change your alias!");
				return;
			}  catch (...) {
				QMessageBox::critical( this, this->windowTitle(),
						"Connection to directory failed, please check your configuration!");
				return;
			}
		}

	} else if (operation == "Log out") {

		if (!isRegistered) {
			QMessageBox::critical( this, this->windowTitle(),
					"User not registered");
			return;
		}

		// Get directory reference
		QString errorMessage = this->configuration->validateDirectory().c_str();

		if (errorMessage.count() > 0) {
			QMessageBox::critical( this, this->windowTitle(),
					errorMessage);

		} else {
			// search for directory
			try {
				Ice::CommunicatorPtr ic = Ice::initialize();
				stringstream a;
				a << *(configuration->directoryName)
				<< ":default -h " << *(configuration->directoryAddress)
				<< " -p " << *(configuration->directoryPort);
				Ice::ObjectPrx base = ic->stringToProxy ( a.str() );
				DirectoryPrx directory = DirectoryPrx::checkedCast ( base );

				if ( !directory ) {
					QMessageBox::critical( this, this->windowTitle(),
							"Connection to directory failed, please check your configuration!");
				} else {
					directory->removeTerminal(registeredAddress->name);

					QString message("Terminal ");
					message += registeredAddress->name.c_str();
					message += " successfully unregistered.";
					statusbar->showMessage(message, 5000);

					delete registeredAddress;
					isRegistered = false;
				}

				ic->destroy();

			} catch (NoSuchTerminalException ex) {
				QMessageBox::critical( this, this->windowTitle(),
						"Such user does not exists in directory!");
			}  catch (...) {
				QMessageBox::critical( this, this->windowTitle(),
						"Connection to directory failed, please check your configuration!");
				return;
			}
		}
	} else if (operation == "About") {
		QString about;
		QDate curDate = QDate::currentDate();
		about += "AGHPhone VoIP application\n";
		about += "\n\nVersion 0.9.0.2b from ";
		about += curDate.toString();
		about += "\n\nCopyright (C) 2008  Mateusz Kramarczyk <*****@*****.**>\n";
		about += "Copyright (C) 2008  Tomasz Kijas <*****@*****.**>\n";
		about += "Copyright (C) 2008  Tomir Kryza <*****@*****.**>\n";
		about += "Copyright (C) 2008  Maciej Kluczny <*****@*****.**>\n";
		about += "Copyright (C) 2008  AGH University of Science and Technology <www.agh.edu.pl>\n";
		QMessageBox::about(this, "About AGHPhone", about);
	} else if (operation == "About Qt") {
		QMessageBox::aboutQt(this, "About Qt");
	} else if (operation == "License") {
		QString msg;
		msg += "This program is free software: you can redistribute it and/or modify\n";
		msg += "it under the terms of the GNU General Public License as published by\n";
		msg += "the Free Software Foundation, either version 3 of the License, or\n";
		msg += "(at your option) any later version.\n";
		msg += "\n";
		msg += "This program is distributed in the hope that it will be useful,\n";
		msg += "but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
		msg += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
		msg += "GNU General Public License for more details.\n";
		msg += "\n";
		msg += "You should have received a copy of the GNU General Public License\n";
		msg += "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n";

		QMessageBox::about(this, "AGHPhone license regulations", msg);
	}
}
コード例 #9
0
ファイル: mixer.cpp プロジェクト: fffaraz/Multimedia
int main(int argc, char **argv) {

	int lIcePort;
	int lRtpPort;
	int rDirPort;
	string rDirAddr;
	string alias;
	DirectoryPrx directory;

	if (argc < 6) {
		cout << "bad usage:\n\n";
		cout << "\t\tprogram lIcePort lRtpPort rDirPort rDirAddr alias\n\n";
		return 0;
	}

	/* arguments */
	lIcePort = atoi(argv[1]);
	lRtpPort = atoi(argv[2]);
	rDirPort = atoi(argv[3]);
	rDirAddr.append(argv[4]);
	alias.append(argv[5]);

	try {
		/* locate directory */
		Ice::CommunicatorPtr ic = Ice::initialize ();
		stringstream a;
		a << string("Directory") << ":default -h " << rDirAddr << " -p " << rDirPort;
		Ice::ObjectPrx base = ic->stringToProxy ( a.str() );
		directory = DirectoryPrx::checkedCast ( base );
		if ( !directory )
			throw "Invalid proxy";
		/* log in */
		TerminalAddress address;
		address.name = alias;
		std::ostringstream o2;
		o2 << string("") << lIcePort;
		address.port = o2.str();
		address.type = MCUTERMINAL;

		try {
			directory->registerTerminal(address);
		} catch(BadLoginException e) {
			cerr << "Bad login\n";
		} catch(TerminalExistsException e) {
			cerr << "Terminal already exists\n";
		}

	} catch(...) {
		clog << "Directory lookup error" << endl;
	}

	try {
		// Set up a simple configuration that logs on the console.
		BasicConfigurator::configure();
	} catch(log4cxx::helpers::Exception& e) {
		clog << "severe error" << endl;
	}

	Mixer m(lIcePort);
	m.setLocalRtpPort(lRtpPort);
}