Patchwork [RFC] Header file for hglib - Level 0 API

login
register
mail settings
Submitter Iulian Stana
Date July 11, 2013, 7:14 p.m.
Message ID <18aef8a7d291d53a9f02.1373570099@doppler>
Download mbox | patch
Permalink /patch/1832/
State Superseded, archived
Headers show

Comments

Iulian Stana - July 11, 2013, 7:14 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1373564942 -10800
#      Thu Jul 11 20:49:02 2013 +0300
# Node ID 18aef8a7d291d53a9f02b13b71372ea238af3bd9
# Parent  0000000000000000000000000000000000000000
Header file for hglib - Level 0 API

The header file contains the basic functions that will be use in the hglib API.
With those functions, I will have the possibility to establish a connection with
the mercurial command server, and the possibility to exchange messages.

Patch

diff --git a/client.h b/client.h
new file mode 100644
--- /dev/null
+++ b/client.h
@@ -0,0 +1,146 @@ 
+#ifndef _CLIENT_H_
+#define _CLIENT_H_
+#include <stdint.h>
+#include <errno.h>
+
+/*
+ * This structure contains the variables for the header.
+ * The channel will stock a letter that will indicate the type of channel.
+ * The length will stock the size of data that will be send or the maxim data
+ * that can be received by the server.
+ * */
+typedef struct hg_header{
+    char channel;
+    uint32_t length;
+} hg_header;
+
+/*
+ * This structure will be use the handle the connection with the server.
+ * He contains 2 pipes for the biderectional connection.
+ * The childpid, the pid of the process that will open the connection
+ * The header that will contain the current action-header. 
+ */
+typedef struct hg_handle{
+    int wpipe[2];
+    int rpipe[2];
+    pid_t childpid;
+    hg_header header;
+} hg_handle;
+
+
+/*
+ * Open the connection with the mecudial command server.
+ * The handle structure will be allocated.
+ * \param path The path to the repository wherewith I want to create a connection
+ *        NULL argument means the repository in which I am
+ * \param encoding Will set HGENCODING to the given encoding
+ *        NULL argument means the default encoding
+ * \return A handle for this connection. 
+ *        NULL to indicate an error, with errno set appropriately.
+ * errno can be :
+ *      ECONNREFUSED
+ *      EPIPE
+ *      EFAULT - for a bad path address
+ *      EINVAL - for a bad encoding
+ *      ENOEXEC
+ * */
+hg_handle *hg_open(const char *path, char *encoding);
+
+/*
+ * Close the connection for the given handle.
+ * Erase the handle and free the memory
+ * \param handle The handle of the connection that I want to close
+ * \return   0 if successful
+ *          -1 to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ * */
+int hg_close(hg_handle *handle);
+
+/*
+ * Sending a command to the mercurial command server, through the given handle.
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param command The command that will be send to command server
+ *          It's a string that can contain a simple command "log" or a command
+ *          with spaces "log -r 1"
+ * \return   0 if successful
+ *          -1 to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ *      EIO
+ *      ECOMM
+ * */
+int hg_rawcommand(hg_handle *handle, const char *command);
+
+/*
+ * Reading some unparse data from the server. Will read just a 'line', the 
+ * header that is received from server and the data that comes after the header
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param buffer It will be a string where the data will be stock. The string
+ *              must have a size of 4096, for a good working.
+ * \param sizebuff Here will be pass the size of the buffer.
+ * \return   0 if successful
+ *          -1 to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ *      EIO
+ *      ECOMM
+ * */
+int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff);
+
+/*
+ * Will write the buffer to server for the connection establish by the handle.
+ * This function will be used when one of the input channels will be received 
+ * from the command server. ('I' or 'L' channels)
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param buffer The buffer that will be send to the command server
+ * \return   0 if successful
+ *          -1 to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ *      EIO
+ *      ECOMM
+ * */
+int hg_rawwrite(hg_handle *handle, const char *buffer);
+
+/*
+ * Before you read or write data, you will want to know for what kind of data is 
+ * server waiting, an input data or an output data.
+ * This function will return the current channel for the connection established
+ * by the handle.
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \return   0 if successful
+ *          -1 to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ *      EIO
+ *      ECOMM
+ * */
+char hg_channel(hg_handle *handle);
+
+/*
+ * Sometimes, the user needs the entire header. This is a way to do that.
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \return  The hader stucture for the given handle.
+ *          NULL to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ * */
+hg_header hg_channel(hg_handle *handle);
+
+/*
+ * The server tell use that he finished his action when the 'r' channel is send.
+ * This function will get the exitcode from the server, in as a measure to tell
+ * that the command was finished.
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \return   0 if successful
+ *          -1 to indicate an error, with errno set appropriately.
+ * errno can be:
+ *      EINVAL
+ *      EIO
+ *      ECOMM
+ * */
+int hg_exitcode(hg_handle *handle);
+
+#endif
+