evolution-data-server r8723 - trunk/camel



Author: mbarnes
Date: Wed Apr 30 21:46:42 2008
New Revision: 8723
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8723&view=rev

Log:
2008-04-30  Matthew Barnes  <mbarnes redhat com>

	* camel-session.c:
	* camel-session.h:
	Replace assertions with g_return_val_if_fail().
	Clean up coding style in the threading functions.



Modified:
   trunk/camel/ChangeLog
   trunk/camel/camel-session.c
   trunk/camel/camel-session.h

Modified: trunk/camel/camel-session.c
==============================================================================
--- trunk/camel/camel-session.c	(original)
+++ trunk/camel/camel-session.c	Wed Apr 30 21:46:42 2008
@@ -536,12 +536,13 @@
 	CS_CLASS(m->session)->thread_status(m->session, m, what, pc);
 }
 
-static void *session_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size)
+static void *
+session_thread_msg_new (CamelSession *session,
+                        CamelSessionThreadOps *ops,
+                        unsigned int size)
 {
 	CamelSessionThreadMsg *m;
 
-	g_assert(size >= sizeof(*m));
-
 	m = g_malloc0(size);
 	m->ops = ops;
 	m->session = session;
@@ -556,9 +557,12 @@
 	return m;
 }
 
-static void session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg)
+static void
+session_thread_msg_free (CamelSession *session,
+                         CamelSessionThreadMsg *msg)
 {
-	g_assert(msg->ops != NULL);
+	g_return_if_fail (CAMEL_IS_SESSION (session));
+	g_return_if_fail (msg != NULL && msg->ops != NULL);
 
 	d(printf("free message %p session %p\n", msg, session));
 
@@ -578,7 +582,8 @@
 }
 
 static void
-session_thread_proxy(CamelSessionThreadMsg *msg, CamelSession *session)
+session_thread_proxy (CamelSessionThreadMsg *msg,
+                      CamelSession *session)
 {
 	if (msg->ops->receive) {
 		CamelOperation *oldop;
@@ -591,7 +596,10 @@
 	camel_session_thread_msg_free(session, msg);
 }
 
-static int session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags)
+static int
+session_thread_queue (CamelSession *session,
+                      CamelSessionThreadMsg *msg,
+                      int flags)
 {
 	GThreadPool *thread_pool;
 	int id;
@@ -612,7 +620,9 @@
 	return id;
 }
 
-static void session_thread_wait(CamelSession *session, int id)
+static void
+session_thread_wait (CamelSession *session,
+                     int id)
 {
 	int wait;
 
@@ -627,7 +637,11 @@
 	} while (wait);
 }
 
-static void session_thread_status(CamelSession *session, CamelSessionThreadMsg *msg, const char *text, int pc)
+static void
+session_thread_status (CamelSession *session,
+                       CamelSessionThreadMsg *msg,
+                       const char *text,
+                       int pc)
 {
 }
 
@@ -646,13 +660,15 @@
  * Returns a new #CamelSessionThreadMsg
  **/
 void *
-camel_session_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size)
-{
-	g_assert(CAMEL_IS_SESSION(session));
-	g_assert(ops != NULL);
-	g_assert(size >= sizeof(CamelSessionThreadMsg));
+camel_session_thread_msg_new (CamelSession *session,
+                              CamelSessionThreadOps *ops,
+                              unsigned int size)
+{
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+	g_return_val_if_fail (ops != NULL, NULL);
+	g_return_val_if_fail (size >= sizeof (CamelSessionThreadMsg), NULL);
 
-	return CS_CLASS (session)->thread_msg_new(session, ops, size);
+	return CS_CLASS (session)->thread_msg_new (session, ops, size);
 }
 
 /**
@@ -664,13 +680,13 @@
  * msg_new, and must nto have been submitted to any queue function.
  **/
 void
-camel_session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg)
+camel_session_thread_msg_free (CamelSession *session,
+                               CamelSessionThreadMsg *msg)
 {
-	g_assert(CAMEL_IS_SESSION(session));
-	g_assert(msg != NULL);
-	g_assert(msg->ops != NULL);
+	g_return_if_fail (CAMEL_IS_SESSION (session));
+	g_return_if_fail (msg != NULL && msg->ops != NULL);
 
-	CS_CLASS (session)->thread_msg_free(session, msg);
+	CS_CLASS (session)->thread_msg_free (session, msg);
 }
 
 /**
@@ -686,12 +702,14 @@
  * Returns the id of the operation queued
  **/
 int
-camel_session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags)
+camel_session_thread_queue (CamelSession *session,
+                            CamelSessionThreadMsg *msg,
+                            int flags)
 {
-	g_assert(CAMEL_IS_SESSION(session));
-	g_assert(msg != NULL);
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), -1);
+	g_return_val_if_fail (msg != NULL, -1);
 
-	return CS_CLASS (session)->thread_queue(session, msg, flags);
+	return CS_CLASS (session)->thread_queue (session, msg, flags);
 }
 
 /**
@@ -702,14 +720,15 @@
  * Wait on an operation to complete (by id).
  **/
 void
-camel_session_thread_wait(CamelSession *session, int id)
+camel_session_thread_wait (CamelSession *session,
+                           int id)
 {
-	g_assert(CAMEL_IS_SESSION(session));
+	g_return_if_fail (CAMEL_IS_SESSION (session));
 
 	if (id == -1)
 		return;
 
-	CS_CLASS (session)->thread_wait(session, id);
+	CS_CLASS (session)->thread_wait (session, id);
 }
 
 /**
@@ -723,7 +742,7 @@
 gboolean
 camel_session_check_junk (CamelSession *session)
 {
-	g_assert(CAMEL_IS_SESSION(session));
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
 
 	return session->check_junk;
 }
@@ -736,9 +755,10 @@
  * Set check_junk flag, if set, incoming mail will be checked for being junk.
  **/
 void
-camel_session_set_check_junk (CamelSession *session, gboolean check_junk)
+camel_session_set_check_junk (CamelSession *session,
+                              gboolean check_junk)
 {
-	g_assert(CAMEL_IS_SESSION(session));
+	g_return_if_fail (CAMEL_IS_SESSION (session));
 
 	session->check_junk = check_junk;
 }
@@ -746,24 +766,30 @@
 gboolean
 camel_session_get_network_state (CamelSession *session)
 {
-	g_return_val_if_fail (CAMEL_IS_SESSION(session), FALSE);
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
 
 	return session->network_state;
 }
 
 void
-camel_session_set_network_state (CamelSession *session, gboolean network_state)
+camel_session_set_network_state (CamelSession *session,
+                                 gboolean network_state)
 {
-	g_return_if_fail (CAMEL_IS_SESSION(session));
+	g_return_if_fail (CAMEL_IS_SESSION (session));
 
 	session->network_state = network_state;
 }
 
 void
