From owner-svn-soc-all@FreeBSD.ORG Wed May 28 17:03:33 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 44DA986D for ; Wed, 28 May 2014 17:03:33 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 311D82CF9 for ; Wed, 28 May 2014 17:03:33 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4SH3XbB019547 for ; Wed, 28 May 2014 17:03:33 GMT (envelope-from zkorchev@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s4SH3WpF019388 for svn-soc-all@FreeBSD.org; Wed, 28 May 2014 17:03:32 GMT (envelope-from zkorchev@FreeBSD.org) Date: Wed, 28 May 2014 17:03:32 GMT Message-Id: <201405281703.s4SH3WpF019388@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to zkorchev@FreeBSD.org using -f From: zkorchev@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r268779 - soc2014/zkorchev/freebsd_head/usr.bin/vmstat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2014 17:03:33 -0000 Author: zkorchev Date: Wed May 28 17:03:32 2014 New Revision: 268779 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268779 Log: Added several features to SOL Added: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h Added: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c Wed May 28 17:03:32 2014 (r268779) @@ -0,0 +1,158 @@ +/*- + * Copyright (c) 2014 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include "sol.h" + +//static struct sol_stream sol; + +// TODO error checks + +int sol_init(struct sol_stream *restrict stream, enum sol_format format) +{ + stream->f = format; + stream->ctx.g = yajl_gen_alloc(0); + + //sol.f = format; + //sol.ctx.g = yajl_gen_alloc(0); + + return 0; +} + +void sol_term(struct sol_stream *restrict stream) +{ + const char *buffer; + size_t length; + + switch (stream->f) + { + case SOL_JSON: + yajl_gen_get_buf(stream->ctx.g, (const unsigned char **)&buffer, &length); + write(1, buffer, length); + write(1, "\n", 1); // TODO change this + yajl_gen_clear(stream->ctx.g); + break; + } + + yajl_gen_free(stream->ctx.g); + + /*switch (sol.f) + { + case SOL_JSON: + yajl_gen_get_buf(sol.ctx.g, (const unsigned char **)&buffer, &length); + write(1, buffer, length); + write(1, "\n", 1); // TODO change this + yajl_gen_clear(sol.ctx.g); + break; + } + + yajl_gen_free(sol.ctx.g);*/ +} + +int sol_array_start(struct sol_stream *restrict stream) +{ + yajl_gen_array_open(stream->ctx.g); + + return 0; +} + +int sol_array_end(struct sol_stream *restrict stream) +{ + yajl_gen_array_close(stream->ctx.g); + + return 0; +} + +int sol_string(struct sol_stream *restrict stream, const char *data, size_t length) +{ + // TODO ?handle special characters + yajl_gen_string(stream->ctx.g, (const unsigned char *)data, length); + + return 0; +} + +int sol_integer(struct sol_stream *restrict stream, long long value) +{ + yajl_gen_integer(stream->ctx.g, value); + + return 0; +} + +int sol_map_start(struct sol_stream *restrict stream) +{ + yajl_gen_map_open(stream->ctx.g); + + return 0; +} + +int sol_map_end(struct sol_stream *restrict stream) +{ + yajl_gen_map_close(stream->ctx.g); + + return 0; +} + +int sol_map_key(struct sol_stream *restrict stream, const char *key, size_t length) +{ + // TODO error if value is expected + + // TODO ?handle special characters + yajl_gen_string(stream->ctx.g, (const unsigned char *)key, length); + + return 0; +} + +int sol_map_string(struct sol_stream *restrict stream, const char *value, size_t length) +{ + // TODO error if key is expected? + + // TODO ?handle special characters + yajl_gen_string(stream->ctx.g, (const unsigned char *)value, length); + + return 0; +} + +int sol_map_integer(struct sol_stream *restrict stream, long long value) +{ + // TODO error if key is expected? + + yajl_gen_integer(stream->ctx.g, value); + + return 0; +} + +int sol_map_float(struct sol_stream *restrict stream, double value) +{ + // TODO error if key is expected? + + // TODO round mantissa? + yajl_gen_double(stream->ctx.g, value); + + return 0; +} Added: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h Wed May 28 17:03:32 2014 (r268779) @@ -0,0 +1,32 @@ +#include // libyajl + +enum sol_format +{ + SOL_JSON = 1, +}; + +struct sol_stream +{ + enum sol_format f; + union + { + yajl_gen g; + } ctx; +}; + +int sol_init(struct sol_stream *restrict stream, enum sol_format format); +void sol_term(struct sol_stream *restrict stream); + +int sol_array_start(struct sol_stream *restrict stream); +int sol_array_end(struct sol_stream *restrict stream); + +int sol_integer(struct sol_stream *restrict stream, long long value); +int sol_string(struct sol_stream *restrict stream, const char *data, size_t length); + +int sol_map_start(struct sol_stream *restrict stream); +int sol_map_end(struct sol_stream *restrict stream); + +int sol_map_key(struct sol_stream *restrict stream, const char *key, size_t length); +int sol_map_string(struct sol_stream *restrict stream, const char *value, size_t length); +int sol_map_integer(struct sol_stream *restrict stream, long long value); +int sol_map_float(struct sol_stream *restrict stream, double value);