]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added contract merge operation
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 16 Apr 2009 05:46:22 +0000 (07:46 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 23 Apr 2009 11:20:09 +0000 (13:20 +0200)
fres/contract/fres_container.c
fres/contract/fres_container.h
fres/contract/fres_contract.h

index daf8f8d7da5638b44f8bff2edba1b0ab48e9ba14..14a202e35daf0dcca3c1c2b08ba430d4f230f233 100644 (file)
@@ -645,3 +645,33 @@ fres_container_get_num_blocks(const struct fres_container *c)
        }
        return num;
 }
+
+/** 
+ * Merges two block containers. Blocks present @a src and missing in
+ * @a dest are duplicated in @a dest.
+ * 
+ * @param dest Destination of merge operation
+ * @param src Source of merge operation
+ * 
+ * @return Zero on success, non-zero error core on error.
+ */
+int fres_container_merge(struct fres_container *dest,
+                        const struct fres_container *src)
+{
+       enum fres_block_type type;
+       int ret;
+       
+       for (type=0; type<FRES_NUM_BLOCKS; type++) {
+               const struct fres_block *sb = &src->blocks[type];
+               struct fres_block *db = &dest->blocks[type];
+               
+               if (sb->state != FRES_BLOCK_EMPTY &&
+                   db->state == FRES_BLOCK_EMPTY) {
+                       ret = fres_block_duplicate(db, sb, type);
+                       if (ret) {
+                               return ret;
+                       }
+               }
+       }
+       return 0;
+}
index 7308b0cac2cfd5a2ffbe2ba5495c23d84f0275e6..228e266b6609bc54fd71d9dbb2082b4dde5b3720 100644 (file)
@@ -181,6 +181,9 @@ fres_container_to_string(char *dest, size_t size, const struct fres_container *c
 int
 fres_container_get_num_blocks(const struct fres_container *c);
 
+int fres_container_merge(struct fres_container *dest,
+                        const struct fres_container *src);
+
 #ifdef __cplusplus
 } /* extern "C"*/
 #endif
index 79607fae25f1dad8f4d3949e9ed9a6297682486b..897e05bb185a5d04dff605321adc51f91424ad74 100644 (file)
@@ -161,6 +161,14 @@ fres_contract_get_num_blocks(const struct fres_contract *c)
        return fres_container_get_num_blocks(c->container);
 }
 
+static inline int
+fres_contract_merge(struct fres_contract *dest,
+                    const struct fres_contract *src)
+{
+       return fres_container_merge(dest->container, src->container);
+}
+
+
 /**
  * Macro which defines type-safe contract "accessor" functions for
  * various blocks.