Kaydet (Commit) ac2fffa6 authored tarafından Gürer Özen's avatar Gürer Özen

dökümante et, register/remove/list çalışsın, binding güncelle

üst 5487fe1f
......@@ -65,11 +65,23 @@ class Link:
If there isn't any data waiting at connection, this function
immediately returns None. If there is data, returned value
is a tuple of three items: (command, id, data)
is a tuple of three or four items: (command, id, data, package)
Command is a reply code defined at the start of this class.
ID is the original id value from the request sent to the comard.
Data is the return value in string format.
Last item package is only available in RESULT replies and indicates
which package's script that the reply came from.
Reply code meanings:
RESULT: Operation successful.
FAIL: Called script had a problem while trying to perform operation.
DENIED: You aren't allowed to do that operation.
ERROR: Comar had a problem while trying to perform operation.
RESULT_START: Class is implemented by multiple scripts, and their
result will follow.
RESULT_END: All of the class' scripts run.
NOTIFY: You got a notification event.
"""
fds = select.select([self.sock], [], [], 0)
......@@ -89,7 +101,11 @@ class Link:
raise Error('Connection closed')
else:
data = None
return (cmd, head[1], data)
if cmd == self.RESULT:
t = data.split(' ', 1)
return (cmd, head[1], t[0], t[1])
else:
return (cmd, head[1], data)
def read_cmd(self):
"""Read a reply from comard.
......
......@@ -51,6 +51,7 @@ struct comar_struct {
unsigned char *buffer;
size_t max;
size_t size;
char *pakname;
};
comar_t *
......@@ -204,17 +205,41 @@ comar_read(comar_t *com, int *cmdp, unsigned int *idp, char **strp)
*strp = NULL;
size = get_data_size(head);
if (size) {
buf = malloc(size + 1);
if (size >= com->max) {
if (0 == com->max) {
com->max = size + 1;
} else {
while (com->max < size) com->max *= 2;
}
com->buffer = realloc(com->buffer, com->max);
}
len = 0;
buf = com->buffer;
while (len < size) {
len += recv(com->sock, buf + len, size - len, 0);
}
buf[size] = '\0';
if (*cmdp == COMAR_RESULT) {
char *t;
t = strchr(buf, ' ');
if (t) {
*t = '\0';
com->pakname = buf;
*strp = t + 1;
}
return 1;
}
*strp = buf;
}
return 1;
}
char *
comar_package_name(comar_t *com)
{
return com->pakname;
}
void
comar_disconnect(comar_t *com)
{
......
......@@ -65,6 +65,7 @@ int comar_send_finish(comar_t *com);
int comar_send(comar_t *com, unsigned int id, int cmd, ...);
int comar_wait(comar_t *com, int timeout);
int comar_read(comar_t *com, int *cmdp, unsigned int *idp, char **strp);
char *comar_package_name(comar_t *com);
void comar_disconnect(comar_t *com);
......
......@@ -59,7 +59,10 @@ send_result(int cmd, const char *data, size_t size)
{
ipc_start(cmd, chan, chan_id, 0);
if (CMD_RESULT == cmd) {
ipc_pack_arg(bk_app, strlen(bk_app));
if (bk_app)
ipc_pack_arg(bk_app, strlen(bk_app));
else
ipc_pack_arg("comar", 5);
}
if (data) {
if (size == 0) size = strlen(data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment