commit d6f534c69d148582e0bea8be79ae48c0d75475a6
parent 77cd4006050649876ed8f8c414ad89eecb374935
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Sun, 20 Mar 2016 10:46:43 -0600
viewer: rename text to runtime_client
Diffstat:
6 files changed, 107 insertions(+), 93 deletions(-)
diff --git a/viewer/Makefile b/viewer/Makefile
@@ -1,7 +1,7 @@
PROG = scv_viewer
SRCS = viewer.cxx \
- text.cxx \
+ runtime_client.cxx \
af_unix.cxx \
demo-atlas.cxx \
demo-buffer.cxx \
diff --git a/viewer/runtime_client.cxx b/viewer/runtime_client.cxx
@@ -0,0 +1,66 @@
+#include <err.h>
+
+#include <cassert>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <vector>
+
+#include "default-text.h"
+#include "runtime_client.h"
+
+RuntimeClient::RuntimeClient(af_unix *sock, demo_buffer_t *buf, demo_font_t *f) :
+ socket(sock),
+ buffer(buf),
+ font(f)
+{
+ assert(socket->read_all(num_tus) == 8);
+
+ for (int i = 0; i < num_tus; i++) {
+ uint64_t file_name_sz;
+ assert(socket->read_all(file_name_sz) == 8);
+
+ file_name.resize(file_name_sz);
+ assert(socket->read_all((uint8_t *)&file_name[0], file_name_sz) == file_name_sz);
+
+ read_file();
+
+ assert(socket->read_all(num_lines) == 8);
+ execution_counts.resize(num_lines);
+ }
+
+ glyphy_point_t top_left = { 0, 0 };
+ demo_buffer_move_to(buffer, &top_left);
+ demo_buffer_add_text(buffer, default_text, font, 1);
+}
+
+void
+RuntimeClient::read_file()
+{
+ std::string line;
+ std::ifstream file_stream(file_name);
+
+ if (file_stream.is_open() == 0)
+ errx(1, "ifstream.open()");
+
+ while (std::getline(file_stream, line))
+ source_file_contents.push_back(line);
+
+ file_stream.close();
+}
+
+void
+RuntimeClient::draw()
+{
+}
+
+void
+RuntimeClient::idle()
+{
+ size_t bytes_total = num_lines * sizeof(uint64_t);
+ assert(socket->read_all((uint8_t *)&execution_counts[0], bytes_total) == bytes_total);
+
+ // Send response back
+ uint8_t msg_type = 1;
+ assert(socket->write_all(&msg_type, 1) == 1);
+}
diff --git a/viewer/runtime_client.h b/viewer/runtime_client.h
@@ -0,0 +1,34 @@
+#ifndef TEXT_H
+#define TEXT_H
+
+#include <string>
+#include <vector>
+
+#include "af_unix.h"
+#include "draw.h"
+
+#include "demo-buffer.h"
+#include "demo-font.h"
+
+class RuntimeClient : public drawable {
+public:
+ RuntimeClient(af_unix *, demo_buffer_t *, demo_font_t *);
+
+ void draw();
+ void idle();
+private:
+ void read_file();
+
+ af_unix *socket;
+ demo_buffer_t *buffer;
+ demo_font_t *font;
+
+ uint64_t num_tus;
+ std::string file_name;
+ uint64_t num_lines;
+
+ std::vector<std::string> source_file_contents;
+ std::vector<uint64_t> execution_counts;
+};
+
+#endif
diff --git a/viewer/text.cxx b/viewer/text.cxx
@@ -1,59 +0,0 @@
-#include <err.h>
-
-#include <cassert>
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <vector>
-
-#include "text.h"
-
-text::text(af_unix *sock) :
- socket(sock)
-{
- assert(socket->read_all(num_tus) == 8);
-
- for (int i = 0; i < num_tus; i++) {
- uint64_t file_name_sz;
- assert(socket->read_all(file_name_sz) == 8);
-
- file_name.resize(file_name_sz);
- assert(socket->read_all((uint8_t *)&file_name[0], file_name_sz) == file_name_sz);
-
- read_file();
-
- assert(socket->read_all(num_lines) == 8);
- execution_counts.resize(num_lines);
- }
-}
-
-void
-text::read_file()
-{
- std::string line;
- std::ifstream file_stream(file_name);
-
- if (file_stream.is_open() == 0)
- errx(1, "ifstream.open()");
-
- while (std::getline(file_stream, line))
- source_file_contents.push_back(line);
-
- file_stream.close();
-}
-
-void
-text::draw()
-{
-}
-
-void
-text::idle()
-{
- size_t bytes_total = num_lines * sizeof(uint64_t);
- assert(socket->read_all((uint8_t *)&execution_counts[0], bytes_total) == bytes_total);
-
- // Send response back
- uint8_t msg_type = 1;
- assert(socket->write_all(&msg_type, 1) == 1);
-}
diff --git a/viewer/text.h b/viewer/text.h
@@ -1,28 +0,0 @@
-#ifndef TEXT_H
-#define TEXT_H
-
-#include <vector>
-
-#include "af_unix.h"
-#include "draw.h"
-
-class text : public drawable {
-public:
- text(af_unix *);
-
- void draw();
- void idle();
-private:
- void read_file();
-
- af_unix *socket;
-
- uint64_t num_tus;
- std::string file_name;
- uint64_t num_lines;
-
- std::vector<std::string> source_file_contents;
- std::vector<uint64_t> execution_counts;
-};
-
-#endif
diff --git a/viewer/viewer.cxx b/viewer/viewer.cxx
@@ -4,7 +4,7 @@
#include <vector>
#include "af_unix.h"
-#include "text.h"
+#include "runtime_client.h"
#include "default-text.h"
#include "demo-buffer.h"
@@ -13,7 +13,8 @@
demo_glstate_t *st;
demo_view_t *vu;
-demo_buffer_t *buffer;
+static demo_buffer_t *buffer;
+static demo_font_t *font;
class window {
public:
@@ -34,7 +35,6 @@ private:
};
-// fuckin c++
std::vector<drawable*> window::drawables;
af_unix window::socket;
@@ -67,9 +67,10 @@ window::window(int argc, char *argv[])
FT_Face ft_face = NULL;
FT_New_Face(ft_library, "DejaVuSansMono.ttf", /* face_index */ 0, &ft_face);
- demo_font_t *font = demo_font_create(ft_face, demo_glstate_get_atlas(st));
+ font = demo_font_create(ft_face, demo_glstate_get_atlas(st));
buffer = demo_buffer_create();
+
glyphy_point_t top_left = { 0, 0 };
demo_buffer_move_to(buffer, &top_left);
demo_buffer_add_text(buffer, default_text, font, 1);
@@ -129,7 +130,7 @@ window::idle(void)
{
af_unix *temp_socket = socket.accept();
if (temp_socket)
- drawables.push_back(new text(temp_socket));
+ drawables.push_back(new RuntimeClient(temp_socket, buffer, font));
for (auto &i : drawables)
i->idle();