ekiga r7830 - in trunk/lib/engine/components: avahi evolution local-roster
- From: jpuydt svn gnome org
- To: svn-commits-list gnome org
- Subject: ekiga r7830 - in trunk/lib/engine/components: avahi evolution local-roster
- Date: Sun, 29 Mar 2009 08:38:21 +0000 (UTC)
Author: jpuydt
Date: Sun Mar 29 08:38:21 2009
New Revision: 7830
URL: http://svn.gnome.org/viewvc/ekiga?rev=7830&view=rev
Log:
Removed all uses of iterators, as they're my prime suspects for crashes
Modified:
trunk/lib/engine/components/avahi/avahi-heap.cpp
trunk/lib/engine/components/evolution/evolution-book.cpp
trunk/lib/engine/components/evolution/evolution-source.cpp
trunk/lib/engine/components/local-roster/local-heap.cpp
Modified: trunk/lib/engine/components/avahi/avahi-heap.cpp
==============================================================================
--- trunk/lib/engine/components/avahi/avahi-heap.cpp (original)
+++ trunk/lib/engine/components/avahi/avahi-heap.cpp Sun Mar 29 08:38:21 2009
@@ -225,6 +225,33 @@
}
}
+class resolver_callback_helper
+{
+public:
+
+ resolver_callback_helper (const std::string name_): name(name_)
+ {}
+
+ bool test (gmref_ptr<Ekiga::URIPresentity> presentity_)
+ {
+ bool result;
+
+ if (presentity_->get_name () == name) {
+
+ presentity = presentity_;
+ result = false;
+ }
+ return result;
+ }
+
+ gmref_ptr<Ekiga::URIPresentity> found_presentity () const
+ { return presentity; }
+
+private:
+ gmref_ptr<Ekiga::URIPresentity> presentity;
+ const std::string name;
+};
+
void
Avahi::Heap::ResolverCallback (AvahiServiceResolver *resolver,
AvahiIfIndex /*interface*/,
@@ -243,13 +270,12 @@
std::string software;
std::string presence;
std::string status;
- bool already_known = false;
gchar *url = NULL;
AvahiStringList *txt_tmp = NULL;
switch (event) {
- case AVAHI_RESOLVER_FOUND:
+ case AVAHI_RESOLVER_FOUND: {
name = name_;
for (txt_tmp = txt; txt_tmp != NULL; txt_tmp = txt_tmp->next) {
@@ -274,19 +300,14 @@
}
}
- for (iterator iter = begin ();
- iter != end ();
- iter++) {
-
- if ((*iter)->get_name () == name) {
-
- /* known contact has been updated */
- presence_received.emit ((*iter)->get_uri (), presence);
- status_received.emit ((*iter)->get_uri (), status);
- already_known = true;
- }
- }
- if (already_known == false) {
+ resolver_callback_helper helper(name);
+ visit_presentities (sigc::mem_fun (helper, &resolver_callback_helper::test));
+ if (helper.found_presentity ()) {
+
+ /* known contact has been updated */
+ presence_received.emit (helper.found_presentity ()->get_uri (), presence);
+ status_received.emit (helper.found_presentity ()->get_uri (), status);
+ } else {
/* ok, this is a new contact */
gchar** broken = NULL;
@@ -305,7 +326,7 @@
}
g_strfreev (broken);
}
- break;
+ break;}
case AVAHI_RESOLVER_FAILURE:
avahi_service_resolver_free (resolver);
Modified: trunk/lib/engine/components/evolution/evolution-book.cpp
==============================================================================
--- trunk/lib/engine/components/evolution/evolution-book.cpp (original)
+++ trunk/lib/engine/components/evolution/evolution-book.cpp Sun Mar 29 08:38:21 2009
@@ -89,18 +89,38 @@
((Evolution::Book *)data)->on_view_contacts_removed (ids);
}
+class contacts_removed_helper
+{
+public:
+
+ contacts_removed_helper (const std::string id_): id(id_)
+ {}
+
+ bool test (Evolution::ContactPtr contact)
+ {
+ bool result;
+
+ if (contact->get_id () == id) {
+
+ contact->removed.emit ();
+ result = false;
+ }
+
+ return result;
+ }
+
+private:
+ const std::string id;
+};
+
void
Evolution::Book::on_view_contacts_removed (GList *ids)
{
- for (; ids != NULL; ids = g_list_next (ids))
- for (iterator iter = begin ();
- iter != end ();
- iter++)
- if ((*iter)->get_id () == (gchar *)ids->data) {
-
- remove_contact (*iter);
- break; // will do the loop on ids, but stop using iter which is invalid
- }
+ for (; ids != NULL; ids = g_list_next (ids)) {
+
+ contacts_removed_helper helper((gchar*)ids->data);
+ visit_contacts (sigc::mem_fun (helper, &contacts_removed_helper::test));
+ }
}
static void
@@ -111,22 +131,41 @@
((Evolution::Book*)data)->on_view_contacts_changed (econtacts);
}
+class contact_updated_helper
+{
+public:
+
+ contact_updated_helper (EContact* econtact_): econtact(econtact_)
+ {
+ id = (const gchar*)e_contact_get_const (econtact, E_CONTACT_UID);
+ }
+
+ bool test (Evolution::ContactPtr contact)
+ {
+ bool result = true;
+
+ if (contact->get_id () == id) {
+
+ contact->update_econtact (econtact);
+ result = false;
+ }
+
+ return result;
+ }
+
+private:
+ EContact* econtact;
+ std::string id;
+};
+
void
Evolution::Book::on_view_contacts_changed (GList *econtacts)
{
- EContact *econtact = NULL;
-
for (; econtacts != NULL; econtacts = g_list_next (econtacts)) {
- econtact = E_CONTACT (econtacts->data);
+ contact_updated_helper helper (E_CONTACT (econtacts->data));
- for (iterator iter = begin ();
- iter != end ();
- iter++)
-
- if ((*iter)->get_id()
- == (const gchar *)e_contact_get_const (econtact, E_CONTACT_UID))
- (*iter)->update_econtact (econtact);
+ visit_contacts (sigc::mem_fun (helper, &contact_updated_helper::test));
}
}
@@ -262,13 +301,7 @@
void
Evolution::Book::refresh ()
{
- /* we flush */
- iterator iter = begin ();
- while (iter != end ()) {
-
- remove_contact (*iter);
- iter = begin ();
- }
+ remove_all_objects ();
/* we go */
if (e_book_is_opened (book))
Modified: trunk/lib/engine/components/evolution/evolution-source.cpp
==============================================================================
--- trunk/lib/engine/components/evolution/evolution-source.cpp (original)
+++ trunk/lib/engine/components/evolution/evolution-source.cpp Sun Mar 29 08:38:21 2009
@@ -100,36 +100,49 @@
self->remove_group (group);
}
-void
-Evolution::Source::remove_group (ESourceGroup *group)
+class remove_helper
{
- gboolean found = FALSE;
- ESource *book_source = NULL;
- ESourceGroup *book_group = NULL;
- EBook *book_ebook = NULL;
+public :
- do {
+ remove_helper (ESourceGroup* group_): group(group_)
+ { ready (); }
- found = FALSE;
+ inline void ready ()
+ { found = false; }
- for (iterator iter = begin ();
- iter != end ();
- iter++) {
+ bool test (Evolution::BookPtr book)
+ {
+ EBook *book_ebook = book->get_ebook ();
+ ESource *book_source = e_book_get_source (book_ebook);
+ ESourceGroup *book_group = e_source_peek_group (book_source);
- book_ebook = (*iter)->get_ebook ();
+ if (book_group == group) {
- book_source = e_book_get_source (book_ebook);
+ book->removed.emit ();
+ found = true;
+ }
+ return !found;
+ }
- book_group = e_source_peek_group (book_source);
+ bool has_found () const
+ { return found; }
- if (book_group == group) {
+private:
+ ESourceGroup* group;
+ bool found;
+};
- found = TRUE;
- (*iter)->removed.emit ();
- }
- }
+void
+Evolution::Source::remove_group (ESourceGroup *group)
+{
+ remove_helper helper (group);
+
+ do {
+
+ helper.ready ();
+ visit_books (sigc::mem_fun (helper, &remove_helper::test));
- } while (found);
+ } while (helper.has_found ());
}
Evolution::Source::Source (Ekiga::ServiceCore &_services)
Modified: trunk/lib/engine/components/local-roster/local-heap.cpp
==============================================================================
--- trunk/lib/engine/components/local-roster/local-heap.cpp (original)
+++ trunk/lib/engine/components/local-roster/local-heap.cpp Sun Mar 29 08:38:21 2009
@@ -63,7 +63,7 @@
doc = std::tr1::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
if ( !doc)
doc = std::tr1::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
-
+
root = xmlDocGetRootElement (doc.get ());
if (root == NULL) {
@@ -129,32 +129,60 @@
return true;
}
+struct has_presentity_with_uri_helper
+{
+ has_presentity_with_uri_helper (const std::string uri_): uri(uri_),
+ found(false)
+ {}
+
+ const std::string uri;
+
+ bool found;
+
+ bool test (Local::PresentityPtr presentity)
+ {
+ if (presentity->get_uri () == uri) {
+
+ found = true;
+ }
+
+ return !found;
+ }
+};
bool
Local::Heap::has_presentity_with_uri (const std::string uri)
{
- bool result = false;
+ has_presentity_with_uri_helper helper(uri);
- for (iterator iter = begin ();
- iter != end () && result != true;
- iter++)
- result = ((*iter)->get_uri () == uri);
+ visit_presentities (sigc::mem_fun (helper, &has_presentity_with_uri_helper::test));
- return result;
+ return helper.found;
}
+struct existing_groups_helper
+{
+ std::set<std::string> groups;
+
+ bool test (Local::PresentityPtr presentity)
+ {
+ groups.insert (presentity->get_groups ().begin (),
+ presentity->get_groups ().end ());
+
+ return true;
+ }
+};
const std::set<std::string>
Local::Heap::existing_groups ()
{
std::set<std::string> result;
- for (iterator iter = begin ();
- iter != end ();
- iter++) {
+ {
+ existing_groups_helper helper;
- std::set<std::string> groups = (*iter)->get_groups ();
- result.insert (groups.begin (), groups.end ());
+ visit_presentities (sigc::mem_fun (helper, &existing_groups_helper::test));
+ result = helper.groups;
}
result.insert (_("Family"));
@@ -225,31 +253,64 @@
}
}
+struct push_presence_helper
+{
+ push_presence_helper (const std::string uri_,
+ const std::string presence_): uri(uri_),
+ presence(presence_)
+ {}
+
+ bool test (Local::PresentityPtr presentity)
+ {
+ if (presentity->get_uri () == uri) {
+
+ presentity->set_presence (presence);
+ }
+
+ return true;
+ }
+
+ const std::string uri;
+ const std::string presence;
+};
void
Local::Heap::push_presence (const std::string uri,
const std::string presence)
{
- for (iterator iter = begin ();
- iter != end ();
- ++iter) {
+ push_presence_helper helper(uri, presence);
- if ((*iter)->get_uri () == uri)
- (*iter)->set_presence (presence);
- }
+ visit_presentities (sigc::mem_fun (helper, &push_presence_helper::test));
}
+struct push_status_helper
+{
+ push_status_helper (const std::string uri_,
+ const std::string status_): uri(uri_),
+ status(status_)
+ {}
+
+ bool test (Local::PresentityPtr presentity)
+ {
+ if (presentity->get_uri () == uri) {
+
+ presentity->set_status (status);
+ }
+
+ return true;
+ }
+
+ const std::string uri;
+ const std::string status;
+};
+
void
Local::Heap::push_status (const std::string uri,
const std::string status)
{
- for (iterator iter = begin ();
- iter != end ();
- ++iter) {
+ push_status_helper helper(uri, status);
- if ((*iter)->get_uri () == uri)
- (*iter)->set_status (status);
- }
+ visit_presentities (sigc::mem_fun (helper, &push_status_helper::test));
}
@@ -388,6 +449,24 @@
}
}
+struct rename_group_form_submitted_helper
+{
+ rename_group_form_submitted_helper (const std::string old_name_,
+ const std::string new_name_):
+ old_name(old_name_),
+ new_name(new_name_)
+ {}
+
+ const std::string old_name;
+ const std::string new_name;
+
+ bool rename_group (Local::PresentityPtr presentity)
+ {
+ presentity->rename_group (old_name, new_name);
+ return true;
+ }
+};
+
void
Local::Heap::rename_group_form_submitted (std::string old_name,
bool submitted,
@@ -401,12 +480,8 @@
if ( !new_name.empty () && new_name != old_name) {
- for (iterator iter = begin ();
- iter != end ();
- ++iter) {
-
- (*iter)->rename_group (old_name, new_name);
- }
+ rename_group_form_submitted_helper helper (old_name, new_name);
+ visit_presentities (sigc::mem_fun (helper, &rename_group_form_submitted_helper::rename_group));
}
} catch (Ekiga::Form::not_found) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]