Permalink
Browse files

A bit of code cleanup, more comments here and there.

Major change, collabclient.c is now always built, but the body
of the functions are #ifdef guarded. This way code through the rest
of fontforge can call the collabclient_foo() functions without needing
any #ifdef guards. They simply do nothing when the zeromq + collab code
is not built.
  • Loading branch information...
1 parent 57689f5 commit e7626badf89579f0509e160d297ab36657a0a99a @monkeyiq monkeyiq committed Mar 5, 2013
View
@@ -179,15 +179,15 @@ void u_strncat(unichar_t *to, const unichar_t *from, int len) {
}
-int u_strlen(register const unichar_t *str) {
+int u_strlen(register const unichar_t *str) {
register int len = 0;
while ( *str++!='\0' )
++len;
return( len );
}
-int c_strlen(const char * p )
+int c_strlen( const char * p )
{
if(!p)
return 0;
@@ -967,7 +967,7 @@ int u_endswith(const unichar_t *haystack,const unichar_t *needle) {
return p == ( haystack + haylen - nedlen );
}
-char* c_itostr( int v )
+char* c_itostr( int v )
{
static char ret[100+1];
snprintf(ret,100,"%d",v );
View
@@ -187,23 +187,17 @@ kvmsg_destroy (kvmsg_t **self_p)
kvmsg_t *
kvmsg_recv_full (void *socket, int sockopts )
{
- // This method is almost unchanged from kvsimple
- // .skip
assert (socket);
kvmsg_t *self = kvmsg_new (0);
-// printf("kvmsg_recv_full() top...\n");
-
// Read all frames off the wire, reject if bogus
int frame_nbr;
for (frame_nbr = 0; frame_nbr < KVMSG_FRAMES; frame_nbr++) {
-// printf("kvmsg_recv_full() frame_nbr:%d\n", frame_nbr );
if (self->present [frame_nbr])
zmq_msg_close (&self->frame [frame_nbr]);
zmq_msg_init (&self->frame [frame_nbr]);
self->present [frame_nbr] = 1;
if (zmq_msg_recv (&self->frame [frame_nbr], socket, sockopts ) == -1) {
-// printf("kvmsg_recv_full() can't get more\n");
kvmsg_destroy (&self);
break;
}
@@ -214,10 +208,8 @@ kvmsg_recv_full (void *socket, int sockopts )
break;
}
}
- // .until
if (self)
s_decode_props (self);
-// printf("kvmsg_recv_full() bottom...\n");
return self;
}
@@ -592,79 +584,6 @@ kvmsg_dump (kvmsg_t *self)
else
fprintf (stderr, "NULL message\n");
}
-// .until
-
-// .split test method
-// The selftest method is the same as in kvsimple with added support
-// for the uuid and property features of kvmsg:
-
-int
-kvmsg_test (int verbose)
-{
- // .skip
- kvmsg_t
- *kvmsg;
-
- printf (" * kvmsg: ");
-
- // Prepare our context and sockets
- zctx_t *ctx = zctx_new ();
- void *output = zsocket_new (ctx, ZMQ_DEALER);
- int rc = zmq_bind (output, "ipc://kvmsg_selftest.ipc");
- assert (rc == 0);
- void *input = zsocket_new (ctx, ZMQ_DEALER);
- rc = zmq_connect (input, "ipc://kvmsg_selftest.ipc");
- assert (rc == 0);
-
- zhash_t *kvmap = zhash_new ();
-
- // .until
- // Test send and receive of simple message
- kvmsg = kvmsg_new (1);
- kvmsg_set_key (kvmsg, "key");
- kvmsg_set_uuid (kvmsg);
- kvmsg_set_body (kvmsg, (byte *) "body", 4);
- if (verbose)
- kvmsg_dump (kvmsg);
- kvmsg_send (kvmsg, output);
- kvmsg_store (&kvmsg, kvmap);
-
- kvmsg = kvmsg_recv (input);
- if (verbose)
- kvmsg_dump (kvmsg);
- assert (streq (kvmsg_key (kvmsg), "key"));
- kvmsg_store (&kvmsg, kvmap);
-
- // Test send and receive of message with properties
- kvmsg = kvmsg_new (2);
- kvmsg_set_prop (kvmsg, "prop1", "value1");
- kvmsg_set_prop (kvmsg, "prop2", "value1");
- kvmsg_set_prop (kvmsg, "prop2", "value2");
- kvmsg_set_key (kvmsg, "key");
- kvmsg_set_uuid (kvmsg);
- kvmsg_set_body (kvmsg, (byte *) "body", 4);
- assert (streq (kvmsg_get_prop (kvmsg, "prop2"), "value2"));
- if (verbose)
- kvmsg_dump (kvmsg);
- kvmsg_send (kvmsg, output);
- kvmsg_destroy (&kvmsg);
-
- kvmsg = kvmsg_recv (input);
- if (verbose)
- kvmsg_dump (kvmsg);
- assert (streq (kvmsg_key (kvmsg), "key"));
- assert (streq (kvmsg_get_prop (kvmsg, "prop2"), "value2"));
- kvmsg_destroy (&kvmsg);
- // .skip
- // Shutdown and destroy all objects
- zhash_destroy (&kvmap);
- zctx_destroy (&ctx);
-
- printf ("OK\n");
- return 0;
-}
-// .until
-
struct kvmap_visit_buildq_foreach_data
{
View
@@ -1,6 +1,52 @@
-/* =====================================================================
- * kvmsg - key-value message class for example applications
- * ===================================================================== */
+/******************************************************************************
+*******************************************************************************
+*******************************************************************************
+
+ Copyright (C) 2013 Ben Martin
+
+ This file is part of FontForge.
+
+ FontForge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ FontForge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with FontForge. If not, see <http://www.gnu.org/licenses/>.
+
+ For more details see the COPYING.gplv3 file in the root directory of this
+ distribution.
+
+ Based on example code in the zguide:
+
+Copyright (c) 2010-2011 iMatix Corporation and Contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+*******************************************************************************
+*******************************************************************************
+******************************************************************************/
#ifndef __KVMSG_H_INCLUDED__
#define __KVMSG_H_INCLUDED__
@@ -14,79 +60,99 @@ typedef struct _kvmsg kvmsg_t;
extern "C" {
#endif
-// Constructor, sets sequence as provided
-kvmsg_t * kvmsg_new (int64_t sequence);
+ enum { socket_offset_snapshot = 0,
+ socket_offset_subscriber,
+ socket_offset_publisher,
+ socket_offset_ping
+ };
+
+ enum { socket_srv_offset_snapshot = socket_offset_snapshot,
+ socket_srv_offset_publisher = socket_offset_subscriber,
+ socket_srv_offset_collector = socket_offset_publisher,
+ socket_srv_offset_ping = socket_offset_ping
+ };
+
+ // Constructor, sets sequence as provided
+ kvmsg_t * kvmsg_new (int64_t sequence);
-// Destructor
-void kvmsg_destroy (kvmsg_t **self_p);
+ // Destructor
+ void kvmsg_destroy (kvmsg_t **self_p);
-// Create duplicate of kvmsg
-kvmsg_t * kvmsg_dup (kvmsg_t *self);
+ // Create duplicate of kvmsg
+ kvmsg_t * kvmsg_dup (kvmsg_t *self);
-// Reads key-value message from socket, returns new kvmsg instance.
-kvmsg_t * kvmsg_recv (void *socket);
+ // Reads key-value message from socket, returns new kvmsg instance.
+ kvmsg_t * kvmsg_recv (void *socket);
-kvmsg_t * kvmsg_recv_full (void *socket, int sockopts );
+ kvmsg_t * kvmsg_recv_full (void *socket, int sockopts );
-// Send key-value message to socket; any empty frames are sent as such.
-void kvmsg_send (kvmsg_t *self, void *socket);
+ // Send key-value message to socket; any empty frames are sent as such.
+ void kvmsg_send (kvmsg_t *self, void *socket);
-// Return key from last read message, if any, else NULL
-char * kvmsg_key (kvmsg_t *self);
+ // Return key from last read message, if any, else NULL
+ char * kvmsg_key (kvmsg_t *self);
-// Return sequence nbr from last read message, if any
-int64_t kvmsg_sequence (kvmsg_t *self);
+ // Return sequence nbr from last read message, if any
+ int64_t kvmsg_sequence (kvmsg_t *self);
-// Return UUID from last read message, if any, else NULL
-byte * kvmsg_uuid (kvmsg_t *self);
+ // Return UUID from last read message, if any, else NULL
+ byte * kvmsg_uuid (kvmsg_t *self);
-// Return body from last read message, if any, else NULL
-byte * kvmsg_body (kvmsg_t *self);
+ // Return body from last read message, if any, else NULL
+ byte * kvmsg_body (kvmsg_t *self);
-// Return body size from last read message, if any, else zero
-size_t kvmsg_size (kvmsg_t *self);
+ // Return body size from last read message, if any, else zero
+ size_t kvmsg_size (kvmsg_t *self);
-// Set message key as provided
-void kvmsg_set_key (kvmsg_t *self, char *key);
+ // Set message key as provided
+ void kvmsg_set_key (kvmsg_t *self, char *key);
-// Set message sequence number
-void kvmsg_set_sequence (kvmsg_t *self, int64_t sequence);
+ // Set message sequence number
+ void kvmsg_set_sequence (kvmsg_t *self, int64_t sequence);
-// Set message UUID to generated value
-void kvmsg_set_uuid (kvmsg_t *self);
+ // Set message UUID to generated value
+ void kvmsg_set_uuid (kvmsg_t *self);
-// Set message body
-void kvmsg_set_body (kvmsg_t *self, byte *body, size_t size);
+ // Set message body
+ void kvmsg_set_body (kvmsg_t *self, byte *body, size_t size);
-// Set message key using printf format
-void kvmsg_fmt_key (kvmsg_t *self, char *format, ...);
+ // Set message key using printf format
+ void kvmsg_fmt_key (kvmsg_t *self, char *format, ...);
-// Set message body using printf format
-void kvmsg_fmt_body (kvmsg_t *self, char *format, ...);
+ // Set message body using printf format
+ void kvmsg_fmt_body (kvmsg_t *self, char *format, ...);
-// Get message property, if set, else ""
-char * kvmsg_get_prop (kvmsg_t *self, char *name);
+ // Get message property, if set, else ""
+ char * kvmsg_get_prop (kvmsg_t *self, char *name);
-// Set message property
-// Names cannot contain '='. Max length of value is 255 chars.
-void kvmsg_set_prop (kvmsg_t *self, char *name, char *format, ...);
+ // Set message property
+ // Names cannot contain '='. Max length of value is 255 chars.
+ void kvmsg_set_prop (kvmsg_t *self, char *name, char *format, ...);
-// Store entire kvmsg into hash map, if key/value are set
-// Nullifies kvmsg reference, and destroys automatically when no longer
-// needed.
-void kvmsg_store (kvmsg_t **self_p, zhash_t *hash);
+ // Store entire kvmsg into hash map, if key/value are set
+ // Nullifies kvmsg reference, and destroys automatically when no longer
+ // needed.
+ void kvmsg_store (kvmsg_t **self_p, zhash_t *hash);
-// Dump message to stderr, for debugging and tracing
-void kvmsg_dump (kvmsg_t *self);
+ // Dump message to stderr, for debugging and tracing
+ void kvmsg_dump (kvmsg_t *self);
-// Runs self test of class
-int kvmsg_test (int verbose);
+ // Runs self test of class
+ int kvmsg_test (int verbose);
-void kvmsg_free (void *ptr);
+ void kvmsg_free (void *ptr);
typedef int (kvmsg_visit_fn) (kvmsg_t* msg, void *argument);
+ /**
+ * Visit all entries in the kvmap with a sequence number
+ * greater than minsequence in the natural integer ordering
+ * of sequence numbers, ie: 5,6,7,8...n
+ *
+ * Each msg is passed to your callback function along with a
+ * given argument that you supply.
+ */
void kvmap_visit( zhash_t* kvmap, int64_t minsequence,
kvmsg_visit_fn* callback, void *argument );
View
@@ -96,9 +96,6 @@ fontforge_LDFLAGS = $(MY_CFLAGS) $(MY_LIBS) -export-dynamic
endif THE_PROGRAMS
-if LIBZMQ
-ZMQSRCS = collabclient.c collabclient.h
-endif
#--------------------------------------------------------------------------
libfontforge_la_SOURCES = asmfpst.c autohint.c autosave.c autotrace.c \
@@ -119,7 +116,7 @@ libfontforge_la_SOURCES = asmfpst.c autohint.c autosave.c autotrace.c \
ttfspecial.c ufo.c unicoderange.c utils.c winfonts.c zapfnomen.c \
groups.c langfreq.c ftdelta.c autowidth2.c woff.c stamp.c \
activeinui.c pluginloading.c is_LIGATURE.c flaglist.c strlist.c \
- $(ZMQSRCS)
+ collabclient.c collabclient.h
nodist_libfontforge_la_SOURCES = libstamp.c
EXTRA_libfontforge_la_SOURCES = splinerefigure.c
Oops, something went wrong.

0 comments on commit e7626ba

Please sign in to comment.