[{"id":3225,"web_url":"https://patchwork.libcamera.org/comment/3225/","msgid":"<20191209172558.GB27340@bigcity.dyn.berto.se>","date":"2019-12-09T17:25:58","subject":"Re: [libcamera-devel] [PATCH v3 02/10] libcamera: controls: Parse\n\t'enum' in gen-controls.py","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2019-12-09 17:34:38 +0100, Jacopo Mondi wrote:\n> In preparation to add libcamera Camera properties definitions by re-using\n> the control generation framework, augment the gen_controls.py script to\n> support parsing the 'enum' yaml tag and generate documentation and\n> definition of possible values associated with a Control or a Property\n> and defined through an enumeration of supported values.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/gen-controls.py | 41 +++++++++++++++++++++++++++++++++++\n>  1 file changed, 41 insertions(+)\n> \n> diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py\n> index 940386cc68c8..4a1ee52cdb04 100755\n> --- a/src/libcamera/gen-controls.py\n> +++ b/src/libcamera/gen-controls.py\n> @@ -17,6 +17,10 @@ def snake_case(s):\n>  \n>  \n>  def generate_cpp(controls):\n> +    enum_doc_start_template = string.Template('''/**\n> + * \\enum ${name}Values\\n * Supported ${name} values\\n\\n''')\n> +    enum_doc_value_template = string.Template(''' * \\\\var ${name}Values::${value}\n> +${description}\\n *\\n''')\n>      doc_template = string.Template('''/**\n>   * \\\\var extern const Control<${type}> ${name}\n>  ${description}\n> @@ -42,6 +46,27 @@ ${description}\n>              'id_name': id_name,\n>          }\n>  \n> +        enum_doc = []\n> +        try:\n> +            enum = ctrl['enum']\n> +            enum_doc += enum_doc_start_template.substitute(info)\n> +\n> +            for value in enum:\n> +                enum_description = value['description'].strip('\\n').split('\\n')\n> +                enum_description[0] = '\\\\brief ' + enum_description[0]\n> +                enum_description = '\\n'.join([' * ' + line for line in enum_description])\n> +                value_info = {\n> +                    'name' : name,\n> +                    'value': list(value.keys())[0],\n> +                    'description': enum_description,\n> +                }\n> +                enum_doc += enum_doc_value_template.substitute(value_info)\n> +            enum_doc += \" */\"\n> +            enum_doc = ''.join(enum_doc)\n> +            ctrls_doc.append(enum_doc)\n> +        except KeyError:\n> +            pass\n> +\n>          ctrls_doc.append(doc_template.substitute(info))\n>          ctrls_def.append(def_template.substitute(info))\n>          ctrls_map.append('\\t{ ' + id_name + ', &' + name + ' },')\n> @@ -54,6 +79,8 @@ ${description}\n>  \n>  \n>  def generate_h(controls):\n> +    enum_template_start = string.Template('''enum ${name}Values {''')\n> +    enum_value_template = string.Template('''\\t${name} = ${value},''')\n>      template = string.Template('''extern const Control<${type}> ${name};''')\n>  \n>      ctrls = []\n> @@ -71,6 +98,20 @@ def generate_h(controls):\n>              'type': ctrl['type'],\n>          }\n>  \n> +        try:\n> +            enum = ctrl['enum']\n> +            ctrls.append(enum_template_start.substitute(info))\n> +\n> +            for value in enum:\n> +                value_info = {\n> +                    'name': list(value.keys())[0],\n> +                    'value': value['value'],\n> +                }\n> +                ctrls.append(enum_value_template.substitute(value_info))\n> +            ctrls.append(\"};\")\n> +        except KeyError:\n> +            pass\n> +\n>          ctrls.append(template.substitute(info))\n>          id_value += 1\n>  \n> -- \n> 2.24.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x244.google.com (mail-lj1-x244.google.com\n\t[IPv6:2a00:1450:4864:20::244])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4516860BDB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 Dec 2019 18:26:00 +0100 (CET)","by mail-lj1-x244.google.com with SMTP id u17so16578542lja.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 09 Dec 2019 09:26:00 -0800 (PST)","from localhost (h-93-159.A463.priv.bahnhof.se. [46.59.93.159])\n\tby smtp.gmail.com with ESMTPSA id\n\ty14sm266054ljk.46.2019.12.09.09.25.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 09 Dec 2019 09:25:58 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=60/nxgxMCTNuD9JqRvK5pGXTFChq+BLfNdRg6H6Z/8E=;\n\tb=DOBww5oCkg2LIh6Mam9YVJkmhBjegf5bhJlXsMBtw6Nov//do8hSVUEINsKbD+3Hvb\n\tEtyZHITJ0ERPASi6SfcHnzvp4+69ayWSw/SwQIlkmpHhS+LZUB4ZVbLVwpxyspf/4k/4\n\tRIyrZR6/N6DGLWaAkyO8fTJjxely07xsprw8eBDGe1pXZNPXq1v5I8ZaTJvMtfRtdGSM\n\tDSKGSHs4bnHWh+1wQ5q/gjkjS0weqJiKghLuVD/LVW56u+pIz+wQZ0eKp///ZF5Vm5ll\n\t04lyJf6OmPDAmoer7zLIoQKiT+3SL0TU6F4YQL8DpEeSvYzAx8c02JSYWCIIvf+553xN\n\tu0tw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=60/nxgxMCTNuD9JqRvK5pGXTFChq+BLfNdRg6H6Z/8E=;\n\tb=PuOxF8A6r+9VECZKoHSg3eIMhdC0MaRVEKhfSXM7wKGbKf8ZuI+YXuoEjmvnIEdaSL\n\t6ATNdIOd7TbeNsMti7Is5Mx0Pu+sbq7GdK+1hZgXk+Sn9Kp/GtqqmwRInJqOMkqQzWQL\n\t8JUoxAEuYxmHcmG++CVXwRB8AbG61eur5ABO950islWs3L+6Arbw6dlyVN55KQDvfNcB\n\tXbOLxB4LgKKkvGkftbCWsjP52x6OSWWDzEKSF787K9vX7H3l4sZOm74hY/wk9dGbSByG\n\tXZTaS8fBIHpHjmLSnece/YAuS26YCi5m0JlS9aOlqr8RGis2FD/JAsunoeFsZHzXnT03\n\tiYZg==","X-Gm-Message-State":"APjAAAWSYzPgaY39Px1pSOBszVFIDpfa1EIKBuY3WUwAqYwRDmqHRa9t\n\t9p9Xf3/ZWNkPm1vy8oL+Chnw9A==","X-Google-Smtp-Source":"APXvYqwRqiWYzTxGgEFFWcCpwIhjsROqKrUVw8+HoHzsmCVI+uT8Honja5eLVORN531/1zUOpMnCvg==","X-Received":"by 2002:a05:651c:152:: with SMTP id\n\tc18mr17413734ljd.146.1575912359562; \n\tMon, 09 Dec 2019 09:25:59 -0800 (PST)","Date":"Mon, 9 Dec 2019 18:25:58 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191209172558.GB27340@bigcity.dyn.berto.se>","References":"<20191209163446.32381-1-jacopo@jmondi.org>\n\t<20191209163446.32381-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191209163446.32381-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH v3 02/10] libcamera: controls: Parse\n\t'enum' in gen-controls.py","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 09 Dec 2019 17:26:00 -0000"}}]