Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Basic communication between core and ui working

  • Loading branch information...
commit 32e98815fef22b1c1a91c52d85c7a90c903e7124 1 parent fd00ad5
@Detegr authored
View
6 core/core.c
@@ -448,7 +448,11 @@ int core_start(void)
{
pipe_accept();
struct Event* e=poll_event();
- if(e) event_free(e);
+ if(e)
+ {
+ printf("Message from pipe client: %s\n", e->data);
+ event_free(e);
+ }
}
printf("Tapi2p core shutting down...\n");
View
24 core/event.c
@@ -2,10 +2,13 @@
#include <stdlib.h>
#include <string.h>
-void event_init(struct Event* evt, EventType t)
+void event_init(struct Event* evt, EventType t, const char* data)
{
evt->m_type=t;
- evt->data=NULL;
+ if(data)
+ {
+ event_set(evt, data);
+ } else evt->data=NULL;
evt->next=NULL;
}
@@ -25,7 +28,7 @@ struct Event* new_event_fromstr(const char* str)
return NULL;
}
-const char* event_str(struct Event* evt)
+const char* eventtype_str(struct Event* evt)
{
return eventtypes[evt->m_type];
}
@@ -42,3 +45,18 @@ void event_free(struct Event* evt)
if(evt->next) event_free(evt->next);
free(evt);
}
+
+void event_free_s(struct Event* evt)
+{
+ if(evt->data) free(evt->data);
+ if(evt->next) event_free(evt->next);
+}
+
+int event_send(struct Event* evt, int fd)
+{
+ char buf[EVENT_MAX];
+ memset(buf, 0, EVENT_MAX);
+ stpncpy(stpncpy(buf, eventtype_str(evt), EVENT_LEN), evt->data, strnlen(evt->data, EVENT_MAX-EVENT_LEN));
+ if(send(fd, buf, strnlen(buf, EVENT_MAX), 0) < 0) return -1;
+ return 0;
+}
View
7 core/event.h
@@ -18,10 +18,13 @@ struct Event
struct Event* next;
};
-void event_init(struct Event* evt, EventType t);
+void event_init(struct Event* evt, EventType t, const char* data);
struct Event* new_event_fromstr(const char* str);
int event_set(struct Event* evt, const char* data);
+int event_send(struct Event* evt, int fd);
void event_free(struct Event* evt);
-const char* event_str(struct Event* evt);
+void event_free_s(struct Event* evt); // Frees event that is allocated from stack
+
+const char* eventtype_str(struct Event* evt);
#endif
View
2  core/pipemanager.c
@@ -122,6 +122,7 @@ int send_event(struct Event* e)
if(s<0)
{
perror("Send");
+ return -1;
}
#ifndef NDEBUG
else
@@ -133,4 +134,5 @@ int send_event(struct Event* e)
}
}
}
+ return 0;
}
View
7 ui/cli/cli.c
@@ -8,6 +8,7 @@
#include <sys/un.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <event.h>
int core_socket()
{
@@ -32,9 +33,11 @@ int core_socket()
int main()
{
- printf("Opening %s\n", socketpath());
int fd=core_socket();
- printf("%d\n", fd);
+ struct Event e;
+ event_init(&e, Message, "foobar");
+ event_send(&e, fd);
+ event_free_s(&e);
close(fd);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.