-camel_session_set_junk_headers (CamelSession *session, const char **headers, const char **values, int len)
+camel_session_set_junk_headers (CamelSession *session,
+                                const char **headers,
+                                const char **values,
+                                int len)
 {
 	int i;
 
+	g_return_if_fail (CAMEL_IS_SESSION (session));
+
 	if (session->priv->junk_headers) {
 		g_hash_table_remove_all (session->priv->junk_headers);
 		g_hash_table_destroy (session->priv->junk_headers);
@@ -779,5 +805,7 @@
 const GHashTable *
 camel_session_get_junk_headers (CamelSession *session)
 {
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+
 	return session->priv->junk_headers;
 }

Modified: trunk/camel/camel-session.h
==============================================================================
--- trunk/camel/camel-session.h	(original)
+++ trunk/camel/camel-session.h	Wed Apr 30 21:46:42 2008
@@ -103,12 +103,22 @@
 						  CamelException *ex);
 
 	/* mechanism for creating and maintaining multiple threads of control */
-	void *(*thread_msg_new)(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
-	void (*thread_msg_free)(CamelSession *session, CamelSessionThreadMsg *msg);
-	int (*thread_queue)(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
-	void (*thread_wait)(CamelSession *session, int id);
-	void (*thread_status)(CamelSession *session, CamelSessionThreadMsg *msg, const char *text, int pc);
-	gboolean (*lookup_addressbook) (CamelSession *session, const char *name);
+	void *          (*thread_msg_new)    (CamelSession *session,
+					      CamelSessionThreadOps *ops,
+					      unsigned int size);
+	void            (*thread_msg_free)   (CamelSession *session,
+					      CamelSessionThreadMsg *msg);
+	int             (*thread_queue)      (CamelSession *session,
+					      CamelSessionThreadMsg *msg,
+					      int flags);
+	void            (*thread_wait)       (CamelSession *session,
+					      int id);
+	void            (*thread_status)     (CamelSession *session,
+					      CamelSessionThreadMsg *msg,
+					      const char *text,
+					      int pc);
+	gboolean        (*lookup_addressbook)(CamelSession *session,
+					      const char *name);
 } CamelSessionClass;
 
 
@@ -131,9 +141,11 @@
 						     CamelException *ex);
 
 #define camel_session_get_store(session, url_string, ex) \
-	((CamelStore *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_STORE, ex))
+	((CamelStore *) camel_session_get_service_connected \
+	(session, url_string, CAMEL_PROVIDER_STORE, ex))
 #define camel_session_get_transport(session, url_string, ex) \
-	((CamelTransport *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_TRANSPORT, ex))
+	((CamelTransport *) camel_session_get_service_connected \
+	(session, url_string, CAMEL_PROVIDER_TRANSPORT, ex))
 
 char *             camel_session_get_storage_path   (CamelSession *session,
 						     CamelService *service,
@@ -156,7 +168,7 @@
 						     const char *prompt,
 						     gboolean cancel);
 
-char *		   camel_session_build_password_prompt
+char *             camel_session_build_password_prompt
 						    (const char *type,
 						     const char *user,
 						     const char *host);
@@ -169,9 +181,9 @@
 						     const char *type,
 						     CamelException *ex);
 
-gboolean  camel_session_check_junk               (CamelSession *session);
-void      camel_session_set_check_junk           (CamelSession *session,
-						  gboolean      check_junk);
+gboolean           camel_session_check_junk         (CamelSession *session);
+void               camel_session_set_check_junk     (CamelSession *session,
+						     gboolean check_junk);
 
 struct _CamelSessionThreadOps {
 	void (*receive)(CamelSession *session, struct _CamelSessionThreadMsg *m);
@@ -192,15 +204,26 @@
 	/* user fields follow */
 };
 
-void *camel_session_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
-void camel_session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg);
-int camel_session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
-void camel_session_thread_wait(CamelSession *session, int id);
-gboolean camel_session_get_network_state (CamelSession *session);
-void camel_session_set_network_state (CamelSession *session, gboolean network_state);
-const GHashTable * camel_session_get_junk_headers (CamelSession *session);
-void camel_session_set_junk_headers (CamelSession *session, const char **headers, const char **values, int len);
-gboolean camel_session_lookup_addressbook (CamelSession *session, const char *name);
+void *             camel_session_thread_msg_new     (CamelSession *session,
+						     CamelSessionThreadOps *ops,
+						     unsigned int size);
+void               camel_session_thread_msg_free    (CamelSession *session,
+						     CamelSessionThreadMsg *msg);
+int                camel_session_thread_queue       (CamelSession *session,
+						     CamelSessionThreadMsg *msg,
+						     int flags);
+void               camel_session_thread_wait        (CamelSession *session,
+						     int id);
+gboolean           camel_session_get_network_state  (CamelSession *session);
+void               camel_session_set_network_state  (CamelSession *session,
+						     gboolean network_state);
+const GHashTable * camel_session_get_junk_headers   (CamelSession *session);
+void               camel_session_set_junk_headers   (CamelSession *session,
+						     const char **headers,
+						     const char **values,
+						     int len);
+gboolean           camel_session_lookup_addressbook (CamelSession *session,
+						     const char *name);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]